瀏覽代碼

add print version

ffdfgdfg 5 年之前
父節點
當前提交
b6d6fedca2
共有 4 個文件被更改,包括 22 次插入1 次删除
  1. 5 0
      cmd/npc/npc.go
  2. 5 0
      cmd/nps/nps.go
  3. 5 0
      docs/run.md
  4. 7 1
      lib/common/util.go

+ 5 - 0
cmd/npc/npc.go

@@ -37,6 +37,7 @@ var (
 	debug        = flag.Bool("debug", true, "npc debug")
 	pprofAddr    = flag.String("pprof", "", "PProf debug addr (ip:port)")
 	stunAddr     = flag.String("stun_addr", "stun.stunprotocol.org:3478", "stun server address (eg:stun.stunprotocol.org:3478)")
+	ver          = flag.Bool("version", false, "show current version")
 )
 
 func main() {
@@ -44,6 +45,10 @@ func main() {
 	logs.Reset()
 	logs.EnableFuncCallDepth(true)
 	logs.SetLogFuncCallDepth(3)
+	if *ver {
+		common.PrintVersion()
+		return
+	}
 	if *logPath == "" {
 		*logPath = common.GetNpcLogPath()
 	}

+ 5 - 0
cmd/nps/nps.go

@@ -28,11 +28,16 @@ import (
 
 var (
 	level string
+	ver   = flag.Bool("version", false, "show current version")
 )
 
 func main() {
 	flag.Parse()
 	// init log
+	if *ver {
+		common.PrintVersion()
+		return
+	}
 	if err := beego.LoadAppConfig("ini", filepath.Join(common.GetRunPath(), "conf", "nps.conf")); err != nil {
 		log.Fatalln("load config file error", err.Error())
 	}

+ 5 - 0
docs/run.md

@@ -32,6 +32,11 @@
 
 如果需要注册到系统服务可查看[注册到系统服务](/use?id=注册到系统服务)
 
+## 版本检查
+- 对客户端以及服务的均可以使用参数`-version`打印版本
+- `nps -version`或`./nps -version`
+- `npc -version`或`./npc -version`
+
 ## 配置
 - 客户端连接后,在web中配置对应穿透服务即可
 - 可以查看[使用示例](/example)

+ 7 - 1
lib/common/util.go

@@ -2,9 +2,11 @@ package common
 
 import (
 	"bytes"
+	"ehang.io/nps/lib/version"
 	"encoding/base64"
 	"encoding/binary"
 	"errors"
+	"fmt"
 	"html/template"
 	"io"
 	"io/ioutil"
@@ -98,7 +100,7 @@ func Getverifyval(vkey string) string {
 }
 
 //Change headers and host of request
-func ChangeHostAndHeader(r *http.Request, host string, header string, addr string,addOrigin bool) {
+func ChangeHostAndHeader(r *http.Request, host string, header string, addr string, addOrigin bool) {
 	if host != "" {
 		r.Host = host
 	}
@@ -461,3 +463,7 @@ func GetServerIpByClientIp(clientIp net.IP) string {
 	_, ip := GetIntranetIp()
 	return ip
 }
+
+func PrintVersion() {
+	fmt.Printf("Version: %s\nCore version: %s\nSame core version of client and server can connect each other\n", version.VERSION, version.GetVersion())
+}