Skip to content

Instantly share code, notes, and snippets.

@nikgalushko
Forked from cthom06/godoc output
Created October 1, 2018 14:05
Show Gist options
  • Save nikgalushko/e1e3d5418fa0ee6b519c4d5adb673a82 to your computer and use it in GitHub Desktop.
Save nikgalushko/e1e3d5418fa0ee6b519c4d5adb673a82 to your computer and use it in GitHub Desktop.
Godoc example
PACKAGE
package example
import "example"
This is the package comment, a top-level piece of documentation
used to explain things about the package (see json or exp/template)
All godoc comments are in this form
with no whitespace between them and what they accompany
CONSTANTS
const (
CONSTA = iota
CONSTB
CONSTC
CONSTD
ANOTHER = 7
)
Some enum examples
VARIABLES
var Default float64 = 0.7
This is just a random variable
TYPES
type Example float64
Example is a float used for demonstration purposes
func (e Example) Sqrt() Example
Returns the square root of an example
type Example2 struct {
X Example
// contains filtered or unexported fields
}
Example2 is also for demonstartion
func NewExample(num int) *Example2
NewExample is used to get a ready-to-use Example2
// This is the package comment, a top-level piece of documentation
// used to explain things about the package (see json or exp/template)
// All godoc comments are in this form
// with no whitespace between them and what they accompany
package example
// Please always use the parenthetical form of import
// even though when only importing one package
// import "fmt"
// will work, it makes it uniform and simpler to add later
import (
"fmt"
"math"
)
// You can godoc constants
// Some enum examples
const (
CONSTA = iota
CONSTB
CONSTC
CONSTD
ANOTHER = 7
)
// You can godoc vars
// This is just a random variable
var Default float64 = 0.7
// var Default = float64(0.7) would've worked as well
// You can godoc types
// Example is a float used for demonstration purposes
type Example float64
// Example2 is also for demonstartion
type Example2 struct {
X Example
y int // Private fields do not appear in godoc
}
// You can godoc functions
// NewExample is used to get a ready-to-use Example2
func NewExample(num int) *Example2 {
return &Example{0.0, num}
}
// You can godoc methods
// Returns the square root of an example
func (e Example) Sqrt() Example {
return Example(math.Sqrt(float64(e)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment