good morning!!!!

Skip to content
Commits on Source (1)
package fxchi
import (
"context"
"log/slog"
"net"
"net/http"
"github.com/go-chi/chi/v5"
"go.uber.org/fx"
)
func HttpApp(opts ...fx.Option) fx.Option {
return fx.Module("fxchi",
fx.Provide(RouterHandler),
fx.Invoke(ServerInvoker),
fx.Options(opts...),
)
}
func RouterHandler(routes []func(chi.Router)) http.Handler {
r := chi.NewRouter()
for _, fn := range routes {
fn(r)
}
return r
}
func ServerInvoker(srv *http.Server, log *slog.Logger, lc fx.Lifecycle) {
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
addr := srv.Addr
if addr == "" {
addr = ":http"
}
ln, err := net.Listen("tcp", addr)
if err != nil {
return err
}
go func() {
log.Info("http server started", "addr", addr)
srv.Serve(ln)
}()
return nil
},
OnStop: func(ctx context.Context) error {
return srv.Shutdown(ctx)
},
})
}
......@@ -8,7 +8,7 @@ require (
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da
github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500
github.com/cristalhq/aconfig v0.18.6-0.20231226125657-6e7f9a54f85d
github.com/cristalhq/aconfig/aconfigdotenv v0.17.1
github.com/go-chi/chi/v5 v5.0.12
github.com/joho/godotenv v1.5.1
github.com/lmittmann/tint v1.0.4
github.com/stretchr/testify v1.8.4
......
......@@ -4,16 +4,14 @@ github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500 h1:6lhrsTEnloDPXyeZBvSYvQf8u86jbKehZPVDDlkgDl4=
github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500/go.mod h1:S/7n9copUssQ56c7aAgHqftWO4LTf4xY6CGWt8Bc+3M=
github.com/cristalhq/aconfig v0.17.0/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E=
github.com/cristalhq/aconfig v0.18.6-0.20231226125657-6e7f9a54f85d h1:Ywr0kz8Pf8uxAVedQ9iuFxtQwwSxozru2QCfAjxIdWo=
github.com/cristalhq/aconfig v0.18.6-0.20231226125657-6e7f9a54f85d/go.mod h1:9ogrGEt9yU5V4pif/ThkVUfhj8JkdV+iDeahZGgfnDU=
github.com/cristalhq/aconfig/aconfigdotenv v0.17.1 h1:HG2ql5fGe4FLL2fUv6o+o0YRyF1mWEcYkNfWGWD82k4=
github.com/cristalhq/aconfig/aconfigdotenv v0.17.1/go.mod h1:gQIKkh+HkVcODvMNz/cLbH65Pk9b0r4tfolCOsI8G9I=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s=
github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/lmittmann/tint v1.0.4 h1:LeYihpJ9hyGvE0w+K2okPTGUdVLfng1+nDNVR4vWISc=
......