Created
July 18, 2011 12:29
-
-
Save cthom06/1089368 to your computer and use it in GitHub Desktop.
Godoc example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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))) | |
} |
godoc -http=:PORT
then visit localhost:PORT
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
what is the command to get the godoc output