更新程序为单文件

This commit is contained in:
bjdgyc
2021-06-17 16:58:38 +08:00
parent a616e42432
commit 0ef18ee2f9
14 changed files with 86 additions and 102 deletions

View File

@@ -1,13 +1,10 @@
package base
import (
"errors"
"fmt"
"math/rand"
"os"
"runtime"
"strings"
"time"
"github.com/bjdgyc/anylink/pkg/utils"
"github.com/spf13/cobra"
@@ -64,13 +61,12 @@ func init() {
viper.SetConfigFile(cfgFile)
viper.AutomaticEnv()
_, err := os.Stat(cfgFile)
if errors.Is(err, os.ErrNotExist) {
// 文件不存在,不做处理
if cfgFile == "" {
// 没有配置文件,不做处理
return
}
err = viper.ReadInConfig()
err := viper.ReadInConfig()
if err != nil {
fmt.Println("Using config file:", err)
}
@@ -79,7 +75,7 @@ func init() {
viper.SetEnvPrefix("link")
// 基础配置
rootCmd.Flags().StringVarP(&cfgFile, "conf", "c", "./conf/server.toml", "config file")
rootCmd.Flags().StringVarP(&cfgFile, "conf", "c", "", "config file")
for _, v := range configs {
if v.Typ == cfgStr {
@@ -118,7 +114,6 @@ func initToolCmd() *cobra.Command {
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)
case secret:
rand.Seed(time.Now().UnixNano())
s, _ := utils.RandSecret(40, 60)
s = strings.Trim(s, "=")
fmt.Printf("Secret:%s\n", s)