In Go it is possible to check if any pointer to an initialized struct has a given method or field. The use of this is to make sure that you can call a given method, or access a given field without receiving a runtime panic.
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.
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.
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.
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.
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.
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...
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.