diff --git a/go.mod b/go.mod index b27bde67..bbf4c774 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/cristalhq/base64 v0.1.2 github.com/goccy/go-yaml v1.12.0 github.com/google/uuid v1.6.0 - github.com/google/wire v0.6.0 github.com/gorilla/handlers v1.5.2 github.com/gorilla/mux v1.8.1 github.com/gripmock/environment v1.0.4 diff --git a/go.sum b/go.sum index 4554dd94..db149794 100644 --- a/go.sum +++ b/go.sum @@ -40,14 +40,10 @@ github.com/goccy/go-yaml v1.12.0/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHv github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/wire v0.6.0 h1:HBkoIh4BdSxoyo9PveV8giw7ZsaBOvzWKfcg/6MrVwI= -github.com/google/wire v0.6.0/go.mod h1:F4QhpQ9EDIdJ1Mbop/NZBRB+5yrR6qg3BnctaoUk6NA= github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE= github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= @@ -105,70 +101,21 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= -golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= -golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 h1:LLhsEBxRTBLuKlQxFBYUOU8xyFgXv6cOTp2HASDlsDk= golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf h1:GillM0Ef0pkZPIB+5iO6SDK+4T9pf6TpaYR6ICD5rVE= diff --git a/internal/deps/zerolog.go b/internal/deps/zerolog.go index 564c4fa7..7c0dc60c 100644 --- a/internal/deps/zerolog.go +++ b/internal/deps/zerolog.go @@ -3,9 +3,10 @@ package deps import ( "context" "log" - "time" "github.com/rs/zerolog" + + "github.com/bavix/gripmock/pkg/zlogger" ) func (b *Builder) Logger(ctx context.Context) context.Context { @@ -14,12 +15,5 @@ func (b *Builder) Logger(ctx context.Context) context.Context { log.Fatal(err) } - return zerolog.New(zerolog.NewConsoleWriter(func(w *zerolog.ConsoleWriter) { - w.TimeFormat = time.RFC3339Nano - })). - Level(level). - With(). - Timestamp(). - Logger(). - WithContext(ctx) + return zlogger.Logger(ctx, level) } diff --git a/pkg/deps/builder.go b/pkg/deps/builder.go deleted file mode 100644 index 3a1acd01..00000000 --- a/pkg/deps/builder.go +++ /dev/null @@ -1,53 +0,0 @@ -//go:build wireinject - -package deps - -import ( - "context" - - "github.com/google/wire" - "github.com/gripmock/environment" - "github.com/gripmock/shutdown" - "github.com/rs/zerolog" - "google.golang.org/grpc" - - "github.com/bavix/gripmock/pkg/grpcreflector" -) - -type Builder struct { - ender *shutdown.Shutdown - config environment.Config - logger *zerolog.Logger - reflector *grpcreflector.GReflector - grpcClient *grpc.ClientConn -} - -func (b *Builder) Config() environment.Config { - return b.config -} - -func (b *Builder) Logger() *zerolog.Logger { - return b.logger -} - -func (b *Builder) Reflector() *grpcreflector.GReflector { - return b.reflector -} - -func (b *Builder) GRPCClient() *grpc.ClientConn { - return b.grpcClient -} - -func New(ctx context.Context) (*Builder, error) { - panic(wire.Build( - environment.New, - NewZerolog, - newLog, - wire.Bind(new(shutdown.Logger), new(*Logger)), - shutdown.New, - grpcClient, - grpcreflector.New, - wire.Struct(new(Builder), "*"), - )) - return &Builder{}, nil -} diff --git a/pkg/deps/grpc_client.go b/pkg/deps/grpc_client.go deleted file mode 100644 index 23ec324e..00000000 --- a/pkg/deps/grpc_client.go +++ /dev/null @@ -1,30 +0,0 @@ -package deps - -import ( - "context" - - "github.com/gripmock/environment" - "github.com/gripmock/shutdown" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" -) - -func grpcClient( - config environment.Config, - shutdown *shutdown.Shutdown, -) (*grpc.ClientConn, error) { - opts := []grpc.DialOption{ - grpc.WithTransportCredentials(insecure.NewCredentials()), - } - - conn, err := grpc.NewClient(config.GRPCAddr, opts...) - if err != nil { - return nil, err - } - - shutdown.Add(func(_ context.Context) error { - return conn.Close() - }) - - return conn, nil -} diff --git a/pkg/deps/logger.go b/pkg/deps/logger.go deleted file mode 100644 index 0d92a4c4..00000000 --- a/pkg/deps/logger.go +++ /dev/null @@ -1,17 +0,0 @@ -package deps - -import ( - "github.com/rs/zerolog" -) - -type Logger struct { - logger *zerolog.Logger -} - -func (l Logger) Err(err error) { - l.logger.Err(err).Send() -} - -func newLog(logger *zerolog.Logger) *Logger { - return &Logger{logger: logger} -} diff --git a/pkg/deps/wire_gen.go b/pkg/deps/wire_gen.go deleted file mode 100644 index 8c16cb9b..00000000 --- a/pkg/deps/wire_gen.go +++ /dev/null @@ -1,70 +0,0 @@ -// Code generated by Wire. DO NOT EDIT. - -//go:generate go run -mod=mod github.com/google/wire/cmd/wire -//go:build !wireinject -// +build !wireinject - -package deps - -import ( - "context" - "github.com/bavix/gripmock/pkg/grpcreflector" - "github.com/gripmock/environment" - "github.com/gripmock/shutdown" - "github.com/rs/zerolog" - "google.golang.org/grpc" -) - -// Injectors from builder.go: - -func New(ctx context.Context) (*Builder, error) { - config, err := environment.New() - if err != nil { - return nil, err - } - logger, err := NewZerolog(config) - if err != nil { - return nil, err - } - depsLogger := newLog(logger) - shutdownShutdown := shutdown.New(depsLogger) - clientConn, err := grpcClient(config, shutdownShutdown) - if err != nil { - return nil, err - } - gReflector := grpcreflector.New(clientConn) - builder := &Builder{ - ender: shutdownShutdown, - config: config, - logger: logger, - reflector: gReflector, - grpcClient: clientConn, - } - return builder, nil -} - -// builder.go: - -type Builder struct { - ender *shutdown.Shutdown - config environment.Config - logger *zerolog.Logger - reflector *grpcreflector.GReflector - grpcClient *grpc.ClientConn -} - -func (b *Builder) Config() environment.Config { - return b.config -} - -func (b *Builder) Logger() *zerolog.Logger { - return b.logger -} - -func (b *Builder) Reflector() *grpcreflector.GReflector { - return b.reflector -} - -func (b *Builder) GRPCClient() *grpc.ClientConn { - return b.grpcClient -} diff --git a/pkg/deps/zerolog.go b/pkg/deps/zerolog.go deleted file mode 100644 index f9aaa21c..00000000 --- a/pkg/deps/zerolog.go +++ /dev/null @@ -1,29 +0,0 @@ -package deps - -import ( - "time" - - "github.com/gripmock/environment" - "github.com/rs/zerolog" -) - -func withTimeFormat(format string) func(w *zerolog.ConsoleWriter) { - return func(w *zerolog.ConsoleWriter) { - w.TimeFormat = format - } -} - -func NewZerolog(config environment.Config) (*zerolog.Logger, error) { - level, err := zerolog.ParseLevel(config.LogLevel) - if err != nil { - return nil, err - } - - logger := zerolog.New(zerolog.NewConsoleWriter(withTimeFormat(time.RFC3339Nano))). - Level(level). - With(). - Timestamp(). - Logger() - - return &logger, nil -} diff --git a/pkg/zlogger/logger.go b/pkg/zlogger/logger.go new file mode 100644 index 00000000..63caa801 --- /dev/null +++ b/pkg/zlogger/logger.go @@ -0,0 +1,32 @@ +package zlogger + +import ( + "context" + "time" + + "github.com/rs/zerolog" +) + +// Logger creates a new zerolog logger with the given log level and wraps it in a context. +// The logger will use a console writer with the time format set to RFC3339Nano. +// The logger will also embed the timestamp in all log entries. +// +// Parameters: +// - ctx: The context to wrap the logger in. +// - level: The log level to use for the logger. +// +// Returns: +// - context.Context: The context with the logger embedded in it. +func Logger(ctx context.Context, level zerolog.Level) context.Context { + // Create a new zerolog logger + logger := zerolog.New(zerolog.NewConsoleWriter(func(w *zerolog.ConsoleWriter) { + // Set the time format of the console writer to RFC3339Nano + w.TimeFormat = time.RFC3339Nano + })). + Level(level). // Set the log level of the logger + With(). // Start a new log entry with no fields + Timestamp() // Add a timestamp to the log entry + + // Wrap the logger in the context and return it + return logger.Logger().WithContext(ctx) +} diff --git a/protoc-gen-gripmock/server.tmpl b/protoc-gen-gripmock/server.tmpl index 054969e7..db1c538f 100644 --- a/protoc-gen-gripmock/server.tmpl +++ b/protoc-gen-gripmock/server.tmpl @@ -28,10 +28,12 @@ import ( "google.golang.org/grpc/health" healthgrpc "google.golang.org/grpc/health/grpc_health_v1" _ "google.golang.org/grpc/encoding/gzip" + "github.com/gripmock/environment" + "github.com/rs/zerolog" "github.com/bavix/gripmock/pkg/grpccontext" sdk "github.com/bavix/gripmock-sdk-go" - "github.com/bavix/gripmock/pkg/deps" + "github.com/bavix/gripmock/pkg/zlogger" ) {{ range $package, $alias := .Dependencies }} import {{$alias}} "{{$package}}" @@ -45,19 +47,27 @@ func main() { ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT) defer cancel() - builder, err := deps.New(ctx) + config, err := environment.New() if err != nil { log.Fatal(err) } - lis, err := net.Listen(builder.Config().GRPCNetwork, builder.Config().GRPCAddr) + level, err := zerolog.ParseLevel(config.LogLevel) if err != nil { - builder.Logger().Fatal().Err(err).Msg("failed to listen") + log.Fatal(err) + } + + ctx = zlogger.Logger(ctx, level) + logger := zerolog.Ctx(ctx) + + lis, err := net.Listen(config.GRPCNetwork, config.GRPCAddr) + if err != nil { + logger.Fatal().Err(err).Msg("failed to listen") } s := grpc.NewServer( - grpc.UnaryInterceptor(grpccontext.UnaryInterceptor(builder.Logger())), - grpc.StreamInterceptor(grpccontext.StreamInterceptor(builder.Logger())), + grpc.UnaryInterceptor(grpccontext.UnaryInterceptor(logger)), + grpc.StreamInterceptor(grpccontext.StreamInterceptor(logger)), ) healthcheck := health.NewServer() @@ -69,9 +79,9 @@ func main() { healthgrpc.RegisterHealthServer(s, healthcheck) reflection.Register(s) - builder.Logger().Info(). - Str("addr", builder.Config().GRPCAddr). - Str("network", builder.Config().GRPCNetwork). + logger.Info(). + Str("addr", config.GRPCAddr). + Str("network", config.GRPCNetwork). Msg("Serving gRPC") // Health check goroutine to wait for the HTTP server to become ready. @@ -79,7 +89,7 @@ func main() { go func() { // Create a new client to interact with the HTTP server API. api, err := sdk.NewClientWithResponses( - fmt.Sprintf("http://%s/api", builder.Config().HTTPAddr), + fmt.Sprintf("http://%s/api", config.HTTPAddr), sdk.WithHTTPClient(http.DefaultClient), ) if err != nil { @@ -110,7 +120,7 @@ func main() { if err == nil && resp.JSON200 != nil { healthcheck.SetServingStatus("gripmock", healthgrpc.HealthCheckResponse_SERVING) - builder.Logger().Info().Msg("gRPC server is ready to accept requests") + logger.Info().Msg("gRPC server is ready to accept requests") return } @@ -119,7 +129,7 @@ func main() { }() if err := s.Serve(lis); err != nil { - builder.Logger().Fatal().Err(err).Msg("failed to serve") + logger.Fatal().Err(err).Msg("failed to serve") } } @@ -128,7 +138,7 @@ func main() { {{ define "services" }} type {{.Name}} struct{ {{.Package}}Unsafe{{.Name}}Server - __builder__ *deps.Builder + __httpAddr__ string } {{ template "methods" .}} @@ -159,7 +169,7 @@ func (s *{{.ServiceName}}) {{.TitleName}}(ctx context.Context, in *{{.Input}}) ( // The stub defines the input and output messages for the method. // If the stub is found, its output message is returned. // If the stub is not found, an error is returned. - err := findStub(ctx, s.__builder__.Config().HTTPAddr, "{{.ServiceName}}", "{{.RpcName}}", md, in, out) + err := findStub(ctx, s.__httpAddr__, "{{.ServiceName}}", "{{.RpcName}}", md, in, out) // Return the output message and any error encountered while finding the stub. return out, err @@ -178,7 +188,7 @@ func (s *{{.ServiceName}}) {{.TitleName}}(in *{{.Input}},srv {{.SvcPackage}}{{.S // The stub defines the input and output messages for the method. // If the stub is found, its output message is returned. // If the stub is not found, an error is returned. - err := findStub(ctx, s.__builder__.Config().HTTPAddr, "{{.ServiceName}}", "{{.RpcName}}", md, in, out) + err := findStub(ctx, s.__httpAddr__, "{{.ServiceName}}", "{{.RpcName}}", md, in, out) if err != nil { // Return the error encountered while finding the stub. return err @@ -214,7 +224,7 @@ func (s *{{.ServiceName}}) {{.TitleName}}(srv {{.SvcPackage}}{{.ServiceName}}_{{ // The stub defines the input and output messages for the method. // If the stub is found, its output message is returned. // If the stub is not found, an error is returned. - err = findStub(ctx, s.__builder__.Config().HTTPAddr, "{{.ServiceName}}","{{.RpcName}}", md, input, out) + err = findStub(ctx, s.__httpAddr__, "{{.ServiceName}}","{{.RpcName}}", md, input, out) if err != nil { // If there is an error finding the stub, return the error. return err @@ -252,7 +262,7 @@ func (s *{{.ServiceName}}) {{.TitleName}}(srv {{.SvcPackage}}{{.ServiceName}}_{{ // The stub defines the input and output messages for the method. // If the stub is found, its output message is returned. // If the stub is not found, an error is returned. - err = findStub(ctx, s.__builder__.Config().HTTPAddr, "{{.ServiceName}}","{{.RpcName}}", md, input, out) + err = findStub(ctx, s.__httpAddr__, "{{.ServiceName}}","{{.RpcName}}", md, input, out) if err != nil { return err } @@ -268,7 +278,7 @@ func (s *{{.ServiceName}}) {{.TitleName}}(srv {{.SvcPackage}}{{.ServiceName}}_{{ {{ define "register_services" }} - {{.Package}}Register{{.Name}}Server(s, &{{.Name}}{__builder__: builder}) + {{.Package}}Register{{.Name}}Server(s, &{{.Name}}{__httpAddr__: config.HTTPAddr}) {{ end }} {{ define "find_stub" }}