lint by golangci-lint (#3080)

This commit is contained in:
fatedier
2022-08-29 01:02:53 +08:00
committed by GitHub
parent f4e4fbea62
commit 9d077b02cf
122 changed files with 947 additions and 1331 deletions

View File

@@ -20,10 +20,10 @@ import (
"path/filepath"
"strings"
"gopkg.in/ini.v1"
"github.com/fatedier/frp/pkg/auth"
"github.com/fatedier/frp/pkg/util/util"
"gopkg.in/ini.v1"
)
// ClientCommonConf contains information for a client service. It is
@@ -113,7 +113,7 @@ type ClientCommonConf struct {
// all supplied proxies are enabled. By default, this value is an empty
// set.
Start []string `ini:"start" json:"start"`
//Start map[string]struct{} `json:"start"`
// Start map[string]struct{} `json:"start"`
// Protocol specifies the protocol to use when interacting with the server.
// Valid values are "tcp", "kcp" and "websocket". By default, this value
// is "tcp".
@@ -214,7 +214,7 @@ func (cfg *ClientCommonConf) Validate() error {
}
}
if cfg.TLSEnable == false {
if !cfg.TLSEnable {
if cfg.TLSCertFile != "" {
fmt.Println("WARNING! tls_cert_file is invalid when tls_enable is false")
}
@@ -281,7 +281,6 @@ func LoadAllProxyConfsFromIni(
source interface{},
start []string,
) (map[string]ProxyConf, map[string]VisitorConf, error) {
f, err := ini.LoadSources(ini.LoadOptions{
Insensitive: false,
InsensitiveSections: false,
@@ -366,7 +365,6 @@ func LoadAllProxyConfsFromIni(
}
func renderRangeProxyTemplates(f *ini.File, section *ini.Section) error {
// Validation
localPortStr := section.Key("local_port").String()
remotePortStr := section.Key("remote_port").String()
@@ -404,8 +402,12 @@ func renderRangeProxyTemplates(f *ini.File, section *ini.Section) error {
}
copySection(section, tmpsection)
tmpsection.NewKey("local_port", fmt.Sprintf("%d", localPorts[i]))
tmpsection.NewKey("remote_port", fmt.Sprintf("%d", remotePorts[i]))
if _, err := tmpsection.NewKey("local_port", fmt.Sprintf("%d", localPorts[i])); err != nil {
return fmt.Errorf("local_port new key in section error: %v", err)
}
if _, err := tmpsection.NewKey("remote_port", fmt.Sprintf("%d", remotePorts[i])); err != nil {
return fmt.Errorf("remote_port new key in section error: %v", err)
}
}
return nil
@@ -413,6 +415,6 @@ func renderRangeProxyTemplates(f *ini.File, section *ini.Section) error {
func copySection(source, target *ini.Section) {
for key, value := range source.KeysHash() {
target.NewKey(key, value)
_, _ = target.NewKey(key, value)
}
}

View File

@@ -17,18 +17,17 @@ package config
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/fatedier/frp/pkg/auth"
"github.com/fatedier/frp/pkg/consts"
"github.com/stretchr/testify/assert"
)
const (
testUser = "test"
)
var (
testClientBytesWithFull = []byte(`
var testClientBytesWithFull = []byte(`
# [common] is integral section
[common]
server_addr = 0.0.0.9
@@ -237,7 +236,6 @@ var (
use_encryption = false
use_compression = false
`)
)
func Test_LoadClientCommonConf(t *testing.T) {
assert := assert.New(t)

View File

@@ -42,7 +42,7 @@ func ParseClientConfig(filePath string) (
}
cfg.Complete()
if err = cfg.Validate(); err != nil {
err = fmt.Errorf("Parse config error: %v", err)
err = fmt.Errorf("parse config error: %v", err)
return
}

View File

@@ -21,10 +21,10 @@ import (
"strconv"
"strings"
"gopkg.in/ini.v1"
"github.com/fatedier/frp/pkg/consts"
"github.com/fatedier/frp/pkg/msg"
"gopkg.in/ini.v1"
)
// Proxy
@@ -420,10 +420,6 @@ func (cfg *BaseProxyConf) checkForCli() (err error) {
return nil
}
func (cfg *BaseProxyConf) checkForSvr(conf ServerCommonConf) error {
return nil
}
// DomainConf
func (cfg *DomainConf) check() (err error) {
if len(cfg.CustomDomains) == 0 && cfg.SubDomain == "" {

View File

@@ -17,10 +17,10 @@ package config
import (
"testing"
"github.com/fatedier/frp/pkg/consts"
"github.com/stretchr/testify/assert"
"gopkg.in/ini.v1"
"github.com/fatedier/frp/pkg/consts"
)
var (
@@ -49,7 +49,6 @@ func Test_Proxy_UnmarshalFromIni(t *testing.T) {
source []byte
expected ProxyConf
}{
{
sname: "ssh",
source: []byte(`
@@ -457,5 +456,4 @@ func Test_RangeProxy_UnmarshalFromIni(t *testing.T) {
assert.Equal(c.expected, actual)
}
}

View File

@@ -18,12 +18,12 @@ import (
"fmt"
"strings"
"github.com/go-playground/validator/v10"
"gopkg.in/ini.v1"
"github.com/fatedier/frp/pkg/auth"
plugin "github.com/fatedier/frp/pkg/plugin/server"
"github.com/fatedier/frp/pkg/util/util"
"github.com/go-playground/validator/v10"
"gopkg.in/ini.v1"
)
// ServerCommonConf contains information for a server service. It is
@@ -236,7 +236,6 @@ func GetDefaultServerConf() ServerCommonConf {
}
func UnmarshalServerConfFromIni(source interface{}) (ServerCommonConf, error) {
f, err := ini.LoadSources(ini.LoadOptions{
Insensitive: false,
InsensitiveSections: false,
@@ -308,7 +307,7 @@ func (cfg *ServerCommonConf) Complete() {
}
func (cfg *ServerCommonConf) Validate() error {
if cfg.DashboardTLSMode == false {
if !cfg.DashboardTLSMode {
if cfg.DashboardTLSCertFile != "" {
fmt.Println("WARNING! dashboard_tls_cert_file is invalid when dashboard_tls_mode is false")
}

View File

@@ -17,10 +17,10 @@ package config
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/fatedier/frp/pkg/auth"
plugin "github.com/fatedier/frp/pkg/plugin/server"
"github.com/stretchr/testify/assert"
)
func Test_LoadServerCommonConf(t *testing.T) {
@@ -126,10 +126,10 @@ func Test_LoadServerCommonConf(t *testing.T) {
HeartbeatTimeout: 99,
UserConnTimeout: 9,
AllowPorts: map[int]struct{}{
10: struct{}{},
11: struct{}{},
12: struct{}{},
99: struct{}{},
10: {},
11: {},
12: {},
99: {},
},
MaxPoolCount: 59,
MaxPortsPerClient: 9,

View File

@@ -75,21 +75,22 @@ func (q *BandwidthQuantity) UnmarshalString(s string) error {
f float64
err error
)
if strings.HasSuffix(s, "MB") {
switch {
case strings.HasSuffix(s, "MB"):
base = MB
fstr := strings.TrimSuffix(s, "MB")
f, err = strconv.ParseFloat(fstr, 64)
if err != nil {
return err
}
} else if strings.HasSuffix(s, "KB") {
case strings.HasSuffix(s, "KB"):
base = KB
fstr := strings.TrimSuffix(s, "KB")
f, err = strconv.ParseFloat(fstr, 64)
if err != nil {
return err
}
} else {
default:
return errors.New("unit not support")
}

View File

@@ -21,9 +21,7 @@ import (
"text/template"
)
var (
glbEnvs map[string]string
)
var glbEnvs map[string]string
func init() {
glbEnvs = make(map[string]string)

View File

@@ -18,9 +18,9 @@ import (
"fmt"
"reflect"
"github.com/fatedier/frp/pkg/consts"
"gopkg.in/ini.v1"
"github.com/fatedier/frp/pkg/consts"
)
// Visitor
@@ -136,6 +136,7 @@ func (cfg *BaseVisitorConf) check() (err error) {
}
func (cfg *BaseVisitorConf) unmarshalFromIni(prefix string, name string, section *ini.Section) error {
_ = section
// Custom decoration after basic unmarshal:
// proxy name

View File

@@ -17,10 +17,10 @@ package config
import (
"testing"
"github.com/fatedier/frp/pkg/consts"
"github.com/stretchr/testify/assert"
"gopkg.in/ini.v1"
"github.com/fatedier/frp/pkg/consts"
)
const testVisitorPrefix = "test."