proxy

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 8 more Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Response `json:",inline"`
	Status   int `json:"-"`
}

type APIPage

type APIPage struct {
	Items      *gojson.RawMessage `json:"items,omitempty"`
	TotalCount int                `json:"total_count"`
}

type APIPageResponse

type APIPageResponse struct {
	// result code
	ResultCode int `json:"result_code,omitempty"`

	// err message
	Msg string `json:"message,omitempty"`

	Data APIPage `json:"data"`
}

func (APIPageResponse) Code

func (p APIPageResponse) Code() int

func (APIPageResponse) Message

func (p APIPageResponse) Message() string

func (APIPageResponse) RawData

func (p APIPageResponse) RawData() *gojson.RawMessage

func (APIPageResponse) SetData

func (p APIPageResponse) SetData(data interface{})

type APIResponse

type APIResponse struct {
	// result code
	ResultCode int `json:"result_code,omitempty"`

	// err message
	Msg string `json:"message,omitempty"`

	// return data,optional
	Raw *gojson.RawMessage `json:"data,omitempty"`

	Data interface{} `json:"-"`
}

APIResponse - API

func (APIResponse) Code

func (a APIResponse) Code() int

func (APIResponse) Message

func (a APIResponse) Message() string

func (APIResponse) RawData

func (a APIResponse) RawData() *gojson.RawMessage

func (APIResponse) SetData

func (a APIResponse) SetData(data interface{})

type BaseAPIResponse

type BaseAPIResponse interface {
	Code() int
	Message() string
	RawData() *gojson.RawMessage
	SetData(data interface{})
}

type DumpResponseWriter

type DumpResponseWriter struct {
	Status int
	Body   bytes.Buffer
	// contains filtered or unexported fields
}

func NewDumpResponseWriter

func NewDumpResponseWriter() *DumpResponseWriter

func (*DumpResponseWriter) Header

func (w *DumpResponseWriter) Header() http.Header

func (*DumpResponseWriter) OnData

func (w *DumpResponseWriter) OnData(fn func(data jsoniter.Any)) (int, error)

func (*DumpResponseWriter) Unmarshal

func (w *DumpResponseWriter) Unmarshal(model BaseAPIResponse) (err error)

func (*DumpResponseWriter) Write

func (w *DumpResponseWriter) Write(b []byte) (int, error)

func (*DumpResponseWriter) WriteHeader

func (w *DumpResponseWriter) WriteHeader(statusCode int)

type LoopPageProxy

type LoopPageProxy struct {
	// contains filtered or unexported fields
}

func NewLoopPageProxy

func NewLoopPageProxy(f func(gojson.RawMessage) ([]interface{}, error), proxyOpts ...Opt) *LoopPageProxy

func (*LoopPageProxy) LastWriter

func (l *LoopPageProxy) LastWriter() DumpResponseWriter

func (*LoopPageProxy) Loop

func (l *LoopPageProxy) Loop(req *http.Request) PageItems

func (*LoopPageProxy) ResponseStatus

func (l *LoopPageProxy) ResponseStatus() (status, resultCode int, msg string)

type Opt

type Opt func(*Proxy)

func WithHeader

func WithHeader(h http.Header) Opt

func WithModifyResponse

func WithModifyResponse(f func(*http.Response) error) Opt

func WithPatch

func WithPatch(pch ...json.Patch) Opt

func WithRequestMethod

func WithRequestMethod(method string) Opt

func WithTargetURL

func WithTargetURL(u *url.URL) Opt

type Page

type Page struct {
	Items      interface{} `json:"items"`
	TotalCount int         `json:"total_count"`
}

type PageItems

type PageItems []interface{}

func (PageItems) Filter

func (p PageItems) Filter(filter func(interface{}) bool) PageItems

func (PageItems) First

func (p PageItems) First(filter func(interface{}) bool) interface{}

func (PageItems) Paging

func (p PageItems) Paging(offset, limit int) (int, PageItems)

type PageQuery

type PageQuery struct {
	Offset int `json:"offset" form:"offset"`
	Limit  int `json:"limit" form:"limit"`
}

type Proxy

type Proxy struct {
	Request *Request

	Director       func(*http.Request)
	ModifyResponse func(*http.Response) error
	ErrorHandler   func(http.ResponseWriter, *http.Request, error)
}

func New

func New(opts ...Opt) *Proxy

func (*Proxy) Proxy

func (p *Proxy) Proxy(w http.ResponseWriter, req *http.Request)

type Request

type Request struct {
	Method      string
	URL         *url.URL
	Header      http.Header
	BodyPatches []json.Patch
	Body        []byte
}

type Response

type Response struct {
	// result code
	ResultCode int `json:"result_code,omitempty"`

	// err message
	Msg string `json:"message,omitempty"`

	// return data,optional
	Data interface{} `json:"data,omitempty"`
}

type TCMErrorResponse

type TCMErrorResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

Jump to

Keyboard shortcuts

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