Default values for config

This commit is contained in:
Alexander
2026-05-04 16:27:04 +02:00
parent 268ee57913
commit f8040ec088
3 changed files with 21 additions and 10 deletions
+10 -7
View File
@@ -2,6 +2,7 @@ package main
import (
"flag"
"fmt"
"net"
"os"
@@ -32,10 +33,9 @@ func main() {
log.Info().Interface("config", cfg).Msg("Loaded config")
// start the grpc in another thread to not block the next http start
go serveGrpc()
go serveGrpc(*cfg)
serveHttp()
}
func serveHttp() {
@@ -49,27 +49,30 @@ func serveHttp() {
router.Run()
}
func serveGrpc() {
func serveGrpc(config config.Config) {
var opts []grpc.ServerOption
server := grpc.NewServer(opts...)
helloServiceHandler := hello.NewHelloServer()
pb.RegisterHelloServiceServer(server, helloServiceHandler)
listener, err := net.Listen("tcp", "localhost:8081")
listener, err := net.Listen("tcp", fmt.Sprintf("%v:%v", config.App.Host, config.App.Port))
if err != nil {
log.Fatal().Err(err).Msg("Failed to listen on localhost:8081")
}
server.Serve(listener)
}
func parseConfig(path *string) (config.Config, error) {
func parseConfig(path *string) (*config.Config, error) {
f, err := os.Open(*path)
if err != nil {
log.Error().Str("path", *path).Msg("Unable to opent config by path")
return config.Config{}, err
return nil, err
}
defer f.Close()
var cfg config.Config
cfg := config.NewConfig()
decoder := yaml.NewDecoder(f)
err = decoder.Decode(&cfg)
if err != nil {