Notes to self -- How to use Go Third Party Packages

Published: 2020-05-08 by Pradeep Gowda.
Tagged: golang

I’ve been following Go programming language since about 2009 or so (have the t-shirt).

Go does package management differently than other languages. For one there was no tar.gz, egg, or gem to download. This note is just a reminder to myself how things work.

How to find new, interesting Go packages? Golang weekly is one place. Rek looks interesting.

Rek is like Python requests

You install the package with: go get

The source is installed under: $GOPATH/src/ On my machines, $GOPATH is usually set to $HOME/go.

I can then use this package in a program like this: import ""

The complete program for posterity (also, the example code from the library home page had syntax errors) is here:

package main

import ""
import "fmt"
import "time"

// Comment Struct
type Comment struct {
    Body string `json:"body"`

func main() {
    comment := Comment{Body: "Test message"}
    headers := map[string]string{"X-Custom-Header": "Custom Header Ino "}
    res, _ := rek.Post("",
        rek.BasicAuth("user", "pass"),


Running this program with go run . will produce:

  "args": {},
  "data": "{\"body\":\"Test message\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept-Encoding": "gzip",
    "Authorization": "Basic dXNlcjpwYXNz",
    "Content-Length": "23",
    "Content-Type": "application/json; charset=utf-8",
    "Host": "",
    "User-Agent": "Go-http-client/2.0",
    "X-Amzn-Trace-Id": "Root=1-5eb56f0a-33437e749f972658c175508a",
    "X-Custom-Header": "Custom Header Ino"
  "json": {
    "body": "Test message"
  "origin": "",
  "url": ""


  1. Running go get -u package (note the -u flag) will update the local copy of the package.
  2. Running go get -u -d foo/... will download all the subpackages of foo.