Browse Source

Merge pull request '修改读取配置文件的路径' (#8) from fix_start into develop

Reviewed-on: http://101.201.121.115:3000/leo/LAPP_ETL/pulls/8
feature_trigger
weichenglei 3 years ago
parent
commit
6ce3d76765
2 changed files with 30 additions and 2 deletions
  1. +2
    -2
      infra/config/config.go
  2. +28
    -0
      utils/util.go

+ 2
- 2
infra/config/config.go View File

@ -1,9 +1,9 @@
package config
import (
"LAPP_ETL/utils"
"github.com/spf13/viper"
"path"
"path/filepath"
)
var AppConfig Config
@ -48,7 +48,7 @@ type ETCD struct {
}
func InitConfig() (err error) {
baseDir, err := filepath.Abs(".")
baseDir, err := utils.GetCurrentPath("/conf")
if err != nil {
return
}


+ 28
- 0
utils/util.go View File

@ -1,11 +1,14 @@
package utils
import (
"errors"
"fmt"
"io"
"log"
"mime/multipart"
"os"
"os/exec"
"path/filepath"
"reflect"
"strconv"
"strings"
@ -207,4 +210,29 @@ func ConvInt2FormatString(input, ilen int)(retstring string){
retstring = strings.Repeat("0", igap) + strconv.Itoa(input)
}
return
}
//windows环境下获取绝对路径
func GetCurrentPath(dir string) (string, error) {
file, err := exec.LookPath(os.Args[0])
if err != nil {
return "", err
}
path, err := filepath.Abs(file)
if err != nil {
return "", err
}
i := strings.LastIndex(path, "/")
if i < 0 {
i = strings.LastIndex(path, "\\")
}
if i < 0 {
return "", errors.New(`error: Can't find "/" or "\".`)
}
pathdir := string(path[0 : i+1])
if len(dir) > 0 {
dir = strings.Replace(dir, "/", "\\", -1)
return filepath.Join(pathdir, dir), nil
}
return string(path[0 : i+1]), nil
}

Loading…
Cancel
Save