Skip to content

Commit

Permalink
add: golangci lint check (#32)
Browse files Browse the repository at this point in the history
Co-authored-by: 源文雨 <[email protected]>
  • Loading branch information
Jiang-Red and fumiama authored Jan 11, 2023
1 parent 246a18c commit 4d8aebd
Show file tree
Hide file tree
Showing 33 changed files with 303 additions and 85 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PullLint
on: [ pull_request ]
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@master
with:
go-version: 1.19

- name: Check out code into the Go module directory
uses: actions/checkout@master

- name: golangci-lint
uses: golangci/golangci-lint-action@master
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
32 changes: 32 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: PushLint
on: [ push ]
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@master
with:
go-version: 1.19

- name: Check out code into the Go module directory
uses: actions/checkout@master

- name: golangci-lint
uses: golangci/golangci-lint-action@master
with:
version: latest

- name: Commit back
if: ${{ !github.head_ref }}
continue-on-error: true
run: |
git config --local user.name 'github-actions[bot]'
git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add --all
git commit -m "🎨 改进代码样式"
- name: Create Pull Request
if: ${{ !github.head_ref }}
continue-on-error: true
uses: peter-evans/create-pull-request@v4
77 changes: 77 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
linters-settings:
errcheck:
ignore: fmt:.*
ignoretests: true

goimports:
local-prefixes: github.com/FloatTech/AnimeAPI

forbidigo:
# Forbid the following identifiers
forbid:
- ^fmt\.Errorf$ # consider errors.Errorf in github.com/pkg/errors

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
fast: false
enable:
- bodyclose
- depguard
- dogsled
- errcheck
- exportloopref
- exhaustive
#- funlen
#- goconst
- gocritic
#- gocyclo
- gofmt
- goimports
- goprintffuncname
#- gosec
- gosimple
- govet
- ineffassign
#- misspell
- nolintlint
- rowserrcheck
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace
- prealloc
- predeclared
- asciicheck
- revive
- forbidigo
- makezero

run:
# default concurrency is a available CPU number.
# concurrency: 4 # explicitly omit this value to fully utilize available resources.
deadline: 5m
issues-exit-code: 1
tests: false
skip-dirs:
- order
go: '1.19'

# output configuration options
output:
format: "colored-line-number"
print-issued-lines: true
print-linter-name: true
uniq-by-line: true

issues:
# Fix found issues (if it's supported by the linter)
fix: true
exclude-use-default: false
exclude:
- "Error return value of .((os.)?std(out|err)..*|.*Close|.*Seek|.*Flush|os.Remove(All)?|.*print(f|ln)?|os.(Un)?Setenv). is not check"
- 'identifier ".*" contain non-ASCII character: U\+.*'
6 changes: 5 additions & 1 deletion aireply/qingyunke.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ type QYK struct {
}

const (
QYKURL = "http://api.qingyunke.com/api.php?key=free&appid=0&msg=%v"
// QYKURL api地址
QYKURL = "http://api.qingyunke.com/api.php?key=free&appid=0&msg=%v"
// QYKBotName ...
QYKBotName = "菲菲"
)

var (
qykMatchFace = regexp.MustCompile(`\{face:(\d+)\}(.*)`)
)

// NewQYK ...
func NewQYK(u, name string, banwords ...string) *QYK {
return &QYK{u: u, n: name, b: banwords}
}

// String ...
func (*QYK) String() string {
return "青云客"
}
Expand Down
6 changes: 5 additions & 1 deletion aireply/xiaoai.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ type XiaoAi struct {
}

const (
XiaoAiURL = "http://81.70.100.130/api/xiaoai.php?n=text&msg=%v"
// XiaoAiURL api地址
XiaoAiURL = "http://81.70.100.130/api/xiaoai.php?n=text&msg=%v"
// XiaoAiBotName ...
XiaoAiBotName = "小爱"
)

// NewXiaoAi ...
func NewXiaoAi(u, name string, banwords ...string) *XiaoAi {
return &XiaoAi{u: u, n: name, b: banwords}
}

// String ...
func (*XiaoAi) String() string {
return "小爱"
}
Expand Down
5 changes: 4 additions & 1 deletion ascii2d/ascii2d.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package ascii2d ascii2d搜图api
package ascii2d

import (
Expand All @@ -10,6 +11,7 @@ import (
xpath "github.com/antchfx/htmlquery"
)

// Result ...
type Result struct {
Info string // Info 图片分辨率 格式 大小信息
Link string // Link 图片链接
Expand All @@ -20,7 +22,8 @@ type Result struct {
Type string // Type pixiv / twitter ...
}

func Ascii2d(image string) (r []*Result, err error) {
// ASCII2d ...
func ASCII2d(image string) (r []*Result, err error) {
const api = "https://ascii2d.net/search/uri"
client := web.NewTLS12Client()
// 包装请求参数
Expand Down
2 changes: 1 addition & 1 deletion ascii2d/ascii2d_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestSearch(t *testing.T) {
r, err := Ascii2d("https://gchat.qpic.cn/gchatpic_new//--05F47960F2546E874F515A403FD174DF/0?term=3")
r, err := ASCII2d("https://gchat.qpic.cn/gchatpic_new//--05F47960F2546E874F515A403FD174DF/0?term=3")
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 4 additions & 0 deletions bilibili/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

var (
// ErrAPINeedCookie ...
ErrAPINeedCookie = errors.New("api need cookie")
)

Expand Down Expand Up @@ -134,6 +135,9 @@ func GetMedalWall(cookiecfg *CookieConfig, uid string) (result []Medal, err erro
func GetAllGuard(mid string) (guardUser GuardUser, err error) {
var data []byte
data, err = web.GetData(AllGuardURL)
if err != nil {
return
}
m := gjson.ParseBytes(data).Get("@this").Map()
err = json.Unmarshal(binary.StringToBytes(m[mid].String()), &guardUser)
if err != nil {
Expand Down
15 changes: 13 additions & 2 deletions bilibili/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,24 +265,31 @@ type MedalInfo struct {
MedalColorBorder int64 `json:"medal_color_border"`
}

// Medal ...
type Medal struct {
Uname string `json:"target_name"`
MedalInfo `json:"medal_info"`
}

// MedalSorter ...
type MedalSorter []Medal

// Len ...
func (m MedalSorter) Len() int {
return len(m)
}

// Swap ...
func (m MedalSorter) Swap(i, j int) {
m[i], m[j] = m[j], m[i]
}

// Less ...
func (m MedalSorter) Less(i, j int) bool {
return m[i].Level > m[j].Level
}

// vtb信息
// VtbDetail vtb信息
type VtbDetail struct {
Mid int `json:"mid"`
Uname string `json:"uname"`
Expand Down Expand Up @@ -343,23 +350,26 @@ type Danmakusuki struct {
} `json:"data"`
}

// 配置结构体
// CookieConfig 配置结构体
type CookieConfig struct {
BilibiliCookie string `json:"bilibili_cookie"`
file string
}

// NewCookieConfig ...
func NewCookieConfig(file string) *CookieConfig {
return &CookieConfig{
file: file,
}
}

// Set ...
func (cfg *CookieConfig) Set(cookie string) (err error) {
cfg.BilibiliCookie = cookie
return cfg.Save()
}

// Load ...
func (cfg *CookieConfig) Load() (cookie string, err error) {
if cfg.BilibiliCookie != "" {
cookie = cfg.BilibiliCookie
Expand All @@ -379,6 +389,7 @@ func (cfg *CookieConfig) Load() (cookie string, err error) {
return
}

// Save ...
func (cfg *CookieConfig) Save() (err error) {
reader, err := os.Create(cfg.file)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions bilibili/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func HumanNum(res int) string {
return strconv.Itoa(res)
}

// GetRealUrl 获取跳转后的链接
func GetRealUrl(url string) (realurl string, err error) {
// GetRealURL 获取跳转后的链接
func GetRealURL(url string) (realurl string, err error) {
data, err := http.Head(url)
if err != nil {
return
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/FloatTech/AnimeAPI

go 1.18
go 1.19

require (
github.com/FloatTech/floatbox v0.0.0-20230111053652-a03d6334fadf
Expand Down
12 changes: 6 additions & 6 deletions huggingface/huggingface.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ const (
TimeoutMax = 300
)

// 推送默认请求
// PushRequest 推送默认请求
type PushRequest struct {
Action string `json:"action,omitempty"`
FnIndex int `json:"fn_index"`
Data []interface{} `json:"data"`
SessionHash string `json:"session_hash"`
}

// 推送默认响应
// PushResponse 推送默认响应
type PushResponse struct {
Hash string `json:"hash"`
QueuePosition int `json:"queue_position"`
}

// 状态默认请求
// StatusRequest 状态默认请求
type StatusRequest struct {
Hash string `json:"hash"`
}

// 状态默认响应
// StatusResponse 状态默认响应
type StatusResponse struct {
Status string `json:"status"`
Data struct {
Expand All @@ -62,7 +62,7 @@ type StatusResponse struct {
}
}

// 推送请求
// Push 推送请求
func Push(pushURL string, pushReq PushRequest) (pushRes PushResponse, err error) {
b, err := json.Marshal(pushReq)
if err != nil {
Expand All @@ -76,7 +76,7 @@ func Push(pushURL string, pushReq PushRequest) (pushRes PushResponse, err error)
return
}

// 状态请求
// Status 状态请求
func Status(statusURL string, statusReq StatusRequest) (data []byte, err error) {
b, err := json.Marshal(statusReq)
if err != nil {
Expand Down
Loading

0 comments on commit 4d8aebd

Please sign in to comment.