Documentation
¶
Index ¶
- func APIValidationWrapper(srv service.Service) service.Service
- func DoGeneratedRequest[ResponseType any](r *http.Request, responseObj *ResponseType) error
- func DoRequest[RequestType request.HttpRequest, ResponseType any](baseUrl string, clientRequest RequestType, responseObj *ResponseType) error
- func GenerateClientRequest(baseUrl string, serviceRequest request.HttpRequest) (*http.Request, error)
- func GenerateRequestDecoder(obj request.HttpRequest) (kitDefaults.DecodeRequestFunc, error)
- func GenerateSpecification(requests []ServiceRequest, optionalReflector *openapi3.Reflector) (openapi3.Reflector, error)
- func MakeHandler(serviceRequests []ServiceRequest, option ...config.GkBootOption) (http.Handler, *config.BootConfig)
- func NewServiceBuilder(srv service.Service, option ...config.GkBootOption) *serviceBuilder
- func Start(serviceRequests []ServiceRequest, option ...config.GkBootOption) (*http.Server, <-chan struct{})
- func StartServer(serviceRequests []ServiceRequest, option ...config.GkBootOption)
- func StartServerWithHandler(serviceRequests []ServiceRequest, option ...config.GkBootOption)
- func StartWithHandler(serviceRequests []ServiceRequest, option ...config.GkBootOption) (*http.Server, <-chan struct{})
- type BasicService
- type BasicServiceWithDB
- type HttpDecoder
- type JSONBody
- type ServiceRequest
- type SkipClientValidation
- type UsingSkipClientValidation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoGeneratedRequest ¶ added in v1.0.0
func DoRequest ¶ added in v1.0.0
func DoRequest[RequestType request.HttpRequest, ResponseType any]( baseUrl string, clientRequest RequestType, responseObj *ResponseType, ) error
func GenerateClientRequest ¶ added in v1.0.0
func GenerateRequestDecoder ¶
func GenerateRequestDecoder(obj request.HttpRequest) (kitDefaults.DecodeRequestFunc, error)
GenerateRequestDecoder
When used in go-kit, generates a json decoder function that translates http requests to go concrete objects.
This reads 'request' tags in a concrete object to perform transformations from the relative http request parts to the given field in the result object. The 'request' tag may be applied to a field of type bool, string, int, int8, int16, int32, int64, float32, float64, complex64, complex128 or a slice of any of these (the relative part of the request must list slice values separated by comma).
The 'request' tag itself may be structured thus:
type ConcreteObject struct { Value string `request:"header"` // find in headers with name "Value" MyInt int `request:"header" alias:"New-Integer"` // "New-Integer" in headers not "MyInt" MyBool bool `request:"query" json:"myBool"` // "myBool" in the query params of request MyFloat float32 `request:"query!"` // query param must be present as "MyFloat" Body CustomBodyStruct `request:"form"` // json request body as an object (json.Unmarshal) }
Note that this function will look for the corresponding field values using the following naming hierarchy:
alias -> json -> field name (exported)
This function will skip over unexported fields ¶
The resulting decoder function always returns a pointer to a new instantiation of the 'obj' argument.
The obj argument may be a reference or a value type
func GenerateSpecification ¶
func MakeHandler ¶
func MakeHandler(serviceRequests []ServiceRequest, option ...config.GkBootOption) (http.Handler, *config.BootConfig)
func NewServiceBuilder ¶
func NewServiceBuilder(srv service.Service, option ...config.GkBootOption) *serviceBuilder
NewServiceBuilder
This will wire up a service-only object that can re-use logging wrappers established elsewhere while maintaining the REST Request-Service established pattern. The associated Mixin chains must be called to identify which functionality is wired in.
Unavailable config options (using the following will not do anything):
config.WithServiceDecorator config.WithHttpServerOpts config.WithHttpPort config.WithRootPath config.WithStrictAPI
func Start ¶
func Start(serviceRequests []ServiceRequest, option ...config.GkBootOption) (*http.Server, <-chan struct{})
Start
Starts the http server for GkBoot. Returns the running http.Server and a blocking function that waits until a signal (syscall.SIGINT, syscall.SIGTERM, syscall.SIGALRM) is sent.
func StartServer ¶
func StartServer(serviceRequests []ServiceRequest, option ...config.GkBootOption)
StartServer
Convenience method.
If the service and blocker of Start are unnecessary, this conveniently does all of that for us.
func StartServerWithHandler ¶
func StartServerWithHandler(serviceRequests []ServiceRequest, option ...config.GkBootOption)
func StartWithHandler ¶
func StartWithHandler(serviceRequests []ServiceRequest, option ...config.GkBootOption) (*http.Server, <-chan struct{})
Types ¶
type BasicService ¶
type BasicService struct {
service.UsingConfig
}
BasicService
This is the typical service with no DB attached, with an associated Configuration set by WithCustomConfig ¶
It is recommended to use config.WithCustomConfig on gkBoot.Start followed by implementing member Execute function of your struct
type BasicServiceWithDB ¶
type BasicServiceWithDB struct { service.UsingConfig service.UsingDB }
BasicServiceWithDB
This is the typical service with custom config and DB ¶
It is recommended to use config.WithCustomConfig and config.WithDatabase on gkBoot.Start followed by implementing member Execute function of your struct
type HttpDecoder ¶
type HttpDecoder interface {
Decode(ctx context.Context, httpRequest *http.Request) (request interface{}, err error)
}
HttpDecoder
Objects that implement this interface will pass the defined function to the decoder part of the go-kit route definition
type JSONBody ¶ added in v0.3.0
type JSONBody struct{}
JSONBody
When embedded into a request, flags the request as a JSON body to allow for automatic decoding.
type ServiceRequest ¶
type ServiceRequest struct { Request request.HttpRequest Service service.Service }
ServiceRequest
The request and service provided in this structure are submitted to the Start functions. The requests, when called from the http client, will route to the associated service to execute the business logic of the Execute method.
type SkipClientValidation ¶ added in v1.0.0
type SkipClientValidation interface {
SkipClientValidation()
}
type UsingSkipClientValidation ¶ added in v1.2.7
type UsingSkipClientValidation struct{}
func (UsingSkipClientValidation) SkipClientValidation ¶ added in v1.2.7
func (u UsingSkipClientValidation) SkipClientValidation()