docs: 优化 README.md 函数签名

This commit is contained in:
kercylan98 2024-01-15 10:37:51 +08:00
parent 8c80c4b00c
commit bd7a3fee6b
58 changed files with 608 additions and 596 deletions

View File

@ -155,7 +155,7 @@ type FeiShu struct {
MsgType string
}
```
#### func (*FeiShu) Format() string, error
#### func (*FeiShu) Format() ( string, error)
> 格式化通知内容
***
### FeiShuMessage `STRUCT`

View File

@ -132,10 +132,10 @@ type DataTmpl interface {
```go
type Exporter struct{}
```
#### func (*Exporter) ExportStruct(tmpl Tmpl, tmplStruct ...*TmplStruct) []byte, error
#### func (*Exporter) ExportStruct(tmpl Tmpl, tmplStruct ...*TmplStruct) ( []byte, error)
> 导出结构
***
#### func (*Exporter) ExportData(tmpl DataTmpl, data map[any]any) []byte, error
#### func (*Exporter) ExportData(tmpl DataTmpl, data map[any]any) ( []byte, error)
> 导出数据
***
### Field `INTERFACE`

View File

@ -49,7 +49,7 @@ type Golang struct {
Templates []*pce.TmplStruct
}
```
#### func (*Golang) Render(templates ...*pce.TmplStruct) string, error
#### func (*Golang) Render(templates ...*pce.TmplStruct) ( string, error)
***
#### func (*Golang) GetVariable(config *pce.TmplStruct) string
***
@ -64,5 +64,5 @@ type JSON struct {
jsonIter.API
}
```
#### func (*JSON) Render(data map[any]any) string, error
#### func (*JSON) Render(data map[any]any) ( string, error)
***

View File

@ -866,7 +866,7 @@ func ExampleServer_Run() {
#### func (*Server) Context() context.Context
> 获取服务器上下文
***
#### func (*Server) TimeoutContext(timeout time.Duration) context.Context, context.CancelFunc
#### func (*Server) TimeoutContext(timeout time.Duration) ( context.Context, context.CancelFunc)
> 获取服务器超时上下文context.WithTimeout 的简写
***
#### func (*Server) Ticker() *timer.Ticker

View File

@ -81,7 +81,7 @@ gateway 是用于处理服务器消息的网关模块,适用于对客户端消
> - 默认情况下,网关会随机选择一个端点作为目标,如果需要自定义端点选择器,可以通过该选项设置
***
#### func MarshalGatewayOutPacket(addr string, packet []byte) []byte, error
#### func MarshalGatewayOutPacket(addr string, packet []byte) ([]byte, error)
<span id="MarshalGatewayOutPacket"></span>
> 将数据包转换为网关出网数据包
> - | identifier(4) | ipv4(4) | port(2) | packet |
@ -93,7 +93,7 @@ gateway 是用于处理服务器消息的网关模块,适用于对客户端消
> - | identifier(4) | ipv4(4) | port(2) | packet |
***
#### func MarshalGatewayInPacket(addr string, currentTime int64, packet []byte) []byte, error
#### func MarshalGatewayInPacket(addr string, currentTime int64, packet []byte) ([]byte, error)
<span id="MarshalGatewayInPacket"></span>
> 将数据包转换为网关入网数据包
> - | ipv4(4) | port(2) | cost(4) | packet |
@ -218,11 +218,11 @@ func TestGateway_Run(t *testing.T) {
#### func (*Gateway) Server() *server.Server
> 获取网关服务器核心
***
#### func (*Gateway) GetEndpoint(name string) *Endpoint, error
#### func (*Gateway) GetEndpoint(name string) ( *Endpoint, error)
> 获取一个可用的端点
> - name: 端点名称
***
#### func (*Gateway) GetConnEndpoint(name string, conn *server.Conn) *Endpoint, error
#### func (*Gateway) GetConnEndpoint(name string, conn *server.Conn) ( *Endpoint, error)
> 获取一个可用的端点,如果客户端已经连接到了某个端点,将优先返回该端点
> - 当连接到的端点不可用或没有连接记录时,效果同 GetEndpoint 相同
> - 当连接行为为有状态时,推荐使用该方法
@ -243,7 +243,7 @@ type Scanner interface {
GetInterval() time.Duration
}
```
#### func (*Scanner) GetEndpoints() []*gateway.Endpoint, error
#### func (*Scanner) GetEndpoints() ( []*gateway.Endpoint, error)
***
#### func (*Scanner) GetInterval() time.Duration
***

View File

@ -93,7 +93,7 @@ type Ring[T any] struct {
w int
}
```
#### func (*Ring) Read() T, error
#### func (*Ring) Read() ( T, error)
> 读取数据
<details>
<summary>查看 / 收起基准测试</summary>

View File

@ -145,7 +145,7 @@ func TestPrioritySlice_Append(t *testing.T) {
#### func (*PrioritySlice) Appends(priority int, vs ...V)
> 添加元素
***
#### func (*PrioritySlice) Get(index int) V, int
#### func (*PrioritySlice) Get(index int) ( V, int)
> 获取元素
***
#### func (*PrioritySlice) GetValue(index int) V

View File

@ -30,32 +30,32 @@ compress 提供了一些用于压缩和解压缩数据的函数。
***
## 详情信息
#### func GZipCompress(data []byte) bytes.Buffer, error
#### func GZipCompress(data []byte) (bytes.Buffer, error)
<span id="GZipCompress"></span>
> 对数据进行GZip压缩返回bytes.Buffer和错误信息
***
#### func GZipUnCompress(dataByte []byte) []byte, error
#### func GZipUnCompress(dataByte []byte) ([]byte, error)
<span id="GZipUnCompress"></span>
> 对已进行GZip压缩的数据进行解压缩返回字节数组及错误信息
***
#### func TARCompress(data []byte) bytes.Buffer, error
#### func TARCompress(data []byte) (bytes.Buffer, error)
<span id="TARCompress"></span>
> 对数据进行TAR压缩返回bytes.Buffer和错误信息
***
#### func TARUnCompress(dataByte []byte) []byte, error
#### func TARUnCompress(dataByte []byte) ([]byte, error)
<span id="TARUnCompress"></span>
> 对已进行TAR压缩的数据进行解压缩返回字节数组及错误信息
***
#### func ZIPCompress(data []byte) bytes.Buffer, error
#### func ZIPCompress(data []byte) (bytes.Buffer, error)
<span id="ZIPCompress"></span>
> 对数据进行ZIP压缩返回bytes.Buffer和错误信息
***
#### func ZIPUnCompress(dataByte []byte) []byte, error
#### func ZIPUnCompress(dataByte []byte) ([]byte, error)
<span id="ZIPUnCompress"></span>
> 对已进行ZIP压缩的数据进行解压缩返回字节数组及错误信息

View File

@ -39,7 +39,7 @@
> 对数据进行Base64编码
***
#### func DecodedBase64(data string) []byte, error
#### func DecodedBase64(data string) ([]byte, error)
<span id="DecodedBase64"></span>
> 对数据进行Base64解码

View File

@ -35,12 +35,12 @@
***
## 详情信息
#### func PathExist(path string) bool, error
#### func PathExist(path string) (bool, error)
<span id="PathExist"></span>
> 路径是否存在
***
#### func IsDir(path string) bool, error
#### func IsDir(path string) (bool, error)
<span id="IsDir"></span>
> 路径是否是文件夹
@ -50,7 +50,7 @@
> 向特定文件写入内容
***
#### func ReadOnce(filePath string) []byte, error
#### func ReadOnce(filePath string) ([]byte, error)
<span id="ReadOnce"></span>
> 单次读取文件
> - 一次性对整个文件进行读取,小文件读取可以很方便的一次性将文件内容读取出来,而大文件读取会造成性能影响。

View File

@ -36,7 +36,7 @@
***
## 详情信息
#### func NewPackage(dir string) *Package, error
#### func NewPackage(dir string) (*Package, error)
<span id="NewPackage"></span>
<details>

View File

@ -30,7 +30,7 @@
***
## 详情信息
#### func New(pkgDirPath string, output string) *Builder, error
#### func New(pkgDirPath string, output string) (*Builder, error)
<span id="New"></span>
***
@ -51,11 +51,11 @@ type Builder struct {
```go
func TestBuilder_Generate(t *testing.T) {
filepath.Walk("/Users/kercylan/Coding.localized/Go/minotaur", func(path string, info fs.FileInfo, err error) error {
filepath.Walk("D:/sources/minotaur", func(path string, info fs.FileInfo, err error) error {
if !info.IsDir() {
return nil
}
if strings.Contains(strings.TrimPrefix(path, "/Users/kercylan/Coding.localized/Go/minotaur"), ".") {
if strings.Contains(strings.TrimPrefix(path, "D:/sources/minotaur"), ".") {
return nil
}
b, err := New(path, filepath.Join(path, "README.md"))

View File

@ -163,7 +163,13 @@ func (b *Builder) genStructs() {
}
return f
}(),
funcHandler(function.Results),
func() string {
f := strings.TrimSpace(funcHandler(function.Results))
if len(function.Results) >= 2 && !strings.HasPrefix(f, "(") {
f = "(" + f + ")"
}
return f
}(),
)))
b.newLine(fmt.Sprintf(`<span id="%s"></span>`, function.Name))
b.quote()
@ -260,7 +266,13 @@ func (b *Builder) genStructs() {
}
return f
}(),
funcHandler(function.Results),
func() string {
f := funcHandler(function.Results)
if len(function.Results) >= 2 && !strings.HasPrefix(strings.TrimSpace(f), "(") {
f = "(" + f + ")"
}
return f
}(),
)))
b.quote()
for _, comment := range function.Comments.Clear {

View File

@ -16,11 +16,11 @@ func TestBuilder_Generate(t *testing.T) {
// panic(err)
//}
//return
filepath.Walk("/Users/kercylan/Coding.localized/Go/minotaur", func(path string, info fs.FileInfo, err error) error {
filepath.Walk("D:/sources/minotaur", func(path string, info fs.FileInfo, err error) error {
if !info.IsDir() {
return nil
}
if strings.Contains(strings.TrimPrefix(path, "/Users/kercylan/Coding.localized/Go/minotaur"), ".") {
if strings.Contains(strings.TrimPrefix(path, "D:/sources/minotaur"), ".") {
return nil
}
b, err := New(

View File

@ -795,7 +795,7 @@ func TestNewShapeWithString(t *testing.T) {
> 检查点是否在 edges 的任意一条边上
***
#### func ProjectionPointToShape(point Point[V], shape Shape[V]) Point[V], V
#### func ProjectionPointToShape(point Point[V], shape Shape[V]) (Point[V], V)
<span id="ProjectionPointToShape"></span>
> 将一个点投影到一个多边形上,找到离该点最近的投影点,并返回投影点和距离

View File

@ -137,7 +137,7 @@ func ExampleIsContinuity() {
> 将两个数字合并为一个 int64 数字
***
#### func UnMergeInt64(n int64) V, V
#### func UnMergeInt64(n int64) (V, V)
<span id="UnMergeInt64"></span>
> 将一个 int64 数字拆分为两个数字

View File

@ -80,7 +80,7 @@
> 创建一个用于数据取值去重的结构实例
***
#### func SonyflakeIDE() int64, error
#### func SonyflakeIDE() (int64, error)
<span id="SonyflakeIDE"></span>
> 获取一个雪花id

View File

@ -25,7 +25,7 @@
***
## 详情信息
#### func Topological(slice S, queryIndexHandler func (item V) Index, queryDependsHandler func (item V) []Index) S, error
#### func Topological(slice S, queryIndexHandler func (item V) Index, queryDependsHandler func (item V) []Index) (S, error)
<span id="Topological"></span>
> 拓扑排序是一种对有向图进行排序的算法,它可以用来解决一些依赖关系的问题,比如计算字段的依赖关系。拓扑排序会将存在依赖关系的元素进行排序,使得依赖关系的元素总是排在被依赖的元素之前。
> - slice: 需要排序的切片

View File

@ -135,14 +135,14 @@
> 返回将str进行千位分隔符处理后的字符串。
***
#### func KV(str string, tag ...string) string, string
#### func KV(str string, tag ...string) (string, string)
<span id="KV"></span>
> 返回str经过转换后形成的key、value
> - 这里tag表示使用什么字符串来区分key和value的分隔符。
> - 默认情况即不传入tag的情况下分隔符为“=”。
***
#### func FormatSpeedyInt(numberStr string) int, error
#### func FormatSpeedyInt(numberStr string) (int, error)
<span id="FormatSpeedyInt"></span>
> 返回numberStr经过格式化后去除空格和“,”分隔符的结果
> - 当字符串为“123,456,789”的时候返回结果为“123456789”。
@ -150,7 +150,7 @@
> - 当字符串为“1 23, 45 6, 789”的时候返回结果为“123456789”。
***
#### func FormatSpeedyInt64(numberStr string) int64, error
#### func FormatSpeedyInt64(numberStr string) (int64, error)
<span id="FormatSpeedyInt64"></span>
> 返回numberStr经过格式化后去除空格和“,”分隔符的结果
> - 当字符串为“123,456,789”的时候返回结果为“123456789”。
@ -158,7 +158,7 @@
> - 当字符串为“1 23, 45 6, 789”的时候返回结果为“123456789”。
***
#### func FormatSpeedyFloat32(numberStr string) float64, error
#### func FormatSpeedyFloat32(numberStr string) (float64, error)
<span id="FormatSpeedyFloat32"></span>
> 返回numberStr经过格式化后去除空格和“,”分隔符的结果
> - 当字符串为“123,456,789.123”的时候返回结果为“123456789.123”。
@ -166,7 +166,7 @@
> - 当字符串为“1 23, 45 6, 789.123”的时候返回结果为“123456789.123”。
***
#### func FormatSpeedyFloat64(numberStr string) float64, error
#### func FormatSpeedyFloat64(numberStr string) (float64, error)
<span id="FormatSpeedyFloat64"></span>
> 返回numberStr经过格式化后去除空格和“,”分隔符的结果
> - 当字符串为“123,456,789.123”的时候返回结果为“123456789.123”。

View File

@ -132,7 +132,7 @@
> - 引用将会被重定向到注册的错误信息
***
#### func GetError(err error) int, error
#### func GetError(err error) (int, error)
<span id="GetError"></span>
> 通过错误引用获取错误码和真实错误信息,如果错误不存在则返回 0如果错误引用不存在则返回原本的错误
@ -204,7 +204,7 @@ func ExampleRecoverTransform() {
> - 当转换失败时,将返回 json 格式的空对象
***
#### func MarshalJSONE(v interface {}) []byte, error
#### func MarshalJSONE(v interface {}) ([]byte, error)
<span id="MarshalJSONE"></span>
> 将对象转换为 json
> - 当转换失败时,将返回错误信息
@ -901,7 +901,7 @@ func TestBitSet_Shrink(t *testing.T) {
#### func (*BitSet) String() string
> 返回当前 BitSet 的字符串表示
***
#### func (*BitSet) MarshalJSON() []byte, error
#### func (*BitSet) MarshalJSON() ( []byte, error)
> 实现 json.Marshaler 接口
***
#### func (*BitSet) UnmarshalJSON(data []byte) error