grst

package module
v0.0.0-...-01f7578 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2023 License: BSD-3-Clause Imports: 24 Imported by: 20

Documentation

Index

Constants

This section is empty.

Variables

View Source
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(),
}
View Source
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

type OptionFunc func(*Server) error

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 RestHandler func(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

type RestHandlerAdditional

type RestHandlerAdditional struct {
	Method   string
	Endpoint string
	Handler  runtime.HandlerFunc
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(grpcPort int, restPort int, enableRest bool, options ...OptionFunc) (*Server, error)

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

func (s *Server) GetGrpcAddr() string

GetGrpcAddr will return return :{port}

func (*Server) GetGrpcServer

func (s *Server) GetGrpcServer() *grpc.Server

GetGrpcServer get current grpc server object

func (*Server) GetRestAddr

func (s *Server) GetRestAddr() string

GetRestPort will return return :{port}

func (*Server) GetRestServer

func (s *Server) GetRestServer() *http.Server

GetRestServer get current rest server object

func (*Server) ListenAndServeGRPC

func (s *Server) ListenAndServeGRPC() error

func (*Server) ListenAndServeGrst

func (s *Server) ListenAndServeGrst() <-chan error

func (*Server) ListenAndServeGrstGraceful

func (srv *Server) ListenAndServeGrstGraceful(timeout_graceful int)

func (*Server) ListenAndServeREST

func (s *Server) ListenAndServeREST() error

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)

Directories

Path Synopsis
builtin
interceptor

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL