-
Notifications
You must be signed in to change notification settings - Fork 2
/
module.go
48 lines (40 loc) · 954 Bytes
/
module.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package chi
import (
"context"
"sync"
"github.com/americanas-go/ignite/go-chi/chi.v5"
"github.com/americanas-go/ignite/go.uber.org/fx.v1/module/americanas-go/multiserver.v1"
contextfx "github.com/americanas-go/ignite/go.uber.org/fx.v1/module/context"
server "github.com/americanas-go/multiserver"
c "github.com/go-chi/chi/v5"
"go.uber.org/fx"
)
var once sync.Once
type params struct {
fx.In
Plugins []chi.Plugin `optional:"true"`
}
// Module fx module for chi.
func Module() fx.Option {
options := fx.Options()
once.Do(func() {
options = fx.Options(
contextfx.Module(),
fx.Provide(
func(ctx context.Context, p params) *chi.Server {
return chi.NewServer(ctx, p.Plugins...)
},
func(srv *chi.Server) *c.Mux {
return srv.Mux()
},
fx.Annotated{
Group: multiserver.ServersGroupKey,
Target: func(srv *chi.Server) server.Server {
return srv
},
},
),
)
})
return options
}