These pages about different languages / apis / best practices were mostly jotted down quckily and rarely corrected afterwards.
The languages / apis / best practices may have changed over time (e.g. the facebook api being a prime example), so what was documented as a good way to do something at the time might be outdated when you read it (some pages here are over 15 years old).
Just as a reminder.

Software developer notes about Go (the google language, not the prolog like language)

Developer notes for Go / golang

Save image

	toimg, _ := os.Create("/tmp/tmp.jpg")
	defer toimg.Close()
	jpeg.Encode(toimg, croppedImg, &jpeg.Options{jpeg.DefaultQuality})

Fetching content of urls

	client := &http.Client{}
	req, err := http.NewRequest("GET", url, nil)
	req.Header.Add("User-Agent", "an user agent for my go code")
	resp, err := client.Do(req)

    // alternatively just do:
	//	resp, err := http.Get(s)

	if nil != err {

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if nil != err {

	fmt.Println("%s", string(body))


//string to io.Reader
r := strings.NewReader(str)

//string to int and int to string
import (
i, err := strconv.Atoi(s)

//int to string
str := strconv.Itoa(123)

parsing html

func MyFunc(n *html.Node) {
	if n.Type == html.ElementNode && n.Data == "div" {
		for _, attr := range n.Attr {
			if attr.Key == "class" && attr.Val == "someclass" {
				fmt.Print("Found one
	for c := n.FirstChild; c != nil; c = c.NextSibling {


Struct to json

    jpegMessage := sqspool.JpegMessage{"888"}
	b, err := json.Marshal(jpegMessage)
	if nil != err {
		l.Err("Failed nmarshal json from fillsqs: " + err.Error() )
   	myAmz.GetQueue().SendMessage( string(b) );

json to struct

	byteArray := []byte(msgstr)

	var m JpegMessage
	err = json.Unmarshal(byteArray, &m)
	if nil != err {
		l.Err("Failed unmarshal json from sqs: " + err.Error() )
json decoding in go Go and JSON

Reading a file

path := "/tmp/go.txt"
r, _ := os.Open(path)
defer r.Close()

//parse as html (takes io.Reader)
doc, err := html.Parse(r)

Writing a file

err = ioutil.WriteFile(outputfilename, data, 0644)

Pass N arguments

The arguments are converted to a slice that you for example can do len() on
func DumpStrings( strs ...string ) {
	for _, str := range strs {
		fmt.Println( str );


Use log package to make sure the output wont get messed up by different goroutines
The log in its simplest form can just call log.Println. It writes to STDERR as default.
A Logger represents an active logging object that generates lines of output to an io.Writer. Each logging operation makes a single call to the Writer's Write method. A Logger can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer.

To convert the error message to string, call the Error() funciton, e.g.
l.log("Something went wrong, here is the error: " + err.Error() )


Used in imports to import stuff but we dont need to adress it in our code Blank Identifier _ in Import Statement

Variable declarations

var myvar = "golang";
//is the same as
myvar := "golang";

adding methods to a struct

type GoGoGo struct {

//private (lower case)
func (cs *GoGoGo) hello() string {
    return "hello"

//public (upper case)
func (cs *GoGoGo) Goodbye() string {
    return "goodbye";

Amazon SQS and Go

import (
	sqs "github.com/goamz/goamz/sqs"
	aws "github.com/goamz/goamz/aws"

accesskey := "myaccess"
secretkey := "mysecret"

auth := aws.Auth{AccessKey: accesskey, SecretKey: secretkey}
mySqs := sqs.New(auth, aws.USEast)
lqr, _ := mySqs.ListQueues("")


//send message
queuename := "https://sqs.us-east-1.amazonaws.com/123123123/somename"

q := &sqs.Queue{mySqs, queuename}

resp, _ := q.SendMessage("This is a test message")

//receive msg
resp, _ := q.ReceiveMessage(5)

Amazon S3 and Go

S3 Get

import (
	s3 "github.com/crowdmob/goamz/s3"
		data, err := bucket.Get( filename )
		if nil != err{
			return err
		//save to file
	 	err = ioutil.WriteFile(outputfilename, data, 0644)
		if nil != err{
			return err

S3 Put

		data, err := ioutil.ReadFile(file)
		if nil != err{
			return err
		bucket.Put(filename, data, "image/jpeg", s3.PublicRead, s3.Options{})

Postgresql and golang

package main

import (
  _ "github.com/lib/pq"

func main() {
 	l := sqspool.LogWrap { "main" }
 	l.Log("Started main")
  var sStmt string = "select objectid from mytable where status = 30 order by objectid desc limit 5"
  // lazily open db (doesn't truly open until first request)
  db, err := sql.Open("postgres","user=theuser password=thepassword host=localhost dbname=mydatabase port=5555 sslmode=disable")
  if err != nil {
    l.Err(err.Error() )
    stmt, err := db.Prepare(sStmt)
    if err != nil {
    rows, err := stmt.Query()
    if err != nil || rows == nil {
	for rows.Next() {
		var objectid string
		err = rows.Scan(&objectid)
		if err != nil {
			fmt.Printf("rows.Scan error: %v

		fmt.Printf("objectid: %v
", objectid);
    // close statement
  // close db

Scan array into array-of-arrays

<h3>Changing value of individual pixels</h3>
	b := img.Bounds()
	cimg := image.NewRGBA(b)
	draw.Draw(cimg, b, img, b.Min, draw.Src)

	cimg.Set(10, 10, color.RGBA{255, 0, 0, 255})
	return cimg


<h3>Other stuff</h3>

time.Sleep(15 * time.Second)

"x509: certificate has expired or is not yet valid"
to make it skip verify any expired/invalid/self-signed certificates

	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	client := &http.Client{Transport: tr}


;; Change to wherever you installed Go, emacs mode is included in the Go distribution
(add-to-list 'load-path "/Users/Gopher/bin/go/misc/emacs/")
(require 'go-mode-load)

;; Use space instead of tab and set to 4 width
(add-hook 'go-mode-hook 
  (lambda ()
    (setq tab-width 4) 
    (setq standard-indent 4) 
    (setq indent-tabs-mode nil)))

Golang links

golangprojects - golang open jobs positions
Refactoring With Go Fmt, Description about gofmt. Note that you have to do gofmt -w [filename] to write to the file (the article forgot the -w flag)
Go naming conventions
Documenting Go code
Object orientation in Go
Building a Message Queue Using Redis in Go
The goamz package enables Go programs to interact with the Amazon Web Services, it seems like it is not updated, so going with https://github.com/crowdmob/goamz instead
Gocheck testing framework, seems to be the standard to use in go
Testing in Go, they do not have assert etc as default
More info on testing in Go
someones notes about Go
Using The Log Package In Go, Nov 5 2013 by William Kennedy
Logging approaches in Go
logging used at google
How Goroutines work
Error handling in Go
Writing Go in emacs
High Performance Systems in Go - GopherCon 2014
GopherCon 2014 slides, The Golang conference in Denver, CO
GopherCon 2014 videos, videos of the presentations

TDD in Go
Goblin: A Minimal and Beautiful Testing Framework for the Go Language

More programming related pages

Workflow: Release process
Workflow: Bug tracking
Teambox (Redbooth) - Mantis connector
Design Patterns
Git & Github
Go / Golang
CVS backup script
Distribution process
Installation script
Java Server Faces
Perl tips
Perl links
Python / py2app
Shell scripts
Facebook / Opengraph
PHP developer notes
Redbooth API through php
Website optimization
jqTableKit demo
Javascript / html / css links