当前位置: 首页>>代码示例>>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;未经允许,请勿转载。