feat: add configuration management and update deployment files

This commit is contained in:
2026-01-10 19:56:51 +08:00
parent 6730ceafa6
commit d1a5240c34
10 changed files with 180 additions and 21 deletions

16
main.go
View File

@@ -1,9 +1,13 @@
package main
import (
"flag"
"fmt"
"k8s-example/cmn/conf"
"k8s-example/hello"
"net/http"
"github.com/spf13/viper"
)
var (
@@ -11,10 +15,18 @@ var (
)
func main() {
// read -f parameter (config file)
configPath := flag.String("f", ".linux-config.json", "config file")
flag.Parse()
conf.Init(*configPath)
http.HandleFunc("/hello", hello.Handler)
fmt.Println("server on :8800, version:", version)
err := http.ListenAndServe(":8800", nil)
port := viper.GetInt("server.port")
fmt.Println("server on :", port, "version:", version)
err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
if err != nil {
panic(err)
}