Documentation
¶
Overview ¶
Package scanner helps to scan struct for collection request info eg:
type InBody struct {
Name string `json:"name,nocase,strictcase"`
Data []byte `json:"data"`
Ignored any `name:"-"`
NoTag any
Strings []string
}
type InPath struct {
OrgID int `in:"path" name:"orgID"`
UserID int `in:"path" name:"userID"`
}
type InQuery struct {
Q0 int `in:"query" name:"q0,format:bin"`
Q1 string `in:"query" name:"q1"`
}
type InHeader struct {
V1 int `in:"header" name:"k1"`
V2 string `in:"header" name:"k2"`
}
type InCookie struct {
Token string `in:"cookie" name:"token"`
CookiePayload
}
type CookiePayload struct {
Userdata string `in:"cookie" name:"userdata"`
}
type Request struct {
httpx.MethodGet `path:"/org/{orgID}/user/{userID}"`
Direct bool `in:"query" name:"direct"`
InCookie
InHeader
InPath
*InQuery
InBody `in:"body" mime:"application/json"`
}
Request meta: 1. `in` tag describes data location. eg: path, query, header, cookie, body 2. `name` tag describes data key. 3. `path` tag describes route path. eg: GET /api/v0/user/{userID} 4. json/v2 tag extension is supported. eg: inline, unknown, string, format etc.
eg: request content GET /org/1001/user/8888?direct=true&q0=1010&q1=active HTTP/1.1 Host: api.yourservice.com k1: 200 k2: high-priority Cookie: token=abc_session_99; userdata=gold_member Content-Type: application/json
{
"name": "xoctopus",
"data": "SGVsbG8gV29ybGQ=",
"strings": ["opt1", "opt2"]
}
Collect results: 1. InPath{ OrgID: 1; UserID: 2} 2. InQuery{ Q0: 101; Q1: "active"}; Direct: true 3. InHeader{ V1: 200; V2: "high-priority" } 4. InCookie{ Token: "abc_session_99" Userdata: "gold_member" } 5. InBody{ Name: "xoctopus"; Data: []byte("Hello World"); Strings: []string{"opt1","opt2"}
Index ¶
- Variables
- func CanUnmarshalByString(typ reflect.Type) bool
- func Implements(typ, tar reflect.Type) bool
- func UnwrapField(v any) any
- func WrapField(v any, f *Field) any
- type Casing
- type Field
- type FieldOptions
- type Struct
- func (fs *Struct) FieldsIn(loc string) iter.Seq[*Field]
- func (fs *Struct) FieldsInCookie() iter.Seq[*Field]
- func (fs *Struct) FieldsInHeader() iter.Seq[*Field]
- func (fs *Struct) FieldsInPath() iter.Seq[*Field]
- func (fs *Struct) FieldsInQuery() iter.Seq[*Field]
- func (fs *Struct) Inlined() (*Field, bool)
- func (fs *Struct) Len() int
- func (fs *Struct) Lookup(name string) (*Field, bool)
- func (fs *Struct) LookupIn(in, name string) (*Field, bool)
- func (fs *Struct) Range(fn func(f *Field) bool)
- func (fs *Struct) RangeIn(loc string) iter.Seq[*Field]
- type WrappedField
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CanUnmarshalByString ¶
func Implements ¶
func UnwrapField ¶
Types ¶
type Field ¶
type FieldOptions ¶
type FieldOptions struct {
Name string
HasName bool
Casing Casing
Inline bool
Unknown bool
Omitzero bool
Omitempty bool
String bool
Format string
StringItem bool
// Embedded not in v2.fieldOptions. for parsing duplicated query kvs
// eg: createdAt.gt=x&createdAt.lte=y&updatedAt.gt=x&updatedAt.lte=y
// the gt, lte in createdAt and updatedAt is same type but prefix.
// This is a temporary plan
Embedded bool
}
FieldOptions see encoding/json/v2.fieldOptions. nameNeedEscape is unsupported
func ParseFieldOptions ¶
func ParseFieldOptions(sf reflect.StructField) (FieldOptions, bool, error)
func (*FieldOptions) StrictCase ¶
func (o *FieldOptions) StrictCase() bool