Make linter happy

This commit is contained in:
世界 2022-06-28 22:16:48 +08:00
parent aa7007a947
commit beeeba3388
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
12 changed files with 26 additions and 33 deletions

View file

@ -31,5 +31,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --config=.github/linters/golangci.yml
version: latest

View file

@ -9,7 +9,7 @@ type Authenticator interface {
Users() []string
}
type AuthUser struct {
type User struct {
User string
Pass string
}
@ -26,7 +26,7 @@ func (au *inMemoryAuthenticator) Verify(user string, pass string) bool {
func (au *inMemoryAuthenticator) Users() []string { return au.usernames }
func NewAuthenticator(users []AuthUser) Authenticator {
func NewAuthenticator(users []User) Authenticator {
if len(users) == 0 {
return nil
}
@ -34,6 +34,7 @@ func NewAuthenticator(users []AuthUser) Authenticator {
au := &inMemoryAuthenticator{storage: &sync.Map{}}
for _, user := range users {
au.storage.Store(user.User, user.Pass)
au.usernames = append(au.usernames, user.User)
}
usernames := make([]string, 0, len(users))
au.storage.Range(func(key, value interface{}) bool {

View file

@ -158,11 +158,11 @@ func (b *Buffer) WriteRandom(size int) []byte {
return buffer
}
func (b *Buffer) WriteByte(byte byte) error {
func (b *Buffer) WriteByte(d byte) error {
if b.IsFull() {
return io.ErrShortBuffer
}
b.data[b.end] = byte
b.data[b.end] = d
b.end++
return nil
}

View file

@ -68,8 +68,8 @@ func (r *BufferedReader) WriteTo(w io.Writer) (n int64, err error) {
return CopyExtendedBuffer(NewExtendedWriter(w), NewExtendedReader(r.upstream), r.buffer)
}
func (w *BufferedReader) Upstream() any {
return w.upstream
func (r *BufferedReader) Upstream() any {
return r.upstream
}
type BufferedWriter struct {

View file

@ -92,9 +92,9 @@ func NewCachedReader(upstream io.Reader, buffer *buf.Buffer) *CachedReader {
}
}
func (c *CachedReader) ReadCached() *buf.Buffer {
buffer := c.buffer
c.buffer = nil
func (r *CachedReader) ReadCached() *buf.Buffer {
buffer := r.buffer
r.buffer = nil
return buffer
}
@ -123,15 +123,15 @@ func (r *CachedReader) WriteTo(w io.Writer) (n int64, err error) {
return
}
func (w *CachedReader) Upstream() any {
return w.upstream
func (r *CachedReader) Upstream() any {
return r.upstream
}
func (c *CachedReader) ReaderReplaceable() bool {
return c.buffer == nil
func (r *CachedReader) ReaderReplaceable() bool {
return r.buffer == nil
}
func (c *CachedReader) Close() error {
c.buffer.Release()
func (r *CachedReader) Close() error {
r.buffer.Release()
return nil
}

View file

@ -458,11 +458,11 @@ func (w *ExtendedWriterWrapper) WriteBuffer(buffer *buf.Buffer) error {
return common.Error(w.Write(buffer.Bytes()))
}
func (r *ExtendedWriterWrapper) Upstream() any {
return r.Writer
func (w *ExtendedWriterWrapper) Upstream() any {
return w.Writer
}
func (r *ExtendedReaderWrapper) WriterReplaceable() bool {
func (w *ExtendedReaderWrapper) WriterReplaceable() bool {
return true
}

View file

@ -35,7 +35,7 @@ func Contains[T comparable](arr []T, target T) bool {
}
func Map[T any, N any](arr []T, block func(it T) N) []N {
var retArr []N
retArr := make([]N, 0, len(arr))
for index := range arr {
retArr = append(retArr, block(arr[index]))
}
@ -43,7 +43,7 @@ func Map[T any, N any](arr []T, block func(it T) N) []N {
}
func MapIndexed[T any, N any](arr []T, block func(index int, it T) N) []N {
var retArr []N
retArr := make([]N, 0, len(arr))
for index := range arr {
retArr = append(retArr, block(index, arr[index]))
}

View file

@ -13,9 +13,7 @@ func LocalAddrs() ([]netip.Addr, error) {
if err != nil {
return nil, err
}
return common.Map(interfaceAddrs, func(addr net.Addr) netip.Addr {
return M.AddrFromNetAddr(addr)
}), nil
return common.Map(interfaceAddrs, M.AddrFromNetAddr), nil
}
func IsPublicAddr(addr netip.Addr) bool {
@ -27,7 +25,5 @@ func LocalPublicAddrs() ([]netip.Addr, error) {
if err != nil {
return nil, err
}
return common.Filter(publicAddrs, func(addr netip.Addr) bool {
return IsPublicAddr(addr)
}), nil
return common.Filter(publicAddrs, IsPublicAddr), nil
}

View file

@ -134,7 +134,7 @@ func ClientHandshakeRaw(conn net.Conn, key [KeyLength]byte, command byte, destin
if err != nil {
return err
}
_, err = conn.Write(CRLF[:])
_, err = conn.Write(CRLF)
if err != nil {
return err
}
@ -146,7 +146,7 @@ func ClientHandshakeRaw(conn net.Conn, key [KeyLength]byte, command byte, destin
if err != nil {
return err
}
_, err = conn.Write(CRLF[:])
_, err = conn.Write(CRLF)
if err != nil {
return err
}

View file

@ -5,7 +5,6 @@ import (
)
func newPAC(proxyAddr netip.AddrPort) string {
// TODO: socks4 not supported
return `
function FindProxyForURL(url, host) {
return "SOCKS5 ` + proxyAddr.String() + `; PROXY ` + proxyAddr.String() + `";

View file

@ -206,7 +206,6 @@ func (l *Listener) loop() {
l.handler.HandleError(err)
}
}
}
}
@ -261,6 +260,5 @@ func (l *Listener) loopThreadSafe() {
l.handler.HandleError(err)
}
}
}
}