Category Archives: Go

Go – About goimport tool .

A Go developer know the code must be formatted with standard gofmt tool.
While gofmt attracks much attention, goimport is overlooked despite often being more useful.
Basically, goimport does everything that gofmt do.
First, you need to install into go using:

This will auto import Go packages using goimports tool.
While correcting, goimports removes unused imports and adds missing ones.
Additionally it groups and corrects imported packages.
You can used with vim and atom editors.
To setup vim editor to auto run goimports on save using vim-go, use this :

If you want to use the atom editor then you need to install the atom package named go-imports from abiosoft.
Use command palette cmd-shift-p, search for Go Imports: Process or using keybinding ctrl-shift-i.

Posted in All, Commands, Go. Tagged with , , , , .

Go – Using the go command .

After install go programming language from here, you will need to deal with the go command.
I’m not very good with golang , but I found some interesting issues for those who want to use go command with golang.
About go command can you read here and the go help output come with this help:

There are a few things you should know:

  • don’t use go list to see packages , use this command:go list all
  • take a look at install go on environment: go env
  • use help argument to get more help, like: go help gopath , go help env
  • see your go version  for  debug issues: go version
  • you can build your file (here called term_size.go) passing some gcflags : go build -gcflags=-m term_size.go
    # command-line-arguments
    .\term_size.go:13:25: inlining call to termbox.Size
    .\term_size.go:15:16: w escapes to heap
    .\term_size.go:15:16: h escapes to heap
    .\term_size.go:15:16: main ... argument does not escape
  • do not try this on Windows OS : go build -ldflags , first read more about: C:\Go\pkg\tool\windows_amd64\link.exe: -X flag requires argument of the form importpath.name=value
  • the Windows shell doesn’t have single quoted strings:
    go list -f "{{ .TestGoFiles }}" archive/tar
    [reader_test.go strconv_test.go tar_test.go writer_test.go]
Posted in All, Commands, Go, Windows 10. Tagged with , , , , , .

Go – Testing Golang with android application – part 001 .

This is my first tutorial in a long series about Go and Android programming. In the limit of my free time I will try to show you how to do simple applications with the Go programming language (or known as Golang).
You need to install the Go programming language using MSI installer from here.
I set the folder with this path – C:\Go\ but my windows also put some go files under Users folder.
If you want you can to add the Go path into windows environment.
You will have this path in this case: C:\Users\your_account\go\.
The next step is to install the Android NDK from here.
I install the Windows 64-bit into Users folder. You need to install at: C:\Users\your_account\go\.
Because I don’t have a good go programming android example I used the basic default example from golang mobile.
Let’s see the commands to install and used it:

About the gomobile command then the help tell us:

If you have the adb command installed on your machine, you can use gomobile command with the argument install to push the APK to your mobile device.
I used Bluestacks emulator for android and the basic example working well.

Posted in All, Android, Go, Programming, Windows 10. Tagged with , , , , , .