當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Request.ParseForm方法代碼示例

本文整理匯總了Golang中http.Request.ParseForm方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.ParseForm方法的具體用法?Golang Request.ParseForm怎麽用?Golang Request.ParseForm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在http.Request的用法示例。


在下文中一共展示了Request.ParseForm方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: handleDeleteForm

func handleDeleteForm(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	_, kind := path.Split(r.URL.Path)
	key := DefaultMaster.delegator.(DelegatorBroadcaster).KeyFromForm(r.Form)
	ser := DefaultMaster.delegator.Delegate(kind)
	keys := ser.Keys()
	n := ser.Init()
	for _, v := range keys {
		if v != key {
			n = n.Insert(ser.At(v))
		}
	}
	ser.All(n)
	s := ser.At(key).(SerialSender)
	DefaultMaster.Delete(s)
	out := bytes.NewBufferString("")
	host := s.Host()
	if host != "" {
		DefaultMaster.save(out, s)
		http.Post("http://"+host+DefaultMaster.deletePattern+kind, "application/octet-stream", out)
	} else {
		bc := DefaultMaster.delegator.(DelegatorBroadcaster)
		for _, h := range bc.Hosts() {
			out = bytes.NewBufferString("")
			DefaultMaster.save(out, s)
			http.Post("http://"+h+DefaultMaster.deletePattern+kind, "application/octet-stream", out)
		}
	}
	DefaultMaster.Logger.Printf("%v erfolgreich gelöscht", s.Log())
	redir := "http://" + r.Host + r.FormValue("Redir")
	w.SetHeader("Location", redir)
	w.WriteHeader(302)
}
開發者ID:shaban,項目名稱:Kengal-Server,代碼行數:33,代碼來源:gobzip.go

示例2: handleVerify

func handleVerify(conn http.ResponseWriter, req *http.Request) {
	if !(req.Method == "POST" && req.URL.Path == "/camli/sig/verify") {
		httputil.BadRequestError(conn, "Inconfigured handler.")
		return
	}

	req.ParseForm()
	sjson := req.FormValue("sjson")
	if sjson == "" {
		httputil.BadRequestError(conn, "Missing sjson parameter.")
		return
	}

	m := make(map[string]interface{})

	vreq := jsonsign.NewVerificationRequest(sjson, pubKeyFetcher)
	if vreq.Verify() {
		m["signatureValid"] = 1
		m["verifiedData"] = vreq.PayloadMap
	} else {
		errStr := vreq.Err.String()
		m["signatureValid"] = 0
		m["errorMessage"] = errStr
	}

	conn.WriteHeader(http.StatusOK) // no HTTP response code fun, error info in JSON
	httputil.ReturnJson(conn, m)
}
開發者ID:ipeet,項目名稱:camlistore,代碼行數:28,代碼來源:verify.go

示例3: handleReplaceForm

func handleReplaceForm(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	_, kind := path.Split(r.URL.Path)
	ser := DefaultMaster.delegator.Delegate(kind).(SerializerFormParser)
	s := ser.NewFromForm(r.Form)
	if s == nil {
		r.Form = nil
		w.SetHeader("Location", r.Referer)
		w.WriteHeader(302)
		return
	}
	ser.Replace(s)
	DefaultMaster.Save(s)
	out := bytes.NewBufferString("")
	host := s.Host()
	if host != "" {
		DefaultMaster.save(out, s)
		http.Post("http://"+host+DefaultMaster.replacePattern+kind, "application/octet-stream", out)
	} else {
		bc := DefaultMaster.delegator.(DelegatorBroadcaster)
		for _, h := range bc.Hosts() {
			out = bytes.NewBufferString("")
			DefaultMaster.save(out, s)
			http.Post("http://"+h+DefaultMaster.replacePattern+kind, "application/octet-stream", out)
		}
	}
	DefaultMaster.Logger.Printf("%v erfolgreich modifiziert", s.Log())
	redir := "http://" + r.Host + r.FormValue("Redir")
	w.SetHeader("Location", redir)
	w.WriteHeader(302)
}
開發者ID:shaban,項目名稱:Kengal-Server,代碼行數:31,代碼來源:gobzip.go

示例4: join

func join(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	u := user.Current(c)
	if u == nil {
		url, err := user.LoginURL(c, r.URL.String())
		if err != nil {
			http.Error(w, err.String(), http.StatusInternalServerError)
			return
		}
		w.Header().Set("Location", url)
		w.WriteHeader(http.StatusFound)
		return
	}
	r.ParseForm()
	// TODO check table arg
	state, err := joinTable(c, r.Form["table"][0], u.String())
	if err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	}
	var b []byte
	b, err = json.Marshal(state)
	if err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	}
	fmt.Fprintf(w, "%s", b)
}
開發者ID:bclement,項目名稱:sabacc,代碼行數:28,代碼來源:sabacc.go

示例5: getSearchPanelHtml

func (h *SearchPanelHandler) getSearchPanelHtml(hr *http.Request) string {
	fmt.Println("\n=== SearchPanelHandler : Requete reçue ====================")
	fmt.Println(" URL : " + hr.RawURL)
	hr.ParseForm()

	askerId := GetFormValueAsInt(hr, "asker")
	mdpr := GetFormValue(hr, "mdpr") // mot de passe restreint
	tok := GetFormValue(hr, "tok")
	compteOk := false
	var compte *Compte

	db, err := h.store.Connect()
	if err != nil {
		fmt.Printf("Erreur ouverture connexion BD dans makeBestiaryExtractHtml : %s\n", err.String())
		return err.String()
	}
	defer db.Close()

	if askerId > 0 && mdpr != "" {
		compteOk, compte, err = h.store.CheckCompte(db, uint(askerId), mdpr)
	}
	if !compteOk {
		return "Compte non authentifié"
	}
	if tok == "" {
		return "Demande non comprise"
	}
	amis, err := h.store.GetPartageurs(db, askerId)
	if err != nil {
		return fmt.Sprintf("Erreur récupération amis : %s\n", err.String())
	}
	observations, err := h.store.SearchObservations(db, tok, askerId, amis)
	if err != nil {
		return fmt.Sprintf("Erreur recherche : %s\n", err.String())
	}
	if len(observations) == 0 {
		return "Rien trouvé"
	}
	html := fmt.Sprintf("%d résultats :", len(observations))
	html += "<table border='0' cellspacing='1' cellpadding='2' class='mh_tdborder' align='center'>"
	html += "<tr class=mh_tdtitre><td class=mh_tdpage><b>Dist.</b></td><td class=mh_tdpage><b>Réf.</b></td><td class=mh_tdpage><b>Nom</b></td>"
	html += "<td class=mh_tdpage><b>Position</b></td>"
	html += "<td class=mh_tdpage><b>Vu par</b></td><td class=mh_tdpage><b>Le</b></td></tr>"
	for _, o := range observations {
		t := time.SecondsToLocalTime(o.Date)
		var lien string
		if o.Type == "troll" {
			lien = fmt.Sprintf("<a href='javascript:EPV(%d)' class=mh_trolls_1 id=%d>%s</a>", o.Num, o.Num, o.Nom)
		} else if o.Type == "monstre" {
			lien = fmt.Sprintf("<a href='javascript:EMV(%d, 750, 550)' class=mh_monstres id=%d>%s</a>", o.Num, o.Num, o.Nom)
		} else {
			lien = o.Nom
		}
		dist := dist(compte.Troll.X, o.X, compte.Troll.Y, o.Y, compte.Troll.Z, o.Z)
		btnVoir := fmt.Sprintf("<a x=%d y=%d z=%d class=gogo name=zoom>%d  %d  %d</a>", o.X, o.Y, o.Z, o.X, o.Y, o.Z)
		html += fmt.Sprintf("<tr class=mh_tdpage><td>%d</td><td>%d</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td></tr>", dist, o.Num, lien, btnVoir, o.Auteur, t.Format("02/01 à 15h04"))
	}
	html += "</table>"
	return html
}
開發者ID:Chouia,項目名稱:Chrall,代碼行數:60,代碼來源:searchpanelhandler.go

示例6: GetOAuthParams

// Returns a map of all of the oauth_* (including signature) parameters for the
// given request, and the signature base string used to generate the signature.
func (s *HmacSha1Signer) GetOAuthParams(request *http.Request, clientConfig *ClientConfig, userConfig *UserConfig, nonce string, timestamp string) (map[string]string, string) {
	request.ParseForm()
	oauthParams := map[string]string{
		"oauth_consumer_key":     clientConfig.ConsumerKey,
		"oauth_nonce":            nonce,
		"oauth_signature_method": "HMAC-SHA1",
		"oauth_timestamp":        timestamp,
		"oauth_version":          "1.0",
	}
	tokenKey, tokenSecret := userConfig.GetToken()
	if tokenKey != "" {
		oauthParams["oauth_token"] = tokenKey
	}
	signingParams := map[string]string{}
	for key, value := range oauthParams {
		signingParams[key] = value
	}
	for key, value := range request.URL.Query() {
		//TODO: Support multiple parameters with the same name.
		signingParams[key] = value[0]
	}
	for key, value := range request.Form {
		//TODO: Support multiple parameters with the same name.
		signingParams[key] = value[0]
	}
	signingUrl := fmt.Sprintf("%v://%v%v", request.URL.Scheme, request.URL.RawAuthority, request.URL.Path)
	signatureParts := []string{
		request.Method,
		url.QueryEscape(signingUrl),
		s.encodeParameters(signingParams)}
	signatureBase := strings.Join(signatureParts, "&")
	oauthParams["oauth_signature"] = s.GetSignature(clientConfig.ConsumerSecret, tokenSecret, signatureBase)
	return oauthParams, signatureBase
}
開發者ID:paul-lalonde,項目名稱:golibs,代碼行數:36,代碼來源:oauth1a.go

示例7: handleCreate

func handleCreate(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	u := user.Current(c)
	if u == nil {
		return
	}

	r.ParseForm()
	url := r.FormValue("url")
	title := r.FormValue("title")
	tagString := r.FormValue("tags")
	if url == "" {
		output(c, w, "create")
		return
	}

	tags := strings.Split(tagString, ",")
	bm := bookmarks.NewBookmark(u, url, title, tags)
	_, err := bm.Save(c)
	if err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Location", rootURL(c))
	w.WriteHeader(http.StatusFound)
	return
}
開發者ID:xconstruct,項目名稱:bin-o-bookmarks,代碼行數:28,代碼來源:app.go

示例8: getSettings

func getSettings(req *http.Request) (p Settings) {
	req.ParseForm()
	p = DefaultSettings()
	p.Cards = make(map[string]*bridge.ConventionCard)
	prefstr, _ := req.Header["Cookie"] // I don't care about errors!
	// fmt.Println("Trying to unmarshall string", prefstr)
	json.Unmarshal([]byte(prefstr), &p) // I don't care about errors!
	for k, v := range bridge.DefaultConvention().Pts {
		if _, ok := p.Card().Pts[k]; !ok {
			p.Card().Pts[k] = v
		}
	}
	for k, v := range bridge.DefaultConvention().Options {
		if _, ok := p.Card().Options[k]; !ok {
			p.Card().Options[k] = v
		}
	}
	for k, v := range bridge.DefaultConvention().Radio {
		if _, ok := p.Card().Radio[k]; !ok {
			p.Card().Radio[k] = v
		}
	}
	// fmt.Println("Unmarshal gave: %v", e)
	return p
}
開發者ID:droundy,項目名稱:abridge,代碼行數:25,代碼來源:settings.go

示例9: handleSign

func (h *JSONSignHandler) handleSign(rw http.ResponseWriter, req *http.Request) {
	req.ParseForm()

	badReq := func(s string) {
		http.Error(rw, s, http.StatusBadRequest)
		log.Printf("bad request: %s", s)
		return
	}
	// TODO: SECURITY: auth

	jsonStr := req.FormValue("json")
	if jsonStr == "" {
		badReq("missing \"json\" parameter")
		return
	}
	if len(jsonStr) > kMaxJsonLength {
		badReq("parameter \"json\" too large")
		return
	}

	sreq := &jsonsign.SignRequest{
		UnsignedJson:      jsonStr,
		Fetcher:           h.pubKeyFetcher,
		ServerMode:        true,
		SecretKeyringPath: h.secretRing,
	}
	signedJson, err := sreq.Sign()
	if err != nil {
		// TODO: some aren't really a "bad request"
		badReq(fmt.Sprintf("%v", err))
		return
	}
	rw.Write([]byte(signedJson))
}
開發者ID:ipeet,項目名稱:camlistore,代碼行數:34,代碼來源:sig.go

示例10: RequireParams

func RequireParams(request *http.Request, params []string) (success bool) {
	err := request.ParseForm()
	if err != nil {
		return false
	}

	for _, v := range params {
		if thisParam, exists := request.Form[v]; exists {
			hasGoodValue := false
			for _, paramValue := range thisParam {
				if len(paramValue) > 0 {
					hasGoodValue = true
					break
				}
			}
			if !hasGoodValue {
				return false
			}
		} else {
			return false
		}
	}

	return true
}
開發者ID:natelong,項目名稱:smushfile,代碼行數:25,代碼來源:smushfile.go

示例11: HandleNewPaste

func HandleNewPaste(writer http.ResponseWriter, request *http.Request) {
	err := request.ParseForm()
	if err != nil {
		write_error(writer, err)
		return
	}
	text := request.FormValue("paste_text")
	language := request.FormValue("language")

	var page *Page
	page, err = NewPage(text, language)

	if err != nil {
		write_error(writer, err)
		return
	}
	// check if we already have a page
	// and not store it again
	oldpage, err := GetPageFromDataStore(page.UrlId, request)
	if oldpage == nil {
		err = StorePage(page, request)
		if err != nil {
			write_error(writer, err)
			return
		}
	}
	http.Redirect(writer, request, "/"+page.UrlId[0:LENGTH], http.StatusFound)
}
開發者ID:roxtar,項目名稱:gopasty,代碼行數:28,代碼來源:gopasty.go

示例12: handleLogout

func handleLogout(w http.ResponseWriter, r *http.Request) {
	c = appengine.NewContext(r)
	returnURL := "/"
	// parse form
	err := r.ParseForm()
	if err != nil {
		serveError(c, w, err)
		return
	}
	if r.FormValue("continue") != "" {
		returnURL = r.FormValue("continue")
	}

	if useOpenID {
		// adjust returnURL to bring us back to a local user login form
		laterReturnUrl := returnURL
		returnURL = "/Login/?chooseLogin=1&continue=" + http.URLEscape(laterReturnUrl)
	}
	// redirect to google logout (for OpenID as well, or else we won't be locally logged out)
	lourl, err := user.LogoutURL(c, returnURL)
	if err != nil {
		c.Errorf("handleLogout: error getting LogoutURL")
	}
	c.Debugf("handleLogout: redirecting to logoutURL=%v", lourl)
	http.Redirect(w, r, lourl, http.StatusFound)
	return
}
開發者ID:jrandall,項目名稱:cambridge-challenge.appspot.com,代碼行數:27,代碼來源:handle-logout.go

示例13: HandleUpdateStatus

// handle a request to change the status
func HandleUpdateStatus(c *http.Conn, req *http.Request) {
	req.ParseForm()
	statusStr := req.FormValue("status")
	log.Stdoutf("status to be sent:\n%s\n\n", statusStr)
	jsonStr, _ := twitter.TweetJson(&creds, statusStr)
	io.WriteString(c, jsonStr)
}
開發者ID:tommed,項目名稱:GoogleGo-Twitter-Client,代碼行數:8,代碼來源:ui.go

示例14: handleVerify

func (h *JSONSignHandler) handleVerify(rw http.ResponseWriter, req *http.Request) {
	req.ParseForm()
	sjson := req.FormValue("sjson")
	if sjson == "" {
		http.Error(rw, "missing \"sjson\" parameter", http.StatusBadRequest)
		return
	}

	m := make(map[string]interface{})

	// TODO: use a different fetcher here that checks memory, disk,
	// the internet, etc.
	fetcher := h.pubKeyFetcher

	vreq := jsonsign.NewVerificationRequest(sjson, fetcher)
	if vreq.Verify() {
		m["signatureValid"] = 1
		m["signerKeyId"] = vreq.SignerKeyId
		m["verifiedData"] = vreq.PayloadMap
	} else {
		errStr := vreq.Err.String()
		m["signatureValid"] = 0
		m["errorMessage"] = errStr
	}

	rw.WriteHeader(http.StatusOK) // no HTTP response code fun, error info in JSON
	httputil.ReturnJson(rw, m)
}
開發者ID:ipeet,項目名稱:camlistore,代碼行數:28,代碼來源:sig.go

示例15: CALLBACK

// receives ?returnto=/replies etc.
func CALLBACK(c *http.Conn, req *http.Request, auth_client *oauth.AuthClient) {
	log.Stderr("CALLBACK!");
	req.ParseForm();
	for k,v := range req.Header {
		log.Stderrf("header:%s:%s", k, v);
	}
	for k,vs := range req.Form {
		log.Stderrf("form:%s::", k);
		for i := range vs {
			log.Stderrf("::%s", vs[i]);
		}
	}

	var auth_token = req.FormValue("oauth_token");
	var auth_verifier = req.FormValue("oauth_verifier");
	log.Stderrf("CALLBACK:auth_token:%s:", auth_token);
	log.Stderrf("CALLBACK:auth_verifier:%s:", auth_verifier);

	user_info := auth_client.GetUserInfo(auth_token, auth_verifier);

	log.Stderrf("USER_INFO:");
	for k,v := range user_info {
		log.Stderrf("k:%s v:%s", k, v);
	}

	session_service.StartSession(c, req, user_info);
	var url = "/";
	returnto := req.FormValue("returnto");
	if returnto != "" {
		url = returnto;
	}
	http.Redirect(c, url, http.StatusFound); // should be 303 instead of 302?
}
開發者ID:montsamu,項目名稱:go-twitter-oauth,代碼行數:34,代碼來源:example.go


注:本文中的http.Request.ParseForm方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。