迁移项目

This commit is contained in:
2022-09-07 17:17:11 +08:00
parent 12ea86b2fb
commit 5d4d02d679
29 changed files with 11431 additions and 43 deletions

18
pkg/helpers/config.go Normal file
View 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
View 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
View 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
}