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


Golang Context.PostForm方法代碼示例

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


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

示例1: Login

func Login(c *gin.Context) {
	user := c.PostForm("user")
	pass := c.PostForm("pass")
	fmt.Println(user)
	fmt.Println(pass)
	mail.GoLogin("[email protected]", "402407")
}
開發者ID:yanue,項目名稱:go-webmail,代碼行數:7,代碼來源:auth.go

示例2: OrderDeleteHandler

// 刪除訂單
func OrderDeleteHandler(c *gin.Context) {
	r := render.New(c)

	//超級管理員才可以刪除訂單
	auth := userauth.Auth(c)
	if !auth.IsRole(bean.ROLE_SUPER_ADMIN) {
		r.JSON(util.JsonResult{Msg: "您沒有權限"})
		return
	}

	oids := strings.TrimSpace(c.PostForm("oid"))

	var orderIds []string
	err := json.Unmarshal([]byte(oids), &orderIds)
	if err != nil {
		Logger.Warn("order delete uuids:%v, err: %v", oids, err)
		r.JSON(util.JsonResult{Success: true, Msg: "訂單參數錯誤"})
		return
	}

	if len(orderIds) == 0 {
		r.JSON(util.JsonResult{Success: true, Msg: "請選擇訂單"})
		return
	}

	deleteSQL := "delete from order_info where uuid in ("
	for _, v := range orderIds {
		deleteSQL += "'" + v + "' ,"
	}
	deleteSQL = deleteSQL[:len(deleteSQL)-1] + ")"
	Logger.Debug("order delete sql: %v", deleteSQL)
	_, err = db.Engine.Exec(deleteSQL)
	util.PanicError(err)
	r.JSON(util.JsonResult{Success: true, Msg: "刪除成功"})
}
開發者ID:sdvdxl,項目名稱:wine,代碼行數:36,代碼來源:order.go

示例3: AddCourse

func AddCourse(ctx *gin.Context) (*Course, error) {
	db := ctx.MustGet("db").(*sql.DB)
	course := new(Course)
	course.Name = ctx.PostForm("name")
	course.Email = ctx.PostForm("email")
	course.Url = ctx.PostForm("url")
	course.Priority, _ = strconv.Atoi(ctx.PostForm("priority"))
	course.Checkoff, _ = strconv.Atoi(ctx.PostForm("checkoff"))
	course.Note = ctx.PostForm("note")

	err := db.QueryRow(`
		INSERT INTO 
		courses(name, email, url, priority, checkoff, note) 
		VALUES($1,$2,$3,$4,$5,$6) returning id;`,
		&course.Name,
		&course.Email,
		&course.Url,
		&course.Priority,
		&course.Checkoff,
		&course.Note).Scan(&course.Id)

	if err != nil {
		return nil, err
	}
	return course, nil
}
開發者ID:gophergala2016,項目名稱:learnlink,代碼行數:26,代碼來源:course.go

示例4: New

func (self *EnvController) New(c *gin.Context) {
	username := self.CurrentUser(c)

	if username == "" {
		c.Redirect(http.StatusFound, "/")

		return
	}

	appName := c.Param("appName")
	key := c.PostForm("key")
	value := c.PostForm("value")

	err := env.Create(self.etcd, username, appName, key, value)

	if err != nil {
		fmt.Fprintf(os.Stderr, "%+v\n", err)

		c.HTML(http.StatusInternalServerError, "app.tmpl", gin.H{
			"alert":   true,
			"error":   true,
			"message": "Failed to add environment variable.",
		})

		return
	}

	c.Redirect(http.StatusSeeOther, "/apps/"+appName)
}
開發者ID:dtan4,項目名稱:paus-frontend,代碼行數:29,代碼來源:env_controller.go

示例5: CreateC

// CreateC handles the multipart form upload and creates an encrypted file
func CreateC(c *gin.Context) {
	var err error
	var duration time.Duration
	var once bool

	c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, conf.C.SizeLimit*utils.MegaByte)

	once = c.PostForm("once") != ""
	d := c.DefaultPostForm("duration", "1d")

	if val, ok := models.DurationMap[d]; ok {
		duration = val
	} else {
		logger.ErrC(c, "server", "Invalid duration", d)
		c.String(http.StatusBadRequest, "Invalid duration\n")
		c.AbortWithStatus(http.StatusBadRequest)
		return
	}

	fd, h, err := c.Request.FormFile("file")
	if err != nil {
		logger.ErrC(c, "server", "Couldn't read file", err)
		c.String(http.StatusRequestEntityTooLarge, "Entity is too large (Max : %v MB)\n", conf.C.SizeLimit)
		c.AbortWithStatus(http.StatusRequestEntityTooLarge)
		return
	}
	defer fd.Close()

	res := models.NewResourceFromForm(h, once, duration)
	k, err := res.WriteEncrypted(fd)
	if err != nil {
		logger.ErrC(c, "server", "Couldn't write file", err)
		c.String(http.StatusInternalServerError, "Something went wrong on the server. Try again later.")
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	if conf.C.DiskQuota > 0 {
		if models.S.CurrentSize+uint64(res.Size) > uint64(conf.C.DiskQuota*utils.GigaByte) {
			logger.ErrC(c, "server", "Quota exceeded")
			c.String(http.StatusBadRequest, "Insufficient disk space. Try again later.")
			c.AbortWithStatus(http.StatusBadRequest)
			os.Remove(path.Join(conf.C.UploadDir, res.Key))
			return
		}
	}

	if err = res.Save(); err != nil {
		logger.ErrC(c, "server", "Couldn't save in the database", err)
		c.String(http.StatusInternalServerError, "Something went wrong on the server. Try again later.")
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}
	res.LogCreated(c)
	ns := conf.C.NameServer
	if conf.C.AppendPort {
		ns = fmt.Sprintf("%s:%d", conf.C.NameServer, conf.C.Port)
	}
	c.String(http.StatusCreated, "%v://%s/v/%s/%s\n", utils.DetectScheme(c), ns, res.Key, k)
}
開發者ID:Depado,項目名稱:goploader,代碼行數:61,代碼來源:resources.go

示例6: Delete

func (self *ArgController) Delete(c *gin.Context) {
	username := self.CurrentUser(c)

	if username == "" {
		c.Redirect(http.StatusFound, "/")

		return
	}

	appName := c.Param("appName")
	key := c.PostForm("key")

	err := arg.Delete(self.etcd, username, appName, key)

	if err != nil {
		fmt.Fprintf(os.Stderr, "%+v\n", err)

		c.HTML(http.StatusInternalServerError, "app.tmpl", gin.H{
			"alert":   true,
			"error":   true,
			"message": "Failed to delete build arg.",
		})

		return
	}

	c.Redirect(http.StatusSeeOther, "/apps/"+appName)
}
開發者ID:dtan4,項目名稱:paus-frontend,代碼行數:28,代碼來源:arg_controller.go

示例7: UpdateCourse

func UpdateCourse(ctx *gin.Context) (*Course, error) {
	db := ctx.MustGet("db").(*sql.DB)
	course := new(Course)
	course.Id, _ = strconv.Atoi(ctx.Param("id"))
	course.Name = ctx.PostForm("name")
	course.Url = ctx.PostForm("url")
	course.Priority, _ = strconv.Atoi(ctx.PostForm("priority"))
	course.Checkoff, _ = strconv.Atoi(ctx.PostForm("checkoff"))
	checkoffTimeStamp := ctx.PostForm("checkoff_time") // , _ = time.Parse(time.RFC3339, ctx.PostForm("checkoff_time"))
	course.Note = ctx.PostForm("note")
	course.UpdatedAt = time.Now()

	err := db.QueryRow("UPDATE courses SET (name, url, priority, checkoff, checkoff_time, note, updated_at) = ($1,$2,$3,$4,$5,$6,$7) WHERE id=$8 returning id;",
		&course.Name,
		&course.Url,
		&course.Priority,
		&course.Checkoff,
		checkoffTimeStamp,
		&course.Note,
		&course.UpdatedAt,
		&course.Id).Scan(&course.Id)

	if err != nil {
		return nil, err
	}
	return course, nil
}
開發者ID:gophergala2016,項目名稱:learnlink,代碼行數:27,代碼來源:course.go

示例8: UpdateWithAttrs

// UpdateWithAttrsInGinContext finds a LineItem with id param,
// updates it with attrs from gin.Contex.PostForm(),
// returns the edited LineItem
func (model *Model) UpdateWithAttrs(id float64, ctx *gin.Context) (LineItem, error) {
	// check if element does exsit
	li, ok := model.Get(id)
	if !ok {
		return li, SeedsErrorf("model %s[id:%d] does not exsit", model.Name, id)
	}

	// update model
	for _, column := range model.Columns {
		value := ctx.PostForm(column.Name)

		if value == "" || column.Name == "id" {
			continue
		}

		formatVal, err := FormatValue(column.Type, value)
		if err == nil {
			err = column.CheckValue(formatVal, model)
		}

		if err != nil {
			return li, err
		} else {
			oldValue, _ := li.Get(column.Name)
			column.RemoveUniquenessOf(oldValue)
			li.Set(column.Name, formatVal)
			column.AddUniquenessOf(formatVal)
		}
	}
	return li, nil
}
開發者ID:Focinfi,項目名稱:apifaker,代碼行數:34,代碼來源:model.go

示例9: uploadRecipients

func uploadRecipients(c *gin.Context) {
	if c.PostForm("delete") != "" {
		log.Printf("DeleteAll")
		_, err := Db.Exec("DELETE FROM `recipient` WHERE `campaign_id`=?", c.Param("id"))
		checkErr(err)
	}

	if c.PostForm("submit") != "" {
		file, head, err := c.Request.FormFile("file")
		checkErr(err)
		if err == nil {
			fpath := "tmp/" + string(time.Now().UnixNano()) + head.Filename
			out, err := os.Create(fpath)
			checkErr(err)
			defer out.Close()
			_, err = io.Copy(out, file)
			checkErr(err)
			postRecipientCsv(c.Param("id"), fpath)
			os.Remove(fpath)
		}

	}

	hRecipients(c)
}
開發者ID:gitter-badger,項目名稱:gonder,代碼行數:25,代碼來源:recipients.go

示例10: postCheck

func postCheck(c *gin.Context) {
	lang := c.PostForm("lang")
	text := c.PostForm("text")

	speller, err := aspell.NewSpeller(map[string]string{
		"lang": lang,
	})

	if err != nil {
		c.JSON(500, gin.H{"error": err.Error()})
	}
	defer speller.Delete()

	test := strings.Fields(text)

	result := make(map[string][]string)

	for i := range test {
		if speller.Check(stripchars(test[i], ".,!?+=")) != true {
			result[stripchars(test[i], ".,!?+=")] = speller.Suggest(test[i])
		}
	}

	c.JSON(200, gin.H{"lang": lang, "misspelled": result})
}
開發者ID:vkolev,項目名稱:spellrcheck,代碼行數:25,代碼來源:spellrcheck.go

示例11: Salvar

// Salvar define a rota para salvar o link
func Salvar(c *gin.Context) {

	link := construirLink(c)

	if c.PostForm("inputId") != "" {

		modelo.AtualizarLink(link)
		c.HTML(http.StatusOK, "favoritos.html", gin.H{
			"proxPagina": 1,
			"links":      modelo.ObterPagina(0, true),
			"msg":        "Link atualizado!!",
		})
	} else {

		erro := modelo.NovoLink(link)
		msg := "Link salvo com sucesso!"
		if erro != nil {
			msg = "OPA! Esse link já foi cadastrado O.o"
			log.Printf("Erro ao inserir novo link: %v\n", erro)
		}
		c.HTML(http.StatusOK, "resp-salvar.html", gin.H{
			"error": erro,
			"msg":   msg,
		})
	}
}
開發者ID:viliamjr,項目名稱:favoritos,代碼行數:27,代碼來源:rotas.go

示例12: V1RegisterHandler

/**
 * Handler for POST /api/v1/admin/register
 */
func V1RegisterHandler(c *gin.Context) {
	request := AdminUser{
		Email:    c.PostForm("email"),
		Password: c.PostForm("password"),
	}

	failureResponse := gin.H{
		"status":  "failed",
		"message": "Could not complete registration",
	}

	currentUsers := GetAdminUsers()

	if len(currentUsers) > 0 {
		for _, user := range currentUsers {
			if request.Email == user.Email {
				c.JSON(http.StatusOK, failureResponse)
				return
			}
		}
	}

	request.hashPassword()
	err := SaveAdminUser(request)
	if err != nil {
		c.JSON(http.StatusOK, failureResponse)
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"status":  "OK",
		"message": "User created successfully",
	})
}
開發者ID:eduncan26,項目名稱:evan-duncan.com,代碼行數:37,代碼來源:admin.go

示例13: PostLogin

func (h *FrontendHandlers) PostLogin(c *gin.Context) {
	data := &LoginData{
		Username: c.PostForm("username"),
		Password: c.PostForm("password"),
	}

	if v := validateLogin(data); v.HasError() {
		data.Validate = v.Messages()
		h.render.HTML(c.Writer, 200, "login", data)
		return
	}

	info, err := h.loginService.Login(data.Username, data.Password)
	if err != nil {
		data.Error = err.Error()
		h.render.HTML(c.Writer, 200, "login", data)
		return
	}

	session := sessions.Default(c)
	session.Set("user_id", info.Id)
	session.Save()

	c.Redirect(302, "/")
}
開發者ID:thanhliem89dn,項目名稱:microservices-book-code,代碼行數:25,代碼來源:frontend_handlers.go

示例14: UserLogin

func UserLogin(c *gin.Context) {
	var cookie middleware.CookieManager
	cookie = c.MustGet("CM").(middleware.CookieManager)
	if c.Request.Method == "GET" {
		data := tool.GetTD(c)

		fmt.Println(data)
		c.HTML(http.StatusOK, "login.html", data)
	} else if c.Request.Method == "POST" {

		email := c.PostForm("email")
		password := c.PostForm("password")
		user := model.User{}
		model.T.DB.Debug().Where("email = ? and password = ?", email, password).First(&user)
		if user.Name != "" {
			cookie.Add("user_id", user.ID)
			cookie.WriteCookies()
			c.Redirect(http.StatusMovedPermanently, "/")
		} else {
			cookie.Flash("fail_msg", "login failed :(")
			c.Redirect(http.StatusMovedPermanently, "/user/login")
		}

	}
}
開發者ID:highsoul,項目名稱:eshop,代碼行數:25,代碼來源:main.go

示例15: New

func (self *AppController) New(c *gin.Context) {
	username := self.CurrentUser(c)

	if username == "" {
		c.Redirect(http.StatusFound, "/")

		return
	}

	appName := c.PostForm("appName")

	err := app.Create(self.etcd, username, appName)

	if err != nil {
		fmt.Fprintf(os.Stderr, "%+v\n", err)

		c.HTML(http.StatusInternalServerError, "apps.tmpl", gin.H{
			"alert":   true,
			"error":   true,
			"message": "Failed to create app.",
		})

		return
	}

	c.Redirect(http.StatusSeeOther, "/apps/"+appName)
}
開發者ID:dtan4,項目名稱:paus-frontend,代碼行數:27,代碼來源:app_controller.go


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