代码拉取完成,页面将自动刷新
package go_sensitive
import (
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
type Options struct {
//默认脏词库
DefaultDictDataPath string `yaml:"DefaultDictDataPath"`
//自定义脏词库
UserDictDataPath string `yaml:"UserDictDataPath"`
//TCP监听地址
TCPAddr string `yaml:"TCPAddr"`
}
func NewOptions(configPath string) *Options {
var err error
workDir, err := workDir()
if err != nil {
panic(err)
}
if len(configPath) == 0 {
configPath = path.Join(workDir, "../conf/app.yaml")
}
bConf, err := ioutil.ReadFile(configPath)
if err != nil {
panic(err)
}
options := &Options{}
err = yaml.Unmarshal(bConf, options)
if err != nil {
panic(err)
}
return options
}
// return app work dir.
func workDir() (string, error) {
appPath, err := exec.LookPath(os.Args[0])
if err != nil {
return "", err
}
appPath, err = filepath.Abs(appPath)
if err != nil {
return "", err
}
// Note: we don't use path.Dir here because it does not handle case
// which path starts with two "/" in Windows: "//psf/Home/..."
appPath = strings.Replace(appPath, "\\", "/", -1)
i := strings.LastIndex(appPath, "/")
if i == -1 {
return appPath, nil
}
return appPath[:i], nil
}
func init() {
customFormatter := new(log.TextFormatter)
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
log.SetFormatter(customFormatter)
customFormatter.FullTimestamp = true
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。