godoc: Tips & Tricks

Package Overview & License

// Copyright Some Company Corp.
// All Rights Reserved
// Here is where we explain the package.
// Some other stuff.
package doc

Paragraphs

// Here is where we explain the package.
//
// Some other stuff.
package doc

Constants

// This is the host
const Host = "example.com"
// The port number for the host.
const Port = 1234
// This appears under the const.
const (
// This causes Foo to happen.
OptionFoo = 1
// This causes Bar to happen.
OptionBar = 2
// Documented, but not visible.
optionSecret = 3
)

Methods

// Math stuff.// Absolute value.
func Abs(x float64) float64 {
}
// Sine value.
func Sin(x float64) float64 {
}
// Internal stuff.// Docs are important even for internal stuff.
func secretMethod() {
}

Headings & Sections

// Here is where we explain the package.
//
// See Also
//
// Some other stuff.
package doc

Code Blocks

// This is how to create a Hello World:
// fmt.Printf("Hello, World")
// Or:
// fmt.Printf("Hello, " + name)

Links

Examples

// My awesome package.
package doc
package doc_test// This is a package-level example:
func Example() {
fmt.Printf("Hi")
}
// This is a package-level example:
func Example() {
fmt.Printf("Hi")
}
package doc// Real is just another name for float64.
type Real float64
package doc_test// Use Real like a general floating type:
func ExampleReal() {
var x Real = 1.23
}
package doc// Absolute value.
func Abs(x Real) Real {
}
package doc_testfunc ExampleAbs_positive() {
Abs(1.23)
// Output: 1.23
}
func ExampleAbs_negative() {
Abs(-1.23)
// Output: 1.23
}

--

--

--

I’m a data nerd and TDD enthusiast originally from Sydney. Currently working for Uber in New York. My thoughts here are my own. 🤓 elliotchance@gmail.com

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Elliot Chance

Elliot Chance

I’m a data nerd and TDD enthusiast originally from Sydney. Currently working for Uber in New York. My thoughts here are my own. 🤓 elliotchance@gmail.com

More from Medium

Hexagonal architecture: catch ‘em all

How I got “Hot reloading” to work with Golang and nodemon (UNIX)

Why should you learn Golang?

Week 2: Concurrency Vs Parallelism