当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Form方法代码示例

本文整理汇总了Golang中github.com/labstack/echo.Context.Form方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Form方法的具体用法?Golang Context.Form怎么用?Golang Context.Form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/labstack/echo.Context的用法示例。


在下文中一共展示了Context.Form方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: upload

func upload(c *echo.Context) error {
	req := c.Request()
	req.ParseMultipartForm(16 << 20) // Max memory 16 MiB

	// Read form fields
	name := c.Form("name")
	email := c.Form("email")

	// Read files
	files := req.MultipartForm.File["files"]
	for _, f := range files {
		// Source file
		src, err := f.Open()
		if err != nil {
			return err
		}
		defer src.Close()

		// Destination file
		dst, err := os.Create(f.Filename)
		if err != nil {
			return err
		}
		defer dst.Close()

		if _, err = io.Copy(dst, src); err != nil {
			return err
		}
	}
	return c.String(http.StatusOK, "Thank You! %s <%s>, %d files uploaded successfully.",
		name, email, len(files))
}
开发者ID:jameswei,项目名称:kingtask,代码行数:32,代码来源:server.go

示例2: Update

/**
 * @api {put} /topics/{id} Updates a topic
 * @apiName UpdateTopic
 * @apiGroup Topics
 *
 * @apiParam {Number} id The id of the topic to update
 * @apiParam {String} [name] The new name of the topic
 */
func (tc *TopicsController) Update(c *echo.Context) error {
	resp := response.New(c)
	defer resp.Render()

	// Getting params
	id, err := strconv.ParseInt(c.Param("id"), 10, 64)
	if err != nil {
		resp.SetResponse(http.StatusBadRequest, nil)
		return nil
	}

	// Loading the topic
	topic := new(models.Topic)
	err = topic.Load(id)
	if err != nil {
		resp.SetResponse(http.StatusNotFound, nil)
		return nil
	}

	name := c.Form("name")
	if name != "" {
		topic.Name = name
	}

	err = topic.Update()
	if err != nil {
		resp.SetResponse(http.StatusInternalServerError, nil)
		return nil
	}

	resp.SetResponse(http.StatusOK, topic)
	return nil
}
开发者ID:carrot,项目名称:burrow,代码行数:41,代码来源:topics_controller.go

示例3: AddToFavPostHandler

func (h *handler) AddToFavPostHandler(c *echo.Context) error {
	s := session.Default(c)
	if s.Get("user") == "" {
		return c.JSON(http.StatusForbidden, "Access denied")
	}
	user, err := h.back.Model.User.GetByLogin(s.Get("user").(string))
	if (err != nil || user == &model.UserRow{}) {
		return c.JSON(http.StatusBadRequest, err.Error())
	}

	p, err := h.back.Model.Package.GetItem(c.Form("package"))
	if err != nil {
		log.Println(err)
		return c.JSON(http.StatusBadRequest, err.Error())
	}

	user.Packages = append(user.Packages, p.Id)
	_, err = h.back.Model.User.Upsert(user)
	if err != nil {
		log.Println(err)
		return c.JSON(http.StatusBadRequest, err.Error())
	}

	return c.JSON(http.StatusOK, nil)
}
开发者ID:gophergala2016,项目名称:gobench,代码行数:25,代码来源:dashboard.go

示例4: RemoveFromFavPostHandler

func (h *handler) RemoveFromFavPostHandler(c *echo.Context) error {
	s := c.Get("session").(session.Session)
	if s.Get("username") == "" {
		return c.JSON(http.StatusForbidden, "")
	}
	user := c.Get("user").(model.UserRow)

	p, err := h.back.Model.Package.GetItem(c.Form("package"))
	if err != nil {
		log.Println(err)
		return c.JSON(http.StatusBadRequest, err.Error())
	}

	var packages []bson.ObjectId
	for _, up := range user.Packages {
		if up != p.Id {
			packages = append(packages, up)
		}
	}
	user.Packages = packages
	_, err = h.back.Model.User.Upsert(&user)
	if err != nil {
		log.Println(err)
		return c.JSON(http.StatusBadRequest, err.Error())
	}

	return c.JSON(http.StatusOK, nil)
}
开发者ID:goben-ch,项目名称:gobench,代码行数:28,代码来源:dashboard.go

示例5: RemoveFromFavPostHandler

func (h *handler) RemoveFromFavPostHandler(c *echo.Context) error {

	s := session.Default(c)
	if s.Get("user") == "" {
		return c.JSON(http.StatusForbidden, "Access denied")
	}
	user, err := h.back.Model.User.GetByLogin(s.Get("user").(string))
	if (err != nil || user == &model.UserRow{}) {
		return c.JSON(http.StatusBadRequest, err.Error())
	}
	p, err := h.back.Model.Package.GetItem(c.Form("package"))
	if err != nil {
		log.Println(err)
		return c.JSON(http.StatusBadRequest, err.Error())
	}

	var packages []bson.ObjectId
	for _, up := range user.Packages {
		if up != p.Id {
			packages = append(packages, up)
		}
	}
	user.Packages = packages
	_, err = h.back.Model.User.Upsert(user)
	if err != nil {
		log.Println(err)
		return c.JSON(http.StatusBadRequest, err.Error())
	}

	return c.JSON(http.StatusOK, nil)
}
开发者ID:gophergala2016,项目名称:gobench,代码行数:31,代码来源:dashboard.go

示例6: UserRegister

func UserRegister(c *echo.Context) error {
	r, err := uhander.Register(c.Form("u"), "")
	if err == nil {
		return c.String(http.StatusOK, r)
	} else {
		return c.String(http.StatusInternalServerError, err.Error())
	}
}
开发者ID:proudlily,项目名称:Auth_ser,代码行数:8,代码来源:funcs.go

示例7: UserLogin

func UserLogin(c *echo.Context) error {
	r, err := uhander.Login(c.Form("username"), c.Form("password"), "")

	if err == nil {
		return c.String(http.StatusOK, r)
	} else {
		return c.String(http.StatusInternalServerError, err.Error())
	}
}
开发者ID:proudlily,项目名称:Auth_ser,代码行数:9,代码来源:funcs.go

示例8: DoContact

// DoContact adds a new contact message into database and sends an email
func DoContact(c *echo.Context) error {
	var contact models.Contact
	var err error

	contact.Name = c.Form("name")
	contact.Email = c.Form("email")
	contact.Company = c.Form("company")
	contact.Reason = c.Form("text")

	if contact.Name == "" {
		return c.Redirect(302, fmt.Sprintf("/contact?error=%s", url.QueryEscape("Empty contact name")))
	}

	if contact.Reason == "" {
		return c.Redirect(302, fmt.Sprintf("/contact?error=%s", url.QueryEscape("Empty contact text")))
	}

	_, err = database.Current.NamedExec(database.Queries.InsertContact, contact)
	if err != nil {
		log.Println(database.Queries.InsertContact)
		log.Println("Cannot insert new contact data:", err)
		return c.Redirect(302, fmt.Sprintf("/contact?error=%s", url.QueryEscape("Cannot create your comment")))
	}

	return c.Redirect(302, fmt.Sprintf("/contact?msg=%s", url.QueryEscape("Thank you! We will contact you back in a few hours.")))
}
开发者ID:cedmundo,项目名称:site,代码行数:27,代码来源:handlers.go

示例9: expressQueryUsers

/**
 * 快递查询用户接口POST
 */
func expressQueryUsers(c *echo.Context) error {
	userName := c.Form("userName")
	userPhone := c.Form("userPhone")

	if userName == "" {
		return c.JSON(http.StatusOK, errorMsg{errorNo: expressUserNameEmpty, errorMsg: "expressUserNameEmpty"})
	}

	if userPhone == "" {
		return c.JSON(http.StatusOK, errorMsg{errorNo: expressUserPhoneEmpty, errorMsg: "expressUserPhoneEmpty"})
	}

	engine.Where("user_name = ? and user_phone = ?", userName, userPhone).AllCols().Get(&tcUser)

	return c.JSON(http.StatusOK, tcUser)
}
开发者ID:aslijiasheng,项目名称:jasongo,代码行数:19,代码来源:server.go

示例10: download

func download(c *echo.Context) error {
	type assets struct {
		Background int `json:"background"`
		Face       int `json:"face"`
		Clothes    int `json:"clothes"`
		Mouth      int `json:"mouth"`
		Hair       int `json:"hair"`
		Eye        int `json:"eye"`
	}
	gender_str := c.Form("gender")
	data_str := c.Form("data")

	var gender govatar.Gender
	var _assets assets

	switch gender_str {
	case "male":
		gender = govatar.MALE
	case "female":
		gender = govatar.FEMALE
	default:
		return c.String(http.StatusBadRequest, "Incorrect gender param")
	}

	if err := json.Unmarshal([]byte(data_str), &_assets); err != nil {
		return c.String(http.StatusBadRequest, err.Error())
	}

	img, err := govatar.GenerateFromAssets(gender, []int{_assets.Background - 1, _assets.Face - 1, _assets.Clothes - 1,
		_assets.Mouth - 1, _assets.Hair - 1, _assets.Eye - 1})

	if err != nil {
		return c.String(http.StatusBadRequest, err.Error())
	}

	buf := new(bytes.Buffer)
	if err := png.Encode(buf, img); err != nil {
		return c.String(http.StatusInternalServerError, err.Error())
	}

	c.Response().Header().Set(echo.ContentDisposition, "attachment; filename=avatar.png")
	http.ServeContent(c.Response(), c.Request(), "avatar.png", time.Now(), bytes.NewReader(buf.Bytes()))
	return nil
}
开发者ID:o1egl,项目名称:govatar,代码行数:44,代码来源:handlers.go

示例11: postGroup

func postGroup(ctx *echo.Context) error {
	g := Group{
		ID:            ctx.Form("id"),
		Name:          ctx.Form("name"),
		Location:      ctx.Form("timezone"),
		DefaultTarget: ctx.Form("defaultTarget"),
	}
	if g.ID == "" {
		g.ID = uuid.NewV1().String()
	}
	return saveGroup(dbFromContext(ctx), &g)
}
开发者ID:CyCoreSystems,项目名称:ipc-schedule,代码行数:12,代码来源:main.go

示例12: expressEmailMessage

/**
 *  快递通知接口
 */
func expressEmailMessage(c *echo.Context) error {
	userID := c.Form("userID")         //收件人ID
	takeUserID := c.Form("takeUserID") //取件人ID 通知ID
	var takeUser model.TcUser
	engine.Id(userID).Get(&takeUser) //通过取件人ID获取取件人信息
	go sendMail(takeUser)
	_, err = engine.Insert(&model.TcExpressMail{
		ExpressFromUserId:    userID,
		ExpressToUserId:      takeUserID,
		ExpressCreateUserId:  userID,
		ExpressCreateDate:    time.Now(),
		ExpressToExpressDate: time.Now(),
		ExpressTakeStatus:    expressSucc,
	})
	if err != nil {
		return c.JSON(http.StatusOK, errorMsg{errorNo: expressMailFailed, errorMsg: "expressMailFailed"})
	}
	return c.JSON(http.StatusOK, errorMsg{errorNo: expressMailSucc, errorMsg: "expressMailSucc"})
}
开发者ID:aslijiasheng,项目名称:jasongo,代码行数:22,代码来源:server.go

示例13: login

func (a *Application) login(c *echo.Context) error {
	id := c.Form("Id")
	user := a.Redis.GetUser(domain.ShaHashString(id))
	password := domain.HashPassword([]byte(c.Form("Password")), []byte(id))
	sessionKey := domain.HashPassword([]byte(id), []byte(user.CreateDate.String()))
	if user.Password == password {
		http.SetCookie(c.Response(), &http.Cookie{Name: "login", Value: sessionKey, MaxAge: 2592000})
		userAsJson, err := json.Marshal(user)
		if err != nil {
			fmt.Println(err)
		} else {
			a.Redis.Put(sessionKey, string(userAsJson))
			return c.Redirect(302, "/")
		}
	} else {
		fmt.Println("not a match")
	}

	return c.Redirect(302, "/login?failed=true")
}
开发者ID:JC1738,项目名称:go-react-seed,代码行数:20,代码来源:server.go

示例14: postRegister

// postRegister регистрирует устройство, чтобы на него можно было отсылать push-уведомления.
func postRegister(c *echo.Context) error {
	pushType := c.Param("push-type") // получаем идентификатор типа уведомлений
	switch pushType {
	case "apns": // Apple Push Notification
	case "gcm": // Google Cloud Messages
	default: // не поддерживаемы тип
		return echo.NewHTTPError(http.StatusNotFound)
	}
	groupID := c.Get("GroupID").(string)  // идентификатор группы
	userID := c.Get("ID").(bson.ObjectId) // идентификатор пользователя
	token := c.Form("token")              // токен устройства
	if len(token) != 32 {
		return echo.NewHTTPError(http.StatusBadRequest, "bad token size")
	}
	btoken, err := hex.DecodeString(token)
	if err != nil {
		return echo.NewHTTPError(http.StatusBadRequest, "bad token format")
	}
	_, _, _ = btoken, groupID, userID
	return echo.NewHTTPError(http.StatusNotImplemented)
}
开发者ID:jtprog,项目名称:geotrack,代码行数:22,代码来源:push.go

示例15: AddToFavPostHandler

func (h *handler) AddToFavPostHandler(c *echo.Context) error {
	s := c.Get("session").(session.Session)
	if s.Get("username") == "" {
		return c.JSON(http.StatusForbidden, "")
	}
	user := c.Get("user").(model.UserRow)

	p, err := h.back.Model.Package.GetItem(c.Form("package"))
	if err != nil {
		log.Println(err)
		return c.JSON(http.StatusBadRequest, err.Error())
	}

	user.Packages = append(user.Packages, p.Id)
	_, err = h.back.Model.User.Upsert(&user)
	if err != nil {
		log.Println(err)
		return c.JSON(http.StatusBadRequest, err.Error())
	}

	return c.JSON(http.StatusOK, nil)
}
开发者ID:goben-ch,项目名称:gobench,代码行数:22,代码来源:dashboard.go


注:本文中的github.com/labstack/echo.Context.Form方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。