|
1 |
| -/* |
2 |
| -Package apiware provides a tools which can bind the http/fasthttp request params to the structure and validate. |
3 |
| -
|
4 |
| -Copyright 2016 HenryLee. All Rights Reserved. |
5 |
| -
|
6 |
| -Licensed under the Apache License, Version 2.0 (the "License"); |
7 |
| -you may not use this file except in compliance with the License. |
8 |
| -You may obtain a copy of the License at |
9 |
| -
|
10 |
| - http://www.apache.org/licenses/LICENSE-2.0 |
11 |
| -
|
12 |
| -Unless required by applicable law or agreed to in writing, software |
13 |
| -distributed under the License is distributed on an "AS IS" BASIS, |
14 |
| -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 |
| -See the License for the specific language governing permissions and |
16 |
| -limitations under the License. |
17 |
| -
|
18 |
| -Param tag value description: |
19 |
| - tag | key | required | value | desc |
20 |
| - ------|----------|----------|---------------|---------------------------------- |
21 |
| - param | in | only one | path | (position of param) if `required` is unsetted, auto set it. e.g. url: "http://www.abc.com/a/{path}" |
22 |
| - param | in | only one | query | (position of param) e.g. url: "http://www.abc.com/a?b={query}" |
23 |
| - param | in | only one | formData | (position of param) e.g. "request body: a=123&b={formData}" |
24 |
| - param | in | only one | body | (position of param) request body can be any content |
25 |
| - param | in | only one | header | (position of param) request header info |
26 |
| - param | in | only one | cookie | (position of param) request cookie info, support: `http.Cookie`,`fasthttp.Cookie`,`string`,`[]byte` |
27 |
| - param | name | no | (e.g.`id`) | specify request param`s name |
28 |
| - param | required | no | | request param is required |
29 |
| - param | desc | no | (e.g.`id`) | request param description |
30 |
| - param | len | no | (e.g.`3:6` `3`) | length range of param's value |
31 |
| - param | range | no | (e.g.`0:10`) | numerical range of param's value |
32 |
| - param | nonzero | no | | param`s value can not be zero |
33 |
| - param | maxmb | no | (e.g.`32`) | when request Content-Type is multipart/form-data, the max memory for body.(multi-param, whichever is greater) |
34 |
| - param | regexp | no | (e.g.`^\\w+$`) | verify the value of the param with a regular expression(param value can not be null) |
35 |
| - param | err | no |(e.g.`incorrect password format`)| the custom error for binding or validating |
36 |
| -
|
37 |
| - NOTES: |
38 |
| - 1. the binding object must be a struct pointer |
39 |
| - 2. in addition to `*multipart.FileHeader`, the binding struct's field can not be a pointer |
40 |
| - 3. `regexp` or `param` tag is only usable when `param:"type(xxx)"` is exist |
41 |
| - 4. if the `param` tag is not exist, anonymous field will be parsed |
42 |
| - 5. when the param's position(`in`) is `formData` and the field's type is `multipart.FileHeader`, the param receives file uploaded |
43 |
| - 6. if param's position(`in`) is `cookie`, field's type must be `http.Cookie` |
44 |
| - 7. param tags `in(formData)` and `in(body)` can not exist at the same time |
45 |
| - 8. there should not be more than one `in(body)` param tag |
46 |
| -
|
47 |
| -List of supported param value types: |
48 |
| - base | slice | special |
49 |
| - --------|------------|------------------------------------------------------- |
50 |
| - string | []string | [][]byte |
51 |
| - byte | []byte | [][]uint8 |
52 |
| - uint8 | []uint8 | *multipart.FileHeader (only for `formData` param) |
53 |
| - bool | []bool | []*multipart.FileHeader (only for `formData` param) |
54 |
| - int | []int | http.Cookie (only for `net/http`'s `cookie` param) |
55 |
| - int8 | []int8 | fasthttp.Cookie (only for `fasthttp`'s `cookie` param) |
56 |
| - int16 | []int16 | struct (struct type only for `body` param or as an anonymous field to extend params) |
57 |
| - int32 | []int32 | |
58 |
| - int64 | []int64 | |
59 |
| - uint8 | []uint8 | |
60 |
| - uint16 | []uint16 | |
61 |
| - uint32 | []uint32 | |
62 |
| - uint64 | []uint64 | |
63 |
| - float32 | []float32 | |
64 |
| - float64 | []float64 | |
65 |
| -*/ |
66 |
| -package apiware |
| 1 | +/* |
| 2 | +Package apiware provides a tools which can bind the http/fasthttp request params to the structure and validate. |
| 3 | +
|
| 4 | +Copyright 2016 HenryLee. All Rights Reserved. |
| 5 | +
|
| 6 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +you may not use this file except in compliance with the License. |
| 8 | +You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | +Unless required by applicable law or agreed to in writing, software |
| 13 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +See the License for the specific language governing permissions and |
| 16 | +limitations under the License. |
| 17 | +
|
| 18 | +Param tag value description: |
| 19 | + tag | key | required | value | desc |
| 20 | + ------|----------|----------|---------------|---------------------------------- |
| 21 | + param | in | only one | path | (position of param) if `required` is unsetted, auto set it. e.g. url: "http://www.abc.com/a/{path}" |
| 22 | + param | in | only one | query | (position of param) e.g. url: "http://www.abc.com/a?b={query}" |
| 23 | + param | in | only one | formData | (position of param) e.g. "request body: a=123&b={formData}" |
| 24 | + param | in | only one | body | (position of param) request body can be any content |
| 25 | + param | in | only one | header | (position of param) request header info |
| 26 | + param | in | only one | cookie | (position of param) request cookie info, support: `http.Cookie`,`fasthttp.Cookie`,`string`,`[]byte` |
| 27 | + param | name | no | (e.g.`id`) | specify request param`s name |
| 28 | + param | required | no | | request param is required |
| 29 | + param | desc | no | (e.g.`id`) | request param description |
| 30 | + param | len | no | (e.g.`3:6` `3`) | length range of param's value |
| 31 | + param | range | no | (e.g.`0:10`) | numerical range of param's value |
| 32 | + param | nonzero | no | | param`s value can not be zero |
| 33 | + param | maxmb | no | (e.g.`32`) | when request Content-Type is multipart/form-data, the max memory for body.(multi-param, whichever is greater) |
| 34 | + param | regexp | no | (e.g.`^\\w+$`) | verify the value of the param with a regular expression(param value can not be null) |
| 35 | + param | err | no |(e.g.`incorrect password format`)| the custom error for binding or validating |
| 36 | +
|
| 37 | + NOTES: |
| 38 | + 1. the binding object must be a struct pointer |
| 39 | + 2. in addition to `*multipart.FileHeader`, the binding struct's field can not be a pointer |
| 40 | + 3. `regexp` or `param` tag is only usable when `param:"type(xxx)"` is exist |
| 41 | + 4. if the `param` tag is not exist, anonymous field will be parsed |
| 42 | + 5. when the param's position(`in`) is `formData` and the field's type is `multipart.FileHeader`, the param receives file uploaded |
| 43 | + 6. if param's position(`in`) is `cookie`, field's type must be `http.Cookie` |
| 44 | + 7. param tags `in(formData)` and `in(body)` can not exist at the same time |
| 45 | + 8. there should not be more than one `in(body)` param tag |
| 46 | +
|
| 47 | +List of supported param value types: |
| 48 | + base | slice | special |
| 49 | + --------|------------|------------------------------------------------------- |
| 50 | + string | []string | [][]byte |
| 51 | + byte | []byte | [][]uint8 |
| 52 | + uint8 | []uint8 | *multipart.FileHeader (only for `formData` param) |
| 53 | + bool | []bool | []*multipart.FileHeader (only for `formData` param) |
| 54 | + int | []int | http.Cookie (only for `net/http`'s `cookie` param) |
| 55 | + int8 | []int8 | fasthttp.Cookie (only for `fasthttp`'s `cookie` param) |
| 56 | + int16 | []int16 | struct (struct type only for `body` param or as an anonymous field to extend params) |
| 57 | + int32 | []int32 | |
| 58 | + int64 | []int64 | |
| 59 | + uint8 | []uint8 | |
| 60 | + uint16 | []uint16 | |
| 61 | + uint32 | []uint32 | |
| 62 | + uint64 | []uint64 | |
| 63 | + float32 | []float32 | |
| 64 | + float64 | []float64 | |
| 65 | +*/ |
| 66 | +package apiware |
0 commit comments