Documentation ¶
Index ¶
- Variables
- type CORSPolicy
- type GRPCServerOption
- type OptionFunc
- func AddForwardHeaderToContext(headerKey []string) OptionFunc
- func RegisterGRPCUnaryInterceptor(name string, unaryServerInterceptor grpc.UnaryServerInterceptor, ...) OptionFunc
- func SetGrpcServerOption(maxRecvMsgSize, maxSendMsgSize, maxMsgSize int) OptionFunc
- func SetRestServerOption(readTimeout time.Duration, writeTimeout time.Duration) OptionFunc
- func UseDefaultHealthcheck(ok bool) OptionFunc
- func WithCustomCORSCredential(enable bool) OptionFunc
- func WithCustomCORSOrigins(origins []string) OptionFunc
- func WithCustomCORSPreflightHeaders(headers []string) OptionFunc
- func WithCustomCORSPreflightMethods(methods []string) OptionFunc
- func WithCustomErrorHandler(customErrorHandler runtime.ErrorHandlerFunc) OptionFunc
- func WithCustomForwardResponseOption(...) OptionFunc
- func WithCustomResponseMessageForwarder(...) OptionFunc
- type RESTServerOption
- type RestHandler
- type RestHandlerAdditional
- type Server
- func (s *Server) GetForwardResponseMessage() ...
- func (s *Server) GetGrpcAddr() string
- func (s *Server) GetGrpcServer() *grpc.Server
- func (s *Server) GetRestAddr() string
- func (s *Server) GetRestServer() *http.Server
- func (s *Server) ListenAndServeGRPC() error
- func (s *Server) ListenAndServeGrst() <-chan error
- func (srv *Server) ListenAndServeGrstGraceful(timeout_graceful int)
- func (s *Server) ListenAndServeREST() error
- func (s *Server) RegisterRestHandler(h RestHandler)
- func (s *Server) RegisterRestHandlerAdditional(method, endpoint string, hf runtime.HandlerFunc)
Constants ¶
This section is empty.
Variables ¶
var DefaultCORSPreflightHeaders = []string{"Accept", "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization", grst_context.CONTEXT_CLIENT_APPNAME.String(), grst_context.CONTEXT_CLIENT_APPVERSION.String(), grst_context.CONTEXT_CLIENT_APPVERSIONCODE.String(), grst_context.CONTEXT_CLIENT_MANUFACTURER.String(), grst_context.CONTEXT_CLIENT_MODEL.String(), grst_context.CONTEXT_CLIENT_PLATFORM.String(), grst_context.CONTEXT_CLIENT_PLATFORMVERSION.String(), grst_context.CONTEXT_CLIENT_SDKVERSION.String(), }
var DefaultCORSPreflightMethods = []string{"GET", "HEAD", "POST", "PUT", "DELETE"}
Functions ¶
This section is empty.
Types ¶
type CORSPolicy ¶
type CORSPolicy struct {
// contains filtered or unexported fields
}
type GRPCServerOption ¶
type GRPCServerOption struct {
// contains filtered or unexported fields
}
type OptionFunc ¶
func AddForwardHeaderToContext ¶
func AddForwardHeaderToContext(headerKey []string) OptionFunc
AddForwardHeaderToContext to forward request header to handler's metadata context (with prefix grst.*). For example, if you pass req header "country", then you can access the data in metadata context with grst.country | Notes: starttime / grst.starttime is reserved
func RegisterGRPCUnaryInterceptor ¶
func RegisterGRPCUnaryInterceptor(name string, unaryServerInterceptor grpc.UnaryServerInterceptor, includeMethods ...string) OptionFunc
func SetGrpcServerOption ¶
func SetGrpcServerOption(maxRecvMsgSize, maxSendMsgSize, maxMsgSize int) OptionFunc
func SetRestServerOption ¶
func SetRestServerOption(readTimeout time.Duration, writeTimeout time.Duration) OptionFunc
func UseDefaultHealthcheck ¶
func UseDefaultHealthcheck(ok bool) OptionFunc
UseDefaultHealthcheck using default healthcheck endpoint. default: true, you can access on http://{host}/_status
func WithCustomCORSCredential ¶
func WithCustomCORSCredential(enable bool) OptionFunc
WithCustomCORSCredential Access-Control-Allow-Credentials. default false
func WithCustomCORSOrigins ¶
func WithCustomCORSOrigins(origins []string) OptionFunc
WithCustomCORSOrigin default Access-Control-Allow-Origin: *
func WithCustomCORSPreflightHeaders ¶
func WithCustomCORSPreflightHeaders(headers []string) OptionFunc
WithCustomCORSPreflightHeader default Access-Control-Allow-Headers: Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, appname, appversion, appversioncode, manufacturer, model, platform, platformversion, sdkversion, User-Agent (grst.DefaultCORSPreflightHeaders)
func WithCustomCORSPreflightMethods ¶
func WithCustomCORSPreflightMethods(methods []string) OptionFunc
default default Access-Control-Allow-Methods: GET, HEAD, POST, PUT, DELETE (grst.DefaultCORSPreflightMethods)
func WithCustomErrorHandler ¶
func WithCustomErrorHandler(customErrorHandler runtime.ErrorHandlerFunc) OptionFunc
WithCustomErrorHandler To change error response handler (including error format)
func WithCustomForwardResponseOption ¶
func WithCustomForwardResponseOption(forwardResponseOption func(ctx context.Context, req http.ResponseWriter, resp proto.Message) error) OptionFunc
WithCustomCORSPreflightHeader default Access-Control-Allow-Headers: Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, appname, appversion, appversioncode, manufacturer, model, platform, platformversion, sdkversion, User-Agent (grst.DefaultCORSPreflightHeaders)
func WithCustomResponseMessageForwarder ¶
func WithCustomResponseMessageForwarder(customForwardResponseMessage func(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, req *http.Request, resp proto.Message, opts ...func(context.Context, http.ResponseWriter, proto.Message) error)) OptionFunc
WithCustomResponseMessageForwarder To change/manipulate response message (including success response format and behavior)
type RESTServerOption ¶
type RESTServerOption struct {
// contains filtered or unexported fields
}
type RestHandler ¶
type RestHandlerAdditional ¶
type RestHandlerAdditional struct { Method string Endpoint string Handler runtime.HandlerFunc }
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) GetForwardResponseMessage ¶
func (s *Server) GetForwardResponseMessage() func(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, w http.ResponseWriter, req *http.Request, resp proto.Message, opts ...func(context.Context, http.ResponseWriter, proto.Message) error)
GetForwardResponseMessage get current forwardResponseMessage (useful for intercepting response)
func (*Server) GetGrpcAddr ¶
GetGrpcAddr will return return :{port}
func (*Server) GetGrpcServer ¶
GetGrpcServer get current grpc server object
func (*Server) GetRestAddr ¶
GetRestPort will return return :{port}
func (*Server) GetRestServer ¶
GetRestServer get current rest server object
func (*Server) ListenAndServeGRPC ¶
func (*Server) ListenAndServeGrst ¶
func (*Server) ListenAndServeGrstGraceful ¶
func (*Server) ListenAndServeREST ¶
func (*Server) RegisterRestHandler ¶
func (s *Server) RegisterRestHandler(h RestHandler)
RegisterRestHandler registering rest handler from grpc-gateway
func (*Server) RegisterRestHandlerAdditional ¶
func (s *Server) RegisterRestHandlerAdditional(method, endpoint string, hf runtime.HandlerFunc)
RegisterRestHandlerAdditional registering rest handler additional (customize / not from *.proto)