Documentation
¶
Index ¶
- Constants
- Variables
- func Any(_ *http.Response) bool
- func ContentTypeConflictError(former string, latter string) error
- func DuplicatedPathKeyError(key string) error
- func EmptyRequiredVariableError(name string) error
- func MustPassPtrToImplError(p reflect.Type) error
- func NoUnmarshalerFoundForResponseError(response *http.Response) error
- func ParamTypeMustBePtrOfStructError(p reflect.Type) error
- func ServiceMustBeStructError(p reflect.Type) error
- func SomePathVarHasNoValueError(list PathKeyList) error
- func UnrecognizedHTTPMethodError(method string) error
- func UnrecognizedPathKeyError(key string) error
- func UnsupportedFieldTypeError(fieldType reflect.Type, valueType string) error
- func UnsupportedFuncTypeError(p reflect.Type) error
- func UnsupportedValueTypeError(valueType string) error
- func ValueIsNotIntError(p reflect.Type) error
- func ValueIsNotStringError(p reflect.Type) error
- type Builder
- func (builder *Builder) AddCookie(cookie *http.Cookie) *Builder
- func (builder *Builder) AddCookies(cookies []*http.Cookie) *Builder
- func (builder *Builder) AddHeader(key, value string) *Builder
- func (builder *Builder) AddReadUnmarshalFunc(unmarshaler ReadUnmarshalFunc, checker Checker) *Builder
- func (builder *Builder) AddReaderUnmarshaler(unmarshaler ReadUnmarshaler, checker Checker) *Builder
- func (builder *Builder) AddUnmarshalFunc(unmarshaler UnmarshalFunc, checker Checker) *Builder
- func (builder *Builder) AddUnmarshaler(unmarshaler Unmarshaler, checker Checker) *Builder
- func (builder *Builder) Build() (creator *Creator, err error)
- func (builder *Builder) SetBaseUrl(url string) *Builder
- func (builder *Builder) SetClient(client Client) *Builder
- func (builder *Builder) SetHeader(key, value string) *Builder
- type Checker
- type CheckerFactory
- func (factory *CheckerFactory) Create() (checker CheckerFunc)
- func (factory *CheckerFactory) When(key string, values ...string) *CheckerFactory
- func (factory *CheckerFactory) WhenContentType(values ...string) *CheckerFactory
- func (factory *CheckerFactory) WhenStatuses(statuses ...int) *CheckerFactory
- type CheckerFunc
- type Client
- type ConditionalUnmarshaler
- type ConditionalUnmarshalers
- type Creator
- type Field
- type FilePath
- type HeaderSet
- type IOField
- type MultipartReader
- type PathKeyList
- type ReadCloser
- type ReadUnmarshalFunc
- type ReadUnmarshaler
- type Reader
- type ReaderAdapter
- type ReaderImpl
- type Response
- type ResponseImpl
- type StatusSet
- type Types
- type UnmarshalFunc
- type Unmarshaler
- type UrlCtr
- type VarsController
- type VarsCtr
- type VarsParser
Constants ¶
View Source
const ( BaseUrlCannotBeEmpty = "baseUrl cannot be empty" MustPassPtrToImpl = "must pass the ptr of the service to be implemented" ServiceMustBeStruct = "service must be struct" UnrecognizedHTTPMethod = "http method is unrecognized" ParamTypeMustBePtrOfStruct = "param type must be ptr of struct" ValueIsNotString = "value is not a string" ValueIsNotInt = "value is not a int" DuplicatedPathKey = "duplicated path key" UnsupportedValueType = "field type is unrecognized" UnrecognizedPathKey = "path key is unrecognized" EmptyRequiredVariable = "required variable is empty" UnsupportedFieldType = "field type is unsupported" SomePathVarHasNoValue = "some pathValue has no value" NoUnmarshalerFoundForResponse = "no unmarshaler found for response" ContentTypeConflict = "content type conflict: " UnsupportedFuncType = "function type is not supported" )
View Source
const ( // support types: fmt.Stringer, int, string TypeHeader = "header" // support types: fmt.Stringer, int, string TypePath = "path" // support types: fmt.Stringer, int, string TypeQuery = "query" // support types: fmt.Stringer, int, string TypeForm = "form" // support types: fmt.Stringer, int, string TypeCookie = "cookie" // support types: fmt.Stringer, int, string, Reader, FilePath TypeMultipart = "part" // support types: fmt.Stringer, Reader, string, struct, slice, map TypeJSON = "json" // support types: fmt.Stringer, Reader, string, struct, slice, map TypeXML = "xml" )
value types
View Source
const ( KeyKey = "key" KeyMethod = "method" KeyType = "type" //KeyStatus = "status" KeyPath = "path" KeyDefault = "default" KeyRequire = "require" )
View Source
const ( PathKeyRegexp = `\{[a-zA-Z_][0-9a-zA-Z_]*\}` ZeroStr = "" // json Marshal nil NullStr = "null" ZeroInt = 0 )
Variables ¶
View Source
var ( FilePathType = reflect.TypeOf(filePath) IntType = reflect.TypeOf(int(1)) StringType = reflect.TypeOf("") )
View Source
var ( ZeroStringer fmt.Stringer = bytes.NewBufferString("") ZeroReader io.Reader = bytes.NewBufferString("") )
View Source
var ( StringerType = typesValue.FieldByName("stringer").Type() ReaderType = typesValue.FieldByName("reader").Type() ErrorType = typesValue.FieldByName("error").Type() ResponseType = typesValue.FieldByName("response").Type() RequestType = typesValue.FieldByName("request").Type() )
View Source
var ( DefaultUnmarshalers = []*ConditionalUnmarshaler{ { NewReaderAdapter(UnmarshalAdapter(json.Unmarshal)), new(CheckerFactory).WhenContentType( headers.MIMEApplicationJSON, headers.MIMEApplicationJSONCharsetUTF8, ).Create(), }, { NewReaderAdapter(UnmarshalAdapter(xml.Unmarshal)), new(CheckerFactory).WhenContentType( headers.MIMEApplicationXML, headers.MIMEApplicationXMLCharsetUTF8, headers.MIMETextXML, headers.MIMETextXMLCharsetUTF8, ).Create(), }, { NewReaderAdapter(UnmarshalAdapter(unhtml.Unmarshal)), new(CheckerFactory).WhenContentType( headers.MIMETextHTML, headers.MIMETextHTMLCharsetUTF8, ).Create(), }, } )
Functions ¶
func DuplicatedPathKeyError ¶
func MustPassPtrToImplError ¶
func SomePathVarHasNoValueError ¶
func SomePathVarHasNoValueError(list PathKeyList) error
func UnsupportedFuncTypeError ¶ added in v1.0.1
func ValueIsNotIntError ¶
func ValueIsNotStringError ¶
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func NewBuilder ¶
func NewBuilder() *Builder
func (*Builder) AddReadUnmarshalFunc ¶
func (builder *Builder) AddReadUnmarshalFunc(unmarshaler ReadUnmarshalFunc, checker Checker) *Builder
func (*Builder) AddReaderUnmarshaler ¶
func (builder *Builder) AddReaderUnmarshaler(unmarshaler ReadUnmarshaler, checker Checker) *Builder
func (*Builder) AddUnmarshalFunc ¶
func (builder *Builder) AddUnmarshalFunc(unmarshaler UnmarshalFunc, checker Checker) *Builder
func (*Builder) AddUnmarshaler ¶
func (builder *Builder) AddUnmarshaler(unmarshaler Unmarshaler, checker Checker) *Builder
func (*Builder) SetBaseUrl ¶
type CheckerFactory ¶
type CheckerFactory struct {
// contains filtered or unexported fields
}
func (*CheckerFactory) Create ¶
func (factory *CheckerFactory) Create() (checker CheckerFunc)
func (*CheckerFactory) When ¶
func (factory *CheckerFactory) When(key string, values ...string) *CheckerFactory
func (*CheckerFactory) WhenContentType ¶
func (factory *CheckerFactory) WhenContentType(values ...string) *CheckerFactory
func (*CheckerFactory) WhenStatuses ¶
func (factory *CheckerFactory) WhenStatuses(statuses ...int) *CheckerFactory
type CheckerFunc ¶
type ConditionalUnmarshaler ¶
type ConditionalUnmarshaler struct {
// contains filtered or unexported fields
}
type ConditionalUnmarshalers ¶
type ConditionalUnmarshalers []*ConditionalUnmarshaler
func (ConditionalUnmarshalers) Check ¶
func (unmarshalers ConditionalUnmarshalers) Check(response *http.Response) (unmarshaler ReadUnmarshaler, exist bool)
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
TypePath, TypeQuery, TypeForm, TypeHeader, TypeCookie, TypeMultipart(except io.Reader)
type IOField ¶
type IOField struct {
// contains filtered or unexported fields
}
TypeJSON, TypeXML, TypeMultipart(io.Reader)
type MultipartReader ¶
type MultipartReader struct {
// contains filtered or unexported fields
}
type PathKeyList ¶
type ReadCloser ¶
type ReadCloser interface { io.ReadCloser Empty() bool }
type ReadUnmarshalFunc ¶
type ReadUnmarshalFunc func(reader io.ReadCloser, header http.Header, v interface{}) error
func (ReadUnmarshalFunc) Unmarshal ¶
func (fn ReadUnmarshalFunc) Unmarshal(reader io.ReadCloser, header http.Header, v interface{}) error
type ReadUnmarshaler ¶
type ReadUnmarshaler interface {
Unmarshal(reader io.ReadCloser, header http.Header, v interface{}) error
}
func NewReaderAdapter ¶
func NewReaderAdapter(unmarshaler Unmarshaler) ReadUnmarshaler
type ReaderAdapter ¶
type ReaderAdapter struct {
// contains filtered or unexported fields
}
func (*ReaderAdapter) Unmarshal ¶
func (adapter *ReaderAdapter) Unmarshal(reader io.ReadCloser, header http.Header, v interface{}) (err error)
type ReaderImpl ¶
type ReaderImpl struct {
// contains filtered or unexported fields
}
func (ReaderImpl) Close ¶
func (reader ReaderImpl) Close() (err error)
func (ReaderImpl) Empty ¶
func (reader ReaderImpl) Empty() bool
type Response ¶
type Response interface { StatusCode() int Header() http.Header Body() io.ReadCloser ContentType() string Cookies() []*http.Cookie // Location returns the URL of the response's "Location" header, // if present. Relative redirects are resolved relative to // the Response's Request. ErrNoLocation is returned if no // Location header is present. Location() (*url.URL, error) // ProtoAtLeast reports whether the HTTP protocol used // in the response is at least major.minor. ProtoAtLeast(major, minor int) bool Unmarshal(ptr interface{}) error }
type ResponseImpl ¶
func (ResponseImpl) Body ¶
func (resp ResponseImpl) Body() io.ReadCloser
func (ResponseImpl) ContentType ¶
func (resp ResponseImpl) ContentType() string
func (ResponseImpl) Header ¶
func (resp ResponseImpl) Header() http.Header
func (ResponseImpl) StatusCode ¶
func (resp ResponseImpl) StatusCode() int
func (ResponseImpl) Unmarshal ¶
func (resp ResponseImpl) Unmarshal(ptr interface{}) error
type UnmarshalFunc ¶
func (UnmarshalFunc) Unmarshal ¶
func (fn UnmarshalFunc) Unmarshal(data []byte, v interface{}) error
type Unmarshaler ¶
func UnmarshalAdapter ¶
func UnmarshalAdapter(fn UnmarshalFunc) Unmarshaler
type VarsController ¶
type VarsController interface {
// contains filtered or unexported methods
}
type VarsParser ¶
type VarsParser struct {
// contains filtered or unexported fields
}
func (*VarsParser) Build ¶
func (parser *VarsParser) Build() VarsController
Source Files
¶
Click to show internal directories.
Click to hide internal directories.