mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-08 03:10:32 +08:00
添加 deploy 部署脚本
优化应用易用性
This commit is contained in:
@@ -155,6 +155,7 @@ type SCfg struct {
|
||||
Env string `json:"env"`
|
||||
Info string `json:"info"`
|
||||
Data interface{} `json:"data"`
|
||||
Val interface{} `json:"default"`
|
||||
}
|
||||
|
||||
func ServerCfg2Slice() []SCfg {
|
||||
@@ -169,18 +170,27 @@ func ServerCfg2Slice() []SCfg {
|
||||
field := typ.Field(i)
|
||||
value := s.Field(i)
|
||||
tag := field.Tag.Get("json")
|
||||
usage, env := getUsageEnv(tag)
|
||||
usage, env, val := getUsageEnv(tag)
|
||||
|
||||
datas = append(datas, SCfg{Name: tag, Env: env, Info: usage, Data: value.Interface()})
|
||||
datas = append(datas, SCfg{Name: tag, Env: env, Info: usage, Data: value.Interface(), Val: val})
|
||||
}
|
||||
|
||||
return datas
|
||||
}
|
||||
|
||||
func getUsageEnv(name string) (usage, env string) {
|
||||
func getUsageEnv(name string) (usage, env string, val interface{}) {
|
||||
for _, v := range configs {
|
||||
if v.Name == name {
|
||||
usage = v.Usage
|
||||
if v.Typ == cfgStr {
|
||||
val = v.ValStr
|
||||
}
|
||||
if v.Typ == cfgInt {
|
||||
val = v.ValInt
|
||||
}
|
||||
if v.Typ == cfgBool {
|
||||
val = v.ValBool
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -57,6 +57,21 @@ func execute() {
|
||||
envs[rr.Key().String()] = rr.Value().Index(0).String()
|
||||
}
|
||||
|
||||
if !runSrv {
|
||||
if debug {
|
||||
scfgData := ServerCfg2Slice()
|
||||
fmtStr := "%-18v %-23v %-20v %v\n"
|
||||
fmt.Printf(fmtStr, "Name", "Env", "Value", "Info")
|
||||
for _, v := range scfgData {
|
||||
if v.Name == "admin_pass" || v.Name == "jwt_secret" {
|
||||
v.Val = "******"
|
||||
}
|
||||
fmt.Printf(fmtStr, v.Name, v.Env, v.Val, v.Info)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// 移动配置解析代码
|
||||
conf := linkViper.GetString("conf")
|
||||
linkViper.SetConfigFile(conf)
|
||||
@@ -65,10 +80,6 @@ func execute() {
|
||||
// 没有配置文件,直接报错
|
||||
panic("config file err:" + err.Error())
|
||||
}
|
||||
|
||||
if !runSrv {
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
func initCmd() {
|
||||
@@ -112,28 +123,6 @@ func initCmd() {
|
||||
|
||||
cobra.OnInitialize(func() {
|
||||
linkViper.AutomaticEnv()
|
||||
|
||||
// ver := linkViper.GetBool("version")
|
||||
// if ver {
|
||||
// printVersion()
|
||||
// os.Exit(0)
|
||||
// }
|
||||
//
|
||||
// return
|
||||
//
|
||||
// conf := linkViper.GetString("conf")
|
||||
// _, err := os.Stat(conf)
|
||||
// if errors.Is(err, os.ErrNotExist) {
|
||||
// // 没有配置文件,不做处理
|
||||
// panic("conf stat err:" + err.Error())
|
||||
// }
|
||||
//
|
||||
//
|
||||
// linkViper.SetConfigFile(conf)
|
||||
// err = linkViper.ReadInConfig()
|
||||
// if err != nil {
|
||||
// panic("config file err:" + err.Error())
|
||||
// }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -151,6 +140,8 @@ func initToolCmd() *cobra.Command {
|
||||
toolCmd.Flags().BoolVarP(&debug, "debug", "d", false, "list the config viper.Debug() info")
|
||||
|
||||
toolCmd.Run = func(cmd *cobra.Command, args []string) {
|
||||
runSrv = false
|
||||
|
||||
switch {
|
||||
case rev:
|
||||
printVersion()
|
||||
@@ -169,7 +160,7 @@ func initToolCmd() *cobra.Command {
|
||||
pass, _ := utils.PasswordHash(passwd)
|
||||
fmt.Printf("Passwd:%s\n", pass)
|
||||
case debug:
|
||||
linkViper.Debug()
|
||||
// linkViper.Debug()
|
||||
default:
|
||||
fmt.Println("Using [anylink tool -h] for help")
|
||||
}
|
||||
@@ -179,6 +170,6 @@ func initToolCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
func printVersion() {
|
||||
fmt.Printf("%s v%s build on %s [%s, %s] BuildDate:%s commit_id(%s)\n",
|
||||
fmt.Printf("%s v%s build on %s [%s, %s] date:%s commit_id(%s)\n",
|
||||
APP_NAME, APP_VER, runtime.Version(), runtime.GOOS, runtime.GOARCH, BuildDate, CommitId)
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ var configs = []config{
|
||||
{Typ: cfgStr, Name: "conf", Usage: "config file", ValStr: "./conf/server.toml", Short: "c"},
|
||||
{Typ: cfgStr, Name: "profile", Usage: "profile.xml file", ValStr: "./conf/profile.xml"},
|
||||
{Typ: cfgStr, Name: "server_addr", Usage: "TCP服务监听地址(任意端口)", ValStr: ":443"},
|
||||
{Typ: cfgBool, Name: "server_dtls", Usage: "开启DTLS", ValBool: false},
|
||||
{Typ: cfgBool, Name: "server_dtls", Usage: "开启DTLS", ValBool: true},
|
||||
{Typ: cfgStr, Name: "server_dtls_addr", Usage: "DTLS监听地址(任意端口)", ValStr: ":443"},
|
||||
{Typ: cfgStr, Name: "admin_addr", Usage: "后台服务监听地址", ValStr: ":8800"},
|
||||
{Typ: cfgBool, Name: "proxy_protocol", Usage: "TCP代理协议", ValBool: false},
|
||||
|
@@ -31,8 +31,8 @@ jwt_secret = "abcdef.0123456789.abcdef"
|
||||
|
||||
#TCP服务监听地址(任意端口)
|
||||
server_addr = ":443"
|
||||
#开启 DTLS, 默认关闭
|
||||
server_dtls = false
|
||||
#开启 DTLS
|
||||
server_dtls = true
|
||||
#UDP监听地址(任意端口)
|
||||
server_dtls_addr = ":443"
|
||||
#后台服务监听地址
|
||||
@@ -40,6 +40,7 @@ admin_addr = ":8800"
|
||||
#开启tcp proxy protocol协议
|
||||
proxy_protocol = false
|
||||
|
||||
#虚拟网络类型[tun macvtap tap]
|
||||
link_mode = "tun"
|
||||
|
||||
#客户端分配的ip地址池
|
||||
|
@@ -25,10 +25,15 @@ jwt_secret = "abcdef.0123456789.abcdef"
|
||||
|
||||
#TCP服务监听地址(任意端口)
|
||||
server_addr = ":443"
|
||||
#开启 DTLS
|
||||
server_dtls = true
|
||||
#UDP监听地址(任意端口)
|
||||
server_dtls_addr = ":443"
|
||||
#后台服务监听地址
|
||||
admin_addr = ":8800"
|
||||
|
||||
|
||||
#虚拟网络类型[tun macvtap]
|
||||
link_mode = "tun"
|
||||
#客户端分配的ip地址池
|
||||
ipv4_master = "eth0"
|
||||
ipv4_cidr = "192.168.90.0/24"
|
||||
|
@@ -4,7 +4,6 @@ import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -66,7 +65,7 @@ func startTls() {
|
||||
|
||||
ln, err = net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
base.Fatal(err)
|
||||
}
|
||||
defer ln.Close()
|
||||
|
||||
|
Reference in New Issue
Block a user