Go Code Snippets
Static File Server
A simple static file server that binds to localhost. Use --port
(-p
) to specify the port and --dir
(-d
) to specify the directory, otherwise it'll default to port 3000 and the current working directory, respectively.
Parse a SQL Connection URI
A function for easily converting a SQL connection URI to a flavor and connection details that can be passed directly into Go's sql.Open() function.
Simple Unit Test
This is what a basic unit test looks like in Go. It must exist in a file named with the form *_test.go
, and the name of each test must follow the form TestXxx
where the first letter after "Test" is capitalized. Execute go test
in the terminal to run unit tests. A t.Error(str)
is equivalent to a t.Log(str)
followed by a t.Fail()
.