nats-proxy: github.com/sohlich/nats-proxy Index | Files

package natsproxy

import "github.com/sohlich/nats-proxy"

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

Package Files

client.go context.go protobuf.go protobuf.pb.go proxy.go request.go response.go util.go

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")
)

func IsWebSocketRequest Uses

func IsWebSocketRequest(r *http.Request) bool

IsWebSocketRequest returns a boolean indicating whether the request has the headers of a WebSocket handshake request.

func SubscribeURLToNats Uses

func SubscribeURLToNats(method string, urlPath string) string

SubscribeURLToNats buils the subscription channel name with placeholders (started with ":"). The placeholders are than used to obtain path variables

func URLToNats Uses

func URLToNats(method string, urlPath string) string

URLToNats builds the channel name from an URL and Method of http.Request

type Connector Uses

type Connector interface {
    Subscribe(url string, handler NatsHandler)
    UnSubscribe(url string, handler NatsHandler)
}

Connector is the interface for generic pub/sub client.

type Context Uses

type Context struct {
    Request     *Request
    Response    *Response
    RequestForm url.Values
    // contains filtered or unexported fields
}

Context wraps the processed request/response

func (*Context) Abort Uses

func (c *Context) Abort()

Abort abortsthe request that it won's be processed further

func (*Context) AbortWithJSON Uses

func (c *Context) AbortWithJSON(obj interface{})

AbortWithJSON aborts the request and sets the HTTP status code to 500.

func (*Context) BindJSON Uses

func (c *Context) BindJSON(obj interface{}) error

BindJSON unmarshall the request body to given struct

func (*Context) FormVariable Uses

func (c *Context) FormVariable(name string) string

FormVariable returns the variable from request form if available or empty string if not present.

func (*Context) GetWebsocketID Uses

func (c *Context) GetWebsocketID() (wdsID string, err error)

func (*Context) HeaderVariable Uses

func (c *Context) HeaderVariable(name string) string

HeaderVariable returns the header variable if avalable or empty string if header not present.

func (*Context) IsAborted Uses

func (c *Context) IsAborted() bool

IsAborted returns true if the request in context were aborted by previous middleware

func (*Context) JSON Uses

func (c *Context) JSON(statusCode int, obj interface{})

JSON writes the serialized json to response

func (*Context) ParseForm Uses

func (c *Context) ParseForm() error

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 Uses

func (c *Context) PathVariable(name string) string

PathVariable returns the path variable based on its name (:xxx) defined in subscription URL

type HookFunc Uses

type HookFunc func(*Response)

HookFunc is the function that is used to modify response just before its transformed to HTTP response

type NatsClient Uses

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 Uses

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 Uses

func (nc *NatsClient) DELETE(url string, handler NatsHandler)

DELETE subscribes the client for an url with DELETE method.

func (*NatsClient) GET Uses

func (nc *NatsClient) GET(url string, handler NatsHandler)

GET subscribes the client for an url with GET method.

func (*NatsClient) HandleWebsocket Uses

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 Uses

func (nc *NatsClient) POST(url string, handler NatsHandler)

POST subscribes the client for an url with POST method.

func (*NatsClient) PUT Uses

func (nc *NatsClient) PUT(url string, handler NatsHandler)

PUT subscribes the client for an url with PUT method.

func (*NatsClient) Send Uses

func (nc *NatsClient) Send(method string, url string, req *Request) (response *Response, err error)

func (*NatsClient) SendDELETE Uses

func (nc *NatsClient) SendDELETE(url string, req *Request) (response *Response, err error)

func (*NatsClient) SendGET Uses

func (nc *NatsClient) SendGET(url string, req *Request) (response *Response, err error)

func (*NatsClient) SendPOST Uses

func (nc *NatsClient) SendPOST(url string, req *Request) (response *Response, err error)

func (*NatsClient) SendPUT Uses

func (nc *NatsClient) SendPUT(url string, req *Request) (response *Response, err error)

func (*NatsClient) Subscribe Uses

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 Uses

func (nc *NatsClient) Use(middleware NatsHandler)

Use will add the middleware NatsHandler for a client.

func (*NatsClient) WriteWebsocket Uses

func (nc *NatsClient) WriteWebsocket(websocketID string, data []byte) error

WriteWebsocket writes given bytes to given websocket subject.

func (*NatsClient) WriteWebsocketJSON Uses

func (nc *NatsClient) WriteWebsocketJSON(websocketID string, msg interface{}) error

WriteWebsocketJSON writes struct serialized to JSON to registered websocketID NATS subject.

type NatsHandler Uses

type NatsHandler func(c *Context)

NatsHandler handles the tranforrmed HTTP request from NatsProxy. The context c wraps the request and response.

type NatsHandlers Uses

type NatsHandlers []NatsHandler

NatsHandlers is an array of NatsHandler functions. This type primary function is to group filters in NatsClient.

type NatsProxy Uses

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 Uses

func NewNatsProxy(conn *nats.Conn) (*NatsProxy, error)

NewNatsProxy creates an initialized NatsProxy

func (*NatsProxy) AddHook Uses

func (np *NatsProxy) AddHook(urlRegex string, hook HookFunc) error

AddHook add the hook to modify, process response just before its transformed to HTTP form.

func (*NatsProxy) ServeHTTP Uses

func (np *NatsProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type Request Uses

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 `protobuf:"bytes,5,rep,name=Form,json=form" json:"Form,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
    Header      map[string]*Values `protobuf:"bytes,6,rep,name=Header,json=header" json:"Header,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
    WebSocketID string             `protobuf:"bytes,7,opt,name=WebSocketID,json=webSocketID" json:"WebSocketID,omitempty"`
}

func NewRequest Uses

func NewRequest() *Request

func (*Request) Descriptor Uses

func (*Request) Descriptor() ([]byte, []int)

func (*Request) FromHTTP Uses

func (r *Request) FromHTTP(req *http.Request) error

func (*Request) GetForm Uses

func (r *Request) GetForm() Variables

func (*Request) GetHeader Uses

func (r *Request) GetHeader() Variables

func (*Request) GetWebSocketID Uses

func (r *Request) GetWebSocketID() string

func (*Request) IsWebSocket Uses

func (r *Request) IsWebSocket() bool

func (*Request) ProtoMessage Uses

func (*Request) ProtoMessage()

func (*Request) Reset Uses

func (m *Request) Reset()

func (*Request) String Uses

func (m *Request) String() string

func (*Request) UnmarshallFrom Uses

func (r *Request) UnmarshallFrom(requestData []byte) error

UnmarshallFrom unmarshal the request from bytes, that usually come from proxy.

type RequestPool Uses

type RequestPool struct {
    sync.Pool
}

func NewRequestPool Uses

func NewRequestPool() RequestPool

func (*RequestPool) GetRequest Uses

func (r *RequestPool) GetRequest() *Request

func (*RequestPool) PutRequest Uses

func (r *RequestPool) PutRequest(req *Request)

type Response Uses

type Response struct {
    StatusCode int32              `protobuf:"varint,1,opt,name=StatusCode,json=statusCode" json:"StatusCode,omitempty"`
    Header     map[string]*Values `protobuf:"bytes,2,rep,name=Header,json=header" json:"Header,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
    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 Uses

func NewResponse() *Response

NewResponse creates blank initialized Response object.

func (*Response) Descriptor Uses

func (*Response) Descriptor() ([]byte, []int)

func (*Response) GetHeader Uses

func (r *Response) GetHeader() Variables

func (*Response) ProtoMessage Uses

func (*Response) ProtoMessage()

func (*Response) ReadFrom Uses

func (r *Response) ReadFrom(responseData []byte) error

DecodeResponse decodes the marshalled Response struct back to struct.

func (*Response) Reset Uses

func (m *Response) Reset()

func (*Response) String Uses

func (m *Response) String() string

type ResponsePool Uses

type ResponsePool struct {
    sync.Pool
}

func NewResponsePool Uses

func NewResponsePool() ResponsePool

func (*ResponsePool) GetResponse Uses

func (r *ResponsePool) GetResponse() *Response

func (*ResponsePool) PutResponse Uses

func (r *ResponsePool) PutResponse(res *Response)

type Values Uses

type Values struct {
    Arr []string `protobuf:"bytes,1,rep,name=arr" json:"arr,omitempty"`
}

func (*Values) Descriptor Uses

func (*Values) Descriptor() ([]byte, []int)

func (*Values) ProtoMessage Uses

func (*Values) ProtoMessage()

func (*Values) Reset Uses

func (m *Values) Reset()

func (*Values) String Uses

func (m *Values) String() string

type Variables Uses

type Variables map[string]*Values

func (Variables) Add Uses

func (h Variables) Add(key, value string)

func (Variables) Del Uses

func (h Variables) Del(key string)

func (Variables) Get Uses

func (h Variables) Get(name string) string

func (Variables) Set Uses

func (h Variables) Set(key, val string)

Package natsproxy imports 20 packages (graph) and is imported by 3 packages. Updated 2018-06-13. Refresh now. Tools for package owners.