本文整理汇总了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",
})
}
示例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)
}
示例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)
}
示例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))
}
}
示例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()
}
示例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)
}
示例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,
})
}
}
示例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
}
示例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>
`)
}
示例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)
}
}
示例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
}
示例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)
}
}
示例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)
}
}
示例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"})
}
示例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
}
}