• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang echo.Context类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: EnvironmentGetAll

func EnvironmentGetAll(ctx *echo.Context) error {
	interactor := ctx.Get("EnvironmentInteractor").(*usecases.EnvironmentInteractor)

	result := interactor.List()

	return ctx.JSON(http.StatusOK, result)
}
开发者ID:jacoelho,项目名称:lodestar,代码行数:7,代码来源:environment.go


示例2: FileServerHandler

// FileServerHandler function
func FileServerHandler(c *echo.Context) error {
	fileType := mime.TypeByExtension(filepath.Ext(filepath.Base(c.Request().URL.String())))
	log.Println(c.Request().URL.String()[1:])
	c.Response().Header().Set("Content-Type", fileType)
	io.Copy(c.Response(), bytes.NewReader(staticFiles.Get(c.Request().URL.String()[1:])))
	return nil
}
开发者ID:go-experimental,项目名称:mongo-me,代码行数:8,代码来源:main.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: UnpublishApplication

// Make an application unusable
func UnpublishApplication(c *echo.Context) error {
	user := c.Get("user").(*users.User)

	appId := c.Param("app_id")
	if len(appId) < 1 {
		return c.JSON(http.StatusBadRequest, hash{
			"error": [1]hash{
				hash{
					"detail": "App id must be specified",
				},
			},
		})
	}

	err := apps.UnpublishApp(user, appId)
	if err == apps.UnpublishFailed {
		return c.JSON(http.StatusInternalServerError, hash{
			"error": [1]hash{
				hash{
					"detail": err.Error(),
				},
			},
		})
	}

	return c.JSON(http.StatusOK, hash{
		"meta": hash{},
	})
}
开发者ID:spacewoox,项目名称:community,代码行数:30,代码来源:apps.go


示例5: renderInstall

func renderInstall(ctx echo.Context, filename string, data map[string]interface{}) error {
	objLog := getLogger(ctx)

	if data == nil {
		data = make(map[string]interface{})
	}

	filename = config.TemplateDir + filename

	requestURI := ctx.Request().URI()
	tpl, err := template.ParseFiles(filename)
	if err != nil {
		objLog.Errorf("解析模板出错(ParseFiles):[%q] %s\n", requestURI, err)
		return err
	}

	buf := new(bytes.Buffer)
	err = tpl.Execute(buf, data)
	if err != nil {
		objLog.Errorf("执行模板出错(Execute):[%q] %s\n", requestURI, err)
		return err
	}

	return ctx.HTML(http.StatusOK, buf.String())
}
开发者ID:studygolang,项目名称:studygolang,代码行数:25,代码来源:install.go


示例6: UserList

func UserList(ctx *echo.Context) error {
	interactor := ctx.Get("UserInteractor").(*usecases.UserInteractor)

	result := interactor.List()

	return ctx.JSON(http.StatusOK, result)
}
开发者ID:jacoelho,项目名称:lodestar,代码行数:7,代码来源:user.go


示例7: ArchiveView

// ArchiveView shows a list of posts arranged by its date
func ArchiveView(c *echo.Context) error {
	id := c.Param("id")
	var err error

	// Get archive data
	var archive models.Archive
	err = database.Current.Get(&archive, database.Queries.ArchiveBySignature, id)
	if err != nil {
		log.Println("Cannot get archive by signature", err)
		return echo.NewHTTPError(http.StatusInternalServerError)
	}

	// Get related posts
	var posts []models.AuthoredPost
	err = database.Current.Select(&posts, database.Queries.ArchiveAuthoredPosts, id)
	if err != nil {
		log.Println("Cannot select posts", err)
		return echo.NewHTTPError(http.StatusInternalServerError)
	}

	// Create our render context and fill base data
	ac := archiveContext{
		Archive:      archive,
		RelatedPosts: posts,
	}

	err = fillBlogContext(c, &ac.blogContext)
	if err != nil {
		log.Println("Cannot fill blog context", err)
		return echo.NewHTTPError(http.StatusInternalServerError)
	}

	return c.Render(200, "archive", ac)
}
开发者ID:cedmundo,项目名称:site,代码行数:35,代码来源:handlers.go


示例8: MakeCookie

func MakeCookie(context echo.Context, name string, value string) {
	cookie := new(echo.Cookie)
	cookie.SetName(name)
	cookie.SetValue(value)
	cookie.SetExpires(time.Now().Add(24 * 365 * time.Hour)) // Make the cookie good for a year
	context.SetCookie(cookie)
}
开发者ID:jessemillar,项目名称:byudzhet,代码行数:7,代码来源:cookies.go


示例9: welcome

func welcome(c *echo.Context) error {
	type User struct {
		Name string
		Age  int8
	}
	return c.Render(http.StatusOK, "welcome", User{Name: "schaffer", Age: 23})
}
开发者ID:schaffers,项目名称:typed,代码行数:7,代码来源:handler.go


示例10: GetNodesStatus

//get nodes status
func (s *ApiServer) GetNodesStatus(c echo.Context) error {
	var masterStatus, slaveStatus DBStatus

	dbStatus := make([]DBStatus, 0, 1)
	nodes := s.proxy.GetAllNodes()

	for nodeName, node := range nodes {
		//get master status
		masterStatus.Node = nodeName
		masterStatus.Address = node.Master.Addr()
		masterStatus.Type = "master"
		masterStatus.Status = node.Master.State()
		masterStatus.LastPing = fmt.Sprintf("%v", time.Unix(node.Master.GetLastPing(), 0))
		masterStatus.MaxConn = node.Cfg.MaxConnNum
		masterStatus.IdleConn = node.Master.IdleConnCount()
		dbStatus = append(dbStatus, masterStatus)

		//get slaves status
		for _, slave := range node.Slave {
			slaveStatus.Node = nodeName
			slaveStatus.Address = slave.Addr()
			slaveStatus.Type = "slave"
			slaveStatus.Status = slave.State()
			slaveStatus.LastPing = fmt.Sprintf("%v", time.Unix(slave.GetLastPing(), 0))
			slaveStatus.MaxConn = node.Cfg.MaxConnNum
			slaveStatus.IdleConn = slave.IdleConnCount()
			dbStatus = append(dbStatus, slaveStatus)
		}
	}
	return c.JSON(http.StatusOK, dbStatus)
}
开发者ID:flike,项目名称:kingshard,代码行数:32,代码来源:api.go


示例11: Retrieve

// Retrieve writes profile public information, if requested id is the same as the
// session, then full data is written.
func Retrieve(c *echo.Context) (int, interface{}) {
	reqid, _ := strconv.ParseInt(c.Param("id"), 10, 64)
	attid, _ := c.Get("digitsID").(int64)

	if reqid == attid {
		// Serve private profile
		var profile models.Profile

		log.Printf("Awaiting for [Profile = %d] fetch", reqid)
		err := mangos.FindOne(collection, bson.M{"_id": reqid}, &profile)
		if err != nil {
			log.Printf("Cannot retrieve [Profile = %d]: %s", reqid, err)
			return msg.InternalError(err)
		}

		log.Printf("Served profile ->\n%s", msg.Detail(profile))
		return msg.Ok(profile)
	}

	// Serve public profile
	var public models.PublicProfile
	log.Printf("Awaiting for [PublicProfile = %d] fetch", reqid)
	err := mangos.FindOne(collection, bson.M{"_id": reqid}, &public)
	if err != nil {
		log.Printf("Cannot retrieve [PublicProfile = %d]: %s", reqid, err)
		return msg.InternalError(err)
	}

	log.Printf("Served PublicProfile ->\n%s", msg.Detail(public))
	return msg.Ok(public)
}
开发者ID:cedmundo,项目名称:hablo,代码行数:33,代码来源:profiles.go


示例12: SaveProxyConfig

func (s *ApiServer) SaveProxyConfig(c echo.Context) error {
	err := s.proxy.SaveProxyConfig()
	if err != nil {
		return err
	}
	return c.JSON(http.StatusOK, "ok")
}
开发者ID:flike,项目名称:kingshard,代码行数:7,代码来源:api.go


示例13: ChangeMasterStatus

func (s *ApiServer) ChangeMasterStatus(c echo.Context) error {
	args := struct {
		Opt  string `json:"opt"`
		Node string `json:"node"`
		Addr string `json:"addr"`
	}{}

	err := c.Bind(&args)
	if err != nil {
		return err
	}

	args.Opt = strings.ToLower(args.Opt)
	if args.Opt != "up" && args.Opt != "down" {
		return errors.New("opt only can be up or down")
	}
	if args.Opt == "down" {
		err = s.proxy.DownMaster(args.Node, args.Addr)
	} else {
		err = s.proxy.UpMaster(args.Node, args.Addr)
	}
	if err != nil {
		return err
	}
	return c.JSON(http.StatusOK, "ok")
}
开发者ID:flike,项目名称:kingshard,代码行数:26,代码来源:api.go


示例14: 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


示例15: Create

// Create inserts a new group into database
func Create(c *echo.Context) (int, interface{}) {
	digitsID, ok := c.Get("digitsID").(int64)
	if !ok {
		return msg.Forbidden("session required")
	}

	// Bind request body with group
	var group models.Group
	err := c.Bind(&group)

	// Validate group
	err = validator.Validate(group)
	if err != nil {
		return msg.BadRequest(err)
	}

	// Set values
	group.ID = bson.NewObjectId()
	group.Admins = []int64{digitsID}
	group.Creator = digitsID
	group.Members = []int64{digitsID}

	// Create group
	err = mangos.Insert(constants.CGroups, group)
	if err != nil {
		return msg.InternalError(err)
	}

	return msg.Ok(group)
}
开发者ID:cedmundo,项目名称:hablo,代码行数:31,代码来源:groups.go


示例16: OauthResponse

func OauthResponse(c *echo.Context) (goth.Session, *goth.User, error) {

	//println("gothic.OauthResponse")
	platform, err := getPlatform(c)
	if err != nil {
		return nil, nil, err
	}
	req := c.Request()
	//println("gothic.getSession")
	sess, err := getSession(platform, req)
	if err != nil {
		return nil, nil, err
	}
	//println("gothic.Authorize")
	_, err = sess.Authorize(platform, req.URL.Query())
	if err != nil {
		return sess, nil, err
	}
	//println("gothic.OauthResponse.Authorize response", authorized)

	user, err := platform.FetchUser(sess)
	if err != nil {
		return nil, nil, err
	}
	return sess, user, nil
}
开发者ID:laicosly,项目名称:goth,代码行数:26,代码来源:gothic.go


示例17: Retrieve

// Retrieve writes the requested group from database
func Retrieve(c *echo.Context) (int, interface{}) {
	digitsID, ok := c.Get("digitsID").(int64)
	if !ok {
		return msg.Forbidden("session required")
	}

	// Get group id and convert it from string to objectid
	rawGID := c.Param("gid")
	if !bson.IsObjectIdHex(rawGID) {
		return msg.BadRequest("bad id: not a ObjectId")
	}

	// find the group
	groupID := bson.ObjectIdHex(rawGID)
	var group models.Group
	err := mangos.FindOne(constants.CGroups, bson.M{"_id": groupID}, &group)
	if err != nil {
		return msg.InternalError(err)
	}

	// check if user is member (is not part of the query because we need to light bson query)
	for _, member := range group.Members {
		if member == digitsID {
			return msg.Ok(group)
		}
	}

	return msg.Forbidden("you must be part of the group")
}
开发者ID:cedmundo,项目名称:hablo,代码行数:30,代码来源:groups.go


示例18: PublishApp

func PublishApp(c *echo.Context) error {
	body, err := ioutil.ReadAll(c.Request().Body)
	if err != nil {
		log.Error(err)
		return reterr(err, "", c)
	}
	var all struct {
		Data struct {
			Attributes struct {
				Alias          string `json:"alias"`
				CollectionName string `json:"collection-name"`
				DisplayName    string `json:"display-name"`
				FilePath       string `json:"file-path"`
				Path           string `json:"path"`
			}
			Type string `json:"type"`
		} `json:"data"`
	}
	err = json.Unmarshal(body, &all)
	if err != nil {
		log.Error(err)
		return reterr(err, "", c)
	}

	username, pwd, _ := c.Request().BasicAuth()
	utils.ExecuteCommandAsAdmin("C:\\Windows\\System32\\WindowsPowershell\\v1.0\\powershell.exe Import-module RemoteDesktop; New-RDRemoteApp -CollectionName "+all.Data.Attributes.CollectionName+" -DisplayName "+all.Data.Attributes.DisplayName+" -FilePath '"+all.Data.Attributes.Path+"'", username, pwd, domain)
	return checkIfPublishSucceeded(c, all.Data.Attributes.DisplayName)
}
开发者ID:dynamiccast,项目名称:community,代码行数:28,代码来源:apps.go


示例19: List

func List(c *echo.Context) error {

	user := c.Get("user").(*users.User)

	winUser, err := user.WindowsCredentials()
	if err != nil {
		return err
	}

	sessionList, err := sessions.GetAll(winUser.Sam)

	if err != nil {
		log.Error(err)
		return utils.JSON(c, http.StatusInternalServerError, hash{
			"error": [1]hash{
				hash{
					"detail": err.Error(),
				},
			},
		})
	}

	var response = make([]hash, len(sessionList))
	for i, val := range sessionList {
		res := hash{
			"id":         val.Id,
			"type":       "session",
			"attributes": val,
		}
		response[i] = res
	}

	return c.JSON(http.StatusOK, hash{"data": response})
}
开发者ID:spacewoox,项目名称:community,代码行数:34,代码来源:sessions.go


示例20: addSubscribersHandler

func addSubscribersHandler(c echo.Context) error {
	cfg := c.Get("config").(*Config)

	var (
		err    error
		emails []string
	)

	if err = c.Bind(&emails); err != nil {
		return c.JSON(StatusUnprocessableEntity, map[string]interface{}{
			"message": "problem decoding request body",
			"error":   err,
		})
	}

	subs, err := SubscribeEmail(cfg, emails...)

	if err != nil {
		return c.JSON(StatusUnprocessableEntity, map[string]interface{}{
			"message": "problem subscribing emails",
			"error":   err,
		})
	}

	return c.JSON(http.StatusOK, map[string]interface{}{
		"subscribed": len(subs),
	})
}
开发者ID:chop-dbhi,项目名称:scds,代码行数:28,代码来源:http.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang echo.Echo类代码示例发布时间:2022-05-23
下一篇:
Golang echo.NewResponse函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap