gotten: github.com/Hexilee/gotten Index | Files | Directories

package gotten

import "github.com/Hexilee/gotten"

Index

Package Files

Checker.go Client.go Creator.go ErrorMessages.go Reader.go RequestFields.go Response.go TagKeys.go Unmarshaler.go UrlCtr.go VarsCtr.go interfaceTypes.go

Constants

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"
)
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

const (
    KeyKey    = "key"
    KeyMethod = "method"
    KeyType   = "type"
    //KeyStatus  = "status"
    KeyPath    = "path"
    KeyDefault = "default"
    KeyRequire = "require"
)
const (
    PathKeyRegexp = `\{[a-zA-Z_][0-9a-zA-Z_]*\}`
    ZeroStr       = ""

    // json Marshal nil
    NullStr = "null"
    ZeroInt = 0
)

Variables

var (
    FilePathType = reflect.TypeOf(filePath)
    IntType      = reflect.TypeOf(int(1))
    StringType   = reflect.TypeOf("")
)
var (
    ZeroStringer fmt.Stringer = bytes.NewBufferString("")
    ZeroReader   io.Reader    = bytes.NewBufferString("")
)
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()
)
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(),
        },
    }
)

func Any Uses

func Any(_ *http.Response) bool

func ContentTypeConflictError Uses

func ContentTypeConflictError(former string, latter string) error

func DuplicatedPathKeyError Uses

func DuplicatedPathKeyError(key string) error

func EmptyRequiredVariableError Uses

func EmptyRequiredVariableError(name string) error

func MustPassPtrToImplError Uses

func MustPassPtrToImplError(p reflect.Type) error

func NoUnmarshalerFoundForResponseError Uses

func NoUnmarshalerFoundForResponseError(response *http.Response) error

func ParamTypeMustBePtrOfStructError Uses

func ParamTypeMustBePtrOfStructError(p reflect.Type) error

func ServiceMustBeStructError Uses

func ServiceMustBeStructError(p reflect.Type) error

func SomePathVarHasNoValueError Uses

func SomePathVarHasNoValueError(list PathKeyList) error

func UnrecognizedHTTPMethodError Uses

func UnrecognizedHTTPMethodError(method string) error

func UnrecognizedPathKeyError Uses

func UnrecognizedPathKeyError(key string) error

func UnsupportedFieldTypeError Uses

func UnsupportedFieldTypeError(fieldType reflect.Type, valueType string) error

func UnsupportedFuncTypeError Uses

func UnsupportedFuncTypeError(p reflect.Type) error

func UnsupportedValueTypeError Uses

func UnsupportedValueTypeError(valueType string) error

func ValueIsNotIntError Uses

func ValueIsNotIntError(p reflect.Type) error

func ValueIsNotStringError Uses

func ValueIsNotStringError(p reflect.Type) error

type Builder Uses

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

func NewBuilder Uses

func NewBuilder() *Builder

func (*Builder) AddCookie Uses

func (builder *Builder) AddCookie(cookie *http.Cookie) *Builder

func (*Builder) AddCookies Uses

func (builder *Builder) AddCookies(cookies []*http.Cookie) *Builder

func (*Builder) AddHeader Uses

func (builder *Builder) AddHeader(key, value string) *Builder

func (*Builder) AddReadUnmarshalFunc Uses

func (builder *Builder) AddReadUnmarshalFunc(unmarshaler ReadUnmarshalFunc, checker Checker) *Builder

func (*Builder) AddReaderUnmarshaler Uses

func (builder *Builder) AddReaderUnmarshaler(unmarshaler ReadUnmarshaler, checker Checker) *Builder

func (*Builder) AddUnmarshalFunc Uses

func (builder *Builder) AddUnmarshalFunc(unmarshaler UnmarshalFunc, checker Checker) *Builder

func (*Builder) AddUnmarshaler Uses

func (builder *Builder) AddUnmarshaler(unmarshaler Unmarshaler, checker Checker) *Builder

func (*Builder) Build Uses

func (builder *Builder) Build() (creator *Creator, err error)

func (*Builder) SetBaseUrl Uses

func (builder *Builder) SetBaseUrl(url string) *Builder

func (*Builder) SetClient Uses

func (builder *Builder) SetClient(client Client) *Builder

func (*Builder) SetHeader Uses

func (builder *Builder) SetHeader(key, value string) *Builder

type Checker Uses

type Checker interface {
    Check(*http.Response) bool
}

type CheckerFactory Uses

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

func (*CheckerFactory) Create Uses

func (factory *CheckerFactory) Create() (checker CheckerFunc)

func (*CheckerFactory) When Uses

func (factory *CheckerFactory) When(key string, values ...string) *CheckerFactory

func (*CheckerFactory) WhenContentType Uses

func (factory *CheckerFactory) WhenContentType(values ...string) *CheckerFactory

func (*CheckerFactory) WhenStatuses Uses

func (factory *CheckerFactory) WhenStatuses(statuses ...int) *CheckerFactory

type CheckerFunc Uses

type CheckerFunc func(*http.Response) bool

func (CheckerFunc) Check Uses

func (fn CheckerFunc) Check(resp *http.Response) bool

type Client Uses

type Client interface {
    Do(r *http.Request) (*http.Response, error)
}

type ConditionalUnmarshaler Uses

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

type ConditionalUnmarshalers Uses

type ConditionalUnmarshalers []*ConditionalUnmarshaler

func (ConditionalUnmarshalers) Check Uses

func (unmarshalers ConditionalUnmarshalers) Check(response *http.Response) (unmarshaler ReadUnmarshaler, exist bool)

type Creator Uses

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

func (*Creator) Impl Uses

func (creator *Creator) Impl(service interface{}) (err error)

func(*params) (*http.Request, error) || func(*params) (gotten.Response, error)

type Field Uses

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

TypePath, TypeQuery, TypeForm, TypeHeader, TypeCookie, TypeMultipart(except io.Reader)

type FilePath Uses

type FilePath string

type HeaderSet Uses

type HeaderSet map[string]map[string]bool

type IOField Uses

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

TypeJSON, TypeXML, TypeMultipart(io.Reader)

type MultipartReader Uses

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

type PathKeyList Uses

type PathKeyList map[string]bool

type ReadCloser Uses

type ReadCloser interface {
    io.ReadCloser
    Empty() bool
}

type ReadUnmarshalFunc Uses

type ReadUnmarshalFunc func(reader io.ReadCloser, header http.Header, v interface{}) error

func (ReadUnmarshalFunc) Unmarshal Uses

func (fn ReadUnmarshalFunc) Unmarshal(reader io.ReadCloser, header http.Header, v interface{}) error

type ReadUnmarshaler Uses

type ReadUnmarshaler interface {
    Unmarshal(reader io.ReadCloser, header http.Header, v interface{}) error
}

func NewReaderAdapter Uses

func NewReaderAdapter(unmarshaler Unmarshaler) ReadUnmarshaler

type Reader Uses

type Reader interface {
    io.Reader
    Empty() bool
}

type ReaderAdapter Uses

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

func (*ReaderAdapter) Unmarshal Uses

func (adapter *ReaderAdapter) Unmarshal(reader io.ReadCloser, header http.Header, v interface{}) (err error)

type ReaderImpl Uses

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

func (ReaderImpl) Close Uses

func (reader ReaderImpl) Close() (err error)

func (ReaderImpl) Empty Uses

func (reader ReaderImpl) Empty() bool

func (ReaderImpl) Read Uses

func (reader ReaderImpl) Read(p []byte) (n int, err error)

type Response Uses

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 Uses

type ResponseImpl struct {
    *http.Response
    // contains filtered or unexported fields
}

func (ResponseImpl) Body Uses

func (resp ResponseImpl) Body() io.ReadCloser

func (ResponseImpl) ContentType Uses

func (resp ResponseImpl) ContentType() string

func (ResponseImpl) Header Uses

func (resp ResponseImpl) Header() http.Header

func (ResponseImpl) StatusCode Uses

func (resp ResponseImpl) StatusCode() int

func (ResponseImpl) Unmarshal Uses

func (resp ResponseImpl) Unmarshal(ptr interface{}) error

type StatusSet Uses

type StatusSet map[int]bool

type Types Uses

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

type UnmarshalFunc Uses

type UnmarshalFunc func(data []byte, v interface{}) error

func (UnmarshalFunc) Unmarshal Uses

func (fn UnmarshalFunc) Unmarshal(data []byte, v interface{}) error

type Unmarshaler Uses

type Unmarshaler interface {
    Unmarshal(data []byte, v interface{}) error
}

func UnmarshalAdapter Uses

func UnmarshalAdapter(fn UnmarshalFunc) Unmarshaler

type UrlCtr Uses

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

type VarsController Uses

type VarsController interface {
    // contains filtered or unexported methods
}

type VarsCtr Uses

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

type VarsParser Uses

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

func (*VarsParser) Build Uses

func (parser *VarsParser) Build() VarsController

Directories

PathSynopsis
example
headers
mock
unmarshalers

Package gotten imports 21 packages (graph) and is imported by 3 packages. Updated 2018-11-21. Refresh now. Tools for package owners.