Skip to content

Commit 1c87587

Browse files
committed
global: fix some lint warning
1 parent b60a28d commit 1c87587

File tree

6 files changed

+90
-124
lines changed

6 files changed

+90
-124
lines changed

configuration/config.go

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package config
22

33
import (
44
"fmt"
5-
"github.com/fsnotify/fsnotify"
6-
"github.com/spf13/viper"
75
"os"
86
"sync"
9-
"time"
7+
8+
"github.com/fsnotify/fsnotify"
9+
"github.com/spf13/viper"
1010
)
1111

12+
//Config manager
1213
type Config struct {
1314
conf *viper.Viper
1415
lock *sync.RWMutex
@@ -36,66 +37,49 @@ func NewRawConfig() *Config {
3637
}
3738
}
3839

40+
//Get a key return interface
3941
func (cf *Config) Get(key string) interface{} {
4042
cf.lock.RLock()
4143
defer cf.lock.RUnlock()
4244
return cf.conf.Get(key)
4345
}
4446

47+
//GetString a key return string
4548
func (cf *Config) GetString(key string) string {
4649
cf.lock.RLock()
4750
defer cf.lock.RUnlock()
4851
return cf.conf.GetString(key)
4952
}
5053

54+
//GetInt a key return int
5155
func (cf *Config) GetInt(key string) int {
5256
cf.lock.RLock()
5357
defer cf.lock.RUnlock()
5458
return cf.conf.GetInt(key)
5559
}
5660

61+
//GetInt64 a key return int64
5762
func (cf *Config) GetInt64(key string) int64 {
5863
cf.lock.RLock()
5964
defer cf.lock.RUnlock()
6065
return cf.conf.GetInt64(key)
6166
}
6267

68+
//GetFloat64 a key return Float64
6369
func (cf *Config) GetFloat64(key string) float64 {
6470
cf.lock.RLock()
6571
defer cf.lock.RUnlock()
6672
return cf.conf.GetFloat64(key)
6773
}
6874

75+
//GetBool a key return int64
6976
func (cf *Config) GetBool(key string) bool {
7077
cf.lock.RLock()
7178
defer cf.lock.RUnlock()
7279
return cf.conf.GetBool(key)
7380
}
7481

75-
func (cf *Config) GetDuration(key string) time.Duration {
76-
cf.lock.RLock()
77-
defer cf.lock.RUnlock()
78-
return cf.conf.GetDuration(key)
79-
}
80-
81-
func (cf *Config) GetStringMap(key string) map[string]interface{} {
82-
cf.lock.RLock()
83-
defer cf.lock.RUnlock()
84-
return cf.conf.GetStringMap(key)
85-
}
86-
87-
func (cf *Config) GetStringSlice(key string) []string {
88-
cf.lock.RLock()
89-
defer cf.lock.RUnlock()
90-
return cf.conf.GetStringSlice(key)
91-
}
92-
93-
func (cf *Config) GetBytes(key string) uint {
94-
cf.lock.RLock()
95-
defer cf.lock.RUnlock()
96-
return cf.conf.GetSizeInBytes(key)
97-
}
98-
82+
//Set key:value
9983
func (cf *Config) Set(key string, value interface{}) {
10084
cf.lock.Lock()
10185
defer cf.lock.Unlock()
@@ -125,23 +109,3 @@ func (cf *Config) MergeConfig(configPath string) (*Config, error) {
125109
func (cf *Config) OnConfigChange(run func(in fsnotify.Event)) {
126110
cf.conf.OnConfigChange(run)
127111
}
128-
129-
func (cf *Config) Print() {
130-
keys := cf.conf.AllKeys()
131-
for _, key := range keys {
132-
fmt.Printf("key: %s, value: %v\n", key, cf.Get(key))
133-
}
134-
}
135-
136-
func (cf *Config) equals(anotherConfig *Config) bool {
137-
if len(cf.conf.AllKeys()) != len(anotherConfig.conf.AllKeys()) {
138-
return false
139-
}
140-
for _, key := range anotherConfig.conf.AllKeys() {
141-
if !cf.ContainsKey(key) {
142-
fmt.Printf("No value for key %s found \n", key)
143-
return false
144-
}
145-
}
146-
return true
147-
}

handler/generate_handler.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package handler
22

33
import (
4-
"errors"
54
"fmt"
65
"math/rand"
76
"path"
@@ -178,7 +177,7 @@ func genIndexHTML(cnf *config.Config, indexPath string) error {
178177
// 首页的文章信息
179178
files, err := utils.ListDir(postsDir, "md")
180179
if err != nil {
181-
return errors.New(fmt.Sprintf("read directory %s failed", postsDir))
180+
return fmt.Errorf("read directory %s failed", postsDir)
182181
}
183182

184183
indexCtx["articles"] = make([]map[string]interface{}, len(files))

0 commit comments

Comments
 (0)