Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
server: rig up config middleware
go.mod | 1 + go.sum | 2 ++ main.go | 13 +++++++++++--
diff --git a/go.mod b/go.mod index 0bd1c02ab355cd8822f0e5599c11c4be1d5ac40c..5bf335ae4290037f43644f0737479a1b513cf1c5 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,5 @@ require ( github.com/go-chi/chi/v5 v5.0.3 github.com/go-redis/redis/v8 v8.9.0 // indirect + github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec // indirect ) diff --git a/go.sum b/go.sum index 5be9ea3120cd0c316135a9936b1ab6cf5b83efb2..c247c94b038fe706f698e4deeb42f2f63039fe49 100644 --- a/go.sum +++ b/go.sum @@ -31,6 +31,8 @@ github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec h1:DGmKwyZwEB8dI7tbLt/I/gQuP559o/0FrAkHKlQM/Ks= +github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec/go.mod h1:owBmyHYMLkxyrugmfwE/DLJyW8Ro9mkphwuVErQ0iUw= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.opentelemetry.io/otel v0.20.0 h1:eaP0Fqu7SXHwvjiqDq83zImeehOHX8doTvU9AwXON8g= go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo= diff --git a/main.go b/main.go index c40f505f0dc3e282d1ae157a0bdee0870ae86fcf..6350d0d86df1d1c613439b8beb2221e627cf1f22 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" goRedis "github.com/go-redis/redis/v8" + "git.eletrotupi.com/dinheiro/config" "git.eletrotupi.com/dinheiro/redis" ) @@ -66,15 +67,23 @@ fmt.Printf("Usage: %s server\n", os.Args[0]) os.Exit(1) } + appConfig := config.LoadConfig() + router := chi.NewRouter() - // XXX: Fetch from configuration - ropts, err := goRedis.ParseURL("redis://") + // XXX: We should probably have a struct holding all this together + redisHost, ok := appConfig.Get("redis", "redis-host") + if !ok { + log.Fatalf("Invalid redis::redis-host config") + } + + ropts, err := goRedis.ParseURL(redisHost) if err != nil { log.Fatal("Invalid redis host") } rc := goRedis.NewClient(ropts) + router.Use(config.Middleware(appConfig)) router.Use(redis.Middleware(rc)) router.Use(middleware.RealIP) router.Use(middleware.Logger)