升级go version 1.16,ui文件嵌入go二进制内

This commit is contained in:
bjd
2020-12-28 16:10:47 +08:00
parent d8b55de5b5
commit b515406635
21 changed files with 225 additions and 107 deletions

View File

@@ -3,6 +3,7 @@ package base
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strings"
@@ -38,8 +39,7 @@ type ServerConfig struct {
DbFile string `toml:"db_file" info:"数据库地址"`
CertFile string `toml:"cert_file" info:"证书文件"`
CertKey string `toml:"cert_key" info:"证书密钥"`
UiPath string `toml:"ui_path" info:"ui文件路径"`
FilesPath string `toml:"files_path" info:"外部下载文件路径"`
DownFilesPath string `json:"down_files_path" info:"外部下载文件路径"`
LogLevel string `toml:"log_level" info:"日志等级"`
Issuer string `toml:"issuer" info:"系统名称"`
AdminUser string `toml:"admin_user" info:"管理用户名"`
@@ -82,8 +82,12 @@ func initServerCfg() {
Cfg.DbFile = getAbsPath(base, Cfg.DbFile)
Cfg.CertFile = getAbsPath(base, Cfg.CertFile)
Cfg.CertKey = getAbsPath(base, Cfg.CertKey)
Cfg.UiPath = getAbsPath(base, Cfg.UiPath)
Cfg.FilesPath = getAbsPath(base, Cfg.FilesPath)
Cfg.DownFilesPath = getAbsPath(base, Cfg.DownFilesPath)
if len(Cfg.JwtSecret) < 20 {
fmt.Println("请设置 jwt_secret 长度20位以上")
os.Exit(0)
}
fmt.Printf("ServerCfg: %+v \n", Cfg)
}

View File

@@ -3,8 +3,11 @@ package base
import (
"flag"
"fmt"
"math/rand"
"os"
"runtime"
"strings"
"time"
"github.com/bjdgyc/anylink/pkg/utils"
)
@@ -16,13 +19,16 @@ var (
serverFile string
// pass明文
passwd string
// 生成密钥
secret bool
// 显示版本信息
rev bool
)
func initFlag() {
flag.StringVar(&serverFile, "conf", "./conf/server.toml", "server config file path")
flag.StringVar(&passwd, "passwd", "", "the password plaintext")
flag.StringVar(&passwd, "passwd", "", "convert the password plaintext")
flag.BoolVar(&secret, "secret", false, "generate a random jwt secret")
flag.BoolVar(&rev, "rev", false, "display version info")
flag.Parse()
@@ -32,6 +38,14 @@ func initFlag() {
os.Exit(0)
}
if secret {
rand.Seed(time.Now().UnixNano())
s, _ := utils.RandSecret(40, 60)
s = strings.Trim(s, "=")
fmt.Printf("Secret:%s\n", s)
os.Exit(0)
}
if rev {
fmt.Printf("%s v%s build on %s [%s, %s] commit_id(%s) \n",
APP_NAME, APP_VER, runtime.Version(), runtime.GOOS, runtime.GOARCH, CommitId)

View File

@@ -18,7 +18,7 @@ const (
var (
baseLog *log.Logger
baseLevel int
level map[int]string
levels map[int]string
)
func initLog() {
@@ -27,7 +27,7 @@ func initLog() {
}
func logLevel2Int(l string) int {
level = map[int]string{
levels = map[int]string{
_Debug: "Debug",
_Info: "Info",
_Warn: "Warn",
@@ -35,7 +35,7 @@ func logLevel2Int(l string) int {
_Fatal: "Fatal",
}
lvl := _Info
for k, v := range level {
for k, v := range levels {
if strings.ToLower(l) == strings.ToLower(v) {
lvl = k
}
@@ -44,7 +44,7 @@ func logLevel2Int(l string) int {
}
func output(l int, s ...interface{}) {
lvl := fmt.Sprintf("[%s] ", level[l])
lvl := fmt.Sprintf("[%s] ", levels[l])
baseLog.Output(3, lvl+fmt.Sprintln(s...))
}