Documentation ¶
Overview ¶
Package natsproxy is a generated protocol buffer package.
It is generated from these files:
protobuf.proto
It has these top-level messages:
Values Request Response
Index ¶
- Constants
- Variables
- func IsWebSocketRequest(r *http.Request) bool
- func SubscribeURLToNats(method string, urlPath string) string
- func URLToNats(method string, urlPath string) string
- type Connector
- type Context
- func (c *Context) Abort()
- func (c *Context) AbortWithJSON(obj interface{})
- func (c *Context) BindJSON(obj interface{}) error
- func (c *Context) FormVariable(name string) string
- func (c *Context) GetWebsocketID() (wdsID string, err error)
- func (c *Context) HeaderVariable(name string) string
- func (c *Context) IsAborted() bool
- func (c *Context) JSON(statusCode int, obj interface{})
- func (c *Context) ParseForm() error
- func (c *Context) PathVariable(name string) string
- type HookFunc
- type NatsClient
- func (nc *NatsClient) DELETE(url string, handler NatsHandler)
- func (nc *NatsClient) GET(url string, handler NatsHandler)
- func (nc *NatsClient) HandleWebsocket(webSocketID string, handler nats.MsgHandler)
- func (nc *NatsClient) POST(url string, handler NatsHandler)
- func (nc *NatsClient) PUT(url string, handler NatsHandler)
- func (nc *NatsClient) Send(method string, url string, req *Request) (response *Response, err error)
- func (nc *NatsClient) SendDELETE(url string, req *Request) (response *Response, err error)
- func (nc *NatsClient) SendGET(url string, req *Request) (response *Response, err error)
- func (nc *NatsClient) SendPOST(url string, req *Request) (response *Response, err error)
- func (nc *NatsClient) SendPUT(url string, req *Request) (response *Response, err error)
- func (nc *NatsClient) Subscribe(method, url string, handler NatsHandler)
- func (nc *NatsClient) Use(middleware NatsHandler)
- func (nc *NatsClient) WriteWebsocket(websocketID string, data []byte) error
- func (nc *NatsClient) WriteWebsocketJSON(websocketID string, msg interface{}) error
- type NatsHandler
- type NatsHandlers
- type NatsProxy
- type Request
- func (*Request) Descriptor() ([]byte, []int)
- func (r *Request) FromHTTP(req *http.Request) error
- func (r *Request) GetForm() Variables
- func (r *Request) GetHeader() Variables
- func (r *Request) GetWebSocketID() string
- func (r *Request) IsWebSocket() bool
- func (*Request) ProtoMessage()
- func (m *Request) Reset()
- func (m *Request) String() string
- func (r *Request) UnmarshallFrom(requestData []byte) error
- type RequestPool
- type Response
- type ResponsePool
- type Values
- type Variables
Constants ¶
const ( // GET method constant GET = "GET" // POST method constant POST = "POST" // PUT method constant PUT = "PUT" // DELETE method constant DELETE = "DELETE" )
Variables ¶
var ( // ErrNatsClientNotConnected is returned // if the natsclient inserted // in NewNatsProxy is not connected. ErrNatsClientNotConnected = fmt.Errorf("Client not connected") )
Functions ¶
func IsWebSocketRequest ¶
IsWebSocketRequest returns a boolean indicating whether the request has the headers of a WebSocket handshake request.
func SubscribeURLToNats ¶
SubscribeURLToNats buils the subscription channel name with placeholders (started with ":"). The placeholders are than used to obtain path variables
Types ¶
type Connector ¶
type Connector interface { Subscribe(url string, handler NatsHandler) UnSubscribe(url string, handler NatsHandler) }
Connector is the interface for generic pub/sub client.
type Context ¶
type Context struct { Request *Request Response *Response RequestForm url.Values // contains filtered or unexported fields }
Context wraps the processed request/response
func (*Context) Abort ¶
func (c *Context) Abort()
Abort abortsthe request that it won's be processed further
func (*Context) AbortWithJSON ¶
func (c *Context) AbortWithJSON(obj interface{})
AbortWithJSON aborts the request and sets the HTTP status code to 500.
func (*Context) FormVariable ¶
FormVariable returns the variable from request form if available or empty string if not present.
func (*Context) GetWebsocketID ¶
func (*Context) HeaderVariable ¶
HeaderVariable returns the header variable if avalable or empty string if header not present.
func (*Context) IsAborted ¶
IsAborted returns true if the request in context were aborted by previous middleware
func (*Context) ParseForm ¶
ParseForm parses the request to values in RequestForm of the Context. The parsed form also includes the parameters from query and from body. Same as the http.Request, the post params are prior the query.
func (*Context) PathVariable ¶
PathVariable returns the path variable based on its name (:xxx) defined in subscription URL
type HookFunc ¶
type HookFunc func(*Response)
HookFunc is the function that is used to modify response just before its transformed to HTTP response
type NatsClient ¶
type NatsClient struct {
// contains filtered or unexported fields
}
NatsClient serves as Connector to NATS messaging. Allows to subscribe for an specific url or url pattern.
func NewNatsClient ¶
func NewNatsClient(conn *nats.Conn) (*NatsClient, error)
NewNatsClient creates new NATS client from given connection. The connection must be connected or the function will return error ErrNatsClientNotConnected.
func (*NatsClient) DELETE ¶
func (nc *NatsClient) DELETE(url string, handler NatsHandler)
DELETE subscribes the client for an url with DELETE method.
func (*NatsClient) GET ¶
func (nc *NatsClient) GET(url string, handler NatsHandler)
GET subscribes the client for an url with GET method.
func (*NatsClient) HandleWebsocket ¶
func (nc *NatsClient) HandleWebsocket(webSocketID string, handler nats.MsgHandler)
HandleWebsocket subscribes the handler for specific websocketID. The method adds the specific prefix for client to proxy communication.
func (*NatsClient) POST ¶
func (nc *NatsClient) POST(url string, handler NatsHandler)
POST subscribes the client for an url with POST method.
func (*NatsClient) PUT ¶
func (nc *NatsClient) PUT(url string, handler NatsHandler)
PUT subscribes the client for an url with PUT method.
func (*NatsClient) SendDELETE ¶
func (nc *NatsClient) SendDELETE(url string, req *Request) (response *Response, err error)
func (*NatsClient) SendGET ¶
func (nc *NatsClient) SendGET(url string, req *Request) (response *Response, err error)
func (*NatsClient) SendPOST ¶
func (nc *NatsClient) SendPOST(url string, req *Request) (response *Response, err error)
func (*NatsClient) SendPUT ¶
func (nc *NatsClient) SendPUT(url string, req *Request) (response *Response, err error)
func (*NatsClient) Subscribe ¶
func (nc *NatsClient) Subscribe(method, url string, handler NatsHandler)
Subscribe is a generic subscribe function for any http method. It also wraps the processing of the context.
func (*NatsClient) Use ¶
func (nc *NatsClient) Use(middleware NatsHandler)
Use will add the middleware NatsHandler for a client.
func (*NatsClient) WriteWebsocket ¶
func (nc *NatsClient) WriteWebsocket(websocketID string, data []byte) error
WriteWebsocket writes given bytes to given websocket subject.
func (*NatsClient) WriteWebsocketJSON ¶
func (nc *NatsClient) WriteWebsocketJSON(websocketID string, msg interface{}) error
WriteWebsocketJSON writes struct serialized to JSON to registered websocketID NATS subject.
type NatsHandler ¶
type NatsHandler func(c *Context)
NatsHandler handles the tranforrmed HTTP request from NatsProxy. The context c wraps the request and response.
type NatsHandlers ¶
type NatsHandlers []NatsHandler
NatsHandlers is an array of NatsHandler functions. This type primary function is to group filters in NatsClient.
type NatsProxy ¶
type NatsProxy struct {
// contains filtered or unexported fields
}
NatsProxy serves as a proxy between gnats and http. It automatically translates the HTTP requests to nats messages. The url and method of the HTTP request serves as the name of the nats channel, where the message is sent.
func NewNatsProxy ¶
NewNatsProxy creates an initialized NatsProxy
type Request ¶
type Request struct { URL string `protobuf:"bytes,1,opt,name=URL,json=uRL" json:"URL,omitempty"` Method string `protobuf:"bytes,2,opt,name=Method,json=method" json:"Method,omitempty"` RemoteAddr string `protobuf:"bytes,3,opt,name=RemoteAddr,json=remoteAddr" json:"RemoteAddr,omitempty"` Body []byte `protobuf:"bytes,4,opt,name=Body,json=body,proto3" json:"Body,omitempty"` Form map[string]*Values `` /* 138-byte string literal not displayed */ Header map[string]*Values `` /* 144-byte string literal not displayed */ WebSocketID string `protobuf:"bytes,7,opt,name=WebSocketID,json=webSocketID" json:"WebSocketID,omitempty"` }
func NewRequest ¶
func NewRequest() *Request
func (*Request) Descriptor ¶
func (*Request) GetWebSocketID ¶
func (*Request) IsWebSocket ¶
func (*Request) ProtoMessage ¶
func (*Request) ProtoMessage()
func (*Request) UnmarshallFrom ¶
UnmarshallFrom unmarshal the request from bytes, that usually come from proxy.
type RequestPool ¶
func NewRequestPool ¶
func NewRequestPool() RequestPool
func (*RequestPool) GetRequest ¶
func (r *RequestPool) GetRequest() *Request
func (*RequestPool) PutRequest ¶
func (r *RequestPool) PutRequest(req *Request)
type Response ¶
type Response struct { StatusCode int32 `protobuf:"varint,1,opt,name=StatusCode,json=statusCode" json:"StatusCode,omitempty"` Header map[string]*Values `` /* 144-byte string literal not displayed */ Body []byte `protobuf:"bytes,3,opt,name=Body,json=body,proto3" json:"Body,omitempty"` DoUpgrade bool `protobuf:"varint,4,opt,name=DoUpgrade,json=doUpgrade" json:"DoUpgrade,omitempty"` }
func NewResponse ¶
func NewResponse() *Response
NewResponse creates blank initialized Response object.
func (*Response) Descriptor ¶
func (*Response) ProtoMessage ¶
func (*Response) ProtoMessage()
type ResponsePool ¶
func NewResponsePool ¶
func NewResponsePool() ResponsePool
func (*ResponsePool) GetResponse ¶
func (r *ResponsePool) GetResponse() *Response
func (*ResponsePool) PutResponse ¶
func (r *ResponsePool) PutResponse(res *Response)
type Values ¶
type Values struct {
Arr []string `protobuf:"bytes,1,rep,name=arr" json:"arr,omitempty"`
}
func (*Values) Descriptor ¶
func (*Values) ProtoMessage ¶
func (*Values) ProtoMessage()