Documentation ¶
Index ¶
- Variables
- func BuildDownstreamGRPCClient(serviceName string, hooks *Hooks, cfg *config.CommonGRPCDownstreamData) (*grpc.ClientConn, error)
- func BuildDownstreamHTTPClient(serviceName string, cfg *config.CommonDownstreamData) (*http.Client, error)
- func ConfigFileSystemOnto(ctx context.Context, fs afero.Fs) context.Context
- func DefaultGrpcServerOptions(ctx context.Context, grpcPublicServerConfig *config.CommonServerConfig) ([]grpc.ServerOption, error)
- func GetAppConfigType(createService interface{}) reflect.Type
- func InitialiseLogging(ctx context.Context, configs []log.Config, logrusLogger *logrus.Logger) context.Context
- func LoadCustomConfig(ctx context.Context, customConfig interface{}) (interface{}, error)
- func MustTypeCheckCreateService(createService, serviceInterface interface{})
- func NewZeroCustomConfig(downstreamConfigType, appConfigType reflect.Type) interface{}
- func Recoverer(ctx context.Context) func(http.Handler) http.Handler
- func ResolveGRPCAuthorizationRule(ctx context.Context, cfg *config.DefaultConfig, h *Hooks, endpointName string, ...) (authrules.Rule, error)
- func ResolveGrpcDialOptions(serviceName string, h *Hooks, ...) ([]grpc.DialOption, error)
- func ResolveGrpcServerOptions(ctx context.Context, h *Hooks, ...) ([]grpc.ServerOption, error)
- func ResolveRESTAuthorizationRule(ctx context.Context, cfg *config.DefaultConfig, h *Hooks, endpointName string, ...) (authrules.Rule, error)
- func SelectBasePath(fromSpec, dynamic string) string
- func Serve(ctx context.Context, ...) error
- func Server(ctx context.Context, name string, hl Manager, grpcHl GrpcManager, ...) errordeprecated
- func TraceidLogInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- type GrpcGenCallback
- type GrpcManagerdeprecated
- type GrpcServerManager
- type HTTPManagerShim
- func (m *HTTPManagerShim) AdminServerConfig() *config.CommonHTTPServerConfig
- func (m *HTTPManagerShim) EnabledHandlers() []handlerinitialiser.HandlerInitialiser
- func (m *HTTPManagerShim) LibraryConfig() *config.LibraryConfig
- func (m *HTTPManagerShim) PublicServerConfig() *config.CommonHTTPServerConfig
- type Hooks
- type Manager
- type RestGenCallback
- type ServerOption
- func WithGrpcManager(manager GrpcManager) ServerOption
- func WithGrpcServerManager(manager GrpcServerManager) ServerOption
- func WithLogrusLogger(logger *logrus.Logger) ServerOptiondeprecated
- func WithPkgLogger(configs ...log.Config) ServerOption
- func WithPrometheusRegistry(prometheusRegistry *prometheus.Registry) ServerOption
- func WithRestManager(manager Manager) ServerOption
- type ServerParams
- type TLSLogFilter
Constants ¶
This section is empty.
Variables ¶
var ( // Name is set at the build time Name = "" // Version is set at the build time Version = "" // BuildID is set at the build time BuildID = "" // CommitSha is set at the build time CommitSha = "" // BranchName is set at the build time BranchName = "" // TagName is set at the build time TagName = "" )
Functions ¶
func BuildDownstreamGRPCClient ¶ added in v0.56.0
func BuildDownstreamGRPCClient(serviceName string, hooks *Hooks, cfg *config.CommonGRPCDownstreamData) (*grpc.ClientConn, error)
BuildDownstreamGRPCClient creates a grpc client connection to the target indicated by cfg.ServiceAddress. The dial options can be customised by cfg or by hooks, see ResolveGrpcDialOptions for details. The serviceName is the name of the target service. This function is intended to be called from generated code.
func ConfigFileSystemOnto ¶ added in v0.84.0
ConfigFileSystemOnto adds a config filesystem to ctx.
func DefaultGrpcServerOptions ¶ added in v0.97.0
func DefaultGrpcServerOptions(ctx context.Context, grpcPublicServerConfig *config.CommonServerConfig) ([]grpc.ServerOption, error)
func GetAppConfigType ¶ added in v0.87.0
GetAppConfigType extracts the app's config type from createService. Precondition: MustTypeCheckCreateService(createService, serviceInterface) succeeded.
func InitialiseLogging ¶ added in v0.85.0
func InitialiseLogging(ctx context.Context, configs []log.Config, logrusLogger *logrus.Logger) context.Context
initialise the logger sysl-go always uses a pkg logger internally. if custom code passes in a logrus logger, a mechanism which is deprecated, then a hook is added to the internal pkg logger that forwards logged events to the provided logrus logger. sysl-go can be requested to log in a verbose manner. logger in a verbose manner logs additional details within log events where appropriate. the mechanism to set this verbose manner is to either have a sufficiently high logrus log level or the verbose mode set against the pkg logger.
func LoadCustomConfig ¶ added in v0.87.0
LoadCustomConfig populates the given zero customConfig value with configuration data.
func MustTypeCheckCreateService ¶ added in v0.87.0
func MustTypeCheckCreateService(createService, serviceInterface interface{})
MustTypeCheckCreateService checks that the given createService has an acceptable type, and panics otherwise.
func NewZeroCustomConfig ¶ added in v0.87.0
NewZeroCustomConfig uses reflection to create a new type derived from DefaultConfig, but with new GenCode.Downstream and App fields holding the same types as downstreamConfig and appConfig. It returns a pointer to a zero value of that new type.
func ResolveGRPCAuthorizationRule ¶ added in v0.108.0
func ResolveGrpcDialOptions ¶ added in v0.98.0
func ResolveGrpcDialOptions(serviceName string, h *Hooks, grpcDownstreamConfig *config.CommonGRPCDownstreamData) ([]grpc.DialOption, error)
func ResolveGrpcServerOptions ¶ added in v0.97.0
func ResolveGrpcServerOptions(ctx context.Context, h *Hooks, grpcPublicServerConfig *config.CommonServerConfig) ([]grpc.ServerOption, error)
func ResolveRESTAuthorizationRule ¶ added in v0.109.0
func SelectBasePath ¶
SelectBasePath chooses between a specified base path and a dynmaically chosen one.
func Serve ¶ added in v0.84.0
func Serve( ctx context.Context, downstreamConfig, createService, serviceInterface interface{}, newManager func(ctx context.Context, cfg *config.DefaultConfig, serviceIntf interface{}, hooks *Hooks) (interface{}, error), ) error
Serve serves an auto-generated service.
func TraceidLogInterceptor ¶ added in v0.97.0
func TraceidLogInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
Types ¶
type GrpcGenCallback ¶ added in v0.4.0
type GrpcGenCallback interface {
DownstreamTimeoutContext(ctx context.Context) (context.Context, context.CancelFunc)
}
GrpcGenCallback is currently a subset of RestGenCallback so is defined separately for convenience.
type GrpcManager
deprecated
type GrpcManager interface { Interceptors() []grpc.UnaryServerInterceptor EnabledGrpcHandlers() []handlerinitialiser.GrpcHandlerInitialiser GrpcAdminServerConfig() *config.CommonServerConfig GrpcPublicServerConfig() *config.CommonServerConfig }
Deprecated: prefer GrpcServerManager.
type GrpcServerManager ¶ added in v0.97.0
type GrpcServerManager struct { GrpcServerOptions []grpc.ServerOption EnabledGrpcHandlers []handlerinitialiser.GrpcHandlerInitialiser GrpcPublicServerConfig *config.CommonServerConfig }
type HTTPManagerShim ¶ added in v0.91.0
type HTTPManagerShim struct {
// contains filtered or unexported fields
}
func NewHTTPManagerShim ¶ added in v0.91.0
func NewHTTPManagerShim(libraryConfig *config.LibraryConfig, adminServerConfig *config.CommonHTTPServerConfig, publicServerConfig *config.CommonHTTPServerConfig, enabledHandlers []handlerinitialiser.HandlerInitialiser) *HTTPManagerShim
func (*HTTPManagerShim) AdminServerConfig ¶ added in v0.91.0
func (m *HTTPManagerShim) AdminServerConfig() *config.CommonHTTPServerConfig
func (*HTTPManagerShim) EnabledHandlers ¶ added in v0.91.0
func (m *HTTPManagerShim) EnabledHandlers() []handlerinitialiser.HandlerInitialiser
func (*HTTPManagerShim) LibraryConfig ¶ added in v0.91.0
func (m *HTTPManagerShim) LibraryConfig() *config.LibraryConfig
func (*HTTPManagerShim) PublicServerConfig ¶ added in v0.91.0
func (m *HTTPManagerShim) PublicServerConfig() *config.CommonHTTPServerConfig
type Hooks ¶ added in v0.97.0
type Hooks struct { MapError func(ctx context.Context, err error) *common.HTTPError // AdditionalGrpcDialOptions can be used to append to the default grpc.DialOption configuration used by // an autogenerated service when it calls grpc.Dial when using a grpc.Client to connect to a gRPC server. // If given, AdditionalGrpcDialOptions will be appended to the list of default options created by // DefaultGrpcDialOptions(CommonGRPCDownstreamData). // // Use AdditionalGrpcDialOptions if you need both default and custom options. Be careful that you do // not specify any options that clash with the default options. // // If you need to completely override the default options, use OverrideGrpcDialOptions. // It is an error to set both AdditionalGrpcDialOptions and OverrideGrpcDialOptions. AdditionalGrpcDialOptions []grpc.DialOption // OverrideGrpcDialOptions can be used to override the default grpc.DialOption configuration used by an // an autogenerated service when it calls grpc.Dial when using a grpc.Client to connect to a gRPC server. // // The serviceName parameter will be filled with the name of the target service that we // are about to call grpc.Dial to connect to -- a function implementing this hook can use the // serviceName to customise different dial options for different targets. // // Prefer to use AdditionalGrpcDialOptions instead of OverrideGrpcDialOptions if you only need // to append to the default grpc.DialOption configuration instead of overriding it completely. // // It is an error to set both AdditionalGrpcDialOptions and OverrideGrpcDialOptions. OverrideGrpcDialOptions func(serviceName string, cfg *config.CommonGRPCDownstreamData) ([]grpc.DialOption, error) // AdditionalGrpcServerOptions can be used to append to the default grpc.ServerOption configuration used by // an autogenerated service when it creates a gRPC server. If given, AdditionalGrpcServerOptions will be // appended to the list of default options created by DefaultGrpcServerOptions(context.Context, CommonServerConfig). // // Use AdditionalGrpcServerOptions if you need both default and custom options. Be careful that you do // not specify any options that clash with the default options. // // If you need to completely override the default options, use OverrideGrpcServerOptions. // It is an error to set both AdditionalGrpcServerOptions and OverrideGrpcServerOptions. AdditionalGrpcServerOptions []grpc.ServerOption // OverrideGrpcServerOptions can be used to override the default grpc.ServerOption configuration used by an // autogenerated service when it creates a gRPC server. // // Prefer to use AdditionalGrpcServerOptions instead of OverrideGrpcServerOptions if you only need // to append to the default grpc.ServerOption configuration instead of overriding it completely. // // It is an error to set both AdditionalGrpcServerOptions and OverrideGrpcServerOptions. OverrideGrpcServerOptions func(ctx context.Context, grpcPublicServerConfig *config.CommonServerConfig) ([]grpc.ServerOption, error) // OverrideMakeJWTClaimsBasedAuthorizationRule can be used to customise how authorization rule // expressions are evaluated and used to decide if JWT claims are authorised. By default, if this // hook is nil, then authrules.MakeDefaultJWTClaimsBasedAuthorizationRule is used. OverrideMakeJWTClaimsBasedAuthorizationRule func(authorizationRuleExpression string) (authrules.JWTClaimsBasedAuthorizationRule, error) }
Hooks can be used to customise the behaviour of an autogenerated sysl-go service.
type Manager ¶
type Manager interface { EnabledHandlers() []handlerinitialiser.HandlerInitialiser LibraryConfig() *config.LibraryConfig AdminServerConfig() *config.CommonHTTPServerConfig PublicServerConfig() *config.CommonHTTPServerConfig }
type RestGenCallback ¶ added in v0.4.0
type RestGenCallback interface { // AddMiddleware allows hand-crafted code to add middleware to the router AddMiddleware(ctx context.Context, r chi.Router) // BasePath allows hand-crafted code to set the base path for the Router BasePath() string // Config returns a structure representing the server config // This is returned from the status endpoint Config() interface{} // MapError maps an error to an HTTPError in instances where custom error mapping is required. Return nil to perform default error mapping; defined as: // 1. CustomError.HTTPError if the original error is a CustomError, otherwise // 2. common.MapError MapError(ctx context.Context, err error) *common.HTTPError // DownstreamTimeoutContext add the desired timeout duration to the context for downstreams // A separate service timeout (usually greater than the downstream) should also be in // place to automatically respond to callers DownstreamTimeoutContext(ctx context.Context) (context.Context, context.CancelFunc) }
RestGenCallback is used by `sysl-go` to call hand-crafted code.
type ServerOption ¶ added in v0.24.0
type ServerOption interface {
// contains filtered or unexported methods
}
func WithGrpcManager ¶ added in v0.24.0
func WithGrpcManager(manager GrpcManager) ServerOption
func WithGrpcServerManager ¶ added in v0.97.0
func WithGrpcServerManager(manager GrpcServerManager) ServerOption
func WithLogrusLogger
deprecated
added in
v0.24.0
func WithLogrusLogger(logger *logrus.Logger) ServerOption
Deprecated: Use WithPkgLogger instead.
func WithPkgLogger ¶ added in v0.32.0
func WithPkgLogger(configs ...log.Config) ServerOption
func WithPrometheusRegistry ¶ added in v0.24.0
func WithPrometheusRegistry(prometheusRegistry *prometheus.Registry) ServerOption
func WithRestManager ¶ added in v0.24.0
func WithRestManager(manager Manager) ServerOption
type ServerParams ¶ added in v0.24.0
type ServerParams struct { Ctx context.Context Name string // contains filtered or unexported fields }
func NewServerParams ¶ added in v0.24.0
func NewServerParams(ctx context.Context, name string, opts ...ServerOption) *ServerParams
func (*ServerParams) Start ¶ added in v0.24.0
func (params *ServerParams) Start() error
type TLSLogFilter ¶
type TLSLogFilter struct {
// contains filtered or unexported fields
}