add
This commit is contained in:
7
trading_assistant_api/services/country/go.mod
Normal file
7
trading_assistant_api/services/country/go.mod
Normal file
@@ -0,0 +1,7 @@
|
||||
module country
|
||||
|
||||
go 1.25.7
|
||||
|
||||
require common v0.0.0
|
||||
|
||||
replace common => ../../common
|
||||
58
trading_assistant_api/services/country/main.go
Normal file
58
trading_assistant_api/services/country/main.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"common/logger"
|
||||
"common/utils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
port := utils.GetEnv("PORT", "8081")
|
||||
srv := &http.Server{
|
||||
Addr: ":" + port,
|
||||
Handler: routes(),
|
||||
}
|
||||
|
||||
logger.L().Printf("country service starting on :%s", port)
|
||||
|
||||
go func() {
|
||||
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
logger.L().Fatalf("listen: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-quit
|
||||
logger.L().Printf("country service shutting down...")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if err := srv.Shutdown(ctx); err != nil {
|
||||
logger.L().Printf("server shutdown: %v", err)
|
||||
}
|
||||
logger.L().Printf("country service exited")
|
||||
}
|
||||
|
||||
func routes() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("ok"))
|
||||
})
|
||||
mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("country-service v0.1.0"))
|
||||
})
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "hello from country-service")
|
||||
})
|
||||
return mux
|
||||
}
|
||||
Reference in New Issue
Block a user