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


Golang Request.FormValue方法代碼示例

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


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

示例1: DeleteMessageHandler

func (s *Server) DeleteMessageHandler(w http.ResponseWriter, r *http.Request) {
	login, err := getYandexLogin(r)
	if login == "" || err != nil {
		writeError(w, 403, "forbidden")
		return
	}

	subject := r.FormValue("subject")
	if subject != "" {
		log.Printf("DELETE login=%s subject=%s", login, subject)
		err = s.deleteMessagesBySubject(login, subject)
		if err != nil {
			writeError(w, 500, "failed to delete message: "+err.Error())
			return
		}
	}

	id := r.FormValue("id")
	if id != "" {
		log.Printf("DELETE login=%s id=%s", login, id)
		err = s.deleteMessagesByID(login, id)
		if err != nil {
			writeError(w, 500, "failed to delete message: "+err.Error())
			return
		}
	}

	writeResponse(w, 200, map[string]interface{}{
		"status": "success",
	})
}
開發者ID:dmage,項目名稱:pieceofapp,代碼行數:31,代碼來源:pownyapp-backend.go

示例2: key

// key HandleFunc for the http /key endpoint. This only happens if the client
// doesn't support websockets.
func (t *tbfe) key(w http.ResponseWriter, req *http.Request) {
	log.Debug("key: %s", req)
	kc := req.FormValue("keyCode")
	var kp keys.KeyPress
	v, _ := strconv.ParseInt(kc, 10, 32)

	if req.FormValue("altKey") == "true" {
		kp.Alt = true
	}
	if req.FormValue("ctrlKey") == "true" {
		kp.Ctrl = true
	}
	if req.FormValue("metaKey") == "true" {
		kp.Super = true
	}
	if req.FormValue("shiftKey") == "true" {
		kp.Shift = true
	}

	if !kp.Shift {
		v = int64(unicode.ToLower(rune(v)))
	}
	kp.Key = keys.Key(v)
	kp.Text = string(v)
	backend.GetEditor().HandleInput(kp)
}
開發者ID:yzq1979,項目名稱:lime-html,代碼行數:28,代碼來源:main.go

示例3: ServeHTTP

func (c *ClassifierHandler) ServeHTTP(w http.ResponseWriter,
	req *http.Request) {
	sample := core.NewSample()
	if req.Method != "POST" {
		http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
		return
	}
	features := req.FormValue("features")
	if len(features) == 0 {
		http.Error(w, "need input features", http.StatusInternalServerError)
		return
	}
	fs := make(map[string]float64)
	err := json.Unmarshal([]byte(features), &fs)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	for k, v := range fs {
		f := core.Feature{
			Id:    util.Hash(k),
			Value: v,
		}
		sample.AddFeature(f)
	}
	p := c.classifier.Predict(sample)
	output, err := json.Marshal(map[string]interface{}{
		"prediction": p,
	})
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	fmt.Fprint(w, output)
}
開發者ID:jamesbjackson,項目名稱:hector,代碼行數:35,代碼來源:hectorserver.go

示例4: invalidate

func invalidate(w http.ResponseWriter, r *http.Request) {

	c := appengine.NewContext(r)

	ii := instance_mgt.GetByContext(c)

	mkk := r.FormValue("mkk")
	sii := r.FormValue("senderInstanceId")

	if ll > 2 {
		aelog.Infof(c, " %s  ---------  %s\n", sii, mkk)
	}

	w.WriteHeader(http.StatusOK)

	if ii.InstanceID == sii {
		w.Write([]byte("Its ME " + mkk + "\n"))
		w.Write([]byte(sii))
	} else {
		w.Write([]byte("got it " + mkk + "\n"))
		w.Write([]byte(sii + "\n"))
		w.Write([]byte(ii.InstanceID))
	}

}
開發者ID:aarzilli,項目名稱:tools,代碼行數:25,代碼來源:put_get_buffered.go

示例5: PortBindingDelete

func PortBindingDelete(w http.ResponseWriter, r *http.Request) {
	params := r.URL.Query()
	port := params.Get(":port")
	host := r.FormValue("host")
	hostPort := r.FormValue("host_port")

	i, binding, err := getPortBinding(port, false)
	if err != nil {
		w.Write([]byte("{\"error\": \"" + err.Error() + "\"}"))
		return
	}

	if binding == nil {
		w.Write([]byte("{}"))
		return
	}
	if host != "" && hostPort != "" {
		binding.RemoveBackend(host, hostPort)
	}
	currentHost, err := h.GetCurrentHost()
	if err != nil {
		w.Write([]byte("{\"error\": \"" + err.Error() + "\"}"))
		return
	}
	if len(binding.Backends) == 0 || (host == "" && hostPort == "") {
		binding.Stop()
		copy(currentHost.PortBindings[i:], currentHost.PortBindings[i+1:])
		currentHost.PortBindings[len(currentHost.PortBindings)-1] = nil
		currentHost.PortBindings = currentHost.PortBindings[:len(currentHost.PortBindings)-1]
	}
	w.Write([]byte("{\"success\": true}"))
	currentHost.Persist()
}
開發者ID:romanoff,項目名稱:vanguard,代碼行數:33,代碼來源:portbinding.go

示例6: Register

func Register(w http.ResponseWriter, r *http.Request) {

	user := models.User{}

	if r.FormValue("displayName") != "" {
		user.DisplayName = r.FormValue("displayName")
	} else {
		user.DisplayName = "NULL"
	}

	_email := r.FormValue("email")
	if _email != "" {
		user.Email.Scan(_email)
	}

	if r.FormValue("password") != "" {
		user.Password = r.FormValue("password")
	} else {
		user.Password = "NULL"
	}

	createUserToken(&user)

	if err := repository.CreateUser(&user).Error; err != nil {
		w.WriteHeader(http.StatusForbidden)
		json.NewEncoder(w).Encode(err)
		return
	}

	log.Println(user)

	json.NewEncoder(w).Encode(user)
}
開發者ID:khaiql,項目名稱:instagram-go,代碼行數:33,代碼來源:user.go

示例7: serveHTTP

func (srv *Server) serveHTTP(w http.ResponseWriter, req *http.Request) {
	req.ParseForm()
	srv.mutex.Lock()
	defer srv.mutex.Unlock()
	action := req.FormValue("Action")
	if action == "" {
		srv.error(w, &iam.Error{
			StatusCode: 400,
			Code:       "MissingAction",
			Message:    "Missing action",
		})
	}
	if a, ok := actions[action]; ok {
		reqId := fmt.Sprintf("req%0X", srv.reqId)
		srv.reqId++
		if resp, err := a(srv, w, req, reqId); err == nil {
			if err := xml.NewEncoder(w).Encode(resp); err != nil {
				panic(err)
			}
		} else {
			switch err.(type) {
			case *iam.Error:
				srv.error(w, err.(*iam.Error))
			default:
				panic(err)
			}
		}
	} else {
		srv.error(w, &iam.Error{
			StatusCode: 400,
			Code:       "InvalidAction",
			Message:    "Invalid action: " + action,
		})
	}
}
開發者ID:fsouza,項目名稱:go-iam,代碼行數:35,代碼來源:server.go

示例8: createGroup

func (srv *Server) createGroup(w http.ResponseWriter, req *http.Request, reqId string) (interface{}, error) {
	if err := srv.validate(req, []string{"GroupName"}); err != nil {
		return nil, err
	}
	name := req.FormValue("GroupName")
	path := req.FormValue("Path")
	for _, group := range srv.groups {
		if group.Name == name {
			return nil, &iam.Error{
				StatusCode: 409,
				Code:       "EntityAlreadyExists",
				Message:    fmt.Sprintf("Group with name %s already exists.", name),
			}
		}
	}
	group := iam.Group{
		Id:   "GROUP " + reqId + "EXAMPLE",
		Arn:  fmt.Sprintf("arn:aws:iam:::123456789012:group%s%s", path, name),
		Name: name,
		Path: path,
	}
	srv.groups = append(srv.groups, group)
	return iam.CreateGroupResp{
		RequestId: reqId,
		Group:     group,
	}, nil
}
開發者ID:fsouza,項目名稱:go-iam,代碼行數:27,代碼來源:server.go

示例9: cookiehmac

func cookiehmac(res http.ResponseWriter, req *http.Request) {
	cookie, err := req.Cookie("session")
	if err == http.ErrNoCookie {
		cookie = &http.Cookie{
			Name:  "session",
			Value: "",
			//Secure: true,
			HttpOnly: true,
		}
	}
	if req.FormValue("name") != "" {
		needsSalt := req.FormValue("name")
		cookie.Value = needsSalt + " | " + getCode(needsSalt)
	}
	fmt.Fprint(res, `
		<!DOCTYPE html>
		<html>
			<body>
				<form method = "POST">
					`+cookie.Value+`
					<input type = "text" name = "name">
					<input type = "submit">
				</form>
			</body>
		</htmlcd>
	`)
}
開發者ID:arlene725,項目名稱:web130,代碼行數:27,代碼來源:main.go

示例10: registerHandler

func registerHandler(w http.ResponseWriter, r *http.Request) {
	if r.URL.Query()["post"] != nil {
		switch tryRegister(r.FormValue("email")) {
		case 0:
			displayPage(w, "generic",
				GenericPage{
					Title: "Register",
					Body:  "You are registered, please check your inbox"},
			)
		case 1:
			displayPage(w, "generic",
				GenericPage{
					Title: "Register",
					Body:  "Failed to register. Your email seems to be invalid!"},
			)
		case 2:
			displayPage(w, "generic",
				GenericPage{
					Title: "Register",
					Body:  "You are already registered!"},
			)
		}
	} else {
		displayPage(w, "register", nil)
	}
}
開發者ID:sycoso,項目名稱:goserver,代碼行數:26,代碼來源:page_registration.go

示例11: getID

func getID(w http.ResponseWriter, r *http.Request) string {

	var userUUID string
	var cookie *http.Cookie

	cookie, err := r.Cookie("session-id")

	if err == http.ErrNoCookie {
		userUUID = r.FormValue("id")

		if userUUID == "" {
			uuid, _ := uuid.NewV4()
			userUUID = uuid.String()
			http.Redirect(w, r, "/?id="+userUUID, 303)
		}

		modelForCookie := model{
			Name:  "session-id",
			State: false,
			Pictures: []string{
				"one.jpg",
			},
			ID: userUUID,
		}

		makeCookie(modelForCookie, userUUID, r)
		http.SetCookie(w, cookie)

		return userUUID

	}
	return cookie.Value
}
開發者ID:robertg231,項目名稱:CSCI-130-HW,代碼行數:33,代碼來源:UUID+from+URL.go

示例12: shipoptionselect

func shipoptionselect(w http.ResponseWriter, q *http.Request) {
	if q.Method == "POST" {
		err := q.ParseForm()
		if err != nil {
			// Handle error
			fmt.Println(err)
		}
		session, _ := store.Get(q, sessionname)

		order := *session.Values["Order"].(*Order)
		//here put shipping method and price shipping
		order.Shipping = Shipping{
			ShippingMethod: q.FormValue("shippingOfferingId"),
			ShippingCost:   0,
		}
		session.Values["Order"] = order
		session.Save(q, w)
		http.Redirect(w, q, "/payselect", http.StatusFound)
	} else {
		session, _ := store.Get(q, sessionname)
		order := *session.Values["Order"].(*Order)
		newmap := map[string]interface{}{"adress": order.ShippingAdress}
		render(w, "shipoptionselect", newmap)
	}

}
開發者ID:ivansyi,項目名稱:goShop,代碼行數:26,代碼來源:app.go

示例13: addItem

func addItem(w http.ResponseWriter, q *http.Request) {
	//check if SKU exist, if not then generate SKU
	err := q.ParseMultipartForm(32 << 20)

	if err != nil {
		// Handle error
		fmt.Println(err)
	}
	if q.FormValue("SKU") != "" {

		slice := []string{"Image", "Image1", "Image2", "Image3"}

		images := checkifImageneedUpload(q, slice, q.FormValue("SKU"))

		product := Product{
			Title:       q.FormValue("Title"),
			Price:       q.FormValue("Price"),
			SKU:         q.FormValue("SKU"),
			Image:       images,
			Description: q.FormValue("Description"),
		}

		db := dbinit()
		defer db.Close()
		_, err = r.Db("goShop").Table("items").Insert(product).RunWrite(db)
		if err != nil {
			log.Println(err)
		}

		//fmt.Println(q.FormValue("cat"))

		http.Redirect(w, q, "/items", http.StatusFound)
	}

}
開發者ID:ivansyi,項目名稱:goShop,代碼行數:35,代碼來源:app.go

示例14: ServeHTTP

func (h *ManagerKickHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request) {
	h.mgr.Kick(req.FormValue("msg"))
	MustEncode(w, struct {
		Status string `json:"status"`
	}{Status: "ok"})
}
開發者ID:couchbase,項目名稱:cbgt,代碼行數:7,代碼來源:rest_manage.go

示例15: statusSnifferHandler

// Disable or enable the sniffer
func statusSnifferHandler(w http.ResponseWriter, r *http.Request) {
	if r.FormValue("status") == "stop" {
		snifferActive = false
	} else {
		snifferActive = true
	}
}
開發者ID:CompassSecurity,項目名稱:WMBus-Sniffer-MUC,代碼行數:8,代碼來源:sniffer.go


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