Golang Beego implementing and using CAPTCHA

19 January, 2017

In this small tutorial I'll show you how to use CAPTCHA validation inside your application. We won't be using the builtin CAPTCHA of Beego but instead use another package of GitHub user dchest, and his package captcha.

Golang Beego how to use sessions

18 January, 2017

The official documentation on using sessions in Beego is besides being outdated quite unclear. I'll show you how to use sessions inside your Beego application.

Golang Beego use models in your controllers

03 January, 2017

This post is meant to guide you on how to use models inside your controllers, not using the ORM way. Meaning you can implement your own reusable functions, another way of handeling your queries and even better, choose another database besides MySQL, Sqlite, PostgreSQL which ORM only supports.

Golang string to int

02 January, 2017

The built in 'strconv' package contains a function named 'Atoi' (ASCII to integer). Which is just a wrapper for the 'ParseInt' function.

Golang Beego automatically load templates

31 December, 2016

In this small post on how to automatically load a template so you don't have to 'include' your header and footer for every controller.

Golang transmit files over a net/http server to clients

25 July, 2016

In this example I'll show you how to send a file from a net/http listener to a client. 

Golang creating a worker thread pool using maps

24 July, 2016

This example will show you how to create a worker thread that waits for jobs and working them one by one. We use maps to create a list where we add jobs too. This tutorial will process strings and create bcrypt hashes of it, for simulating purposes.

Golang mgo append to a nested array in a document

24 May, 2016

Small tutorial on how to add/push/append a new element to an array/list inside a document, based on my previous post.

Golang mgo retrieve nested structured arrays

24 May, 2016

Small tutorial on how to retrieve nested arrays/lists from a 'mgo.Find()' result.

Golang transfer a file over a TCP socket

21 May, 2016

In this tutorial I'll demonstrate how to send a file in Go over a TCP connection using a server that sends the file and a client that receives it, I'll try to go into detail as much as possible.

You can download the source code here.

Comments and remarks are more than welcome.

Golang mgo create objectid from a hexadecimal string example

19 May, 2016

Storing a string that holds the hexadecimal string of a objectID is done by using the bson package with function 'objectIdHex()'.

Golang mgo findAndModify auto increment id tutorial

17 May, 2016

Here is a brief explanation for the 'findAndModify()' equivalent for mgo. Instead of 'findAndModify()' we will use 'mgo.Find().Apply()'. I will demonstrate how to use auto incremented ids instead of random unique generated IDs for documents, since mongdb does not have a native way of doing this (because MongoDB is not a relational database).

It work's like this, we create a collection, insert a document in that collection that contains the last generated ID. Every time we call 'findAndModify()', mongoDB will increment the value and we get that new value back, which you should use to insert a new document with.

Golang byte to int example

10 May, 2016

In Golang there isn't a native function to convert a character number (!= int number) to int.

An int in bytes is the normal sequence of 0-9 normally, but when you are dealing with number characters, they start of at number 48 (in the ASCII table)

So a character 0 is 48 in bytes, 1 is 49, 2 is 50, and so on...

Golang hash sum and checksum to string tutorial and examples

17 April, 2016

The output of the function "hash.Sum()" is generated in byte code, and the output of "Checksum()" is a unsigned integer.

Generate SHA1 hash of a file in Golang example

08 April, 2016

This function is based on my previous post but adapted for the SHA1 algorithm.

Generate MD5 hash of a file in Golang

07 April, 2016

Why generate a MD5 hash of a file?

You may have noticed before on some websites where you download a file, there is some strange string of text around the download link, named "checksum", for example "md5 checksum: dcdfb1413d7fa48c3cab920c0448f236". Now this may look like a bunch of random characters to you but don't be fooled, it's a one-way mathematical hash that correspondents to the file you want to download.

Home