Documentation ¶
Overview ¶
Copyright 2015 Gravitational, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Form is a minimalist HTTP web form parser library based on functional arguments.
Index ¶
- func Parse(r *http.Request, params ...Param) error
- type BadParameterError
- type FileWrapper
- type Files
- type FilesCloseError
- type MissingParameterError
- type Param
- func Duration(name string, out *time.Duration, predicates ...Predicate) Param
- func FileSlice(name string, files *Files, predicates ...Predicate) Param
- func Int(name string, out *int, predicates ...Predicate) Param
- func String(name string, out *string, predicates ...Predicate) Param
- func StringSlice(name string, out *[]string, predicates ...Predicate) Param
- func Time(name string, out *time.Time, predicates ...Predicate) Param
- type Predicate
- type PredicateFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse takes http.Request and form arguments that it needs to extract
import ( "github.com/gravitational/form" ) var duration time.Duration var count int name := "default" // a simple way to set default argument err := form.Parse(r, form.Duration("duration", &duration), form.Int("count", &count, Required()), // notice the "Required" argument form.String("name", &name), ) if err != nil { // handle error here }
Types ¶
type BadParameterError ¶
type BadParameterError struct { Param string // Param is a paramter name Message string // Message is an error message presented to user }
BadParameterError is returned whenever the parameter format does not match required restrictions.
func (*BadParameterError) Error ¶
func (p *BadParameterError) Error() string
type FileWrapper ¶
func (*FileWrapper) Name ¶
func (f *FileWrapper) Name() string
Name returns file name as set during upload
type Files ¶
type Files []*FileWrapper
Files is a slice of multipart.File that provides additional convenient method to close all files as a single operation
type FilesCloseError ¶
type FilesCloseError struct {
Errors []error
}
func (*FilesCloseError) Error ¶
func (p *FilesCloseError) Error() string
type MissingParameterError ¶
type MissingParameterError struct {
Param string
}
MissingParameterError is an error that indicates that required parameter was not supplied by user.
func (*MissingParameterError) Error ¶
func (p *MissingParameterError) Error() string
type Param ¶
Param is a functional argument parameter passed to the Parse function
func FileSlice ¶
FileSlice reads the files uploaded with name parameter and initialized the slice of files. The files should be closed by the callee after usage, by executing f.Close() on each of them files slice will be nil if there's an error
func StringSlice ¶
StringSlice extracts the string slice of arguments by name