Explorar o código

Windows服务运行npc时读取程序目录下的config文件

xiexiao %!s(int64=4) %!d(string=hai) anos
pai
achega
d43cbde1f6
Modificáronse 2 ficheiros con 12 adicións e 1 borrados
  1. 1 1
      cmd/npc/npc.go
  2. 11 0
      lib/common/run.go

+ 1 - 1
cmd/npc/npc.go

@@ -239,7 +239,7 @@ func run() {
 		}()
 	} else {
 		if *configPath == "" {
-			*configPath = "conf/npc.conf"
+			*configPath = common.GetConfigPath()
 		}
 		go client.StartFromFile(*configPath)
 	}

+ 11 - 0
lib/common/run.go

@@ -76,3 +76,14 @@ func GetTmpPath() string {
 	}
 	return path
 }
+
+//config file path
+func GetConfigPath() string {
+	var path string
+	if IsWindows() {
+		path = filepath.Join(GetAppPath(), "conf/npc.conf")
+	} else {
+		path = "conf/npc.conf"
+	}
+	return path
+}