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


Golang Context.Query方法代码示例

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


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

示例1: GetPage

// GetPage returns pagination attributes from query
func GetPage(c *echo.Context) (pn int, ps int) {
	var err error
	pns := c.Query("pn")
	pss := c.Query("ps")

	pn, err = strconv.Atoi(pns)
	if err != nil || pn < 0 {
		if pns != "" {
			log.Println("Bad argument of ?pn query param: ", pns)
		} else {
			log.Println("Empty ?pn argument")
		}
		pn = 1
	}

	ps, err = strconv.Atoi(pss)
	if err != nil || ps < 0 {
		if pss != "" {
			log.Println("Bad argument of ?ps query param: ", pss)
		} else {
			log.Println("Empty ?ps argument")
		}
		ps = 10
	}

	return
}
开发者ID:cedmundo,项目名称:site,代码行数:28,代码来源:utils.go

示例2: putPlace

// putPlace изменяет определение уже существующего места.
func putPlace(c *echo.Context) error {
	groupID := c.Get("GroupID").(string)
	placeID := c.Query("place-id")
	if !bson.IsObjectIdHex(placeID) {
		return echo.NewHTTPError(http.StatusNotFound)
	}
	var place places.Place // описание места
	err := c.Bind(&place)  // разбираем описание места из запроса
	if err != nil {
		return echo.NewHTTPError(http.StatusBadRequest, err.Error())
	}
	if place.Circle == nil && place.Polygon == nil {
		return echo.NewHTTPError(http.StatusBadRequest)
	}
	place.ID = bson.ObjectIdHex(placeID)
	place.GroupID = groupID
	_, err = placesDB.Save(place)
	if err == mgo.ErrNotFound {
		return echo.NewHTTPError(http.StatusNotFound)
	}
	if err != nil {
		llog.Error("placesDB error: %v", err)
		return err
	}
	return c.NoContent(http.StatusOK)
}
开发者ID:jtprog,项目名称:geotrack,代码行数:27,代码来源:places.go

示例3: Index

/**
 * @api {get} /topics Get a list of topics
 * @apiName GetTopics
 * @apiGroup Topics
 *
 * @apiParam {Number} [limit=10] The maximum number of items to return
 * @apiParam {Number} [offset=0] The offset relative to the number of items (not page number)
 */
func (tc *TopicsController) Index(c *echo.Context) error {
	resp := response.New(c)
	defer resp.Render()

	// Defaults
	var limit int64 = 10
	var offset int64 = 0

	// Getting limit
	limitInt, err := strconv.ParseInt(c.Query("limit"), 10, 64)
	if err == nil {
		limit = limitInt
	}

	// Getting offset
	offsetInt, err := strconv.ParseInt(c.Query("offset"), 10, 64)
	if err == nil {
		offset = offsetInt
	}

	// Fetching models
	res, err := models.AllTopics(limit, offset)
	if err != nil {
		resp.SetResponse(http.StatusInternalServerError, nil)
		return nil
	}

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

示例4: GetDownloadToken

func GetDownloadToken(c *echo.Context) error {
	filename := c.Query("filename")
	if len(filename) == 0 {
		return c.JSON(
			http.StatusBadRequest,
			hash{
				"error": "filename not specified",
			},
		)
	}

	accessToken, fail := oauth2.GetAccessToken(c.Request())
	if fail != nil {
		return oauthError(c, fail)
	}

	user := c.Get("user").(*users.User)
	token, err := createDownloadToken(user, accessToken, filename)
	if err != nil {
		return err
	}
	return c.JSON(
		http.StatusOK,
		hash{
			"token": token,
		},
	)
}
开发者ID:spacewoox,项目名称:community,代码行数:28,代码来源:files.go

示例5: fillBlogContext

// fillBlogContext dumps into a blog context default query values.
func fillBlogContext(c *echo.Context, bc *blogContext) error {
	var err error

	// Query the categories
	err = database.Current.Select(&bc.Categories, database.Queries.Categories)
	if err != nil {
		return err
	}

	// Query the archive
	err = database.Current.Select(&bc.Archives, database.Queries.Archives)
	if err != nil {
		return err
	}

	bc.Info = config.BlogInfo

	errparam := c.Query("error")
	if errparam != "" {
		bc.HasError = true
		bc.ErrorText = errparam
	}

	msgparam := c.Query("msg")
	if msgparam != "" {
		bc.HasMsg = true
		bc.MsgText = msgparam
	}
	return nil
}
开发者ID:cedmundo,项目名称:site,代码行数:31,代码来源:handlers.go

示例6: List

// Lists all the keys in the bucket starting from "offset" key up to "limit" number of keys.
// This returns all the keys joined by "\n" so a simple split will give back an array.
func (app *App) List(c *echo.Context) error {
	// Check that we can parse limit, ignore errors
	limit, err := strconv.ParseInt(c.Query("limit"), 10, 64)
	if err != nil {
		limit = LIMIT
	}
	// Get all keys up to limit
	data := app.Store[c.Param("user")].All("store", c.Query("offset"), int(limit))
	// Join the array with new lines
	return c.String(http.StatusOK, strings.Join(data, "\n"))
}
开发者ID:phrozen,项目名称:rivet,代码行数:13,代码来源:store.go

示例7: OauthCallbackHandler

func (h *handler) OauthCallbackHandler(c *echo.Context) error {
	code := c.Query("code")
	token, err := oauthConf.Exchange(oauth2.NoContext, code)
	if err != nil {
		log.Println(err.Error(), "Can't exchange token")
		return c.Redirect(http.StatusTemporaryRedirect, "/")
	}

	oauthClient := oauthConf.Client(oauth2.NoContext, token)
	client := github.NewClient(oauthClient)
	user, _, err := client.Users.Get("")
	if err != nil {
		log.Println(err.Error(), "Can't get user")
		return c.Redirect(http.StatusTemporaryRedirect, "/")
	}

	userLogin := *user.Login
	userToken := token.AccessToken

	u := &model.UserRow{
		Login:     userLogin,
		Token:     userToken,
		AvatarURL: *user.AvatarURL,
	}
	ci, err := h.back.Model.User.CreateOrUpdate(u)
	if err != nil {
		log.Println(err.Error(), "Can't create user")
		return c.Redirect(http.StatusTemporaryRedirect, "/")
	}

	s := session.Default(c)
	if ci.Updated == 0 {
		s.Set("just_signup", true)
	} else {
		u, err = h.back.Model.User.GetByLogin(userLogin)
		if err != nil {
			return c.Redirect(http.StatusTemporaryRedirect, "/")
		}
	}

	var buf bytes.Buffer
	enc := json.NewEncoder(&buf)
	enc.Encode(*u)

	s.Set("username", userLogin)
	s.Set("user", buf.String())
	// hack to display username in header
	http.SetCookie(c.Response(), &http.Cookie{Name: "username", Value: userLogin, Path: "/"})
	http.SetCookie(c.Response(), &http.Cookie{Name: "useravatar", Value: *user.AvatarURL, Path: "/"})
	s.Set("token", userToken)
	s.Save()

	return c.Redirect(http.StatusFound, "/dashboard")
}
开发者ID:goben-ch,项目名称:gobench,代码行数:54,代码来源:oauth.go

示例8: createEndpoint

func (s *yovpnServer) createEndpoint(c *echo.Context) error {
	region := c.Query("region")
	if len(region) == 0 {
		return echo.NewHTTPError(http.StatusBadRequest, "You need to provide a region!")
	}

	endpoint := s.provisioner.CreateEndpoint(region)
	c.Response().Header().Set(echo.Location, c.Echo().URI(s.getEndpoint, endpoint.ID))
	c.JSON(http.StatusAccepted, endpoint)
	return nil
}
开发者ID:xperimental,项目名称:yovpn,代码行数:11,代码来源:web.go

示例9: expressTakeUser

/**
 *  快递用户取件查询接口GET
 */
func expressTakeUser(c *echo.Context) error {
	userID := c.Query("userID")
	if userID == "" {
		return c.JSON(http.StatusOK, errorMsg{errorNo: expressUserIDEmpty, errorMsg: "expressUserIDEmpty"})
	}
	var express []model.TcExpressMail
	err := engine.Where("express_to_user_id = ?", userID).Cols("*").Find(&express)
	if err != nil {
		return c.JSON(http.StatusOK, errorMsg{errorNo: expressTakeUserFaield, errorMsg: "expressTakeUserFaield"})
	}
	return c.JSON(http.StatusOK, express)
}
开发者ID:aslijiasheng,项目名称:jasongo,代码行数:15,代码来源:server.go

示例10: NowPlaying

func NowPlaying(c *echo.Context) error {
	recent, err := radioparadise.RecentSongs()
	if err != nil {
		return err
	}

	return c.JSONP(http.StatusOK, c.Query("callback"), &struct {
		Songs []*radioparadise.Song `json:"songs"`
	}{
		recent,
	})
}
开发者ID:azer,项目名称:radio-paradise,代码行数:12,代码来源:api.go

示例11: deletePlace

// deletePlace удаляет определение места.
func deletePlace(c *echo.Context) error {
	groupID := c.Get("GroupID").(string)
	placeID := c.Query("place-id")
	if !bson.IsObjectIdHex(placeID) {
		return echo.NewHTTPError(http.StatusNotFound)
	}
	err := placesDB.Delete(groupID, bson.ObjectIdHex(placeID))
	if err == mgo.ErrNotFound {
		return echo.NewHTTPError(http.StatusNotFound)
	}
	if err != nil {
		llog.Error("placesDB error: %v", err)
		return err
	}
	return c.NoContent(http.StatusOK)
}
开发者ID:jtprog,项目名称:geotrack,代码行数:17,代码来源:places.go

示例12: GetProducts

func GetProducts(c *echo.Context) error {
	i := kendoui.Input(c.Request())
	logger.Json(i)

	callback := c.Query("callback")
	if len(callback) == 0 {
		callback = "test"
	}

	products, err := ps.GetAll()
	if err == nil {
		err = c.JSONP(http.StatusOK, callback, products)
	}

	return err
}
开发者ID:amsokol,项目名称:kendo-ui-echo-samples,代码行数:16,代码来源:product.go

示例13: SearchbackHandler

func (h *handler) SearchbackHandler(c *echo.Context) error {
	searchq := strings.ToLower(c.Query("search"))
	packages, err := h.back.Model.Package.GetItems(searchq)
	if err != nil {
		log.Error(err)
		return c.Redirect(http.StatusTemporaryRedirect, "/")
	}
	if len(searchq) > 50 && len(searchq) < 4 {
		return c.Redirect(http.StatusBadRequest, "/")
	}
	data := struct {
		Packages []model.PackageRow
	}{
		packages,
	}
	return c.Render(http.StatusOK, "search.html", data)
}
开发者ID:gophergala2016,项目名称:gobench,代码行数:17,代码来源:search.go

示例14: Get

func Get(c *echo.Context) error {
	user := c.Get("user").(*users.User)
	if c.Query("me") == "true" {
		return utils.JSON(c, http.StatusOK, user)
	}

	if !user.IsAdmin {
		return apiErrors.AdminLevelRequired
	}

	users, err := users.FindUsers()
	if err != nil {
		log.Error(err)
		return apiErrors.InternalError.Detail("Unable to retreive the user list")
	}

	return utils.JSON(c, http.StatusOK, users)
}
开发者ID:corentindrouet,项目名称:community,代码行数:18,代码来源:users.go

示例15: processPhotosHandler

func processPhotosHandler(c *echo.Context) error {
	ctx := appengine.NewContext(c.Request())

	var from time.Time
	var to time.Time
	var err error

	processorName := c.Param("processor")
	fromStr := c.Query("from")
	toStr := c.Query("to")
	now := time.Now().UTC()

	// default to previous day but allow any
	if toStr == "" {
		to = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC)
	} else {
		to, err = time.Parse(dateFormat, toStr)
		if err != nil {
			log.Errorf(ctx, "to error %s", err.Error())
			return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
		}
	}

	if fromStr == "" {
		from = to.Add(time.Duration(-24) * time.Hour)
	} else {
		from, err = time.Parse(dateFormat, fromStr)
		if err != nil {
			log.Errorf(ctx, "from error %s", err.Error())
			return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
		}
	}

	r := &photoProcessorRange{
		From: from,
		To:   to,
	}
	processorFn := photoProcessors[processorName]
	processor := processorFn(r)
	log.Debugf(c, "%#v", processor)
	processPhotosFunc.Call(ctx, processor)

	return c.NoContent(http.StatusOK)
}
开发者ID:komasoftware,项目名称:go-appengine-mapper,代码行数:44,代码来源:photos.go


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