本文整理匯總了Golang中net/url.Values.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang Values.Get方法的具體用法?Golang Values.Get怎麽用?Golang Values.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net/url.Values
的用法示例。
在下文中一共展示了Values.Get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetFromUrlEncoded
func (p *loginAccountContext) SetFromUrlEncoded(values url.Values) {
p.username = values.Get("username")
p.password = values.Get("password")
p.inputValidated = false
p.user = nil
p.result = nil
}
示例2: intFromQuery
func intFromQuery(ps url.Values, name string, defaultVal int) (int, error) {
s := ps.Get(name)
if s == "" {
return defaultVal, nil
}
return strconv.Atoi(s)
}
示例3: challengeFromForm
func challengeFromForm(form url.Values) (Challenge, error) {
var err error
c := Challenge{}
fmt.Println(form)
c.Title = form.Get("title")
if c.Title == "" {
return c, errors.New("No Title")
}
c.Description = template.HTML(form.Get("description"))
if c.Title == "" {
return c, errors.New("No Description")
}
c.Alias = form.Get("path")
if c.Alias == "" {
return c, errors.New("No path")
}
c.MaxScore, err = strconv.Atoi(form.Get("points"))
if err != nil || c.MaxScore <= 0 || c.MaxScore > MaxChallengeScore {
return c, errors.New("Wrong Points Format or Missing")
}
c.Category = form.Get("category")
if c.Category == "" {
return c, errors.New("No Category")
}
return c, nil
}
示例4: saveFile
//磁盤保存文件
func saveFile(reader io.Reader, query url.Values) error {
fileName := query.Get("name")
if fileName == "" {
return errors.New("name is empty")
}
if err := ensureDir("static"); err != nil {
return err
}
body, err := ioutil.ReadAll(reader)
if err != nil {
return err
}
filePath := path.Join("static", fileName)
file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0777)
defer file.Close()
if err != nil {
return err
}
_, err = file.Write(body)
if err != nil {
return err
}
return nil
}
示例5: handleFrontendPost
func handleFrontendPost(self *dialogNode, form url.Values, conf *configparser.Configuration) (*dialogNode, error) {
if form.Get("back") == "true" {
return self.parent, nil
}
var next *dialogNode
sect, _ := conf.Section("frontend")
name := form.Get("name")
locale := form.Get("locale")
allow_files := form.Get("allow_files")
if allow_files != "1" {
allow_files = "0"
}
json_api := form.Get("json")
if json_api != "1" {
json_api = "0"
next = self.children["next"]
} else {
next = self.children["json"]
}
sect.Add("name", name)
sect.Add("locale", locale)
sect.Add("allow_files", allow_files)
sect.Add("json-api", json_api)
err := checkLocale(locale)
if err != nil {
return self, err
}
return next, nil
}
示例6: Dispatch
// Dispatch inspects the "command" parameter and dispatches the request to the
// appropriate handler function.
func Dispatch(params url.Values) (response JSONResponse) {
switch params.Get("command") {
case "fetch-meal-list":
return fetchMealList(params)
case "toggle-favourite":
return toggleFavourite(params)
case "delete-meal":
return deleteMeal(params)
case "fetch-all-tags":
return fetchAllTags(params)
case "fetch-servings":
return fetchServings(params)
case "fetch-suggestions":
return fetchSuggestions(params)
case "update-serving":
return updateServing(params)
case "delete-serving":
return deleteServing(params)
case "update-notes":
return updateNotes(params)
case "fetch-meal-plans":
return fetchMealPlans(params)
}
return JSONResponse{Error: "Invalid or missing command"}
}
示例7: Update
// Update 更新用戶信息
func (self UserLogic) Update(ctx context.Context, me *model.Me, form url.Values) (errMsg string, err error) {
objLog := GetLogger(ctx)
if form.Get("open") != "1" {
form.Set("open", "0")
}
user := &model.User{}
err = schemaDecoder.Decode(user, form)
if err != nil {
objLog.Errorln("userlogic update, schema decode error:", err)
errMsg = "服務內部錯誤"
return
}
cols := "name,open,city,company,github,weibo,website,monlog,introduce"
// 變更了郵箱
if user.Email != me.Email {
cols += ",email,status"
user.Status = model.UserStatusNoAudit
}
_, err = MasterDB.Id(me.Uid).Cols(cols).Update(user)
if err != nil {
objLog.Errorf("更新用戶 【%d】 信息失敗:%s", me.Uid, err)
errMsg = "對不起,服務器內部錯誤,請稍後再試!"
return
}
// 修改用戶資料,活躍度+1
go self.IncrUserWeight("uid", me.Uid, 1)
return
}
示例8: Modify
// Modify 修改主題
// user 修改人的(有可能是作者或管理員)
func (TopicLogic) Modify(ctx context.Context, user *model.Me, form url.Values) (errMsg string, err error) {
objLog := GetLogger(ctx)
change := map[string]interface{}{
"editor_uid": user.Uid,
}
fields := []string{"title", "content", "nid"}
for _, field := range fields {
change[field] = form.Get(field)
}
tid := form.Get("tid")
_, err = MasterDB.Table(new(model.Topic)).Id(tid).Update(change)
if err != nil {
objLog.Errorf("更新主題 【%s】 信息失敗:%s\n", tid, err)
errMsg = "對不起,服務器內部錯誤,請稍後再試!"
return
}
// 修改主題,活躍度+2
go DefaultUser.IncrUserWeight("uid", user.Uid, 2)
return
}
示例9: verifySign
func verifySign(c Config, u url.Values) (err error) {
p := kvpairs{}
sign := ""
for k := range u {
v := u.Get(k)
switch k {
case "sign":
sign = v
continue
case "sign_type":
continue
}
p = append(p, kvpair{k, v})
}
if sign == "" {
err = fmt.Errorf("sign not found")
return
}
p = p.RemoveEmpty()
p.Sort()
fmt.Println(u)
if md5Sign(p.Join(), c.Key) != sign {
err = fmt.Errorf("sign invalid")
return
}
return
}
示例10: parseInt
func parseInt(vals url.Values, v string, def, min, max int) int {
rv, err := strconv.ParseInt(vals.Get(v), 10, 32)
if err != nil || int(rv) < min || int(rv) > max {
return def
}
return int(rv)
}
示例11: testUpdatePost
func testUpdatePost(t *testing.T, title string, markdown string) {
// create JSON payload
var p Post
p.Title = title
p.Markdown = markdown
p.Content = string(blackfriday.MarkdownCommon([]byte(markdown)))
apiPayload, _ := json.Marshal(p)
// save changes to global object for further testing comparison
post.Title = p.Title
post.Content = string(blackfriday.MarkdownCommon([]byte(markdown)))
post.Markdown = markdown
post.Excerpt = excerpt.Make(p.Content, 15)
testUpdatePostAPI(t, apiPayload)
// creates form-encoded payload
p2 := url.Values{}
p2.Set("title", title)
p2.Add("markdown", markdown)
frontendPayload := p2.Encode()
// save changes to global object for further testing comparison
post.Title = p2.Get("title")
post.Markdown = p2.Get("markdown")
post.Excerpt = excerpt.Make(post.Content, 15)
testUpdatePostFrontend(t, frontendPayload)
TestReadPost(t)
}
示例12: ParseURL
// ParseURL parses s into a ConnectionURL struct.
func ParseURL(s string) (conn ConnectionURL, err error) {
var u *url.URL
if strings.HasPrefix(s, connectionScheme+"://") == false {
return conn, fmt.Errorf(`Expecting file:// connection scheme.`)
}
if u, err = url.Parse(s); err != nil {
return conn, err
}
conn.Database = u.Host + u.Path
conn.Options = map[string]string{}
var vv url.Values
if vv, err = url.ParseQuery(u.RawQuery); err != nil {
return conn, err
}
for k := range vv {
conn.Options[k] = vv.Get(k)
}
return conn, err
}
示例13: New
// New creates the HTML for a select menu instance with the specified parameters.
func New(options []string, defaultOption string, query url.Values, queryParameter string) template.HTML {
selectElement := &html.Node{Type: html.ElementNode, Data: "select"}
var selectedOption = defaultOption
if query.Get(queryParameter) != "" {
selectedOption = query.Get(queryParameter)
}
if !contains(options, selectedOption) {
options = append(options, selectedOption)
}
for _, option := range options {
o := &html.Node{Type: html.ElementNode, Data: "option"}
o.AppendChild(htmlg.Text(option))
if option == selectedOption {
o.Attr = append(o.Attr, html.Attribute{Key: "selected"})
}
selectElement.AppendChild(o)
}
selectElement.Attr = append(selectElement.Attr, html.Attribute{
Key: "oninput",
// HACK: Don't use Sprintf, properly encode (as json at this time).
Val: fmt.Sprintf(`SelectMenuOnInput(event, this, %q, %q);`, strconv.Quote(defaultOption), strconv.Quote(queryParameter)),
})
return htmlg.Render(selectElement)
}
示例14: fetchMealPlans
// fetchMealPlans handles an API call to return a list of meal plans that
// overlap with a specified inclusive date range. Expected parameters: from, to.
// Returns: an array of meal plan objects.
func fetchMealPlans(params url.Values) (response JSONResponse) {
from, err := time.Parse(mpdata.JSONDateFormat, params.Get("from"))
if err != nil {
return JSONResponse{Error: "Invalid or missing 'from' parameter"}
}
to, err := time.Parse(mpdata.JSONDateFormat, params.Get("to"))
if err != nil {
return JSONResponse{Error: "Invalid or missing 'to' parameter"}
}
var mps []*mpdata.MealPlan
err = mpdb.WithConnection(func(db *sql.DB) (err error) {
return mpdb.WithTransaction(db, func(tx *sql.Tx) (err error) {
mps, err = mpdb.ListMealPlansBetween(tx, from, to)
return err
})
})
if err != nil {
log.Printf("Database error: %s\n", err.Error())
return JSONResponse{Error: "Database error"}
}
return JSONResponse{Success: mps}
}
示例15: Test_client_buildWriteFileRequest
func Test_client_buildWriteFileRequest(t *testing.T) {
c := client{
options: ClientOptions{
Locale: "init__locale",
Root: "init__root",
Token: "init__token",
}}
var f bytes.Buffer
p := url.Values{}
p.Set("locale", "callers__locale")
r, e := c.buildWriteFileRequest("somepath", &f, 100, p)
assert.NoError(t, e)
assert.Equal(t, r.Method, "PUT")
auth := r.Header.Get("Authorization")
assert.Contains(t, auth, "Bearer")
assert.Contains(t, auth, "init__token")
clen := r.Header.Get("Content-Length")
assert.Equal(t, clen, "100")
u := r.URL
assert.Equal(t, u.Scheme, "https")
assert.Equal(t, u.Host, "api-content.dropbox.com")
assert.Equal(t, u.Path, "/1/files_put/init__root/somepath")
p = u.Query()
assert.Equal(t, p.Get("locale"), "callers__locale")
assert.Equal(t, len(p), 1)
}