Skip to content

Commit e844d05

Browse files
committed
gofmt -w
1 parent e16b291 commit e844d05

File tree

141 files changed

+27687
-27688
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+27687
-27688
lines changed

apidoc.go

+324-324
Large diffs are not rendered by default.

apiware/apiware.go

+70-70
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
1-
// Copyright 2016 HenryLee. All Rights Reserved.
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
14-
15-
package apiware
16-
17-
import (
18-
"errors"
19-
"net/http"
20-
// "github.com/valyala/fasthttp"
21-
)
22-
23-
type (
24-
Apiware struct {
25-
ParamNameMapper
26-
Pathdecoder
27-
Bodydecoder
28-
}
29-
30-
// Pathdecoder parses path params function, return pathParams of KV type
31-
Pathdecoder func(urlPath, pattern string) (pathParams KV)
32-
)
33-
34-
// Create a new apiware engine.
35-
// Parse and store the struct object, requires a struct pointer,
36-
// if `paramNameMapper` is nil, `paramNameMapper=toSnake`,
37-
// if `bodydecoder` is nil, `bodydecoder=bodyJONS`,
38-
func New(pathdecoder Pathdecoder, bodydecoder Bodydecoder, paramNameMapper ParamNameMapper) *Apiware {
39-
return &Apiware{
40-
ParamNameMapper: paramNameMapper,
41-
Pathdecoder: pathdecoder,
42-
Bodydecoder: bodydecoder,
43-
}
44-
}
45-
46-
// Check whether structs meet the requirements of apiware, and register them.
47-
// note: requires a structure pointer.
48-
func (a *Apiware) Register(structPointers ...interface{}) error {
49-
var errStr string
50-
for _, obj := range structPointers {
51-
err := Register(obj, a.ParamNameMapper, a.Bodydecoder)
52-
if err != nil {
53-
errStr += err.Error() + "\n"
54-
}
55-
}
56-
if len(errStr) > 0 {
57-
return errors.New(errStr)
58-
}
59-
return nil
60-
}
61-
62-
// Bind the net/http request params to the structure and validate.
63-
// note: structPointer must be structure pointer.
64-
func (a *Apiware) Bind(
65-
structPointer interface{},
66-
req *http.Request,
67-
pattern string,
68-
) error {
69-
return Bind(structPointer, req, a.Pathdecoder(req.URL.Path, pattern))
70-
}
1+
// Copyright 2016 HenryLee. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package apiware
16+
17+
import (
18+
"errors"
19+
"net/http"
20+
// "github.com/valyala/fasthttp"
21+
)
22+
23+
type (
24+
Apiware struct {
25+
ParamNameMapper
26+
Pathdecoder
27+
Bodydecoder
28+
}
29+
30+
// Pathdecoder parses path params function, return pathParams of KV type
31+
Pathdecoder func(urlPath, pattern string) (pathParams KV)
32+
)
33+
34+
// Create a new apiware engine.
35+
// Parse and store the struct object, requires a struct pointer,
36+
// if `paramNameMapper` is nil, `paramNameMapper=toSnake`,
37+
// if `bodydecoder` is nil, `bodydecoder=bodyJONS`,
38+
func New(pathdecoder Pathdecoder, bodydecoder Bodydecoder, paramNameMapper ParamNameMapper) *Apiware {
39+
return &Apiware{
40+
ParamNameMapper: paramNameMapper,
41+
Pathdecoder: pathdecoder,
42+
Bodydecoder: bodydecoder,
43+
}
44+
}
45+
46+
// Check whether structs meet the requirements of apiware, and register them.
47+
// note: requires a structure pointer.
48+
func (a *Apiware) Register(structPointers ...interface{}) error {
49+
var errStr string
50+
for _, obj := range structPointers {
51+
err := Register(obj, a.ParamNameMapper, a.Bodydecoder)
52+
if err != nil {
53+
errStr += err.Error() + "\n"
54+
}
55+
}
56+
if len(errStr) > 0 {
57+
return errors.New(errStr)
58+
}
59+
return nil
60+
}
61+
62+
// Bind the net/http request params to the structure and validate.
63+
// note: structPointer must be structure pointer.
64+
func (a *Apiware) Bind(
65+
structPointer interface{},
66+
req *http.Request,
67+
pattern string,
68+
) error {
69+
return Bind(structPointer, req, a.Pathdecoder(req.URL.Path, pattern))
70+
}

apiware/doc.go

+66-66
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
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

Comments
 (0)