golang中的godoc使用简介
学习go语法的同时为了方便查看对应的文档,不同的Go版本会有一些改动,所以,使用本地Go源码生成的文档显然更精确。
go在1.13之前是自带godoc的,之后的版本需要自行安装。
go get -u golang.org/x/tools/cmd/godoc
// 并没有自动安装
go install golang.org/x/tools/cmd/godoc
// 手动安装
> godoc -husage: godoc -http=localhost:6060-goroot stringGo root directory (default "D:\\Go")-http stringHTTP service address (default "localhost:6060")-indexenable search index-index_files stringglob pattern specifying index files; if not empty, the index is read from these files in sorted order-index_interval durationinterval of indexing; 0 for default (5m), negative to only index once at startup-index_throttle floatindex throttle value; 0.0 = no time allocated, 1.0 = full throttle (default 0.75)-linkslink identifiers to their declarations (default true)-maxresults intmaximum number of full text search results shown (default 10000)-notes stringregular expression matching note markers to show (default "BUG")-playenable playground-templates stringload templates/JS/CSS from disk in this directory-timestampsshow timestamps with directory listings-url stringprint HTML for named URL-v verbose mode-write_indexwrite index to a file; the file name must be specified with -index_files-zip stringzip file providing the file system to serve; disabled if empty
进入到Go源码目录,D:\Go\src
godoc -http=:6060
扫描文件需要时间,启动之后有时候还要等一会。
访问浏览器 http://localhost:6060/
访问指定的包
http://localhost:6060/pkg/fmt/
http://localhost:6060/pkg/archive/tar/
可以通过godoc -url "http://localhost:6060/pkg/" > doc.html
导出为静态的html单个文件,但是这个体验很差。
如果我们要查看一个第三方包的文档,比如 github.com/julienschmidt/httprouter
首先要进入它的源码目录
godoc -http=localhost:6060
第一部分依然是 Go Standard library,第二部分 Third party 才是 httprouter 的文档
如果我们要查看某个项目的文档也可以使用这种方式,然后我就发现我们自己写的项目大多没有什么注释,于是这就牵涉到注释的规范。
注释使用//
加一个空格并且要紧跟着被注释对象的上方。
首先需要给package加上注释,说明此包的作用,例如
// Package bufio implements buffered I/O. It wraps an io.Reader or io.Writer
// object, creating another object (Reader or Writer) that also implements
// the interface but provides buffering and some help for textual I/O.
package bufio
同一目录下的包可以由很多个文件组成,如果每个文件都有对package进行注释的话,godoc会自动将所有注释"按照文件名的字母数序"进行合并
在无效注释中以BUG(who)开头的注释, 将被识别为已知bug, 显示在bugs区域
// BUG(who): 因为前面有BUG(who)这个关键字,所以这句注释就算没有紧跟关键字不会被隐藏掉
关于DEPRECATED
弃用
// Time returns an int64 unix timestamp in milliseconds of the snowflake ID time
// DEPRECATED: the below function will be removed in a future release.
func (f ID) Time() int64 {return (int64(f) >> timeShift) + Epoch
}
在注释符要缩进的话,第二行注释符后面的空格要比上一行的空格多一个
example:// 123// 123
关于 go doc xxx
主要用来在终端上查看某个包的文档,它也是通过扫描包内的一些注释,然后格式化输出,但很少这么用。
> go doc fmtpackage fmt // import "fmt"Package fmt implements formatted I/O with functions analogous to C's printf
and scanf. The format 'verbs' are derived from C's but are simpler.PrintingThe verbs:General:%v the value in a default formatwhen printing structs, the plus flag (%+v) adds field names%#v a Go-syntax representation of the value%T a Go-syntax representation of the type of the value%% a literal percent sign; consumes no value
...
...
golang中的godoc使用简介相关推荐
- Go实战--golang中使用redis(redigo和go-redis/redis这个已测试)
自己做测试了没有问题,虚拟机连不上可以把包下载到本地. 版权声明:本文为博主原创文章,未经博主允许不得转载. http://blog.csdn.net/wangshubo1989/article/de ...
- Golang中闭包的理解
简介 参考博客: https://www.calhoun.io/what-is-a-closure/ https://blog.cloudflare.com/a-go-gotcha-when-clos ...
- Go实战--golang中使用MongoDB(mgo)
生命不止,继续 go go go !!! 昨天分享了golang如何操作redis数据库,那今天就介绍一下golang中如何使用mongodb数据库. 何为MongoDB? 简介 MongoDB 是由 ...
- golang中使用opencv(gocv)将本地摄像头转为ip摄像头
#1.gocv简介 gocv是golang中对opencv库封装. #2.gocv安装 ##2.1下载 go get -u -d gocv.io/x/gocv ##2.2编译 略 #3.demo pa ...
- Golang 中的 Goroutine 调度原理与 Chanel 通信
简介 在 Go 中,每一个并发的活动称为一个 Goroutine 或者 协程.当一个程序启动时,只有一个 Goroutine 来调用 main 函数,称之为 主Goroutine.新的 Gorou ...
- Golang中的GoPath和GoModule
文章目录 什么是GoPath? 什么是GoModule? GoModule的设置 GoModule无法下载国外的依赖包问题 在Golang中,有两个概念非常容易弄错,第一个就是GoPath,第二个则是 ...
- Go实战--golang中操作PDF(rsc.io/pdf、jung-kurt/gofpdf、signintech/gopdf)
生命不止,继续 go go go !!! 昨天介绍了golang中如何操作excel: Go实战–golang中操作excel(tealeg/xlsx.360EntSecGroup-Skylar/ex ...
- Go实战--golang中操作excel(tealeg/xlsx、360EntSecGroup-Skylar/excelize)
生命不止,继续 go go go !!! 匆匆十一假期,继续go,北京阴雨连连: 渲染了一种悲凉的气氛: 暗示了人物双假结束的悲惨命运: 揭露了下半年再无假期的凄惨社会环境: 为假期后各种辛苦的工作埋 ...
- Golang中Buffer高效拼接字符串以及自定义线程安全Buffer
本文原创文章,转载注明出处,博客地址 https://segmentfault.com/u/to... 第一时间看后续精彩文章.觉得好的话,顺手分享到朋友圈吧,感谢支持. Go中可以使用"+ ...
最新文章
- 优达学城《DeepLearning》项目2:犬种分类器
- 《大话设计模式》勘误
- Exchange 2013学习(二),关于约会、会议和事件
- 小米11和小米10至尊版纪念版哪个好
- 论文浅尝 | 改善多语言KGQA的 Zero-shot 跨语言转换
- 安卓案例:帧式布局演示(切换颜色)
- 自学c语言后的感受,一路走来,浅谈c语言的学习感想
- pbewithmd5anddes算法 对应.net_常用插值算法详解
- github的学习和使用
- 李宏毅 || 机器学习笔记一
- excel文件修复工具_Excel文件打开后出错,部分内容丢失的修复技巧
- 中国一线二线三线城市名单
- iTop-4412精英版的u-boot-2017.11移植教程(二)
- 日记app制作(OC)
- 手机打车APP的机遇与挑战
- 大数据数仓建模(3)
- Day008 - 字典与集合
- 电脑ping手机该怎么玩(很多网友都说电脑ping不通手机)?
- 基于Python的地理数据分析之一元线性回归分析-数学原理02.md
- ESP32设备驱动-CPU频率设置
热门文章
- 关于Atom无法下载插件的问题
- 【读书小记】学术“咸鱼”自救指南
- 【BZOJ3213】抛硬币(ZJOI2013)-期望DP+KMP+高精度
- Exception in thread “main“ java.lang.Error: Unresolved compilation problem: No enclosing instance
- 父亲节:再见,总有一天
- 原生js 解决offsetX兼容性问题
- Git更新代码到本地
- python数据清洗-时间格式化
- WWW21 GCA: Graph Contrastive Learning with Adaptive Augmentation
- 赛思互动:如何成为Salesforce专家