Documentation ¶
Overview ¶
Package descriptor the idl descriptor for describe the idls with golang
Index ¶
- Variables
- func FindAnnotation(key, value string) (interface{}, bool)
- func RegisterAnnotation(an Annotation)
- type Annotation
- type Cookies
- type FieldDescriptor
- type FiledMapping
- type FunctionDescriptor
- type HTTPMapping
- type HTTPRequest
- type HTTPResponse
- type NewFieldMapping
- type NewHTTPMapping
- type NewRoute
- type NewValueMapping
- type Param
- type Params
- type Route
- type Router
- type ServiceDescriptor
- type StructDescriptor
- type Type
- type TypeDescriptor
- type ValueMapping
- type Void
Constants ¶
This section is empty.
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 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 }
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 { Header http.Header Query url.Values Cookies Cookies Method string Host string Path string Params *Params // path params RawBody []byte Body map[string]interface{} }
HTTPRequest ...
type HTTPResponse ¶
HTTPResponse ...
func (*HTTPResponse) Write ¶
func (resp *HTTPResponse) Write(w http.ResponseWriter) error
Write to ResponseWriter
type NewFieldMapping ¶
type NewFieldMapping func(value string) FiledMapping
NewFieldMapping FiledMapping creator
var NewGoTag NewFieldMapping = func(value string) FiledMapping { 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 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 }
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 }
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 )
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