✨ 迁移项目
This commit is contained in:
18
pkg/helpers/config.go
Normal file
18
pkg/helpers/config.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// LoadConfig read YAML-formatted config from filename into cfg.
|
||||
func LoadConfig(filename string, cfg interface{}) error {
|
||||
buf, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error reading config file")
|
||||
}
|
||||
|
||||
return yaml.UnmarshalStrict(buf, cfg)
|
||||
}
|
13
pkg/helpers/logerror.go
Normal file
13
pkg/helpers/logerror.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/log"
|
||||
"github.com/go-kit/kit/log/level"
|
||||
)
|
||||
|
||||
// LogError logs any error returned by f; useful when deferring Close etc.
|
||||
func LogError(logger log.Logger, message string, f func() error) {
|
||||
if err := f(); err != nil {
|
||||
level.Error(logger).Log("message", message, "error", err)
|
||||
}
|
||||
}
|
9
pkg/helpers/math.go
Normal file
9
pkg/helpers/math.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package helpers
|
||||
|
||||
// MinUint32 return the min of a and b.
|
||||
func MinUint32(a, b uint32) uint32 {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
Reference in New Issue
Block a user