build: make lint format code

This commit is contained in:
Xinwei Xiong (cubxxw) 2024-03-19 16:47:27 +08:00
parent 0bd177f362
commit b6759fe604
26 changed files with 419 additions and 9 deletions

87
docs/contrib/go-doc.md Normal file
View File

@ -0,0 +1,87 @@
# go doc
Go语言项目十分重视代码的文档在软件设计中文档对于软件的可维护和易使用具有重大的影响。因此文档必须是书写良好并准确的与此同时它还需要易于书写和维护。
**OpenIM 支持的命令
Go语言注释
Go语言中注释一般分为两种分别是单行注释和多行注释
单行注释是以 // 开头的注释,可以出现在任何地方。
多行注释也叫块注释,以 /* 开头,以 */ 结尾,不可以嵌套使用,一般用于包的文档描述或注释成块的代码片段。
每一个 package 都应该有相关注释,在 package 语句之前的注释内容将被默认认为是这个包的文档, package 的注释应该提供一些相关信息并对整体功能做简要的介绍。
在日常开发过程中可以使用go doc和godoc命令生成代码的文档。
go doc
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
国内的安装方法
Explain
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命令
$ go doc help
usage: go doc [-u] [-c] [package|[package.]symbol[.method]]
可以看到go doc接受的参数可以是包名也可以是包里的结构、方法等默认为显示当前目录下的文档。
通过网页查看文档
godoc命令
$ godoc -http=:6060
godoc会监听6060端口通过网页访问 http://127.0.0.1:6060godoc基于GOROOT和GOPATH路径下的代码生成文档的。打开首页如下我们自己项目工程文档和通过go get的代码文档都在Packages中的Third party里面。
编写自己的文档
1、设计接口函数代码
创建documents/calc.go文件
编写文档规则
1、文档中显示的详细主体内容大多是由用户注释部分提供注释的方式有两种单行注释"//"和代码块"/* */"注释。
2、在源码文件中在package语句前做注释在文档中看到的就是Overview部分 注意此注释必须紧挨package语句前一行要作为Overview部分的注释块中间不能有空行。
3、在函数、结构、变量等前做注释的在文档中看到的就是该项详细描述。注释规则同上。
4、编写的Example程序函数名必须以Example为前缀可将测试的输出结果放在在函数尾部以"// Output:"另起一行,然后将输出内容注释,并追加在后面。

View File

@ -16,12 +16,12 @@ package fcm
import (
"context"
"github.com/OpenIMSDK/tools/errs"
"path/filepath"
firebase "firebase.google.com/go"
"firebase.google.com/go/messaging"
"github.com/OpenIMSDK/protocol/constant"
"github.com/OpenIMSDK/tools/errs"
"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"

View File

@ -1,3 +1,17 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package config
const ConfKey = "conf"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cos // import "internal/pkg/pkg/common/db/s3/cos"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package minio // import "internal/pkg/pkg/common/db/s3/minio"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package oss // import "internal/pkg/pkg/common/db/s3/oss"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package relation // import "internal/pkg/pkg/common/db/table/relation"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package direct // import "internal/pkg/pkg/common/discoveryregister/direct"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package discoveryregister // import "internal/pkg/pkg/common/discoveryregister"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package kubernetes // import "internal/pkg/pkg/common/discoveryregister/kubernetes"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package zookeeper // import "internal/pkg/pkg/common/discoveryregister/zookeeper"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ginprometheus // import "internal/pkg/pkg/common/ginprometheus"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package prommetrics // import "internal/pkg/pkg/common/prommetrics"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package redispubsub // import "internal/pkg/pkg/common/redispubsub"

15
pkg/common/tls/doc.go Normal file
View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tls // import "internal/pkg/pkg/common/tls"

15
pkg/common/version/doc.go Normal file
View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package version // import "internal/pkg/pkg/common/version"

15
pkg/localcache/doc.go Normal file
View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package localcache // import "internal/pkg/pkg/localcache"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package link // import "internal/pkg/pkg/localcache/link"

15
pkg/localcache/lru/doc.go Normal file
View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package lru // import "internal/pkg/pkg/localcache/lru"

15
pkg/rpccache/doc.go Normal file
View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rpccache // import "internal/pkg/pkg/rpccache"

View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package grouphash // import "internal/pkg/pkg/rpcclient/grouphash"

15
pkg/util/flag/doc.go Normal file
View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package flag // import "internal/pkg/pkg/util/flag"

15
pkg/util/genutil/doc.go Normal file
View File

@ -0,0 +1,15 @@
// Copyright © 2024 OpenIM. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package genutil // import "internal/pkg/pkg/util/genutil"

View File

@ -17,7 +17,7 @@ DEFAULT_DIRS=(
"pkg"
"internal/pkg"
)
BASE_URL="github.com/openimsdk/open-im-server"
BASE_URL="github.com/openimsdk/open-im-server/v3"
usage() {
echo "Usage: $0 [OPTIONS]"
@ -35,7 +35,7 @@ usage() {
process_dir() {
local dir=$1
local base_url=$2
for d in $(find $dir -type d); do
if [ ! -f $d/doc.go ]; then
if ls $d/*.go > /dev/null 2>&1; then

View File

@ -88,11 +88,6 @@ gen.docgo.check: gen.docgo.doc
gen.docgo.add:
@git ls-files --others '*/doc.go' | $(XARGS) -- git add
## gen.docgo: Generate missing doc.go for go packages ✨
.PHONY: gen.defaultconfigs
gen.defaultconfigs:
@${ROOT_DIR}/scripts/gen_default_config.sh
## gen.docgo: Generate missing doc.go for go packages ✨
.PHONY: gen.clean
gen.clean:
@ -101,5 +96,5 @@ gen.clean:
## gen.help: show help for gen
.PHONY: gen.help
gen.help: scripts/make-rules/gen.mk
gen.help: scripts/make-rules/gen.m
$(call smallhelp)

View File

@ -1,3 +1,17 @@
# Copyright © 2024 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# config.yaml 示例配置
# 基础配置