From 81230bd7a458b165cd5e4a38432eb7900ed90ad2 Mon Sep 17 00:00:00 2001 From: caixw Date: Thu, 2 Jun 2022 12:25:05 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/codeql-analysis.yml | 6 +++--- .github/workflows/test.yml | 2 +- CHANGELOG.md | 6 ++++++ apidoc.go | 12 +++-------- core/core.go | 8 ++----- core/message.go | 16 ++++---------- core/uri.go | 4 +++- go.mod | 16 +++++++------- go.sum | 31 ++++++++++++++------------- internal/cmd/cmd.go | 14 ++++-------- internal/lexer/lexer.go | 13 +++-------- internal/lexer/position.go | 12 +++-------- internal/locale/locale.go | 4 +--- internal/xmlenc/decode.go | 6 +++--- internal/xmlenc/encode.go | 4 ++-- 15 files changed, 62 insertions(+), 92 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 6a261186..6fc54373 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -43,7 +43,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -54,7 +54,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -68,4 +68,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8b0bff48..157caec5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest, windows-latest] - go: ['1.18.0-beta2'] + go: ['1.18.x'] steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f5b8c22..72d98770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## [unreleased] +## [v7.2.4] + +### Changed + +- 仅支持 go1.18 版本; + ## [v7.2.3] ### Added diff --git a/apidoc.go b/apidoc.go index 7dcec44b..6716206b 100644 --- a/apidoc.go +++ b/apidoc.go @@ -39,19 +39,13 @@ type Config = build.Config // 如果不调用此函数,则默认会采用 internal/locale.DefaultLocaleID 的值。 // 如果想采用当前系统的本地化信息,可以使用 // github.com/issue9/localeutil.SystemLanguageTag 函数。 -func SetLocale(tag language.Tag) { - locale.SetTag(tag) -} +func SetLocale(tag language.Tag) { locale.SetTag(tag) } // Locale 获取当前设置的本地化 ID -func Locale() language.Tag { - return locale.Tag() -} +func Locale() language.Tag { return locale.Tag() } // Locales 返回当前所有支持的本地化信息 -func Locales() []language.Tag { - return locale.Tags() -} +func Locales() []language.Tag { return locale.Tags() } // Version 当前程序的版本号 // diff --git a/core/core.go b/core/core.go index 5f52d2b9..ee7c0b9b 100644 --- a/core/core.go +++ b/core/core.go @@ -70,9 +70,7 @@ func (r Range) Equal(v Range) bool { } // IsEmpty 表示 Range 表示的范围长度为空 -func (r Range) IsEmpty() bool { - return r.End == r.Start -} +func (r Range) IsEmpty() bool { return r.End == r.Start } // Contains 是否包含了 p 这个点 func (r Range) Contains(p Position) bool { @@ -83,9 +81,7 @@ func (r Range) Contains(p Position) bool { } // Loc 返回当前的范围 -func (l Location) Loc() Location { - return l -} +func (l Location) Loc() Location { return l } // Contains l 是否包含 pos 这个点 func (l Location) Contains(uri URI, pos Position) bool { diff --git a/core/message.go b/core/message.go index ef9e8242..9d694040 100644 --- a/core/message.go +++ b/core/message.go @@ -93,21 +93,13 @@ func (h *MessageHandler) Locale(t MessageType, key message.Reference, val ...int } // Error 发送错误类型的值 -func (h *MessageHandler) Error(err interface{}) { - h.Message(Erro, err) -} +func (h *MessageHandler) Error(err interface{}) { h.Message(Erro, err) } // Warning 发送错误类型的值 -func (h *MessageHandler) Warning(err interface{}) { - h.Message(Warn, err) -} +func (h *MessageHandler) Warning(err interface{}) { h.Message(Warn, err) } // Success 发送错误类型的值 -func (h *MessageHandler) Success(err interface{}) { - h.Message(Succ, err) -} +func (h *MessageHandler) Success(err interface{}) { h.Message(Succ, err) } // Info 发送错误类型的值 -func (h *MessageHandler) Info(err interface{}) { - h.Message(Info, err) -} +func (h *MessageHandler) Info(err interface{}) { h.Message(Info, err) } diff --git a/core/uri.go b/core/uri.go index d03a40a8..bb825417 100644 --- a/core/uri.go +++ b/core/uri.go @@ -3,6 +3,8 @@ package core import ( + "errors" + "io/fs" "io/ioutil" "net/http" "net/url" @@ -116,7 +118,7 @@ func (uri URI) Exists() (bool, error) { switch scheme { case SchemeFile, "": _, err := os.Stat(path) - return (err == nil || os.IsExist(err)), nil + return err == nil || errors.Is(err, fs.ErrExist), nil case SchemeHTTP, SchemeHTTPS: return remoteFileIsExists(string(uri)) default: diff --git a/go.mod b/go.mod index 50104155..7bce2f03 100644 --- a/go.mod +++ b/go.mod @@ -1,28 +1,28 @@ module github.com/caixw/apidoc/v7 require ( - github.com/issue9/assert/v2 v2.2.1 + github.com/issue9/assert/v2 v2.3.2 github.com/issue9/cmdopt v0.7.2 github.com/issue9/errwrap v0.2.1 github.com/issue9/jsonrpc v0.12.1 - github.com/issue9/localeutil v0.9.0 - github.com/issue9/mux/v6 v6.0.0-beta.6 + github.com/issue9/localeutil v0.12.0 + github.com/issue9/mux/v6 v6.1.1 github.com/issue9/qheader v0.5.5 github.com/issue9/rands v1.2.0 - github.com/issue9/sliceutil v0.8.0 + github.com/issue9/sliceutil v0.10.1 github.com/issue9/source v0.1.2 - github.com/issue9/term/v2 v2.1.5 - github.com/issue9/validation v0.5.1 + github.com/issue9/term/v3 v3.0.0 + github.com/issue9/validation v0.6.1 github.com/issue9/version v1.0.5 golang.org/x/text v0.3.7 - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.0 ) require ( github.com/gorilla/websocket v1.4.2 // indirect github.com/issue9/autoinc v1.0.8 // indirect github.com/issue9/unique v1.3.1 // indirect - golang.org/x/sys v0.0.0-20211123173158-ef496fb156ab // indirect + golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect ) go 1.18 diff --git a/go.sum b/go.sum index 9abaa006..d1dfe4a0 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,9 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/issue9/assert/v2 v2.0.0/go.mod h1:rKr1eVGzXUhAo2af1thiKAhIA8uiSK9Wyn7mcZ4BzAg= -github.com/issue9/assert/v2 v2.2.1 h1:XQEnAFrGiT1Z55Tav39muM/Jg9ECiSLm7ehHQWoCHmA= github.com/issue9/assert/v2 v2.2.1/go.mod h1:rKr1eVGzXUhAo2af1thiKAhIA8uiSK9Wyn7mcZ4BzAg= +github.com/issue9/assert/v2 v2.3.2 h1:J8TxGeak/CvrMchXHjs9CFChsZvpX0hGE/HTnwT6L+8= +github.com/issue9/assert/v2 v2.3.2/go.mod h1:rKr1eVGzXUhAo2af1thiKAhIA8uiSK9Wyn7mcZ4BzAg= github.com/issue9/autoinc v1.0.8 h1:Vpi4ElzJOxyNKqw9wIsvNOSoh1xL9CNOp9vVQzouztI= github.com/issue9/autoinc v1.0.8/go.mod h1:5LsFXszqd49znHXyPng+wFt6TYom5jCZoYNinFoKGgc= github.com/issue9/cmdopt v0.7.2 h1:riBT70kOOU00rKmP4vseFI7hfDZBO0l00FosVcexWH8= @@ -11,33 +12,33 @@ github.com/issue9/errwrap v0.2.1 h1:hrzBGbOCRs8acitpWSg54xNl2oaLGA/WZEf71bKaiEU= github.com/issue9/errwrap v0.2.1/go.mod h1:hjjkt9S/owgy48er68ACFfA6YPDO/xax18QE3lsguVQ= github.com/issue9/jsonrpc v0.12.1 h1:HApT4tU8icb1iRStCidMvQfZvKI4MHZYipsAkPNsDQU= github.com/issue9/jsonrpc v0.12.1/go.mod h1:uRoxqflqgG/+R9B2Axwsc9OG85TwmdSlJSZwjULwVBc= -github.com/issue9/localeutil v0.9.0 h1:SeNzwzr/t1JfuVGt6xq6NXc/+RyWcLhT7etFIH3gUQc= -github.com/issue9/localeutil v0.9.0/go.mod h1:VDMtz5Y+YJopG+ibgDvrITYkGYC0WxrH20LOWIgTs9g= -github.com/issue9/mux/v6 v6.0.0-beta.6 h1:ZcIt/HEHzplZcYTTmmTMdj49DXrYOpj3Nb5/biFemp8= -github.com/issue9/mux/v6 v6.0.0-beta.6/go.mod h1:UX37BZvI3OEe20S2Jrw6LizgDnqO99NHqGXuVhzZ/7U= +github.com/issue9/localeutil v0.12.0 h1:1YaBHkEs4LwSA/HES+mwW+JAmAvAx209kNEMDRMJIno= +github.com/issue9/localeutil v0.12.0/go.mod h1:QkjGsEjoAqW66rwDZnTjjaUZUE4vQiD8OnxuPX3SbGY= +github.com/issue9/mux/v6 v6.1.1 h1:QV8pWb31nS3BmaOjv5w6GQv9PM5pusVM4ctKzxSsPj8= +github.com/issue9/mux/v6 v6.1.1/go.mod h1:ZYVzLEcesR+Hj/42c78lsFtUWKhSPXG+87j0x+Q9F74= github.com/issue9/qheader v0.5.5 h1:6LxVoqnxIthEuoZn2rFBGxOdoxN9gh+n1GI1TiGQe4Q= github.com/issue9/qheader v0.5.5/go.mod h1:oZVXJYWaO2ha6yFlYPrdkTpEpg8InAIRo65fGytoWRo= github.com/issue9/rands v1.2.0 h1:gXxfhibkFTIhg9M57jsH9BcuCe7rpNMEpuTAzSGr7bk= github.com/issue9/rands v1.2.0/go.mod h1:Bayx3LQFKasAHNTGVN3APtfeoNATAdNwWUN3b4X8Blw= github.com/issue9/sliceutil v0.7.1/go.mod h1:8e+l2bD67pBUtV8cVnGChE/Ltlq8czcDLR1pOGCC2tE= -github.com/issue9/sliceutil v0.8.0 h1:a6I3vXPXMXkLw5Vhmz5+cD4kaiO+vWNBzZ/CUJ14slk= -github.com/issue9/sliceutil v0.8.0/go.mod h1:zzOSPwPHTsowvoCCx2RqCxQvPTKsxlb5eaPWWbSNAQ8= +github.com/issue9/sliceutil v0.10.1 h1:zoI2YWYSaAcp1uQUNSiApVVlOHF+wBjTOMrB8AnwIbE= +github.com/issue9/sliceutil v0.10.1/go.mod h1:zzOSPwPHTsowvoCCx2RqCxQvPTKsxlb5eaPWWbSNAQ8= github.com/issue9/source v0.1.2 h1:Y70bsJOy9ks5MjY9O/3UnYsEu0a6lkzVm2AHQsqOl9c= github.com/issue9/source v0.1.2/go.mod h1:HPkW33uwl4Kew44lERZ1jzV9Hr+a9Z32IaxgQPJKuPY= -github.com/issue9/term/v2 v2.1.5 h1:qU8C5Y7Zbv7amINkUirs/dtFxislNdW7QGHAuzssOX4= -github.com/issue9/term/v2 v2.1.5/go.mod h1:BA5+fQqPopRYlYfW3+NNmArSsHyPOmrsKksPh34DRdE= +github.com/issue9/term/v3 v3.0.0 h1:MJ0eavCCqZ9lv2souDyCkSDeVo3XM9auqFVE0s2Esos= +github.com/issue9/term/v3 v3.0.0/go.mod h1:D/UzioFydVy7DKLRit8ttJdGDkAa1Ni5fA9ZDWVD3lw= github.com/issue9/unique v1.3.1 h1:OfM05QsuhKhLrHSUhwTFCBmQaqptwpUk1S5r6xZvaZU= github.com/issue9/unique v1.3.1/go.mod h1:kXuutx4Mj60iR2/bCk4tAoXqxuO081rxIJjn+MucJRc= -github.com/issue9/validation v0.5.1 h1:olnraMrm4aKqkT60ILUVIJH3alZNLhEU/8NkCQJ7Ab4= -github.com/issue9/validation v0.5.1/go.mod h1:xi4eqjEdtwTXi4wepoyi68tvdYpSYzuU4JyVN9piFXA= +github.com/issue9/validation v0.6.1 h1:sbTiTgQ+RtWRepQTTiE52Ss8yqxBob3y6VG6Q9WYpJQ= +github.com/issue9/validation v0.6.1/go.mod h1:dFQbBVlr2dqd/7AippilmGK/tv/yT3aqtXVsRUIxPl4= github.com/issue9/version v1.0.5 h1:y4JRHcAM0nXMBju9Vhe13Wv08KP/uNveP4uwg3Wknh8= github.com/issue9/version v1.0.5/go.mod h1:bgni2RNBbtygajgpVeqBiEXT9JZjkLCuYJ4ceoSXjYo= -golang.org/x/sys v0.0.0-20211123173158-ef496fb156ab h1:rfJ1bsoJQQIAoAxTxB7bme+vHrNkRw8CqfsYh9w54cw= -golang.org/x/sys v0.0.0-20211123173158-ef496fb156ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index eac3e00d..0b8a5ab4 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -10,7 +10,7 @@ import ( "os" "github.com/issue9/cmdopt" - "github.com/issue9/term/v2/colors" + "github.com/issue9/term/v3/colors" "golang.org/x/text/message" "github.com/caixw/apidoc/v7/core" @@ -51,22 +51,16 @@ type printer struct { type uri core.URI -func (u uri) Get() interface{} { - return string(u) -} +func (u uri) Get() interface{} { return string(u) } func (u *uri) Set(v string) error { *u = uri(core.FileURI(v)) return nil } -func (u *uri) String() string { - return core.URI(*u).String() -} +func (u *uri) String() string { return core.URI(*u).String() } -func (u uri) URI() core.URI { - return core.URI(u) -} +func (u uri) URI() core.URI { return core.URI(u) } // Init 初始化 cmdopt.CmdOpt 实例 func Init(out io.Writer) *cmdopt.CmdOpt { diff --git a/internal/lexer/lexer.go b/internal/lexer/lexer.go index 5d48ed4d..cf2d3cab 100644 --- a/internal/lexer/lexer.go +++ b/internal/lexer/lexer.go @@ -67,10 +67,7 @@ func BlockEndPosition(b core.Block) (Position, error) { return p, nil } -// AtEOF 是否已经结束 -func (l *Lexer) AtEOF() bool { - return l.Current().Offset > l.lastIndex -} +func (l *Lexer) AtEOF() bool { return l.Current().Offset > l.lastIndex } // Match 接下来的 n 个字符是否匹配指定的字符串, // 若匹配,则将指定移向该字符串这后,否则不作任何操作。 @@ -97,9 +94,7 @@ func (l *Lexer) Match(word string) bool { } // Current 返回当前在 data 中的偏移量 -func (l *Lexer) Current() Position { - return l.current -} +func (l *Lexer) Current() Position { return l.current } // Move 移动当前的分析器的位置 // @@ -257,6 +252,4 @@ func (l *Lexer) Rollback() { // Bytes 返回指定范围的内容 // // NOTE: 并不会改变定位信息 -func (l *Lexer) Bytes(start, end int) []byte { - return l.Data[start:end] -} +func (l *Lexer) Bytes(start, end int) []byte { return l.Data[start:end] } diff --git a/internal/lexer/position.go b/internal/lexer/position.go index e612852c..bb221143 100644 --- a/internal/lexer/position.go +++ b/internal/lexer/position.go @@ -18,19 +18,13 @@ type Position struct { } // Equal 判断与 v 是否相等 -func (p Position) Equal(v Position) bool { - return p.Offset == v.Offset -} +func (p Position) Equal(v Position) bool { return p.Offset == v.Offset } // AddRune 向后移动一个字符 -func (p Position) AddRune(r rune) Position { - return p.add(r, utf8.RuneLen(r)) -} +func (p Position) AddRune(r rune) Position { return p.add(r, utf8.RuneLen(r)) } // SubRune 向前移动一个字符 -func (p Position) SubRune(r rune) Position { - return p.sub(r, utf8.RuneLen(r)) -} +func (p Position) SubRune(r rune) Position { return p.sub(r, utf8.RuneLen(r)) } // 将 p 的定位回滚一个文字 r // diff --git a/internal/locale/locale.go b/internal/locale/locale.go index 4770d0a5..435655a1 100644 --- a/internal/locale/locale.go +++ b/internal/locale/locale.go @@ -65,9 +65,7 @@ func SetTag(tag language.Tag) { } // Tag 获取当前的本地化 ID -func Tag() language.Tag { - return localeTag -} +func Tag() language.Tag { return localeTag } // Tags 所有支持语言的列表 func Tags() []language.Tag { diff --git a/internal/xmlenc/decode.go b/internal/xmlenc/decode.go index af730c98..4f45e60f 100644 --- a/internal/xmlenc/decode.go +++ b/internal/xmlenc/decode.go @@ -18,7 +18,7 @@ import ( type ( // Decoder 实现从 p 中解码内容到当前对象的值 Decoder interface { - // 从 p 中读取内容并实例化到当前对象中 + // DecodeXML 从 p 中读取内容并实例化到当前对象中 // // 必须要同时从 p 中读取相应的 EndElement 才能返回。 // end 表示 EndElement.End 的值。 @@ -31,7 +31,7 @@ type ( // AttrDecoder 实现从 attr 中解码内容到当前对象的值 AttrDecoder interface { - // 解析属性值 + // DecodeXMLAttr 解析属性值 // // 接口应该只返回 *core.Error 作为错误对象。 DecodeXMLAttr(p *Parser, attr *Attribute) error @@ -39,7 +39,7 @@ type ( // Sanitizer 用于验证和修改对象中的数据 Sanitizer interface { - // 验证数据是否正确 + // Sanitize 验证数据是否正确 // // 可以通过 p.Error 等方法输出错误信息 Sanitize(p *Parser) diff --git a/internal/xmlenc/encode.go b/internal/xmlenc/encode.go index 60e5fd1e..192a7e7b 100644 --- a/internal/xmlenc/encode.go +++ b/internal/xmlenc/encode.go @@ -15,13 +15,13 @@ import ( // Encoder 将元素内容编码成 XML 内容 type Encoder interface { - // 仅需要返回元素内容的 XML 编码,不需要包含本身的标签和属性。 + // EncodeXML 仅需要返回元素内容的 XML 编码,不需要包含本身的标签和属性。 EncodeXML() (string, error) } // AttrEncoder 将属性值编码成符合 XML 规范的值 type AttrEncoder interface { - // 仅需要返回属性的 XML 表示,不需要包含属性值的引号字符。 + // EncodeXMLAttr 仅需要返回属性的 XML 表示,不需要包含属性值的引号字符。 EncodeXMLAttr() (string, error) }