使用命令传递启动参数

This commit is contained in:
2024-11-14 11:12:57 +08:00
parent ca7ff275c6
commit 54092a0b9a
2 changed files with 6 additions and 2 deletions

View File

@@ -19,7 +19,7 @@ build:
go mod tidy go mod tidy
go build -o dist/main bin/main.go go build -o dist/main bin/main.go
# 更新部署到服务器 # 更新部署到服务器(生产和测试)
update: build update: build
scp dist/main $(HOST):~/webp/main_new scp dist/main $(HOST):~/webp/main_new
ssh ${HOST} "mv ~/webp/main ~/webp/main_old" ssh ${HOST} "mv ~/webp/main ~/webp/main_old"

View File

@@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"flag"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
@@ -217,7 +218,10 @@ func (image *Image) GetSimilarImagesIdList(collection_name string) (ids []int64)
func main() { func main() {
runtime.GOMAXPROCS(runtime.NumCPU() - 1) runtime.GOMAXPROCS(runtime.NumCPU() - 1)
viper.SetConfigFile("./data/config.yaml") configFilePath := flag.String("config", "./data/config.yaml", "配置文件路径")
flag.Parse()
viper.SetConfigFile(*configFilePath)
if err := viper.ReadInConfig(); err != nil { if err := viper.ReadInConfig(); err != nil {
log.Println("读取配置文件失败", err) log.Println("读取配置文件失败", err)
} }