Commit 1d972ac5 by lichenggang

用户自行配置

parent 6ecaf9d1
Showing with 6 additions and 1 deletions
package config package config
import ( import (
"flag"
"log" "log"
"os" "os"
"strings" "strings"
...@@ -8,6 +9,7 @@ import ( ...@@ -8,6 +9,7 @@ import (
var Directory string var Directory string
var UserConfigPath string var UserConfigPath string
var Port string
func GetCurrentPath() string { func GetCurrentPath() string {
dir, err := os.Getwd() dir, err := os.Getwd()
...@@ -17,6 +19,9 @@ func GetCurrentPath() string { ...@@ -17,6 +19,9 @@ func GetCurrentPath() string {
return strings.Replace(dir, "\\", "/", -1) return strings.Replace(dir, "\\", "/", -1)
} }
func InitConfig() { func InitConfig() {
flag.StringVar(&Directory, "dir", "/data/inotify_logs", "监听目录")
flag.StringVar(&Port, "port", "9997", "监听端口")
Directory = "E:\\test_logs" // directory of the log Directory = "E:\\test_logs" // directory of the log
logenv := os.Getenv("GOLOGENV") logenv := os.Getenv("GOLOGENV")
if logenv == "TEST" { if logenv == "TEST" {
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
// example // example
func main() { func main() {
addrs := "0.0.0.0:9997" addrs := "0.0.0.0:" + config.Port
config.InitConfig() config.InitConfig()
fmt.Printf("查看日志目录: %s \n用户配置文件: %s", config.Directory, config.UserConfigPath) fmt.Printf("查看日志目录: %s \n用户配置文件: %s", config.Directory, config.UserConfigPath)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment