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


Golang echo.Context类代码示例

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


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


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