Go doc for simple hello world program

Issue

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

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.

Answered By – icza

Answer Checked By – Willingham (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.