简单的Hello World程序的Go文档

huangapple go评论106阅读模式
英文:

Go doc for simple hello world program

问题

如何编写一个 Go 程序,使其具有简单的文档?

示例代码如下:

  1. package HelloWorld
  2. import "fmt"
  3. // HelloWorld 打印 "hello world"
  4. func HelloWorld() {
  5. fmt.Println("hello world")
  6. }

对于这段代码,如果执行以下更改后:

  1. go doc <需要的命令>

它应该打印出:

  1. 这是一个 hello world 程序
英文:

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

example

  1. package HelloWorld
  2. import &quot;fmt&quot;
  3. func HelloWorld() {
  4. fmt.Println(&quot;hello world&quot;)
  5. }

after making changes for this code if exec

  1. go doc &lt;needed command&gt;

it should print

  1. this is a hello world program

答案1

得分: 2

我不完全确定你在问什么。
但是你可以像这样描述一个Go包,然后go doc会识别它。

  1. // 这是包的一些描述
  2. package mypackage

然后你可以使用以下命令在浏览器中查看文档:

  1. godoc -http=:6060

使用GoDoc可以实现许多技巧,这些技巧在这个GitHub仓库 - godoc-tricks或者这篇Go团队的博文中有描述。

英文:

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.

  1. // this is some description for the package
  2. package mypackage

You could then view the documentation in the browser using

  1. 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.

答案2

得分: 2

在包声明之前,用注释形式编写文档,注释与包声明之间不要有空行。

例如:

  1. /*
  2. 这是一个Hello World程序。
  3. */
  4. package main

然后使用go doc命令提供包的路径,如下所示:

  1. go doc path/to/your/package

输出结果将是:

  1. 这是一个Hello World程序。
英文:

Enter the documentation in a comment before the package declaration, leaving no empty lines between them.

For example:

  1. /*
  2. This is a hello world program.
  3. */
  4. package main

Then provide the package to go doc, like this:

  1. go doc path/to/your/package

Output will be:

  1. This is a hello world program.

huangapple
  • 本文由 发表于 2022年3月11日 19:03:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/71437529.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定