Files
go-example/main.go
Zpekii 8aa1fe3ca7
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 2m16s
feat: add prometheus metrics
2026-03-01 15:08:07 +08:00

36 lines
668 B
Go

package main
import (
"flag"
"fmt"
"go-example/cmn/conf"
"go-example/hello"
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/viper"
)
var (
version = "1.0.0-local"
)
func main() {
// read -f parameter (config file)
configPath := flag.String("f", ".linux-config.yaml", "config file")
flag.Parse()
conf.Init(*configPath)
http.HandleFunc("/hello", hello.Middleware(hello.Handler))
http.Handle("/metrics", promhttp.Handler())
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)
}
}