Skip to content

Commit

Permalink
chore: 依赖库更新至泛型版本
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Feb 20, 2022
1 parent f1953c5 commit 3c27f8b
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x
go-version: 1.18.x
id: go

- name: Check out code into the Go module directory
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
go: ['1.17.x', '1.16.x']
go: ['1.18.0-beta2']

steps:

- name: Set git to use LF
Expand All @@ -25,6 +25,7 @@ jobs:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v2
with:
stable: '!contains(${{ matrix.go }}, "beta") && !contains(${{ matrix.go }}, "rc")'
go-version: ${{ matrix.go }}
id: go

Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# CHANGELOG

## [Unreleased]
## [unreleased]

## [v7.2.3]

### Added

Expand Down
4 changes: 2 additions & 2 deletions apidoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func Buffer(h *core.MessageHandler, o *build.Output, i ...*build.Input) (*bytes.
}

// CheckSyntax 测试文档语法
func CheckSyntax(h *core.MessageHandler, i ...*build.Input) {
build.CheckSyntax(h, i...)
func CheckSyntax(h *core.MessageHandler, i ...*build.Input) error {
return build.CheckSyntax(h, i...)
}

// ServeLSP 提供 language server protocol 服务
Expand Down
2 changes: 1 addition & 1 deletion build/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (o *Input) recursivePath() error {

func (o *Input) isIgnore(root, path string) (bool, error) {
ext := filepath.Ext(path)
if sliceutil.Count(o.Exts, func(i int) bool { return o.Exts[i] == ext }) == 0 {
if sliceutil.Count(o.Exts, func(i string) bool { return i == ext }) == 0 {
return true, nil
}

Expand Down
10 changes: 3 additions & 7 deletions core/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,10 @@ func (err *Error) Error() string {
}

// Unwrap 实现 errors.Unwrap 接口
func (err *Error) Unwrap() error {
return err.Err
}
func (err *Error) Unwrap() error { return err.Err }

// Is 实现 errors.Is 接口
func (err *Error) Is(target error) bool {
return err.Err == target
}
func (err *Error) Is(target error) bool { return err.Err == target }

// Relate 添加关联的错误信息
func (err *Error) Relate(loc Location, msg string) *Error {
Expand Down Expand Up @@ -107,7 +103,7 @@ func (err *Error) AddTypes(t ...ErrorType) *Error {
}

for _, typ := range t {
if sliceutil.Count(err.Types, func(i int) bool { return err.Types[i] == typ }) <= 0 {
if sliceutil.Count(err.Types, func(i ErrorType) bool { return i == typ }) <= 0 {
err.Types = append(err.Types, typ)
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/example/index.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet type="text/xsl" href="../v6/apidoc.xsl"?>
<apidoc apidoc="6.1.0" created="2021-04-07T23:54:42+08:00" version="1.1.1">
<apidoc apidoc="6.1.0" created="2022-02-20T23:19:19+08:00" version="1.1.1">
<title>示例文档</title>
<description type="html"><![CDATA[
<p>这是一个用于测试的文档用例</p>
Expand Down
19 changes: 13 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module github.com/caixw/apidoc/v7

require (
github.com/issue9/assert/v2 v2.0.0
github.com/issue9/cmdopt v0.7.1
github.com/issue9/assert/v2 v2.2.1
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.8.1
github.com/issue9/mux/v5 v5.1.2
github.com/issue9/localeutil v0.9.0
github.com/issue9/mux/v6 v6.0.0-beta.6
github.com/issue9/qheader v0.5.5
github.com/issue9/rands v1.2.0
github.com/issue9/sliceutil v0.7.1
github.com/issue9/sliceutil v0.8.0
github.com/issue9/source v0.1.2
github.com/issue9/term/v2 v2.1.5
github.com/issue9/validation v0.5.1
Expand All @@ -18,4 +18,11 @@ require (
gopkg.in/yaml.v2 v2.4.0
)

go 1.16
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
)

go 1.18
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
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 h1:vN7fr70g5ND6zM39tPZk/E4WCyjGMqApmFbujSTmEo0=
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/autoinc v1.0.8 h1:Vpi4ElzJOxyNKqw9wIsvNOSoh1xL9CNOp9vVQzouztI=
github.com/issue9/autoinc v1.0.8/go.mod h1:5LsFXszqd49znHXyPng+wFt6TYom5jCZoYNinFoKGgc=
github.com/issue9/cmdopt v0.7.1 h1:Jle2Be9ykHPU/1p3uTGfK/QQVb2zoE+8bG5mCHpH4As=
github.com/issue9/cmdopt v0.7.1/go.mod h1:2s73seejsiImh4JGBSJrYoWjK5rCHT+eYntYIUjlzro=
github.com/issue9/cmdopt v0.7.2 h1:riBT70kOOU00rKmP4vseFI7hfDZBO0l00FosVcexWH8=
github.com/issue9/cmdopt v0.7.2/go.mod h1:Cw6wK3MUCagL59FWZY7qJBmJA8lGeatF7Haso7wOk1E=
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.8.1 h1:8ngATedH5SEyZjS37KOjuxlNbPWnIpYhRGE35RDsT6k=
github.com/issue9/localeutil v0.8.1/go.mod h1:611rGRiQKJeEoUSsd5c7PvOuiGkR7a+4C7Ce0NURcu0=
github.com/issue9/mux/v5 v5.1.2 h1:QRE/xMmqHmbIgk1ZF+ZP9GuiiDjWvwVRGLYFC2xwfGE=
github.com/issue9/mux/v5 v5.1.2/go.mod h1:inBNr5pOw2UcCFONZFXffBmKdNF0i40283LzLnfQuyw=
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/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 h1:lnzYryF50+mxqvnsPZRZ1on+gxx0Khx5t5G7q0Cf7gU=
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/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=
Expand Down
18 changes: 9 additions & 9 deletions internal/ast/sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func (api *API) Sanitize(p *xmlenc.Parser) {
}

// 对 Servers 和 Tags 查重
indexes := sliceutil.Dup(api.Servers, func(i, j int) bool { return api.Servers[i].V() == api.Servers[j].V() })
indexes := sliceutil.Dup(api.Servers, func(i, j *ServerValue) bool { return i.V() == j.V() })
if len(indexes) > 0 {
err := api.Servers[indexes[0]].Location.NewError(locale.ErrDuplicateValue).WithField("server")
for _, srv := range indexes[1:] {
err.Relate(api.Servers[srv].Location, locale.Sprintf(locale.ErrDuplicateValue))
}
p.Error(err)
}
indexes = sliceutil.Dup(api.Tags, func(i, j int) bool { return api.Tags[i].V() == api.Tags[j].V() })
indexes = sliceutil.Dup(api.Tags, func(i, j *TagValue) bool { return i.V() == j.V() })
if len(indexes) > 0 {
err := api.Tags[indexes[0]].Location.NewError(locale.ErrDuplicateValue).WithField("server")
for _, tag := range indexes[1:] {
Expand Down Expand Up @@ -204,7 +204,7 @@ func chkEnumsType(t *TypeAttribute, enums []*Enum, p *xmlenc.Parser) error {
}

func checkDuplicateEnum(enums []*Enum, p *xmlenc.Parser) {
indexes := sliceutil.Dup(enums, func(i, j int) bool { return enums[i].Value.V() == enums[j].Value.V() })
indexes := sliceutil.Dup(enums, func(i, j *Enum) bool { return i.Value.V() == j.Value.V() })
if len(indexes) > 0 {
err := enums[indexes[0]].Location.NewError(locale.ErrDuplicateValue).WithField("enum")
for _, i := range indexes[1:] {
Expand All @@ -215,7 +215,7 @@ func checkDuplicateEnum(enums []*Enum, p *xmlenc.Parser) {
}

func checkDuplicateItems(items []*Param, p *xmlenc.Parser) {
indexes := sliceutil.Dup(items, func(i, j int) bool { return items[i].Name.V() == items[j].Name.V() })
indexes := sliceutil.Dup(items, func(i, j *Param) bool { return i.Name.V() == j.Name.V() })
if len(indexes) > 0 {
err := items[indexes[0]].Location.NewError(locale.ErrDuplicateValue).WithField("param")
for _, i := range indexes[1:] {
Expand Down Expand Up @@ -286,8 +286,8 @@ func (doc *APIDoc) checkXMLNamespaces(p *xmlenc.Parser) error {
}

// 按 URN 查重
indexes := sliceutil.Dup(doc.XMLNamespaces, func(i, j int) bool {
return doc.XMLNamespaces[i].URN.V() == doc.XMLNamespaces[j].URN.V()
indexes := sliceutil.Dup(doc.XMLNamespaces, func(i, j *XMLNamespace) bool {
return i.URN.V() == j.URN.V()
})
if len(indexes) > 0 {
err := doc.XMLNamespaces[indexes[0]].URN.Location.NewError(locale.ErrDuplicateValue).WithField("@urn")
Expand All @@ -298,8 +298,8 @@ func (doc *APIDoc) checkXMLNamespaces(p *xmlenc.Parser) error {
}

// 按 prefix 查重
indexes = sliceutil.Dup(doc.XMLNamespaces, func(i, j int) bool {
return doc.XMLNamespaces[i].Prefix.V() == doc.XMLNamespaces[j].Prefix.V()
indexes = sliceutil.Dup(doc.XMLNamespaces, func(i, j *XMLNamespace) bool {
return i.Prefix.V() == j.Prefix.V()
})
if len(indexes) > 0 {
err := doc.XMLNamespaces[indexes[0]].URN.Location.NewError(locale.ErrDuplicateValue).WithField("@prefix")
Expand Down Expand Up @@ -409,7 +409,7 @@ func (api *API) checkDup(p *xmlenc.Parser) {

// 判断是否拥有相同的 server 字段
for _, srv := range api.Servers {
s := sliceutil.Count(item.Servers, func(i int) bool { return srv.V() == item.Servers[i].V() })
s := sliceutil.Count(item.Servers, func(i *ServerValue) bool { return srv.V() == i.V() })
if s > 0 {
err.Relate(item.Location, locale.Sprintf(locale.ErrDuplicateValue))
continue
Expand Down
4 changes: 2 additions & 2 deletions internal/lang/testdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func parseLang(a *assert.Assertion, id, dir string) {
close(blks)
go func() {
for block := range blks {
cnt := sliceutil.Count(blocks, func(i int) bool {
cnt := sliceutil.Count(blocks, func(i string) bool {
// 忽略首层空格的差别,部分语言没有多行注释,
// 单行注释生成的代码块会比多行注释生成的代码多一个换行符。
return strings.TrimSpace(blocks[i]) == strings.TrimSpace(string(block.Data))
return strings.TrimSpace(i) == strings.TrimSpace(string(block.Data))
})

if cnt <= 0 {
Expand Down
4 changes: 2 additions & 2 deletions internal/lsp/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (f *folder) messageHandler(msg *core.Message) {
}

if p, found := f.diagnostics[err.Location.URI]; found && p != nil {
cnt := sliceutil.Count(p.Diagnostics, func(i int) bool {
return p.Diagnostics[i].Range.Equal(err.Location.Range)
cnt := sliceutil.Count(p.Diagnostics, func(i protocol.Diagnostic) bool {
return i.Range.Equal(err.Location.Range)
})
if cnt == 0 {
p.AppendDiagnostic(err, msg.Type)
Expand Down
10 changes: 5 additions & 5 deletions internal/lsp/textdocument.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (f *folder) parseBlock(block core.Block) {
var input *build.Input
ext := filepath.Ext(block.Location.URI.String())
for _, i := range f.cfg.Inputs {
if sliceutil.Count(i.Exts, func(index int) bool { return i.Exts[index] == ext }) > 0 {
if sliceutil.Count(i.Exts, func(index string) bool { return index == ext }) > 0 {
input = i
break
}
Expand All @@ -62,12 +62,12 @@ func (f *folder) parseBlock(block core.Block) {
}

func deleteURI(doc *ast.APIDoc, uri core.URI) (deleted bool) {
size := sliceutil.Delete(doc.APIs, func(i int) bool {
return doc.APIs[i].URI == uri
l := len(doc.APIs)
doc.APIs = sliceutil.Delete(doc.APIs, func(i *ast.API) bool {
return i.URI == uri
})

deleted = len(doc.APIs) > size
doc.APIs = doc.APIs[:size]
deleted = l > len(doc.APIs)

if doc.URI == uri {
*doc = ast.APIDoc{APIs: doc.APIs}
Expand Down
10 changes: 5 additions & 5 deletions internal/lsp/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ func (s *server) workspaceDidChangeWorkspaceFolders(notify bool, in *protocol.Di
s.workspaceMux.Lock()
defer s.workspaceMux.Unlock()

size := sliceutil.Delete(s.folders, func(i int) bool {
return sliceutil.Count(in.Event.Removed, func(j int) bool {
return in.Event.Removed[j].URI == s.folders[i].URI
old := s.folders
s.folders = sliceutil.Delete(s.folders, func(i *folder) bool {
return sliceutil.Count(in.Event.Removed, func(j protocol.WorkspaceFolder) bool {
return j.URI == i.URI
}) > 0
})

var deleted []*folder
s.folders, deleted = s.folders[:size], s.folders[size:]
deleted := old[len(s.folders):]
for _, f := range deleted {
f.close()
}
Expand Down
6 changes: 3 additions & 3 deletions internal/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strings"
"time"

"github.com/issue9/mux/v5"
"github.com/issue9/mux/v6"
"github.com/issue9/qheader"
"github.com/issue9/version"

Expand Down Expand Up @@ -49,7 +49,7 @@ func New(msg *core.MessageHandler, d *ast.APIDoc, indent, imageURL string, serve
return nil, locale.NewError(locale.VersionInCompatible)
}

mu := mux.NewRouter("apidoc mock server")
mu := mux.NewRouter("apidoc mock server", nil)
router := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h := w.Header()
h.Set("Access-Control-Allow-Origin", "*")
Expand All @@ -72,7 +72,7 @@ func New(msg *core.MessageHandler, d *ast.APIDoc, indent, imageURL string, serve
if imageURL[0] != '/' || imageURL[len(imageURL)-1] == '/' {
panic("参数 imageURL 必须以 / 开头且不能以 / 结尾")
}
m.router.GetFunc(imageURL+"/{path}", m.getImage)
m.router.Get(imageURL+"/{path}", http.HandlerFunc(m.getImage))
}

m.parse()
Expand Down

0 comments on commit 3c27f8b

Please sign in to comment.