broker

package
v0.0.0-...-cfd9f02 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2019 License: LGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindFlag

func BindFlag(config *viper.Viper, cmd *cobra.Command)

BindFlag ...

func NewRegisterCmd

func NewRegisterCmd(config *viper.Viper) *cobra.Command

NewRegisterCmd ...

func ParseBroker

func ParseBroker(b IBroker) func(http.ResponseWriter, *http.Request)

ParseBroker convert broker to http handler

func RegisterAPI

func RegisterAPI(filePath, apiSVRURI, serverURI, instanceID, instanceName string) error

RegisterAPI OpenAPI to API-SVR

Types

type Broker

type Broker struct {
}

Broker ...

func (*Broker) AcceptJSON

func (b *Broker) AcceptJSON(r *http.Request)

AcceptJSON 设置请求头 Accept: application/json

func (*Broker) InitResponse

func (b *Broker) InitResponse(r *http.Response) (*ResContent, error)

InitResponse 处理常见标准错误并停供默认提示

func (Broker) LogRequest

func (b Broker) LogRequest(r *http.Request)

LogRequest ...

func (Broker) LogResponse

func (b Broker) LogResponse(r *http.Response)

LogResponse ...

func (*Broker) ReadResponse

func (b *Broker) ReadResponse(c *ResContent, r *http.Response) (err error)

ReadResponse 读取response 内容

func (*Broker) WrapResponse

func (b *Broker) WrapResponse(c *ResContent, r *http.Response) error

WrapResponse 将ResContent以json返回

type DefaultBroker

type DefaultBroker struct {
	Broker
}

DefaultBroker ...

func (DefaultBroker) ProcessRequest

func (b DefaultBroker) ProcessRequest(r *http.Request)

ProcessRequest of DefaultBroker

func (DefaultBroker) ProcessResponse

func (b DefaultBroker) ProcessResponse(r *http.Response) error

ProcessResponse of DefaultBroker

type IBroker

type IBroker interface {
	ProcessRequest(*http.Request)
	ProcessResponse(*http.Response) error
	LogResponse(*http.Response)
	LogRequest(*http.Request)
}

IBroker ...

type ResContent

type ResContent struct {
	Status ResStatus   `json:"status"`
	Result interface{} `json:"result"`
}

ResContent ...

type ResStatus

type ResStatus struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ResStatus ...

Jump to

Keyboard shortcuts

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