How to import local packages in go?

Well, I figured out the problem. Basically Go starting path for import is $HOME/go/src So I just needed to add myapp in front of the package names, that is, the import should be: import ( “log” “net/http” “myapp/common” “myapp/routers” )

Go > operators

The super (possibly over) simplified definition is just that << is used for “times 2” and >> is for “divided by 2” – and the number after it is how many times. So n << x is “n times 2, x times”. And y >> z is “y divided by 2, z times”. For example, … Read more

Is there a way to do repetitive tasks at intervals?

The function time.NewTicker makes a channel that sends a periodic message, and provides a way to stop it. Use it something like this (untested): ticker := time.NewTicker(5 * time.Second) quit := make(chan struct{}) go func() { for { select { case <- ticker.C: // do stuff case <- quit: ticker.Stop() return } } }() You … Read more

How to parse unix timestamp to time.Time

The time.Parse function does not do Unix timestamps. Instead you can use strconv.ParseInt to parse the string to int64 and create the timestamp with time.Unix: package main import ( “fmt” “time” “strconv” ) func main() { i, err := strconv.ParseInt(“1405544146”, 10, 64) if err != nil { panic(err) } tm := time.Unix(i, 0) fmt.Println(tm) } … Read more

Can I list all standard Go packages?

You can use the new golang.org/x/tools/go/packages for this. This provides a programmatic interface for most of go list: package main import ( “fmt” “golang.org/x/tools/go/packages” ) func main() { pkgs, err := packages.Load(nil, “std”) if err != nil { panic(err) } fmt.Println(pkgs) // Output: [archive/tar archive/zip bufio bytes compress/bzip2 … ] } To get a isStandardPackage() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)