feat: optimize read config file

This commit is contained in:
Zhiqiang Li
2023-09-20 02:49:55 +08:00
parent 6a72aac0b8
commit e3cd10288d
4 changed files with 122 additions and 13 deletions

View File

@@ -2,8 +2,8 @@ package main
import (
"context"
"flag"
"fmt"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/stulzq/azure-openai-proxy/azure"
"log"
@@ -26,7 +26,11 @@ func main() {
viper.AutomaticEnv()
parseFlag()
azure.Init()
err := azure.Init()
if err != nil {
panic(err)
}
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
registerRoute(r)
@@ -59,9 +63,13 @@ func runServer(srv *http.Server) {
}
func parseFlag() {
ver := flag.Bool("v", false, "version")
flag.Parse()
if *ver {
pflag.StringP("configFile", "c", "config.yaml", "config file")
pflag.BoolP("version", "v", false, "version information")
pflag.Parse()
if err := viper.BindPFlags(pflag.CommandLine); err != nil {
panic(err)
}
if viper.GetBool("v") {
fmt.Println("version:", version)
fmt.Println("buildDate:", buildDate)
fmt.Println("gitCommit:", gitCommit)