1 Star 0 Fork 13

陆晓 / GoInk

forked from 傅小黑 / GoInk 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
input.go 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
package hxgo
import (
"net/url"
)
//-------------------------------
// input object
type Input struct {
FormValues url.Values
}
// get new *Input from a *Request
func (this *Request) Input() *Input {
this.Raw.ParseForm()
return &Input{this.Raw.Form}
}
// get input data from key string
func (this *Input) Get(key string) string {
return this.FormValues.Get(key)
}
// get input data slice from key string, sometimes checkbox or select can be multi-value
func (this *Input) GetSlice(key string) []string {
vs, ok := this.FormValues[key]
if !ok || len(vs) == 0 {
return []string{}
}
return vs
}
// get all input data map as map[string]string, not support slice data
func (this *Input) All() map[string]string {
m := make(map[string]string)
for k, _ := range this.FormValues {
m[k] = this.FormValues.Get(k)
}
return m
}
// get all input data without given keys
func (this *Input) Except(v...string) map[string]string {
all := this.All()
for _, n := range v {
delete(all, n)
}
return all
}
// get mapped input data, given a new map reflection with map[new name]key
func (this *Input) Map(m map[string]string) map[string]string {
data := make(map[string]string)
for k, v := range m {
data[k] = this.Get(v)
}
return data
}
Go
1
https://gitee.com/xiaoluuxs/GoInk.git
git@gitee.com:xiaoluuxs/GoInk.git
xiaoluuxs
GoInk
GoInk
master

搜索帮助