package service import ( "os/exec" "service/library/logger" "strconv" "strings" ) var ( DefaultScriptsService *ScriptsService ) type ScriptsService struct { } func NewScriptsService() *ScriptsService { return new(ScriptsService) } // 放置一些执行服务器脚本的service func (s *ScriptsService) QueryCallCount(url string, logpath string) (count int, err error) { cmd := exec.Command("grep", "-c", url, logpath) out, err := cmd.Output() if err != nil { logger.Error("could not run command: %v", err) return } str := string(out) str = strings.ReplaceAll(str, "\n", "") str = strings.ReplaceAll(str, "\r", "") count, err = strconv.Atoi(str) count = count / 2 return }