How to serve documentation using godoc together with go modules?

The issue isn’t modules so much as GOPATH. There’s a github issue thread that discusses this in more detail: https://github.com/golang/go/issues/26827 That thread has evolved a workaround that uses a docker container to run a godoc server with GOPATH set to the base of your dev tree. That godoc server will serve docs for all of … Read more

Difference between *string and sql.NullString

SQL has different null values than Golang. If you look at the definition of sql.NullString then this is what you get: type NullString struct { String string Valid bool // Valid is true if String is not NULL } As you can see, sql.NullString is a way to represent null string coming from SQL (which … Read more

How do I serve CSS and JS in Go

http.Handle(“https://stackoverflow.com/”, http.FileServer(http.Dir(“css/”))) Would serve your css directory at /. Of course you can serve whichever directory at whatever path you choose. You probably want to make sure that the static path isn’t in the way of other paths and use something like this. http.Handle(“/static/”, http.StripPrefix(“/static/”, http.FileServer(http.Dir(“static”)))) Placing both your js and css in the directory … Read more

Concisely deep copy a slice?

Not sure which solution is fastest without a benchmark, but an alternative is using the built in copy: cpy := make([]T, len(orig)) copy(cpy, orig) From the documentation: func copy(dst, src []Type) int The copy built-in function copies elements from a source slice into a destination slice. (As a special case, it also will copy bytes … Read more

How to parse non standard time format from json

That’s a case when you need to implement custom marshal and unmarshal functions. UnmarshalJSON(b []byte) error { … } MarshalJSON() ([]byte, error) { … } By following the example in the Golang documentation of json package you get something like: // First create a type alias type JsonBirthDate time.Time // Add that to your struct … Read more

tech