本文整理汇总了Golang中github.com/purstal/go-tieba-base/logs.Logger.Info方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.Info方法的具体用法?Golang Logger.Info怎么用?Golang Logger.Info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/purstal/go-tieba-base/logs.Logger
的用法示例。
在下文中一共展示了Logger.Info方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LoadStrings
func LoadStrings(file *os.File, set *map[string]struct{}, logger *logs.Logger) error {
bytes, err := ReadAll(file)
if err != nil {
return err
}
lines := split([]rune(string(bytes)), []rune{'\n', ' '})
newSet := map[string]struct{}{}
oldSet := map[string]struct{}{}
for k, v := range *set {
oldSet[k] = v //复制一遍
}
var added []string
for _, _line := range lines {
var line string
if line = strings.TrimSpace(string(_line)); line == "" {
continue
}
newSet[line] = struct{}{}
if _, exist := oldSet[line]; !exist {
added = append(added, line)
}
delete(oldSet, line)
}
*set = newSet
var updateInfo string = fmt.Sprintf("更新关键词(%s):", file.Name())
if len(added) > 0 {
updateInfo = updateInfo + "\n[+]"
for _, str := range added {
updateInfo = updateInfo + str + " "
}
updateInfo = strings.TrimRight(updateInfo, " ")
}
if len(oldSet) > 0 {
updateInfo = updateInfo + "\n[-]"
for str, _ := range oldSet {
updateInfo = updateInfo + str + " "
}
updateInfo = strings.TrimRight(updateInfo, " ")
}
logger.Info(updateInfo)
return nil
}
示例2: LoadExps
func LoadExps(file *os.File, exps *[]RegexpKeyword, logger *logs.Logger) error {
bytes, err := ReadAll(file)
if err != nil {
return err
}
lines := strings.Split(string(bytes), "\n")
oldExps := make(map[string]RegexpKeyword)
for _, exp := range *exps {
if exp.BanFlag {
oldExps["$ban "+exp.Rx.String()] = exp
} else {
oldExps[exp.Rx.String()] = exp
}
}
newExps := make(map[string]RegexpKeyword)
var addedExps []string
for lineNo, line := range lines {
line = strings.TrimRightFunc(line, func(r rune) bool {
return r == '\n' || r == '\r'
})
if line == "" {
continue
}
if exp, exist := oldExps[line]; exist {
newExps[line] = exp
delete(oldExps, line)
} else {
var banFlag bool
var newExp *regexp.Regexp
var err error
if banFlag = strings.HasPrefix(line, "$ban "); banFlag {
newExp, err = regexp.Compile(strings.TrimLeft(line, "$ban "))
} else {
newExp, err = regexp.Compile(line)
}
if err != nil {
logs.Error(fmt.Sprintf("不正确的关键词(第%d行),跳过.", lineNo), err)
} else {
newExps[line] = RegexpKeyword{banFlag, newExp}
addedExps = append(addedExps, line)
}
}
}
newExpSlice := make([]RegexpKeyword, 0, len(newExps))
for _, exp := range newExps {
newExpSlice = append(newExpSlice, exp)
}
*exps = newExpSlice
var updateInfo string = fmt.Sprintf("更新关键词(%s):\n", file.Name())
for _, exp := range addedExps {
updateInfo = updateInfo + "[+] " + exp + "\n"
}
for _, exp := range oldExps {
if exp.BanFlag {
updateInfo = updateInfo + "[-] $ban" + exp.Rx.String() + "\n"
} else {
updateInfo = updateInfo + "[-] " + exp.Rx.String() + "\n"
}
}
updateInfo = strings.TrimSuffix(updateInfo, "\n")
logger.Info(updateInfo)
//logger.Debug("现在的关键词:", newExpSlice, ".")
return nil
}