How to write a go program such that it has a simple doc for it
example
package Hello_world
import "fmt"
func Hello_world() {
fmt.Println("hello world")
}
after making changes for this code if exec
go doc <needed command>
it should print
this is a hello world program
CodePudding user response:
I am not 100% sure what you are asking for.
But you can describe a go package like this and go doc
will pick up on this.
// this is some description for the package
package mypackage
You could then view the documentation in the browser using
godoc -http=:6060
There are many tricks which can be done using GoDoc which are described in this Github Repository - godoc-tricks or this blog post by the Go team.
CodePudding user response:
Enter the documentation in a comment before the package declaration, leaving no empty lines between them.
For example:
/*
This is a hello world program.
*/
package main
Then provide the package to go doc
, like this:
go doc path/to/your/package
Output will be:
This is a hello world program.