mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 12:27:37 +03:00
Add more lint
This commit is contained in:
parent
beeeba3388
commit
849d16c37b
13 changed files with 118 additions and 64 deletions
|
@ -2,5 +2,43 @@ run:
|
||||||
timeout: 5m
|
timeout: 5m
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
|
enable-all: true
|
||||||
disable:
|
disable:
|
||||||
- errcheck
|
- errcheck
|
||||||
|
- wrapcheck
|
||||||
|
- varnamelen
|
||||||
|
- stylecheck
|
||||||
|
- nonamedreturns
|
||||||
|
- nlreturn
|
||||||
|
- ireturn
|
||||||
|
- gomnd
|
||||||
|
- exhaustivestruct
|
||||||
|
- ifshort
|
||||||
|
- goerr113
|
||||||
|
- gochecknoglobals
|
||||||
|
- forcetypeassert
|
||||||
|
- exhaustruct
|
||||||
|
- exhaustive
|
||||||
|
- cyclop
|
||||||
|
- containedctx
|
||||||
|
- wsl
|
||||||
|
- nestif
|
||||||
|
- lll
|
||||||
|
- funlen
|
||||||
|
- goconst
|
||||||
|
- godot
|
||||||
|
- gocognit
|
||||||
|
- golint
|
||||||
|
- goimports
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
revive:
|
||||||
|
rules:
|
||||||
|
- name: var-naming
|
||||||
|
disabled: true
|
||||||
|
govet:
|
||||||
|
enable-all: true
|
||||||
|
disable:
|
||||||
|
- composites
|
||||||
|
- fieldalignment
|
||||||
|
- shadow
|
|
@ -10,29 +10,40 @@ func Put(buf []byte) error {
|
||||||
|
|
||||||
func Make(size int) []byte {
|
func Make(size int) []byte {
|
||||||
var buffer []byte
|
var buffer []byte
|
||||||
if size <= 16 {
|
switch {
|
||||||
|
case size <= 2:
|
||||||
|
buffer = make([]byte, 2)
|
||||||
|
case size <= 4:
|
||||||
|
buffer = make([]byte, 4)
|
||||||
|
case size <= 8:
|
||||||
|
buffer = make([]byte, 8)
|
||||||
|
case size <= 16:
|
||||||
buffer = make([]byte, 16)
|
buffer = make([]byte, 16)
|
||||||
} else if size <= 32 {
|
case size <= 32:
|
||||||
buffer = make([]byte, 32)
|
buffer = make([]byte, 32)
|
||||||
} else if size <= 64 {
|
case size <= 64:
|
||||||
buffer = make([]byte, 64)
|
buffer = make([]byte, 64)
|
||||||
} else if size <= 128 {
|
case size <= 128:
|
||||||
buffer = make([]byte, 128)
|
buffer = make([]byte, 128)
|
||||||
} else if size <= 256 {
|
case size <= 256:
|
||||||
buffer = make([]byte, 256)
|
buffer = make([]byte, 256)
|
||||||
} else if size <= 512 {
|
case size <= 512:
|
||||||
buffer = make([]byte, 512)
|
buffer = make([]byte, 512)
|
||||||
} else if size <= 1024 {
|
case size <= 1024:
|
||||||
buffer = make([]byte, 1024)
|
buffer = make([]byte, 1024)
|
||||||
} else if size <= 4*1024 {
|
case size <= 2048:
|
||||||
buffer = make([]byte, 4*1024)
|
buffer = make([]byte, 2048)
|
||||||
} else if size <= 16*1024 {
|
case size <= 4096:
|
||||||
buffer = make([]byte, 16*1024)
|
buffer = make([]byte, 4096)
|
||||||
} else if size <= 20*1024 {
|
case size <= 8192:
|
||||||
buffer = make([]byte, 20*1024)
|
buffer = make([]byte, 8192)
|
||||||
} else if size <= 65535 {
|
case size <= 16384:
|
||||||
|
buffer = make([]byte, 16384)
|
||||||
|
case size <= 32768:
|
||||||
|
buffer = make([]byte, 32768)
|
||||||
|
case size <= 65535:
|
||||||
buffer = make([]byte, 65535)
|
buffer = make([]byte, 65535)
|
||||||
} else {
|
default:
|
||||||
return make([]byte, size)
|
return make([]byte, size)
|
||||||
}
|
}
|
||||||
return buffer[:size]
|
return buffer[:size]
|
||||||
|
|
|
@ -17,6 +17,7 @@ var dbgvars any
|
||||||
// go.info.runtime.dbgvars: relocation target go.info.[]github.com/sagernet/sing/common/buf.dbgVar not defined
|
// go.info.runtime.dbgvars: relocation target go.info.[]github.com/sagernet/sing/common/buf.dbgVar not defined
|
||||||
// var dbgvars []dbgVar
|
// var dbgvars []dbgVar
|
||||||
|
|
||||||
|
//nolint:gochecknoinits
|
||||||
func init() {
|
func init() {
|
||||||
debugVars := *(*[]dbgVar)(unsafe.Pointer(&dbgvars))
|
debugVars := *(*[]dbgVar)(unsafe.Pointer(&dbgvars))
|
||||||
for _, v := range debugVars {
|
for _, v := range debugVars {
|
||||||
|
|
2
common/cache/lrucache.go
vendored
2
common/cache/lrucache.go
vendored
|
@ -191,7 +191,7 @@ func (c *LruCache[K, V]) StoreWithExpire(key K, value V, expires time.Time) {
|
||||||
c.cache[key] = c.lru.PushBack(e)
|
c.cache[key] = c.lru.PushBack(e)
|
||||||
|
|
||||||
if c.maxSize > 0 {
|
if c.maxSize > 0 {
|
||||||
if len := c.lru.Len(); len > c.maxSize {
|
if n := c.lru.Len(); n > c.maxSize {
|
||||||
c.deleteElement(c.lru.Front())
|
c.deleteElement(c.lru.Front())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ func Must1(_ any, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Must2(_ any, _ any, err error) {
|
func Must2(_, _ any, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -168,8 +168,6 @@ func Close(closers ...any) error {
|
||||||
retErr = err
|
retErr = err
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
|
||||||
switch c := closer.(type) {
|
|
||||||
case WithUpstream:
|
case WithUpstream:
|
||||||
err := Close(c.Upstream())
|
err := Close(c.Upstream())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//nolint:errorlint
|
||||||
package exceptions
|
package exceptions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
// Package list implements a doubly linked list.
|
// Package list implements a doubly linked list.
|
||||||
//
|
//
|
||||||
// To iterate over a list (where l is a *List[T]):
|
// To iterate over a list (where l is a *List[T]):
|
||||||
|
//
|
||||||
// for e := l.Front(); e != nil; e = e.Next() {
|
// for e := l.Front(); e != nil; e = e.Next() {
|
||||||
// // do something with e.Value
|
// // do something with e.Value
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
package list
|
package list
|
||||||
|
|
||||||
// Element is an element of a linked list.
|
// Element is an element of a linked list.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package sing
|
package shadowsocks
|
||||||
|
|
||||||
//go:generate go install -v mvdan.cc/gofumpt@latest
|
//go:generate go install -v mvdan.cc/gofumpt@latest
|
||||||
//go:generate go install -v github.com/daixiang0/gci@latest
|
//go:generate go install -v github.com/daixiang0/gci@latest
|
||||||
//go:generate gofumpt -l -w .
|
//go:generate gofumpt -l -w .
|
||||||
|
//go:generate gofmt -s -w .
|
||||||
//go:generate gci write .
|
//go:generate gci write .
|
||||||
|
|
10
protocol/http/link.go
Normal file
10
protocol/http/link.go
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package http
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"net/http"
|
||||||
|
_ "unsafe" // for linkname
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:linkname ReadRequest net/http.readRequest
|
||||||
|
func ReadRequest(b *bufio.Reader) (req *http.Request, err error)
|
|
@ -1,14 +1,12 @@
|
||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
_ "unsafe"
|
|
||||||
|
|
||||||
"github.com/sagernet/sing/common"
|
"github.com/sagernet/sing/common"
|
||||||
"github.com/sagernet/sing/common/auth"
|
"github.com/sagernet/sing/common/auth"
|
||||||
|
@ -131,9 +129,6 @@ func HandleRequest(ctx context.Context, request *http.Request, conn net.Conn, au
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:linkname ReadRequest net/http.readRequest
|
|
||||||
func ReadRequest(b *bufio.Reader) (req *http.Request, err error)
|
|
||||||
|
|
||||||
func removeHopByHopHeaders(header http.Header) {
|
func removeHopByHopHeaders(header http.Header) {
|
||||||
// Strip hop-by-hop header based on RFC:
|
// Strip hop-by-hop header based on RFC:
|
||||||
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.5.1
|
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.5.1
|
||||||
|
|
|
@ -59,9 +59,8 @@ func (s *Service[K]) RemoveUser(user K) bool {
|
||||||
delete(s.users, user)
|
delete(s.users, user)
|
||||||
delete(s.keys, key)
|
delete(s.keys, key)
|
||||||
return true
|
return true
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service[K]) ResetUsers() {
|
func (s *Service[K]) ResetUsers() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue