Skip to content

Instantly share code, notes, and snippets.

@cthom06
Created July 18, 2011 12:29
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cthom06/1089368 to your computer and use it in GitHub Desktop.
Save cthom06/1089368 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)))
}
@Dash-Abhishek
Copy link

what is the command to get the godoc output

@saniales
Copy link

godoc -http=:PORT then visit localhost:PORT

@tomaspavlic
Copy link

what is the command to get the godoc output

You can do go doc -all example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment