Files
Daniel IssoupovandGitHub f89337ba0c Changed lint (#113)
* Refactoring Logs

* Changed lint

* Removed err with rctx in ctx.go

* Changed ctx.go and marshal.go
2022-12-30 05:35:20 +00:00

58 lines
1.3 KiB
Go

package gserver
import (
"net/http"
"google.golang.org/grpc"
)
// Middleware defines middleware handler
type Middleware func(handler http.Handler) http.Handler
// Option is an option that can be passed to New().
// Option configures how we set up the client
type Option interface {
apply(*options)
}
// WithMiddleware option to provide HTTP handler
func WithMiddleware(otherHandler Middleware) Option {
return newFuncOption(func(o *options) {
o.handlers = append(o.handlers, otherHandler)
})
}
// WithUnaryServerInterceptor option to provide RPC UnaryServerInterceptor
func WithUnaryServerInterceptor(other grpc.UnaryServerInterceptor) Option {
return newFuncOption(func(o *options) {
o.unary = append(o.unary, other)
})
}
// WithStreamServerInterceptor option to provide RPC StreamServerInterceptor
func WithStreamServerInterceptor(other grpc.StreamServerInterceptor) Option {
return newFuncOption(func(o *options) {
o.stream = append(o.stream, other)
})
}
type options struct {
handlers []Middleware
unary []grpc.UnaryServerInterceptor
stream []grpc.StreamServerInterceptor
}
type funcOption struct {
f func(*options)
}
func (fo *funcOption) apply(o *options) {
fo.f(o)
}
func newFuncOption(f func(*options)) *funcOption {
return &funcOption{
f: f,
}
}