Fix lint and format code in core dir

This commit is contained in:
loyalsoldier
2021-06-06 21:00:27 +08:00
parent ca328208cc
commit 41790b80ac
42 changed files with 75 additions and 109 deletions

View File

@@ -66,7 +66,6 @@ func newBaseConfier(str1 string) *BaseConfiger {
} else {
return "", errors.New("mock error")
}
},
}
}

View File

@@ -165,6 +165,7 @@ func (c *BaseConfiger) DefaultBool(key string, defaultVal bool) bool {
}
return defaultVal
}
func (c *BaseConfiger) DefaultFloat(key string, defaultVal float64) float64 {
if res, err := c.Float(key); err == nil {
return res
@@ -370,5 +371,4 @@ func ToString(x interface{}) string {
type DecodeOption func(options decodeOptions)
type decodeOptions struct {
}
type decodeOptions struct{}

View File

@@ -20,7 +20,6 @@ import (
)
func TestExpandValueEnv(t *testing.T) {
testCases := []struct {
item string
want string
@@ -51,5 +50,4 @@ func TestExpandValueEnv(t *testing.T) {
t.Errorf("expand value error, item %q want %q, got %q", c.item, c.want, got)
}
}
}

View File

@@ -119,7 +119,6 @@ func (e *EtcdConfiger) Sub(key string) (config.Configer, error) {
// TODO remove this before release v2.0.0
func (e *EtcdConfiger) OnChange(key string, fn func(value string)) {
buildOptsFunc := func() []clientv3.OpOption {
return []clientv3.OpOption{}
}
@@ -144,11 +143,9 @@ func (e *EtcdConfiger) OnChange(key string, fn func(value string)) {
rch = e.client.Watch(context.Background(), e.prefix+key, buildOptsFunc()...)
}
}()
}
type EtcdConfigerProvider struct {
}
type EtcdConfigerProvider struct{}
// Parse = ParseData([]byte(key))
// key must be json

View File

@@ -32,7 +32,6 @@ func TestEtcdConfigerProvider_Parse(t *testing.T) {
}
func TestEtcdConfiger(t *testing.T) {
provider := &EtcdConfigerProvider{}
cfger, _ := provider.Parse(readEtcdConfig())

View File

@@ -42,15 +42,19 @@ func String(key string) (string, error) {
func Strings(key string) ([]string, error) {
return globalInstance.Strings(key)
}
func Int(key string) (int, error) {
return globalInstance.Int(key)
}
func Int64(key string) (int64, error) {
return globalInstance.Int64(key)
}
func Bool(key string) (bool, error) {
return globalInstance.Bool(key)
}
func Float(key string) (float64, error) {
return globalInstance.Float(key)
}
@@ -64,15 +68,19 @@ func DefaultString(key string, defaultVal string) string {
func DefaultStrings(key string, defaultVal []string) []string {
return globalInstance.DefaultStrings(key, defaultVal)
}
func DefaultInt(key string, defaultVal int) int {
return globalInstance.DefaultInt(key, defaultVal)
}
func DefaultInt64(key string, defaultVal int64) int64 {
return globalInstance.DefaultInt64(key, defaultVal)
}
func DefaultBool(key string, defaultVal bool) bool {
return globalInstance.DefaultBool(key, defaultVal)
}
func DefaultFloat(key string, defaultVal float64) float64 {
return globalInstance.DefaultFloat(key, defaultVal)
}
@@ -89,6 +97,7 @@ func GetSection(section string) (map[string]string, error) {
func Unmarshaler(prefix string, obj interface{}, opt ...DecodeOption) error {
return globalInstance.Unmarshaler(prefix, obj, opt...)
}
func Sub(key string) (Configer, error) {
return globalInstance.Sub(key)
}

View File

@@ -46,8 +46,7 @@ var (
)
// IniConfig implements Config to parse ini file.
type IniConfig struct {
}
type IniConfig struct{}
// Parse creates a new Config and parses the file configuration from the named file.
func (ini *IniConfig) Parse(name string) (Configer, error) {

View File

@@ -23,7 +23,6 @@ import (
)
func TestIni(t *testing.T) {
var (
inicontext = `
;comment one
@@ -129,11 +128,9 @@ password = ${GOPATH}
if res != "astaxie" {
t.Fatal("get name error")
}
}
func TestIniSave(t *testing.T) {
const (
inicontext = `
app = app

View File

@@ -31,8 +31,7 @@ import (
)
// JSONConfig is a json config parser and implements Config interface.
type JSONConfig struct {
}
type JSONConfig struct{}
// Parse returns a ConfigContainer with parsed json config map.
func (js *JSONConfig) Parse(filename string) (config.Configer, error) {

View File

@@ -25,7 +25,6 @@ import (
)
func TestJsonStartsWithArray(t *testing.T) {
const jsoncontextwitharray = `[
{
"url": "user",
@@ -72,7 +71,6 @@ func TestJsonStartsWithArray(t *testing.T) {
}
func TestJson(t *testing.T) {
var (
jsoncontext = `{
"appname": "beeapi",

View File

@@ -47,7 +47,6 @@ func (c *Config) ParseData(data []byte) (config.Configer, error) {
return &configContainer{
t: t,
}, nil
}
// configContainer support key looks like "a.b.c"
@@ -70,7 +69,6 @@ func (c *configContainer) Set(key, val string) error {
// return error if key not found or value is invalid type
func (c *configContainer) String(key string) (string, error) {
res, err := c.get(key)
if err != nil {
return "", err
}
@@ -90,7 +88,6 @@ func (c *configContainer) String(key string) (string, error) {
// return error if key not found or value is invalid type
func (c *configContainer) Strings(key string) ([]string, error) {
val, err := c.get(key)
if err != nil {
return []string{}, err
}
@@ -141,9 +138,7 @@ func (c *configContainer) Int64(key string) (int64, error) {
// bool return bool value
// return error if key not found or value is invalid type
func (c *configContainer) Bool(key string) (bool, error) {
res, err := c.get(key)
if err != nil {
return false, err
}
@@ -330,7 +325,6 @@ func (c *configContainer) get(key string) (interface{}, error) {
segs := strings.Split(key, keySeparator)
t, err := subTree(c.t, segs[0:len(segs)-1])
if err != nil {
return nil, err
}

View File

@@ -102,7 +102,6 @@ func (c *ConfigContainer) Sub(key string) (config.Configer, error) {
return &ConfigContainer{
data: sub,
}, nil
}
func (c *ConfigContainer) sub(key string) (map[string]interface{}, error) {
@@ -170,7 +169,6 @@ func (c *ConfigContainer) DefaultInt64(key string, defaultVal int64) int64 {
return defaultVal
}
return v
}
// Float returns the float value for a given key.

View File

@@ -25,7 +25,6 @@ import (
)
func TestXML(t *testing.T) {
var (
// xml parse should incluce in <config></config> tags
xmlcontext = `<?xml version="1.0" encoding="UTF-8"?>
@@ -149,7 +148,6 @@ func TestXML(t *testing.T) {
err = xmlconf.Unmarshaler("mysection", sec)
assert.Nil(t, err)
assert.Equal(t, "MySection", sec.Name)
}
type Section struct {

View File

@@ -302,7 +302,6 @@ func (c *ConfigContainer) DefaultStrings(key string, defaultVal []string) []stri
// GetSection returns map for the given section
func (c *ConfigContainer) GetSection(section string) (map[string]string, error) {
if v, ok := c.data[section]; ok {
return v.(map[string]string), nil
}
@@ -335,7 +334,6 @@ func (c *ConfigContainer) DIY(key string) (v interface{}, err error) {
}
func (c *ConfigContainer) getData(key string) (interface{}, error) {
if len(key) == 0 {
return nil, errors.New("key is empty")
}

View File

@@ -25,7 +25,6 @@ import (
)
func TestYaml(t *testing.T) {
var (
yamlcontext = `
"appname": beeapi