Documentation ¶
Index ¶
- func BuildService(desc ServiceDesc) kit.Service
- type Contract
- func (c *Contract) AddError(err kit.ErrorMessage) *Contract
- func (c *Contract) AddHandler(h ...kit.HandlerFunc) *Contract
- func (c *Contract) AddModifier(m kit.ModifierFunc) *Contract
- func (c *Contract) AddNamedSelector(name string, s kit.RouteSelector) *Contract
- func (c *Contract) AddRoute(r ...RouteSelector) *Contract
- func (c *Contract) AddSelector(s ...kit.RouteSelector) *Contract
- func (c *Contract) AddWrapper(wrappers ...kit.ContractWrapper) *Contract
- func (c *Contract) Coordinator(f kit.EdgeSelectorFunc) *Contract
- func (c *Contract) In(m kit.Message) *Contract
- func (c *Contract) NamedSelector(name string, s kit.RouteSelector) *Contract
- func (c *Contract) Out(m kit.Message) *Contract
- func (c *Contract) Selector(s ...kit.RouteSelector) *Contract
- func (c *Contract) SetCoordinator(f kit.EdgeSelectorFunc) *Contract
- func (c *Contract) SetEncoding(enc kit.Encoding) *Contract
- func (c *Contract) SetHandler(h ...kit.HandlerFunc) *Contract
- func (c *Contract) SetInput(m kit.Message) *Contract
- func (c *Contract) SetInputHeader(headers ...Header) *Contract
- func (c *Contract) SetName(name string) *Contract
- func (c *Contract) SetOutput(m kit.Message) *Contract
- type ContractType
- type Error
- type Header
- type Kind
- type ParsedContract
- type ParsedElement
- type ParsedField
- type ParsedMessage
- func (pm ParsedMessage) CodeField() string
- func (pm ParsedMessage) FieldByGoName(name string) *ParsedField
- func (pm ParsedMessage) FieldByName(name string) *ParsedField
- func (pm ParsedMessage) IsSpecial() bool
- func (pm ParsedMessage) ItemField() string
- func (pm ParsedMessage) JSON() string
- func (pm ParsedMessage) String() string
- type ParsedRequest
- type ParsedResponse
- type ParsedService
- type ParsedStructTag
- type RouteSelector
- type Service
- func (s *Service) AddContract(contracts ...*Contract) *Service
- func (s *Service) AddError(err kit.ErrorMessage) *Service
- func (s *Service) AddHandler(h ...kit.HandlerFunc) *Service
- func (s *Service) AddWrapper(wrappers ...kit.ServiceWrapper) *Service
- func (s *Service) Build() kit.Service
- func (s *Service) SetDescription(d string) *Service
- func (s *Service) SetEncoding(enc kit.Encoding) *Service
- func (s *Service) SetVersion(v string) *Service
- type ServiceDesc
- type ServiceDescFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildService ¶ added in v0.17.3
func BuildService(desc ServiceDesc) kit.Service
Types ¶
type Contract ¶
type Contract struct { Name string Encoding kit.Encoding Handlers []kit.HandlerFunc Wrappers []kit.ContractWrapper RouteSelectors []RouteSelector EdgeSelector kit.EdgeSelectorFunc Modifiers []kit.ModifierFunc InputHeaders []Header Input kit.Message Output kit.Message PossibleErrors []Error }
Contract is the description of the kit.Contract you are going to create.
func NewContract ¶
func NewContract() *Contract
func (*Contract) AddError ¶
func (c *Contract) AddError(err kit.ErrorMessage) *Contract
AddError sets the possible errors for this Contract. Using this method is OPTIONAL, which mostly could be used by external tools such as Swagger or any other doc generator tools.
func (*Contract) AddHandler ¶
func (c *Contract) AddHandler(h ...kit.HandlerFunc) *Contract
AddHandler add handler for this contract.
func (*Contract) AddModifier ¶
func (c *Contract) AddModifier(m kit.ModifierFunc) *Contract
AddModifier adds a kit.ModifierFunc for this contract. Modifiers are used to modify the outgoing kit.Envelope just before sending to the client.
func (*Contract) AddNamedSelector ¶
func (c *Contract) AddNamedSelector(name string, s kit.RouteSelector) *Contract
AddNamedSelector adds a kit.RouteSelector for this contract and assigns it a unique name. In case you need to use auto-generated stub.Stub for your service/contract, this name will be used in the generated code. Deprecated: use AddRoute instead
func (*Contract) AddRoute ¶ added in v0.17.4
func (c *Contract) AddRoute(r ...RouteSelector) *Contract
AddRoute adds a kit.RouteSelector for this contract.
func (*Contract) AddSelector ¶
func (c *Contract) AddSelector(s ...kit.RouteSelector) *Contract
AddSelector adds a kit.RouteSelector for this contract. Selectors are bundle-specific. Deprecated: use AddRoute instead
func (*Contract) AddWrapper ¶
func (c *Contract) AddWrapper(wrappers ...kit.ContractWrapper) *Contract
AddWrapper adds a kit.ContractWrapper for this contract.
func (*Contract) Coordinator ¶ added in v0.9.15
func (c *Contract) Coordinator(f kit.EdgeSelectorFunc) *Contract
Coordinator is an alias for SetCoordinator
func (*Contract) NamedSelector ¶
func (c *Contract) NamedSelector(name string, s kit.RouteSelector) *Contract
NamedSelector is an alias for AddNamedSelector Deprecated: use AddRoute instead
func (*Contract) Selector ¶
func (c *Contract) Selector(s ...kit.RouteSelector) *Contract
Selector is an alias for AddSelector Deprecated: use AddRoute instead
func (*Contract) SetCoordinator ¶
func (c *Contract) SetCoordinator(f kit.EdgeSelectorFunc) *Contract
SetCoordinator sets a kit.EdgeSelectorFunc for this contract to coordinate requests to right kit.EdgeServer instance.
func (*Contract) SetEncoding ¶
SetEncoding sets the supported encoding for this contract.
func (*Contract) SetHandler ¶
func (c *Contract) SetHandler(h ...kit.HandlerFunc) *Contract
SetHandler set the handler by replacing the already existing ones.
func (*Contract) SetInput ¶
SetInput sets the accepting message for this Contract. Contracts are bound to one input message.
func (*Contract) SetInputHeader ¶ added in v0.10.9
SetInputHeader sets the headers for this Contract. This is an OPTIONAL parameter, which could be used by external tools such as Swagger or any other doc generator tools.
type ContractType ¶ added in v0.10.0
type ContractType string
const ( REST ContractType = "REST" RPC ContractType = "RPC" )
type Header ¶ added in v0.10.9
func OptionalHeader ¶ added in v0.10.9
func RequiredHeader ¶ added in v0.10.9
type ParsedContract ¶ added in v0.10.0
type ParsedContract struct { Index int GroupName string Name string Encoding string Deprecated bool Type ContractType Path string PathParams []string Method string Predicate string Request ParsedRequest Responses []ParsedResponse }
func (ParsedContract) IsPathParam ¶ added in v0.10.5
func (pc ParsedContract) IsPathParam(name string) bool
func (ParsedContract) OKResponse ¶ added in v0.10.5
func (pc ParsedContract) OKResponse() ParsedResponse
func (ParsedContract) SuggestName ¶ added in v0.10.1
func (pc ParsedContract) SuggestName() string
type ParsedElement ¶ added in v0.10.6
type ParsedElement struct { Kind Kind RKind reflect.Kind Type string RType reflect.Type // Message is the parsed message if the kind is Object. Message *ParsedMessage // only if Kind == Object Element *ParsedElement // if Kind == Array || Map Key *ParsedElement // only if Kind == Map }
func (ParsedElement) String ¶ added in v0.10.6
func (pf ParsedElement) String() string
type ParsedField ¶ added in v0.10.6
type ParsedField struct { GoName string Name string Tag ParsedStructTag SampleValue string Optional bool Embedded bool Element *ParsedElement }
type ParsedMessage ¶ added in v0.10.0
type ParsedMessage struct { Name string Kind Kind RKind reflect.Kind Type string RType reflect.Type Fields []ParsedField ImplementError bool // contains filtered or unexported fields }
func (ParsedMessage) CodeField ¶ added in v0.14.12
func (pm ParsedMessage) CodeField() string
func (ParsedMessage) FieldByGoName ¶ added in v0.11.38
func (pm ParsedMessage) FieldByGoName(name string) *ParsedField
func (ParsedMessage) FieldByName ¶ added in v0.11.38
func (pm ParsedMessage) FieldByName(name string) *ParsedField
func (ParsedMessage) IsSpecial ¶ added in v0.14.11
func (pm ParsedMessage) IsSpecial() bool
func (ParsedMessage) ItemField ¶ added in v0.14.12
func (pm ParsedMessage) ItemField() string
func (ParsedMessage) JSON ¶ added in v0.10.0
func (pm ParsedMessage) JSON() string
func (ParsedMessage) String ¶ added in v0.10.6
func (pm ParsedMessage) String() string
type ParsedRequest ¶ added in v0.10.0
type ParsedRequest struct { Headers []Header Message ParsedMessage }
type ParsedResponse ¶ added in v0.10.0
type ParsedResponse struct { Message ParsedMessage ErrCode int ErrItem string }
func (ParsedResponse) IsError ¶ added in v0.10.0
func (pr ParsedResponse) IsError() bool
type ParsedService ¶ added in v0.10.0
type ParsedService struct { // Origin is the original service descriptor untouched by the parser Origin *Service // Contracts is the list of parsed contracts. The relation between ParsedContract // and Contract is not 1:1 because a Contract can have multiple RouteSelectors. // Each RouteSelector will be parsed into a ParsedContract. Contracts []ParsedContract // contains filtered or unexported fields }
func Parse ¶ added in v0.10.0
func Parse(desc ServiceDesc) ParsedService
Parse extracts the Service descriptor from the input ServiceDesc Refer to ParseService for more details.
func ParseService ¶ added in v0.10.0
func ParseService(svc *Service) ParsedService
ParseService extracts information from a Service descriptor using reflection. It returns a ParsedService. The ParsedService is useful to generate custom code based on the service descriptor. In the contrib package this is used to generate the swagger spec and postman collections.
func (*ParsedService) Messages ¶ added in v0.10.5
func (ps *ParsedService) Messages() []ParsedMessage
type ParsedStructTag ¶ added in v0.10.1
type ParsedStructTag struct { Raw reflect.StructTag Name string Value string Optional bool PossibleValues []string Deprecated bool OmitEmpty bool }
func (ParsedStructTag) Get ¶ added in v0.14.12
func (pst ParsedStructTag) Get(key string) string
type RouteSelector ¶
type RouteSelector struct { Name string Selector kit.RouteSelector Deprecated bool }
func Route ¶ added in v0.17.4
func Route(name string, selector kit.RouteSelector) RouteSelector
func (RouteSelector) Deprecate ¶ added in v0.17.4
func (rs RouteSelector) Deprecate() RouteSelector
type Service ¶
type Service struct { Name string Version string Description string Encoding kit.Encoding PossibleErrors []Error Wrappers []kit.ServiceWrapper Contracts []Contract Handlers []kit.HandlerFunc // contains filtered or unexported fields }
Service is the description of the kit.Service you are going to create. It then generates a kit.Service by calling Generate method.
func NewService ¶
func (*Service) AddContract ¶
AddContract adds a contract to the service.
func (*Service) AddError ¶
func (s *Service) AddError(err kit.ErrorMessage) *Service
AddError sets the possible errors for all the Contracts of this Service. Using this method is OPTIONAL, which mostly could be used by external tools such as Swagger or any other doc generator tools. NOTE: The auto-generated stub also use these errors to identifies if the response should be considered
as error or successful.
func (*Service) AddHandler ¶
func (s *Service) AddHandler(h ...kit.HandlerFunc) *Service
AddHandler adds handlers to run before and/or after the contract's handlers
func (*Service) AddWrapper ¶
func (s *Service) AddWrapper(wrappers ...kit.ServiceWrapper) *Service
AddWrapper adds service wrappers to the Service description.
func (*Service) SetDescription ¶
func (*Service) SetVersion ¶
type ServiceDesc ¶
type ServiceDesc interface {
Desc() *Service
}
func ToDesc ¶ added in v0.17.3
func ToDesc(svc ...*Service) []ServiceDesc
type ServiceDescFunc ¶
type ServiceDescFunc func() *Service
ServiceDescFunc is helper utility to convert function to a ServiceDesc interface
func (ServiceDescFunc) Desc ¶
func (f ServiceDescFunc) Desc() *Service