Go doc for simple hello world program


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


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 


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.