Documentation ¶
Overview ¶
Package gateway implements the actual gateway which will listen for requests and forward them to servers wrapped by gatewayrpc
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gateway ¶
type Gateway struct { SRVClient *srvclient.SRVClient // BackupHandler, if not nil, will be used to handle the requests which // don't have a corresponding backend service to forward to (based on their // method) BackupHandler http.Handler // RequestCallback, if not nil, will be called just before actually // forwarding a request onto its backend service. See the Request docstring // for more on what is actually possible with this. If you respond to the // Request using a Write* method then no forwarding will be done RequestCallback func(*Request) // CORSMatch, if not nil, will be used against the Origin header. and if it // matches Access-Control-Allow-* headers will be sent back, including an // Allow-Access-Control-Origin matching the sent in Origin CORSMatch *regexp.Regexp // contains filtered or unexported fields }
Gateway is an http.Handler which implements the JSON RPC2 spec, but forwards all of its requests onto backend services
func (*Gateway) AddURL ¶
AddURL performs the RPC.GetServices request against the given url, and will add all returned services to its mapping.
All DNS will be attempted to be resolved using SRV records first, and will use a normal DNS request as a backup
func (*Gateway) GetMethodURL ¶
GetMethodURL returns the url which should be used to call the given method ("Service.MethodName"). If the service was originally resolved using a srv request it will be re-resolved everytime this is called, in order to load-balance across instances. Will return an error if the service is unknown, or the resolving fails for some reason.
func (*Gateway) RegisterCodec ¶
RegisterCodec is used to register an encoder/decoder which will operate on requests with the given contentType
type Request ¶
type Request struct { *http.Request RemoteMethod gatewaytypes.Method ServiceName string // contains filtered or unexported fields }
Request contains all the data about an incoming request which is currently known. It can be used in conjunction to RequestCallback in order to provide extra functionality or checks to request coming through.
It provides methods to write an error, response, get the method and get the args in a map[string]interface{} that can be modified in order to change the request before it gets sent to the handler
Although the CodecRequest is public, it's use is deprecated. Also, the ResponseWriter should not be used and instead use Write* methods on Request.
func (*Request) ReadRequest ¶
ReadRequest fills in the args into the passed interface If you change the struct you passed, you must call UpdateRequest and pass the updated struct in order to actually affect the forwarded request
func (*Request) UpdateRequest ¶
UpdateRequest takes a new method string and an interface that it json encodes to new params for the request. If method is empty then the method will not be changed. If params is nil, then params will not be changed.
func (*Request) WriteError ¶
WriteError responds to the client with an error code and error it deals with the CodecRequest so you don't have to After calling, you should return false from the callback
func (*Request) WriteResponse ¶
func (r *Request) WriteResponse(i interface{})
WriteResponse responds to the client with the sent result After calling, you should return false from the callback