Skip to content

Commit f52ddd5

Browse files
committed
style: gofmt -w -r 'interface{} -> any'
1 parent 9f16ac0 commit f52ddd5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+147
-135
lines changed

apidoc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ func ServeLSP(header bool, t, addr string, timeout time.Duration, info, erro *lo
101101
// stylesheet 表示是否只展示 XSL 及相关的内容。
102102
//
103103
// 用户可以通过以下代码搭建一个简易的 https://apidoc.tools 网站:
104-
// http.Handle("/apidoc", apidoc.Static(...))
104+
//
105+
// http.Handle("/apidoc", apidoc.Static(...))
105106
func Static(dir core.URI, stylesheet bool, erro *log.Logger) http.Handler {
106107
return docs.Handler(dir, stylesheet, erro)
107108
}

cmd/apidoc/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
// apidoc 是一个 RESTful API 文档生成工具
44
//
55
// 大致的使用方法为:
6-
// apidoc cmd [args]
6+
//
7+
// apidoc cmd [args]
8+
//
79
// 其中的 cmd 为子命令,args 代码传递给该子命令的参数。
810
// 可以使用 help 查看每个子命令的具体说明:
9-
// apidoc help [cmd]
11+
//
12+
// apidoc help [cmd]
1013
package main
1114

1215
import (

core/core.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121

2222
// Searcher 实现了搜索的基本方法集合
2323
//
24-
// 所有内嵌 Location 的对象都可以使用此接口判断是否内嵌 Location。
24+
// 所有内嵌 [Location] 的对象都可以使用此接口判断是否内嵌 [Location]
2525
type Searcher interface {
2626
Contains(URI, Position) bool
2727
Loc() Location

core/errors.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const (
4646
)
4747

4848
// NewHTTPError 声明 HTTPError 实例
49-
func NewHTTPError(code int, key message.Reference, v ...interface{}) *HTTPError {
49+
func NewHTTPError(code int, key message.Reference, v ...any) *HTTPError {
5050
return &HTTPError{
5151
Err: locale.Err{Key: key, Values: v},
5252
Code: code,
@@ -112,7 +112,7 @@ func (err *Error) AddTypes(t ...ErrorType) *Error {
112112
}
113113

114114
// NewError 返回 *Error 实例
115-
func NewError(key message.Reference, v ...interface{}) *Error {
115+
func NewError(key message.Reference, v ...any) *Error {
116116
return &Error{Err: locale.NewError(key, v...)}
117117
}
118118

@@ -131,7 +131,7 @@ func WithError(err error) *Error {
131131
// NewError 在当前位置生成语法错误信息
132132
//
133133
// 其中的 msg 和 val 会被转换成本地化的内容保存。
134-
func (l Location) NewError(key message.Reference, v ...interface{}) *Error {
134+
func (l Location) NewError(key message.Reference, v ...any) *Error {
135135
return &Error{Err: locale.NewError(key, v...), Location: l}
136136
}
137137

core/message.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (t MessageType) String() string {
3737
// Message 输出消息的具体结构
3838
type Message struct {
3939
Type MessageType
40-
Message interface{}
40+
Message any
4141
}
4242

4343
// HandlerFunc 错误处理函数
@@ -80,26 +80,26 @@ func (h *MessageHandler) Stop() {
8080
}
8181

8282
// Message 发送消息
83-
func (h *MessageHandler) Message(t MessageType, msg interface{}) {
83+
func (h *MessageHandler) Message(t MessageType, msg any) {
8484
h.messages <- &Message{
8585
Type: t,
8686
Message: msg,
8787
}
8888
}
8989

9090
// Locale 发送普通的文本信息
91-
func (h *MessageHandler) Locale(t MessageType, key message.Reference, val ...interface{}) {
91+
func (h *MessageHandler) Locale(t MessageType, key message.Reference, val ...any) {
9292
h.Message(t, locale.New(key, val...))
9393
}
9494

9595
// Error 发送错误类型的值
96-
func (h *MessageHandler) Error(err interface{}) { h.Message(Erro, err) }
96+
func (h *MessageHandler) Error(err any) { h.Message(Erro, err) }
9797

9898
// Warning 发送错误类型的值
99-
func (h *MessageHandler) Warning(err interface{}) { h.Message(Warn, err) }
99+
func (h *MessageHandler) Warning(err any) { h.Message(Warn, err) }
100100

101101
// Success 发送错误类型的值
102-
func (h *MessageHandler) Success(err interface{}) { h.Message(Succ, err) }
102+
func (h *MessageHandler) Success(err any) { h.Message(Succ, err) }
103103

104104
// Info 发送错误类型的值
105-
func (h *MessageHandler) Info(err interface{}) { h.Message(Info, err) }
105+
func (h *MessageHandler) Info(err any) { h.Message(Info, err) }

core/messagetest/messagetest.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ package messagetest
66
import "github.com/caixw/apidoc/v7/core"
77

88
type Result struct {
9-
Errors, Warns, Infos, Successes []interface{}
9+
Errors, Warns, Infos, Successes []any
1010
Handler *core.MessageHandler
1111
}
1212

1313
// NewMessageHandler 返回一个用于测试的 core.MessageHandler 实例
1414
func NewMessageHandler() *Result {
1515
rslt := &Result{
16-
Errors: []interface{}{},
17-
Warns: []interface{}{},
18-
Infos: []interface{}{},
19-
Successes: []interface{}{},
16+
Errors: []any{},
17+
Warns: []any{},
18+
Infos: []any{},
19+
Successes: []any{},
2020
}
2121

2222
rslt.Handler = core.NewMessageHandler(func(msg *core.Message) {

core/uri.go

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ package core
44

55
import (
66
"errors"
7+
"io"
78
"io/fs"
8-
"io/ioutil"
99
"net/http"
1010
"net/url"
1111
"os"
@@ -27,23 +27,23 @@ const (
2727
separator = "://"
2828
)
2929

30-
// URI 定义 URI
30+
// URI 定义 [URI]
3131
//
32-
// http://tools.ietf.org/html/rfc3986
33-
//
34-
// foo://example.com:8042/over/there?name=ferret#nose
35-
// \_/ \______________/\_________/ \_________/ \__/
36-
// | | | | |
37-
// scheme authority path query fragment
38-
// | _____________________|__
39-
// / \ / \
40-
// urn:example:animal:ferret:nose
32+
// foo://example.com:8042/over/there?name=ferret#nose
33+
// \_/ \______________/\_________/ \_________/ \__/
34+
// | | | | |
35+
// scheme authority path query fragment
36+
// | _____________________|__
37+
// / \ / \
38+
// urn:example:animal:ferret:nose
4139
//
4240
// 如果是本地相对路径,也可以直接使用 `./path/file` 的形式表示,
4341
// 不需要指定协议。
4442
//
4543
// NOTE: 并非完整的 URI 实现,仅作为了 file:// 和 http:// 支持,
4644
// 也提供对 windows 路径的支持。
45+
//
46+
// [URI]: http://tools.ietf.org/html/rfc3986
4747
type URI string
4848

4949
// FileURI 根据本地文件路径构建 URI 实例
@@ -56,7 +56,6 @@ func FileURI(path string) URI {
5656
return URI(SchemeFile + separator + path)
5757
}
5858

59-
// UnmarshalJSON 实现对非 ascii 字符的解码
6059
func (uri *URI) UnmarshalJSON(v []byte) error {
6160
if len(v) <= 2 {
6261
return locale.NewError(locale.ErrInvalidURI, string(v))
@@ -80,9 +79,7 @@ func (uri URI) File() (string, error) {
8079
return "", locale.NewError(locale.ErrInvalidURIScheme, scheme)
8180
}
8281

83-
func (uri URI) String() string {
84-
return string(uri)
85-
}
82+
func (uri URI) String() string { return string(uri) }
8683

8784
// Append 追加 path 至 URI 生成新的 URI
8885
func (uri URI) Append(path string) URI {
@@ -106,9 +103,7 @@ func (uri URI) Append(path string) URI {
106103
return uri + URI(path)
107104
}
108105

109-
func isPathSeparator(b byte) bool {
110-
return b == '/' || b == os.PathSeparator
111-
}
106+
func isPathSeparator(b byte) bool { return b == '/' || b == os.PathSeparator }
112107

113108
// Exists 判断 uri 指向的内容是否存在
114109
//
@@ -145,7 +140,7 @@ func (uri URI) ReadAll(enc encoding.Encoding) ([]byte, error) {
145140
func (uri URI) WriteAll(data []byte) error {
146141
scheme, path := uri.Parse()
147142
if scheme == SchemeFile || scheme == "" {
148-
return ioutil.WriteFile(path, data, os.ModePerm)
143+
return os.WriteFile(path, data, os.ModePerm)
149144
}
150145
return locale.NewError(locale.ErrInvalidURIScheme, scheme)
151146
}
@@ -171,7 +166,7 @@ func remoteFileIsExists(url string) (bool, error) {
171166
// 以指定的编码方式读取本地文件内容
172167
func readLocalFile(path string, enc encoding.Encoding) ([]byte, error) {
173168
if enc == nil || enc == encoding.Nop {
174-
return ioutil.ReadFile(path)
169+
return os.ReadFile(path)
175170
}
176171

177172
r, err := os.Open(path)
@@ -181,7 +176,7 @@ func readLocalFile(path string, enc encoding.Encoding) ([]byte, error) {
181176
defer r.Close()
182177

183178
reader := transform.NewReader(r, enc.NewDecoder())
184-
return ioutil.ReadAll(reader)
179+
return io.ReadAll(reader)
185180
}
186181

187182
// 以指定的编码方式读取远程文件内容
@@ -197,8 +192,8 @@ func readRemoteFile(url string, enc encoding.Encoding) ([]byte, error) {
197192
}
198193

199194
if enc == nil || enc == encoding.Nop {
200-
return ioutil.ReadAll(resp.Body)
195+
return io.ReadAll(resp.Body)
201196
}
202197
reader := transform.NewReader(resp.Body, enc.NewDecoder())
203-
return ioutil.ReadAll(reader)
198+
return io.ReadAll(reader)
204199
}

core/version.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ func init() {
1717
// FullVersion 完整的版本号
1818
//
1919
// 会包含版本号、构建日期和最后的提交 ID,大致格式如下:
20-
// version+buildDate.commitHash
20+
//
21+
// version+buildDate.commitHash
2122
func FullVersion() string {
2223
return fullVersion
2324
}

internal/ast/ast.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ type (
8282
// Reference 指向引用父对象的数据
8383
Reference struct {
8484
core.Location
85-
Target interface{} // 引用当前父对象的实际数据
85+
Target any // 引用当前父对象的实际数据
8686
}
8787

8888
// Definition 指向父对象的实际定义数据
8989
Definition struct {
9090
core.Location
91-
Target interface{} // 父对象数据定义内容
91+
Target any // 父对象数据定义内容
9292
}
9393

9494
// Referencer 包含了 Reference 数据需要实现的接口

internal/ast/asttest/make.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: MIT
22

3+
//go:build ignore
34
// +build ignore
45

56
package main

internal/cmd/cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type printer struct {
5151

5252
type uri core.URI
5353

54-
func (u uri) Get() interface{} { return string(u) }
54+
func (u uri) Get() any { return string(u) }
5555

5656
func (u *uri) Set(v string) error {
5757
*u = uri(core.FileURI(v))
@@ -94,7 +94,7 @@ func messageHandle(msg *core.Message) {
9494
printers[msg.Type].print(msg.Message)
9595
}
9696

97-
func (p *printer) print(msg interface{}) {
97+
func (p *printer) print(msg any) {
9898
if _, err := colors.Fprint(p.out, colors.Normal, p.color, colors.Default, locale.New(p.prefix)); err != nil {
9999
panic(err)
100100
}

internal/cmd/mock.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type (
2828
}
2929
)
3030

31-
func (s servers) Get() interface{} {
31+
func (s servers) Get() any {
3232
return map[string]string(s)
3333
}
3434

@@ -66,7 +66,7 @@ func (s servers) String() string {
6666
return buf.String()
6767
}
6868

69-
func (r size) Get() interface{} {
69+
func (r size) Get() any {
7070
return r
7171
}
7272

@@ -99,7 +99,7 @@ func (r *size) String() string {
9999
return strconv.Itoa(r.Min) + "," + strconv.Itoa(r.Max)
100100
}
101101

102-
func (s slice) Get() interface{} {
102+
func (s slice) Get() any {
103103
return []string(s)
104104
}
105105

@@ -112,7 +112,7 @@ func (s *slice) String() string {
112112
return strings.Join(*s, ",")
113113
}
114114

115-
func (d dateRange) Get() interface{} {
115+
func (d dateRange) Get() any {
116116
return d
117117
}
118118

internal/docs/make_site.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: MIT
22

3+
//go:build ignore
34
// +build ignore
45

56
package main

internal/docs/site/site.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func Write(target core.URI) error {
9898
return nil
9999
}
100100

101-
func writeXML(uri core.URI, v interface{}, indent string) error {
101+
func writeXML(uri core.URI, v any, indent string) error {
102102
data, err := xml.MarshalIndent(v, "", indent)
103103
if err != nil {
104104
return err

internal/docs/site/spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/caixw/apidoc/v7/internal/node"
1111
)
1212

13-
func (d *doc) newSpec(v interface{}) error {
13+
func (d *doc) newSpec(v any) error {
1414
n := node.New("", reflect.ValueOf(v))
1515
if err := d.dumpToTypes(n); err != nil {
1616
return err

internal/lang/block.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,12 @@ func (b *multipleComment) endFunc(l *parser) (data []byte, ok bool) {
133133
// 转换单行注释为一个合法的 XML
134134
//
135135
// 主要是去掉了注释符号,比如
136-
// // xx
136+
//
137+
// // xx
138+
//
137139
// 会被转换成
138-
// xx
140+
//
141+
// xx
139142
func convertSingleCommentToXML(lines, begin []byte) []byte {
140143
data := make([]byte, 0, len(lines))
141144

internal/lang/swift.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ type swiftNestMCommentBlock struct {
1313
}
1414

1515
// prefix 表示每一行的前缀符号,比如:
16-
// /*
17-
// *
18-
// */
16+
//
17+
// /*
18+
// *
19+
// */
20+
//
1921
// 中的 * 字符
2022
func newSwiftNestMCommentBlock(begin, end, prefix string) blocker {
2123
return &swiftNestMCommentBlock{

0 commit comments

Comments
 (0)