mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 14:44:02 +03:00
Fix lint issues
This commit is contained in:
@@ -60,7 +60,7 @@ func (c *Config) Validate() error {
|
||||
return fmt.Errorf("invalid secret %s", c.Secret.String())
|
||||
}
|
||||
|
||||
if c.BindTo.Get("") == "" {
|
||||
if c.BindTo.Get("") == "" {
|
||||
return fmt.Errorf("incorrect bind-to parameter %s", c.BindTo.String())
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type ConfigTestSuite struct {
|
||||
suite.Suite
|
||||
suite.Suite
|
||||
}
|
||||
|
||||
func (suite *ConfigTestSuite) ReadConfig(filename string) []byte {
|
||||
|
||||
@@ -13,12 +13,12 @@ type TypeBlocklistURI struct {
|
||||
|
||||
func (t *TypeBlocklistURI) Set(value string) error {
|
||||
if stat, err := os.Stat(value); err == nil || os.IsExist(err) {
|
||||
switch {
|
||||
case stat.IsDir():
|
||||
return fmt.Errorf("value is correct filepath but directory")
|
||||
case stat.Mode().Perm() & 0o400 == 0:
|
||||
return fmt.Errorf("value is correct filepath but not readable")
|
||||
}
|
||||
switch {
|
||||
case stat.IsDir():
|
||||
return fmt.Errorf("value is correct filepath but directory")
|
||||
case stat.Mode().Perm()&0o400 == 0:
|
||||
return fmt.Errorf("value is correct filepath but not readable")
|
||||
}
|
||||
|
||||
value, err = filepath.Abs(value)
|
||||
if err != nil {
|
||||
|
||||
@@ -102,9 +102,9 @@ func (suite *TypeBlocklistURITestSuite) TestGet() {
|
||||
value := config.TypeBlocklistURI{}
|
||||
suite.Equal("/path", value.Get("/path"))
|
||||
|
||||
suite.NoError(value.Set("http://lalala.ru"))
|
||||
suite.Equal("http://lalala.ru", value.Get("/path"))
|
||||
suite.Equal("http://lalala.ru", value.Get(""))
|
||||
suite.NoError(value.Set("http://lalala.ru"))
|
||||
suite.Equal("http://lalala.ru", value.Get("/path"))
|
||||
suite.Equal("http://lalala.ru", value.Get(""))
|
||||
}
|
||||
|
||||
func TestTypeBlocklistURI(t *testing.T) {
|
||||
|
||||
@@ -14,7 +14,7 @@ type TypeBytes struct {
|
||||
}
|
||||
|
||||
func (t *TypeBytes) Set(value string) error {
|
||||
normalizedValue := typeBytesStringCleaner.Replace(strings.ToUpper(value))
|
||||
normalizedValue := typeBytesStringCleaner.Replace(strings.ToUpper(value))
|
||||
|
||||
parsedValue, err := units.ParseBase2Bytes(normalizedValue)
|
||||
if err != nil {
|
||||
|
||||
@@ -64,20 +64,20 @@ func (suite *TypeBytesTestSuite) TestUnmarshalOk() {
|
||||
}
|
||||
|
||||
func (suite *TypeBytesTestSuite) TestMarshalOk() {
|
||||
value := typeBytesTestStruct{}
|
||||
suite.NoError(value.Value.Set("1kib"))
|
||||
value := typeBytesTestStruct{}
|
||||
suite.NoError(value.Value.Set("1kib"))
|
||||
|
||||
data, err := json.Marshal(value)
|
||||
suite.NoError(err)
|
||||
suite.JSONEq(`{"value": "1kib"}`, string(data))
|
||||
data, err := json.Marshal(value)
|
||||
suite.NoError(err)
|
||||
suite.JSONEq(`{"value": "1kib"}`, string(data))
|
||||
}
|
||||
|
||||
func (suite *TypeBytesTestSuite) TestGet() {
|
||||
value := config.TypeBytes{}
|
||||
suite.EqualValues(1000, value.Get(1000))
|
||||
value := config.TypeBytes{}
|
||||
suite.EqualValues(1000, value.Get(1000))
|
||||
|
||||
suite.NoError(value.Set("1mib"))
|
||||
suite.EqualValues(1048576, value.Get(1000))
|
||||
suite.NoError(value.Set("1mib"))
|
||||
suite.EqualValues(1048576, value.Get(1000))
|
||||
}
|
||||
|
||||
func TestTypeBytes(t *testing.T) {
|
||||
|
||||
@@ -12,11 +12,11 @@ type TypeConcurrency struct {
|
||||
func (t *TypeConcurrency) Set(value string) error {
|
||||
concurrencyValue, err := strconv.ParseUint(value, 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Value is not uint (%s): %w", value, err)
|
||||
return fmt.Errorf("value is not uint (%s): %w", value, err)
|
||||
}
|
||||
|
||||
if concurrencyValue == 0 {
|
||||
return fmt.Errorf("Value should be >0 (%s)", value)
|
||||
return fmt.Errorf("value should be >0 (%s)", value)
|
||||
}
|
||||
|
||||
t.Value = uint(concurrencyValue)
|
||||
|
||||
@@ -86,12 +86,12 @@ func (suite *TypeDurationTestSuite) TestMarshalOk() {
|
||||
data, err := json.Marshal(testStruct)
|
||||
assert.NoError(t, err)
|
||||
|
||||
expectedJson, err := json.Marshal(map[string]string{
|
||||
expectedJSON, err := json.Marshal(map[string]string{
|
||||
"value": expected,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.JSONEq(t, string(expectedJson), string(data))
|
||||
assert.JSONEq(t, string(expectedJSON), string(data))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ type TypeErrorRate struct {
|
||||
func (t *TypeErrorRate) Set(value string) error {
|
||||
parsedValue, err := strconv.ParseFloat(value, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Value is not a float (%s): %w", value, err)
|
||||
return fmt.Errorf("value is not a float (%s): %w", value, err)
|
||||
}
|
||||
|
||||
if parsedValue <= 0.0 || parsedValue >= 100.0 {
|
||||
return fmt.Errorf("Value should be 0 < x < 100 (%s)", value)
|
||||
return fmt.Errorf("value should be 0 < x < 100 (%s)", value)
|
||||
}
|
||||
|
||||
t.Value = parsedValue
|
||||
|
||||
@@ -62,9 +62,9 @@ func (suite *TypeErrorRateTestSuite) TestMarshalOk() {
|
||||
},
|
||||
}
|
||||
|
||||
encodedJson, err := json.Marshal(testStruct)
|
||||
encodedJSON, err := json.Marshal(testStruct)
|
||||
suite.NoError(err)
|
||||
suite.JSONEq(`{"value": 1.01}`, string(encodedJson))
|
||||
suite.JSONEq(`{"value": 1.01}`, string(encodedJSON))
|
||||
}
|
||||
|
||||
func (suite *TypeErrorRateTestSuite) TestGet() {
|
||||
|
||||
@@ -15,7 +15,7 @@ func (t *TypeIP) Set(value string) error {
|
||||
return fmt.Errorf("incorret ip %s", value)
|
||||
}
|
||||
|
||||
t.Value = ip
|
||||
t.Value = ip
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -11,10 +11,10 @@ type TypeMetricPrefix struct {
|
||||
|
||||
func (t *TypeMetricPrefix) Set(value string) error {
|
||||
if ok, err := regexp.MatchString("^[a-z0-9]+$", value); !ok || err != nil {
|
||||
return fmt.Errorf("incorrect metric prefix %s: %w", value, err)
|
||||
return fmt.Errorf("incorrect metric prefix %s: %w", value, err)
|
||||
}
|
||||
|
||||
t.Value = value
|
||||
t.Value = value
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type TypePort struct {
|
||||
Value uint16
|
||||
Value uint
|
||||
}
|
||||
|
||||
func (t *TypePort) Set(value string) error {
|
||||
@@ -19,12 +19,12 @@ func (t *TypePort) Set(value string) error {
|
||||
return fmt.Errorf("incorrect port number (%s)", value)
|
||||
}
|
||||
|
||||
t.Value = uint16(portValue)
|
||||
t.Value = uint(portValue)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t TypePort) Get(defaultValue uint16) uint16 {
|
||||
func (t TypePort) Get(defaultValue uint) uint {
|
||||
if t.Value == 0 {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func (t *TypePreferIP) Set(value string) error {
|
||||
switch value {
|
||||
case TypePreferIPPreferIPv4, TypePreferIPPreferIPv6,
|
||||
TypePreferOnlyIPv4, TypePreferOnlyIPv6:
|
||||
t.Value = value
|
||||
t.Value = value
|
||||
|
||||
return nil
|
||||
default:
|
||||
|
||||
@@ -15,7 +15,7 @@ type TypeProxyURL struct {
|
||||
func (t *TypeProxyURL) Set(value string) error {
|
||||
parsedURL, err := url.Parse(value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Value is not corect URL (%s): %w", value, err)
|
||||
return fmt.Errorf("value is not corect URL (%s): %w", value, err)
|
||||
}
|
||||
|
||||
if parsedURL.Host == "" {
|
||||
|
||||
@@ -29,7 +29,7 @@ func (t *TypeStatsdTagFormat) Set(value string) error {
|
||||
switch lowercasedValue {
|
||||
case TypeStatsdTagFormatDatadog, TypeStatsdTagFormatInfluxdb,
|
||||
TypeStatsdTagFormatGraphite:
|
||||
t.Value = lowercasedValue
|
||||
t.Value = lowercasedValue
|
||||
|
||||
return nil
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user