'Go doc for simple hello world program

How to write a go program such that it has a simple doc for it

example

package HelloWorld

import "fmt"

func HelloWorld() {
    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 


Solution 1:[1]

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.

Solution 2:[2]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Mushroomator