build: make lint format code

This commit is contained in:
Xinwei Xiong (cubxxw) 2024-03-19 17:04:15 +08:00
parent 3bb25c9cdd
commit 6ad93ef4f7

View File

@ -1,87 +1,50 @@
# go doc # Go Language Documentation for OpenIM
Go语言项目十分重视代码的文档在软件设计中文档对于软件的可维护和易使用具有重大的影响。因此文档必须是书写良好并准确的与此同时它还需要易于书写和维护。 In the realm of software development, especially within Go language projects, documentation plays a crucial role in ensuring code maintainability and ease of use. Properly written and accurate documentation is not only essential for understanding and utilizing software effectively but also needs to be easy to write and maintain. This principle is at the heart of OpenIM's approach to supporting commands and generating documentation.
## Supported Commands in OpenIM
**OpenIM 支持的命令 OpenIM leverages Go language's documentation standards to facilitate clear and maintainable code documentation. Below are some of the key commands used in OpenIM for documentation purposes:
Go语言注释 ### `go doc` Command
Go语言中注释一般分为两种分别是单行注释和多行注释
单行注释是以 // 开头的注释,可以出现在任何地方。 The `go doc` command is used to print documentation for Go language entities such as variables, constants, functions, structures, and interfaces. This command allows specifying the identifier of the program entity to tailor the output. Examples of `go doc` command usage include:
多行注释也叫块注释,以 /* 开头,以 */ 结尾,不可以嵌套使用,一般用于包的文档描述或注释成块的代码片段。
每一个 package 都应该有相关注释,在 package 语句之前的注释内容将被默认认为是这个包的文档, package 的注释应该提供一些相关信息并对整体功能做简要的介绍。
在日常开发过程中可以使用go doc和godoc命令生成代码的文档。 - `go doc sync.WaitGroup.Add` prints the documentation for a specific method of a type in a package.
- `go doc -u -all sync.WaitGroup` displays all program entities, including unexported ones, for a specified type.
- `go doc -u sync` outputs all program entities for a specified package, focusing on exported ones without detailed comments.
### `godoc` Command
For environments lacking internet access, the `godoc` command serves to view the Go language standard library and project dependency library documentation in a web format. Notably, post-Go 1.12 versions, `godoc` is not part of the Go compiler suite. It can be installed using:
go doc ```shell
go doc 命令打印Go语言程序实体上的文档。可以使用参数来指定程序实体的标识符。
Go语言程序实体是指变量、常量、函数、结构体以及接口。
程序实体标识符就是程序实体的名称。
输出指定 package ,指定类型,指定方法的注释
$ go doc sync.WaitGroup.Add
输出指定 package ,指定类型的所有程序实体,包括未导出的
$ go doc -u -all sync.WaitGroup
输出指定 package 的所有程序实体(非所有详细注释)
$ go doc -u sync
godoc
godoc命令主要用于在无法联网的环境下以web形式查看Go语言标准库和项目依赖库的文档。
在 go 1.12 之后的版本中godoc不再做为go编译器的一部分存在。依然可以通过go get命令安装
go get -u -v golang.org/x/tools/cmd/godoc go get -u -v golang.org/x/tools/cmd/godoc
国内的安装方法 ```
The `godoc` command, once running, hosts a local web server (by default on port 6060) to facilitate documentation browsing at http://127.0.0.1:6060. It generates documentation based on the GOROOT and GOPATH directories, showcasing both the project's own documentation and that of third-party packages installed via `go get`.
Explain ### Custom Documentation Generation Commands in OpenIM
mkdir -p $GOPATH/src/golang.org/x
cd $GOPATH/src/golang.org/x
git clone https://github.com/golang/tools.git
cd tools/cmd/godoc
go install
ls -alh $GOPATH/bin
通过终端查看文档
go doc命令 OpenIM includes a suite of commands aimed at initializing, generating, and maintaining project documentation and associated files. Some notable commands are:
$ go doc help - `gen.init`: Initializes the OpenIM server project.
usage: go doc [-u] [-c] [package|[package.]symbol[.method]] - `gen.docgo`: Generates missing `doc.go` files for Go packages, crucial for package-level documentation.
可以看到go doc接受的参数可以是包名也可以是包里的结构、方法等默认为显示当前目录下的文档。 - `gen.errcode.doc`: Generates markdown documentation for OpenIM error codes.
- `gen.ca`: Generates CA files for all certificates, enhancing security documentation.
These commands underscore the project's commitment to thorough and accessible documentation, supporting both developers and users alike.
通过网页查看文档 ## Writing Your Own Documentation
godoc命令 When creating documentation for Go projects, including OpenIM, it's important to follow certain practices:
$ godoc -http=:6060 1. **Commenting**: Use single-line (`//`) and block (`/* */`) comments to provide detailed documentation within the code. Block comments are especially useful for package documentation, which should immediately precede the package statement without any intervening blank lines.
godoc会监听6060端口通过网页访问 http://127.0.0.1:6060godoc基于GOROOT和GOPATH路径下的代码生成文档的。打开首页如下我们自己项目工程文档和通过go get的代码文档都在Packages中的Third party里面。
2. **Overview Section**: To create an overview section in the documentation, place a block comment directly before the package statement. This section should succinctly describe the package's purpose and functionality.
3. **Detailed Descriptions**: Comments placed before functions, structures, or variables will be used to generate detailed descriptions in the documentation. Follow the same commenting rules as for the overview section.
编写自己的文档 4. **Examples**: Include example functions prefixed with `Example` to demonstrate usage. Output from these examples can be documented at the end of the function, starting with `// Output:` followed by the expected result.
1、设计接口函数代码 Through adherence to these documentation practices, OpenIM ensures that its codebase remains accessible, maintainable, and easy to use for developers and users alike.
创建documents/calc.go文件
编写文档规则
1、文档中显示的详细主体内容大多是由用户注释部分提供注释的方式有两种单行注释"//"和代码块"/* */"注释。
2、在源码文件中在package语句前做注释在文档中看到的就是Overview部分 注意此注释必须紧挨package语句前一行要作为Overview部分的注释块中间不能有空行。
3、在函数、结构、变量等前做注释的在文档中看到的就是该项详细描述。注释规则同上。
4、编写的Example程序函数名必须以Example为前缀可将测试的输出结果放在在函数尾部以"// Output:"另起一行,然后将输出内容注释,并追加在后面。