diff --git a/advisor/rules.go b/advisor/rules.go index 3190bea76c4c76f7cbd07cfdae07686c2a83fdc3..6bd1d5f02735d4b34ae031c99de6d431eed40a24 100644 --- a/advisor/rules.go +++ b/advisor/rules.go @@ -115,9 +115,9 @@ func init() { "OK": { Item: "OK", Severity: "L0", - Summary: "✔️", // heavy check mark unicode - Content: `✔️`, - Case: "✔️", + Summary: "OK", + Content: `OK`, + Case: "OK", Func: (*Query4Audit).RuleOK, }, "ALI.001": { diff --git a/common/config.go b/common/config.go index 1cdff0840722074a61c5dcd5f5d563f139aa7dcc..c1609d3164e7fbe2338492368b7096bdfb3094aa 100644 --- a/common/config.go +++ b/common/config.go @@ -26,6 +26,7 @@ import ( "io/ioutil" "os" "regexp" + "runtime" "strings" "gopkg.in/yaml.v2" @@ -120,6 +121,14 @@ type Configration struct { MaxPrettySQLLength int `yaml:"max-pretty-sql-length"` // 超出该长度的SQL会转换成指纹输出 } +// getDefaultLogOutput get default log-output by runtime.GOOS +func getDefaultLogOutput() string { + if runtime.GOOS == "windows" { + return "nul" + } + return os.Stderr.Name() +} + // Config 默认设置 var Config = &Configration{ OnlineDSN: &dsn{ @@ -158,7 +167,7 @@ var Config = &Configration{ SpaghettiQueryLength: 2048, AllowDropIndex: false, LogLevel: 3, - LogOutput: os.Stderr.Name(), + LogOutput: getDefaultLogOutput(), ReportType: "markdown", ReportCSS: "", ReportJavascript: "", @@ -538,7 +547,7 @@ func readCmdFlags() error { maxPrettySQLLength := flag.Int("max-pretty-sql-length", Config.MaxPrettySQLLength, "MaxPrettySQLLength, 超出该长度的SQL会转换成指纹输出") // 一个不存在log-level,用于更新usage。 // 因为vitess里面也用了flag,这些vitess的参数我们不需要关注 - if !Config.Verbose { + if !Config.Verbose && runtime.GOOS != "windows" { flag.Usage = usage } flag.Parse() @@ -570,7 +579,11 @@ func readCmdFlags() error { if BaseDir == "" { Config.LogOutput = *logOutput } else { - Config.LogOutput = BaseDir + "/" + *logOutput + if runtime.GOOS == "windows" { + Config.LogOutput = *logOutput + } else { + Config.LogOutput = BaseDir + "/" + *logOutput + } } } Config.ReportType = strings.ToLower(*reportType) diff --git a/common/config_test.go b/common/config_test.go index 80dcf7d7192652ab03459de1d73b403872661f98..c75bf056f8c6841f6dabaa9bc865d9819c03bc99 100644 --- a/common/config_test.go +++ b/common/config_test.go @@ -18,6 +18,7 @@ package common import ( "flag" + "runtime" "testing" "github.com/kr/pretty" @@ -25,6 +26,17 @@ import ( var update = flag.Bool("update", false, "update .golden files") +func TestGetDefaultLogOutput(t *testing.T) { + output := getDefaultLogOutput() + if runtime.GOOS == "windows" && output != "nul" { + t.Error("windows default -log-output not nul") + } + + if runtime.GOOS != "windows" && output != "/dev/stderr" { + t.Error("default -log-output not /dev/stderr") + } +} + func TestParseConfig(t *testing.T) { err := ParseConfig("") if err != nil {