rest

package
v0.0.0-...-cb472e6 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Verb    string
	Path    string
	Handler func(contexts *Contexts)
}

type Config

type Config struct {
	ErrorIf  errors.CCErrorIf
	Language language.CCLanguageIf
}

type Contexts

type Contexts struct {
	Kit     *Kit
	Request *restful.Request
	// contains filtered or unexported fields
}

func (*Contexts) DecodeInto

func (c *Contexts) DecodeInto(to interface{}) error

func (*Contexts) NewContexts

func (c *Contexts) NewContexts() *Contexts

NewContexts 产生一个新的contexts, 一般用于在创建新的协程的时候,这个时候会对header 做处理,删除不必要的http header。

func (*Contexts) NewHeader

func (c *Contexts) NewHeader() http.Header

NewHeader 产生一个新的header, 一般用于在创建新的协程的时候,这个时候会对header 做处理,删除不必要的http header。

func (*Contexts) RespAutoError

func (c *Contexts) RespAutoError(err error)

func (*Contexts) RespBkEntity

func (c *Contexts) RespBkEntity(data interface{})

func (*Contexts) RespBkError

func (c *Contexts) RespBkError(errCode int, errMsg string)

func (*Contexts) RespCountInfoString

func (c *Contexts) RespCountInfoString(count int64, infoArray []string)

func (*Contexts) RespEntity

func (c *Contexts) RespEntity(data interface{})

func (*Contexts) RespEntityWithCount

func (c *Contexts) RespEntityWithCount(count int64, info interface{})

func (*Contexts) RespEntityWithError

func (c *Contexts) RespEntityWithError(data interface{}, err error)

func (*Contexts) RespErrorCodeF

func (c *Contexts) RespErrorCodeF(errCode int, logMsg string, errorf ...interface{})

WriteErrorf used to write a error response to the request client. it will wrapper the error with error code and other errorf args. errorf is used to format multiple-language error message. it will also will log the error at the same time with logMsg.

func (*Contexts) RespErrorCodeOnly

func (c *Contexts) RespErrorCodeOnly(errCode int, format string, args ...interface{})

func (*Contexts) RespString

func (c *Contexts) RespString(data string)

RespString response the data format to a json string. the data is a string, and do not need marshal, can return directly.

func (*Contexts) RespStringArray

func (c *Contexts) RespStringArray(jsonArray []string)

RespString response the data format to a json string. the data is a string, and do not need marshal, can return directly.

func (*Contexts) RespWithError

func (c *Contexts) RespWithError(err error, errCode int, format string, args ...interface{})

WriteError is used to write a error response to the http client, which means the request occur an error. It receive an err and an optional error code parameter. It will testify the err, if the err is a CCErrorCoder, then the error code inside it will be used. Otherwise, if errCode is set and > 0, then errCode value is used. Finally, if error code is not set and err is not CCErrorCoder, then it will be set with a default CCSystemBusy code. This function will also write a log when it's called which contains the request id field.

func (*Contexts) WithStatusCode

func (c *Contexts) WithStatusCode(statusCode int) *Contexts

type CountInfo

type CountInfo struct {
	Count int64       `json:"count"`
	Info  interface{} `json:"info"`
}

type Kit

type Kit struct {
	Rid             string
	Header          http.Header
	Ctx             context.Context
	CCError         errors.DefaultCCErrorIf
	User            string
	SupplierAccount string
}

func (*Kit) NewHeader

func (kit *Kit) NewHeader() http.Header

NewHeader 产生一个新的header, 一般用于在创建新的协程的时候,这个时候会对header 做处理,删除不必要的http header。

func (*Kit) NewKit

func (kit *Kit) NewKit() *Kit

NewKit 产生一个新的kit, 一般用于在创建新的协程的时候,这个时候会对header 做处理,删除不必要的http header。

type RestUtility

type RestUtility struct {
	Config
	// contains filtered or unexported fields
}

func NewRestUtility

func NewRestUtility(conf Config) *RestUtility

func (*RestUtility) AddHandler

func (r *RestUtility) AddHandler(action Action)

func (*RestUtility) AddToRestfulWebService

func (r *RestUtility) AddToRestfulWebService(ws *restful.WebService)

type RestfulConfig

type RestfulConfig struct {
	RootPath string
}

Jump to

Keyboard shortcuts

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