Documentation ¶
Index ¶
- Variables
- func BadRoleError(req *Request) errors.Error
- func BindAndRun()
- func DisableServiceToServiceAuth()
- func Exit(code int)
- func HandleRequest(req *Request)
- func HealthCheck(id string, checker slhc.Checker)
- func Init()
- func PriorityHealthCheck(id string, checker slhc.Checker, priority slhc.Priority)
- func Register(eps ...*Endpoint) (err error)
- func RegisterPostConnectHandler(pch PostConnectHandler)
- func Run()
- func RunWithOptions(opts *Options)
- func ScopedRequest(service, endpoint string, payload proto.Message) (*client.Request, error)
- func Scoper() *serverScoper
- type Authoriser
- type Endpoint
- type Handler
- type Options
- type PostConnectHandler
- type Request
- func (self *Request) Auth() auth.Scope
- func (self *Request) Authorised() bool
- func (self *Request) Context() string
- func (self *Request) Data() proto.Message
- func (self *Request) Destination() string
- func (self *Request) Endpoint() string
- func (self *Request) From() string
- func (self *Request) IsPublication() bool
- func (self *Request) MessageID() string
- func (self *Request) MessageType() string
- func (self *Request) ParentMessageID() string
- func (self *Request) Payload() []byte
- func (self *Request) ReplyTo() string
- func (self *Request) ScopedJsonRequest(service, endpoint string, payload []byte) (*client.Request, error)
- func (self *Request) ScopedRequest(service, endpoint string, payload proto.Message) (*client.Request, error)
- func (self *Request) Service() string
- func (self *Request) SessionID() string
- func (self *Request) SetAuth(s auth.Scope)
- func (self *Request) SetData(data proto.Message)
- func (self *Request) SetSessionID(sessionID string) *Request
- func (self *Request) String() string
- func (self *Request) Topic() string
- func (self *Request) TraceID() string
- func (self *Request) TraceShouldPersist() bool
- func (self *Request) Unmarshal(into proto.Message) (err error)
- type Response
Constants ¶
This section is empty.
Variables ¶
var ( // Name is the name of the service such as com.hailocab.example Name string // Description is the human readable version for the Name Description string // Version is the timestamp of the release Version uint64 // Source is the URL of the source code, eg: github.com/hailocab/foo Source string // OwnerEmail is the email address of the person who is responsible for this service OwnerEmail string // OwnerMobile is the international mobile number of the person responsible, eg: +44791111111 OwnerMobile string // OwnerTeam is the name of the team who is responsible for this service, e.g. platform OwnerTeam string // InstanceID is the unique id of this running instance InstanceID string // ConcurrentRequests is how many concurrent requests we want to serve per calling service ConcurrentRequests int = 1000 )
var (
PublishErrors = true // Services default to publishing errors to NSQ
)
Functions ¶
func BadRoleError ¶
Given a request, returns a "bad role" error. This is used both by Authorise() and is useful within services which do row-level permission checking.
func DisableServiceToServiceAuth ¶
func DisableServiceToServiceAuth()
DisableServiceToServiceAuth stops the service attempting to load auth rules for service-to-service calls where it is not needed.
func Exit ¶
func Exit(code int)
Exit provides a wrapper to os.Exit so that we can disconnect, cleanup and shutdown in a graceful manner.
func HealthCheck ¶
HealthCheck registers a standard health check for this server
func PriorityHealthCheck ¶
PriorityHealthCheck is a healthcheck with a configurable priority for this server
func RegisterPostConnectHandler ¶
func RegisterPostConnectHandler(pch PostConnectHandler)
RegisterPostConnectHandler adds a post connect handler to the map so we can run it
func RunWithOptions ¶
func RunWithOptions(opts *Options)
RunWithOptions starts the server with user defined options
func ScopedRequest ¶
ScopedRequest returns a client request, prepared with scoping information of the service _making_ the call - such that service-to-service auth can work
Types ¶
type Authoriser ¶
type Authoriser interface { // Authorise should check the request and then return an error if problems Authorise(req *Request) errors.Error }
Authoriser is an interface that anything that wants to authorise endpoints must satisfy
var DefaultAuthoriser Authoriser = RoleAuthoriser([]string{"ADMIN"})
func OpenToTheWorldAuthoriser ¶
func OpenToTheWorldAuthoriser() Authoriser
OpenToTheWorldAuthoriser means ANYONE (in the whole world) can call a service
func RoleAuthoriser ¶
func RoleAuthoriser(roles []string) Authoriser
RoleAuthoriser requires a service or user calling an endpoint to have ANY of these roles
func SignInAuthoriser ¶
func SignInAuthoriser() Authoriser
SignInAuthoriser requires a real person to be signed in, but doesn't care about roles
func SignInRoleAuthoriser ¶
func SignInRoleAuthoriser(roles []string) Authoriser
SignInRoleAuthoriser requires a real person signed in calling an endpoint to have ANY of these roles
type Endpoint ¶
type Endpoint struct { // Name is the endpoint name, which should just be a single word, eg: "register" Name string // Mean is the mean average response time (time to generate response) promised for this endpoint Mean int32 // Upper95 is 95th percentile response promised for this endpoint Upper95 int32 // Handler is the function that will be fed requests to respond to Handler Handler // RequestProtocol is a struct type into which an inbound request for this endpoint can be unmarshaled RequestProtocol proto.Message // ResponseProtocol is the struct type defining the response format for this endpoint ResponseProtocol proto.Message // Subscribe indicates this endpoint should subscribe to a PUB stream - and gives us the stream address to SUB from //(topic name) Subscribe string // Authoriser is something that can check authorisation for this endpoint -- defaulting to ADMIN only (if nothing //specified by service) Authoriser Authoriser // contains filtered or unexported fields }
Endpoint containing the name and handler to call with the request
func (*Endpoint) GetUpper95 ¶
type PostConnectHandler ¶
type PostConnectHandler func()
PostConnectHandler repesents a function we fun after connecting to RabbitMQ
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request just wraps an AMQP delivery
func NewRequestFromDelivery ¶
NewRequestFromDelivery creates the Request object based on an AMQP delivery object
func NewRequestFromProto ¶
func (*Request) Auth ¶
Auth returns a fully-initialised authentication scope, from which you can determine if anyone is authenticated and who they are
func (*Request) Authorised ¶
Authorised returns the whether the request has already been authorised
func (*Request) Context ¶
Context returns some string that is designed for us to base error messages from
func (*Request) Destination ¶
Destination returns the name of the server and endpoint that the request was directed at, for example: com.hailocab.service.customer.retrieve
func (*Request) From ¶
From returns information about which service sent this message @todo make this such that we can cryptographically verify this
func (*Request) IsPublication ¶
IsPublication returns whether this is a publication, i.e. has a topic
func (*Request) MessageID ¶
MessageID returns the ID of the underlying message transport system, which is unique per delivery, and only really useful for debugging
func (*Request) MessageType ¶
func (*Request) ParentMessageID ¶
ParentMessageID returns the message ID of a message (if any) that was received and triggered this message In other words, we use this to build up the call stack / hierarchy
func (*Request) ScopedJsonRequest ¶
func (self *Request) ScopedJsonRequest(service, endpoint string, payload []byte) (*client.Request, error)
ScopedJsonRequest does just the same as ScopedRequest but with JSON payload
func (*Request) ScopedRequest ¶
func (self *Request) ScopedRequest(service, endpoint string, payload proto.Message) (*client.Request, error)
ScopedRequest returns a client request, prepared with any scoping information from _this_ inbound server request (in other words we are forwarding all the scope information such as trace ID, session ID etc.. with our new client request). This includes the scope of the service _making_ the call.
func (*Request) SetSessionID ¶
SetSessionID allows changing of the session ID if it changes during a request
func (*Request) TraceShouldPersist ¶
TraceShouldPersist returns if the trace should be stored persistently
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response wraps an AMQP delivery, with a payload & message type
func ErrorResponse ¶
ErrorResponse wraps a normal response with a messageType of "error"
func ReplyResponse ¶
ReplyResponse sends a normal response
func (*Response) ContentType ¶
ContentType returns the content type of the delivery
func (*Response) MessageType ¶
MessageType returns the message type of the delivery (error, heartbeat etc)