Documentation ¶
Overview ¶
Package descriptor the idl descriptor for describe the idls with golang
Index ¶
- Constants
- Variables
- func FindAnnotation(key, value string) (interface{}, bool)
- func RegisterAnnotation(an Annotation)
- type Annotation
- type FieldDescriptor
- type FiledMapping
- type FunctionDescriptor
- type HTTPMapping
- type HTTPRequest
- func (req *HTTPRequest) GetBody() []byte
- func (req *HTTPRequest) GetCookie(key string) string
- func (req *HTTPRequest) GetHeader(key string) string
- func (req *HTTPRequest) GetHost() string
- func (req *HTTPRequest) GetMapBody(key string) string
- func (req *HTTPRequest) GetMethod() string
- func (req *HTTPRequest) GetParam(key string) string
- func (req *HTTPRequest) GetPath() string
- func (req *HTTPRequest) GetPostForm(key string) string
- func (req *HTTPRequest) GetQuery(key string) string
- func (req *HTTPRequest) GetUri() string
- type HTTPResponse
- type JsonRenderer
- type MIMEType
- type NewFieldMapping
- type NewHTTPMapping
- type NewRoute
- type NewValueMapping
- type Param
- type Params
- type PbRenderer
- type Renderer
- type Route
- type Router
- type ServiceDescriptor
- type StructDescriptor
- type Type
- type TypeDescriptor
- type ValueMapping
- type Void
Constants ¶
const ( MIMEApplicationJson = "application/json" MIMEApplicationProtobuf = "application/x-protobuf" )
Variables ¶
var ( // APIQueryAnnotation api.path annotation APIQueryAnnotation = NewBAMAnnotation("api.query", NewAPIQuery) // APIPathAnnotation api.path annotation APIPathAnnotation = NewBAMAnnotation("api.path", NewAPIPath) // APIHeaderAnnotation api.header annotation APIHeaderAnnotation = NewBAMAnnotation("api.header", NewAPIHeader) // APICookieAnnotation api.cookie annotation APICookieAnnotation = NewBAMAnnotation("api.cookie", NewAPICookie) // APIBodyAnnotation api.body annotation APIBodyAnnotation = NewBAMAnnotation("api.body", NewAPIBody) // APIHttpCodeAnnotation api.http_code annotation APIHttpCodeAnnotation = NewBAMAnnotation("api.http_code", NewAPIHTTPCode) // APINoneAnnotation api.none annotation APINoneAnnotation = NewBAMAnnotation("api.none", NewAPINone) // APIRawBodyAnnotation api.raw_body annotation APIRawBodyAnnotation = NewBAMAnnotation("api.raw_body", NewAPIRawBody) )
var ( // APIGetAnnotation api.get annotation APIGetAnnotation = NewBAMAnnotation("api.get", NewAPIGet) // APIPostAnnotation api.post annotation APIPostAnnotation = NewBAMAnnotation("api.post", NewAPIPost) // APIPutAnnotation api.put annotation APIPutAnnotation = NewBAMAnnotation("api.put", NewAPIPut) // APIDeleteAnnotation api.delete annotation APIDeleteAnnotation = NewBAMAnnotation("api.delete", NewAPIDelete) )
var APIJSConvAnnotation = NewBAMAnnotation("api.js_conv", NewAPIJSConv)
APIJSConvAnnotation api.js_conv annotation
var DefaultNewMapping = NewAPIBody
DefaultNewMapping the default mapping creator
var GoTagAnnatition = NewBAMAnnotation("go.tag", NewGoTag)
GoTagAnnatition go.tag annatation define
Functions ¶
func FindAnnotation ¶
FindAnnotation search an annotation by given key/value
func RegisterAnnotation ¶
func RegisterAnnotation(an Annotation)
RegisterAnnotation register an annotation for parser
Types ¶
type Annotation ¶
type Annotation interface { // Equal assert the given key/value is this Annotation Equal(key, value string) bool // for search // Handle the handle function of the Annotation Handle() interface{} // one of NewHttpMapping/NewKeyMapping/NewValueMapping/NewRoute }
Annotation idl annotation interface
func NewBAMAnnotation ¶
func NewBAMAnnotation(key string, handle interface{}) Annotation
NewBAMAnnotation create a bam annotation
func NewNoneAnnotation ¶
func NewNoneAnnotation(key string) Annotation
NewNoneAnnotation create do nothing annotation
func NewNoneWithValueAnnotation ¶
func NewNoneWithValueAnnotation(key, value string) Annotation
NewNoneWithValueAnnotation create do nothing annotation
type FieldDescriptor ¶
type FieldDescriptor struct { Name string // field name Alias string // alias name ID int32 Required bool Optional bool DefaultValue interface{} IsException bool Type *TypeDescriptor HTTPMapping HTTPMapping ValueMapping ValueMapping }
FieldDescriptor idl field descriptor
func (*FieldDescriptor) FieldName ¶
func (d *FieldDescriptor) FieldName() string
FieldName return field name maybe with an alias
type FiledMapping ¶
type FiledMapping interface {
Handle(field *FieldDescriptor)
}
FiledMapping mapping handle for filed descriptor
type FunctionDescriptor ¶
type FunctionDescriptor struct { Name string Oneway bool Request *TypeDescriptor Response *TypeDescriptor HasRequestBase bool StreamingMode serviceinfo.StreamingMode }
FunctionDescriptor idl function descriptor
type HTTPMapping ¶
type HTTPMapping interface { // get value from request Request(ctx context.Context, req *HTTPRequest, field *FieldDescriptor) (interface{}, bool, error) // set value to response Response(ctx context.Context, resp *HTTPResponse, field *FieldDescriptor, val interface{}) error }
HTTPMapping http mapping annotation
type HTTPRequest ¶
type HTTPRequest struct { Params *Params // path params Request *http.Request RawBody []byte Body map[string]interface{} GeneralBody interface{} // body of other representation, used with ContentType ContentType MIMEType // contains filtered or unexported fields }
HTTPRequest ...
func (*HTTPRequest) GetBody ¶ added in v0.7.0
func (req *HTTPRequest) GetBody() []byte
GetBody implements http.RequestGetter of dynamicgo
func (*HTTPRequest) GetCookie ¶ added in v0.7.0
func (req *HTTPRequest) GetCookie(key string) string
GetCookie implements http.RequestGetter of dynamicgo
func (*HTTPRequest) GetHeader ¶ added in v0.7.0
func (req *HTTPRequest) GetHeader(key string) string
GetHeader implements http.RequestGetter of dynamicgo
func (*HTTPRequest) GetHost ¶ added in v0.7.0
func (req *HTTPRequest) GetHost() string
GetHost implements http.RequestGetter of dynamicgo
func (*HTTPRequest) GetMapBody ¶ added in v0.7.0
func (req *HTTPRequest) GetMapBody(key string) string
GetMapBody implements http.RequestGetter of dynamicgo
func (*HTTPRequest) GetMethod ¶ added in v0.7.0
func (req *HTTPRequest) GetMethod() string
GetMethod implements http.RequestGetter of dynamicgo
func (*HTTPRequest) GetParam ¶ added in v0.7.0
func (req *HTTPRequest) GetParam(key string) string
GetParam implements http.RequestGetter of dynamicgo
func (*HTTPRequest) GetPath ¶ added in v0.7.0
func (req *HTTPRequest) GetPath() string
GetPath implements http.RequestGetter of dynamicgo
func (*HTTPRequest) GetPostForm ¶ added in v0.7.0
func (req *HTTPRequest) GetPostForm(key string) string
GetPostForm implements http.RequestGetter of dynamicgo
func (*HTTPRequest) GetQuery ¶ added in v0.7.0
func (req *HTTPRequest) GetQuery(key string) string
GetQuery implements http.RequestGetter of dynamicgo
func (*HTTPRequest) GetUri ¶ added in v0.7.0
func (req *HTTPRequest) GetUri() string
GetUri implements http.RequestGetter of dynamicgo
type HTTPResponse ¶
type HTTPResponse struct { Header http.Header StatusCode int32 RawBody []byte // this field is set only when generic.UseRawBodyForHTTPResp(true) is set Body map[string]interface{} GeneralBody interface{} // body of other representation, used with ContentType ContentType MIMEType Renderer Renderer }
HTTPResponse ...
func NewGeneralHTTPResponse ¶ added in v0.4.0
func NewGeneralHTTPResponse(contentType MIMEType, initBody interface{}, renderer Renderer) *HTTPResponse
NewGeneralHTTPResponse init response with given MIMEType and body
func NewHTTPPbResponse ¶ added in v0.4.0
func NewHTTPPbResponse(initBody interface{}) *HTTPResponse
func NewHTTPResponse ¶
func NewHTTPResponse() *HTTPResponse
NewHTTPResponse HTTP response for JSON body
func (*HTTPResponse) SetCookie ¶ added in v0.7.0
func (resp *HTTPResponse) SetCookie(key, val string) error
SetCookie implements http.ResponseSetter of dynamicgo
func (*HTTPResponse) SetHeader ¶ added in v0.7.0
func (resp *HTTPResponse) SetHeader(key, val string) error
SetHeader implements http.ResponseSetter of dynamicgo
func (*HTTPResponse) SetRawBody ¶ added in v0.7.0
func (resp *HTTPResponse) SetRawBody(body []byte) error
SetRawBody implements http.ResponseSetter of dynamicgo
func (*HTTPResponse) SetStatusCode ¶ added in v0.7.0
func (resp *HTTPResponse) SetStatusCode(code int) error
SetStatusCode implements http.ResponseSetter of dynamicgo
func (*HTTPResponse) Write ¶
func (resp *HTTPResponse) Write(w http.ResponseWriter) error
Write to ResponseWriter
type JsonRenderer ¶ added in v0.4.0
type JsonRenderer struct{}
func (JsonRenderer) Render ¶ added in v0.4.0
func (j JsonRenderer) Render(w http.ResponseWriter, body interface{}) error
func (JsonRenderer) WriteContentType ¶ added in v0.4.0
func (j JsonRenderer) WriteContentType(w http.ResponseWriter)
type NewFieldMapping ¶
type NewFieldMapping func(value string) FiledMapping
NewFieldMapping FiledMapping creator
var NewGoTag NewFieldMapping = func(value string) FiledMapping { value = escape.ReplaceAllStringFunc(value, func(m string) string { if m[1] == '"' { return m[1:] } return m }) return &goTag{reflect.StructTag(value)} }
NewGoTag go.tag annotation creator
type NewHTTPMapping ¶
type NewHTTPMapping func(value string) HTTPMapping
NewHTTPMapping HTTPMapping creator api.query = value
var NewAPIBody NewHTTPMapping = func(value string) HTTPMapping {
return &apiBody{value}
}
NewAPIBody ...
var NewAPICookie NewHTTPMapping = func(value string) HTTPMapping {
return &apiCookie{value}
}
NewAPICookie ...
var NewAPIHTTPCode NewHTTPMapping = func(value string) HTTPMapping {
return &apiHTTPCode{}
}
NewAPIHTTPCode ...
var NewAPIHeader NewHTTPMapping = func(value string) HTTPMapping {
return &apiHeader{value}
}
NewAPIHeader ...
var NewAPINone NewHTTPMapping = func(value string) HTTPMapping {
return &apiNone{}
}
NewAPINone ...
var NewAPIPath NewHTTPMapping = func(value string) HTTPMapping {
return &apiPath{value}
}
NewAPIPath ...
var NewAPIQuery NewHTTPMapping = func(value string) HTTPMapping {
return &apiQuery{value}
}
NewAPIQuery ...
var NewAPIRawBody NewHTTPMapping = func(value string) HTTPMapping {
return &apiRawBody{}
}
NewAPIRawBody ...
type NewRoute ¶
type NewRoute func(value string, function *FunctionDescriptor) Route
NewRoute route creator
var NewAPIDelete NewRoute = func(value string, function *FunctionDescriptor) Route { return &apiRoute{http.MethodDelete, value, function} }
NewAPIDelete ...
var NewAPIGet NewRoute = func(value string, function *FunctionDescriptor) Route { return &apiRoute{http.MethodGet, value, function} }
NewAPIGet ...
var NewAPIPost NewRoute = func(value string, function *FunctionDescriptor) Route { return &apiRoute{http.MethodPost, value, function} }
NewAPIPost ...
type NewValueMapping ¶
type NewValueMapping func(value string) ValueMapping
NewValueMapping ValueMapping creator
var NewAPIJSConv NewValueMapping = func(value string) ValueMapping {
return &apiJSConv{}
}
NewAPIJSConv ...
type Params ¶
type Params struct {
// contains filtered or unexported fields
}
Params and recyclable
type PbRenderer ¶ added in v0.4.0
type PbRenderer struct{}
func (PbRenderer) Render ¶ added in v0.4.0
func (p PbRenderer) Render(w http.ResponseWriter, body interface{}) error
func (PbRenderer) WriteContentType ¶ added in v0.4.0
func (p PbRenderer) WriteContentType(w http.ResponseWriter)
type Renderer ¶ added in v0.4.0
type Renderer interface { Render(w http.ResponseWriter, body interface{}) error WriteContentType(w http.ResponseWriter) }
type Route ¶
type Route interface { Method() string Path() string Function() *FunctionDescriptor }
Route the route annotation
type Router ¶
type Router interface { // Handle register Route to Router Handle(rt Route) // Lookup FunctionDescriptor from HTTPRequest Lookup(req *HTTPRequest) (*FunctionDescriptor, error) }
Router http router for bam annotations
type ServiceDescriptor ¶
type ServiceDescriptor struct { Name string Functions map[string]*FunctionDescriptor Router Router DynamicGoDsc *dthrift.ServiceDescriptor IsCombinedServices bool }
ServiceDescriptor idl service descriptor
func (*ServiceDescriptor) LookupFunctionByMethod ¶
func (s *ServiceDescriptor) LookupFunctionByMethod(method string) (*FunctionDescriptor, error)
LookupFunctionByMethod lookup function by method
type StructDescriptor ¶
type StructDescriptor struct { Name string FieldsByID map[int32]*FieldDescriptor FieldsByName map[string]*FieldDescriptor RequiredFields map[int32]*FieldDescriptor DefaultFields map[string]*FieldDescriptor }
StructDescriptor idl struct descriptor
func (*StructDescriptor) CheckRequired ¶
func (d *StructDescriptor) CheckRequired(rw map[int32]struct{}) error
CheckRequired check all required fields at the end of read or write
type Type ¶
type Type byte
Type constants in the Thrift protocol
const ( STOP Type = 0 VOID Type = 1 BOOL Type = 2 BYTE Type = 3 I08 Type = 3 DOUBLE Type = 4 I16 Type = 6 I32 Type = 8 I64 Type = 10 STRING Type = 11 UTF7 Type = 11 STRUCT Type = 12 MAP Type = 13 SET Type = 14 LIST Type = 15 UTF8 Type = 16 UTF16 Type = 17 // BINARY Type = 18 wrong and unusued JSON Type = 19 )
Types
func (Type) ToThriftTType ¶
ToThriftTType convert to thrift.TType
type TypeDescriptor ¶
type TypeDescriptor struct { Name string Type Type Key *TypeDescriptor // for map key Elem *TypeDescriptor // for slice or map element Struct *StructDescriptor // for struct IsRequestBase bool }
TypeDescriptor idl type descriptor
type ValueMapping ¶
type ValueMapping interface { Request(ctx context.Context, val interface{}, field *FieldDescriptor) (interface{}, error) Response(ctx context.Context, val interface{}, field *FieldDescriptor) (interface{}, error) }
ValueMapping value mapping annotation