nats_transport

package module
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 12 Imported by: 0

README

nats-transport

HTTP to NATS (https://nats.io/) golang transport (http.RoundTripper) implementation

inspired by and based on https://github.com/sohlich/nats-proxy

dev

generate protobuf

protoc --go_opt=paths=source_relative --go_out=. protobuf.proto

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_protobuf_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type ModifyRequestHookFunc

type ModifyRequestHookFunc = func(req *http.Request, r *Request)

ModifyRequestHookFunc is the hook to modify Request struct (protobuf)

type NatsTransport

type NatsTransport struct {
	// NatsConnection connection to NATS server
	NatsConnection *nats.Conn

	// Subject NATS subject to push wrapped HTTP request on
	Subject string

	// SubjectResolver used only if Subject is not specified
	SubjectResolver SubjectResolveFunc

	// ModifyRequestHook calls after Request struct parsed from HTTP and before sent to NATS
	ModifyRequestHook ModifyRequestHookFunc

	// Timeout NATS request timeout
	Timeout time.Duration
}

func (NatsTransport) RoundTrip

func (nt NatsTransport) RoundTrip(r *http.Request) (*http.Response, error)

type Request

type Request struct {
	Proto      string             `protobuf:"bytes,1,opt,name=Proto,proto3" json:"Proto,omitempty"`
	Scheme     string             `protobuf:"bytes,2,opt,name=Scheme,proto3" json:"Scheme,omitempty"`
	Host       string             `protobuf:"bytes,3,opt,name=Host,proto3" json:"Host,omitempty"`
	URL        string             `protobuf:"bytes,4,opt,name=URL,proto3" json:"URL,omitempty"`
	Method     string             `protobuf:"bytes,5,opt,name=Method,proto3" json:"Method,omitempty"`
	RemoteAddr string             `protobuf:"bytes,6,opt,name=RemoteAddr,proto3" json:"RemoteAddr,omitempty"`
	Body       []byte             `protobuf:"bytes,7,opt,name=Body,proto3" json:"Body,omitempty"`
	Header     map[string]*Values `` /* 153-byte string literal not displayed */
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest() *Request

func (*Request) Descriptor deprecated

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

Deprecated: Use Request.ProtoReflect.Descriptor instead.

func (*Request) FromHTTP

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

func (*Request) GetBody

func (x *Request) GetBody() []byte

func (*Request) GetHeader

func (x *Request) GetHeader() map[string]*Values

func (*Request) GetHost

func (x *Request) GetHost() string

func (*Request) GetMethod

func (x *Request) GetMethod() string

func (*Request) GetProto

func (x *Request) GetProto() string

func (*Request) GetRemoteAddr

func (x *Request) GetRemoteAddr() string

func (*Request) GetScheme

func (x *Request) GetScheme() string

func (*Request) GetURL

func (x *Request) GetURL() string

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) ProtoReflect

func (x *Request) ProtoReflect() protoreflect.Message

func (*Request) Reset

func (x *Request) Reset()

func (*Request) String

func (x *Request) String() string

type Response

type Response struct {
	StatusCode int32              `protobuf:"varint,1,opt,name=StatusCode,proto3" json:"StatusCode,omitempty"`
	Header     map[string]*Values `` /* 153-byte string literal not displayed */
	Body       []byte             `protobuf:"bytes,3,opt,name=Body,proto3" json:"Body,omitempty"`
	Error      string             `protobuf:"bytes,4,opt,name=Error,proto3" json:"Error,omitempty"`
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse() *Response

NewResponse creates blank initialized Response object.

func (*Response) Descriptor deprecated

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

Deprecated: Use Response.ProtoReflect.Descriptor instead.

func (*Response) GetBody

func (x *Response) GetBody() []byte

func (*Response) GetError

func (x *Response) GetError() string

func (*Response) GetHeader

func (x *Response) GetHeader() map[string]*Values

func (*Response) GetStatusCode

func (x *Response) GetStatusCode() int32

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) ProtoReflect

func (x *Response) ProtoReflect() protoreflect.Message

func (*Response) ReadFrom

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

func (*Response) Reset

func (x *Response) Reset()

func (*Response) String

func (x *Response) String() string

func (*Response) ToHTTPResponse

func (resp *Response) ToHTTPResponse(r *http.Request) (*http.Response, error)

type SubjectResolveFunc

type SubjectResolveFunc func(r *http.Request) string

SubjectResolveFunc resolves the NATS subject (based on http.Request struct)

type Values

type Values struct {
	Arr []string `protobuf:"bytes,1,rep,name=arr,proto3" json:"arr,omitempty"`
	// contains filtered or unexported fields
}

func (*Values) Descriptor deprecated

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

Deprecated: Use Values.ProtoReflect.Descriptor instead.

func (*Values) GetArr

func (x *Values) GetArr() []string

func (*Values) ProtoMessage

func (*Values) ProtoMessage()

func (*Values) ProtoReflect

func (x *Values) ProtoReflect() protoreflect.Message

func (*Values) Reset

func (x *Values) Reset()

func (*Values) String

func (x *Values) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL