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


Golang Context.JSONBlob方法代码示例

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


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

示例1: success

func success(ctx echo.Context, data interface{}) error {
	result := map[string]interface{}{
		"ok":   1,
		"msg":  "操作成功",
		"data": data,
	}

	b, err := json.Marshal(result)
	if err != nil {
		return err
	}

	go func(b []byte) {
		if cacheKey := ctx.Get(nosql.CacheKey); cacheKey != nil {
			nosql.DefaultLRUCache.CompressAndAdd(cacheKey, b, nosql.NewCacheData())
		}
	}(b)

	if ctx.Response().Committed() {
		getLogger(ctx).Flush()
		return nil
	}

	return ctx.JSONBlob(http.StatusOK, b)
}
开发者ID:studygolang,项目名称:studygolang,代码行数:25,代码来源:base.go

示例2: appDelete

func appDelete(c echo.Context) error {
	//arg := new(types.DeleteParams)
	//reply := new(types.Event)

	data := []byte{}
	fmt.Println(data)
	return c.JSONBlob(http.StatusOK, data)
}
开发者ID:asyoume,项目名称:paas_srv,代码行数:8,代码来源:app.go

示例3: Create

// Create logs a user in
func (s Controller) Create(e echo.Context) error {
	session := &userSession{}

	if err := e.Bind(session); err != nil {
		return err
	}

	user, err := models.Users(s.DB, qm.Select("hash"), qm.Where("username=$1", session.Username)).One()
	if err != nil {
		s.Error("failed to fetch user", "err", err)
		return e.NoContent(http.StatusInternalServerError)
	}

	if err := bcrypt.CompareHashAndPassword([]byte(user.Hash), []byte(session.Password)); err != nil {
		return e.JSONBlob(http.StatusUnauthorized, errInvalidCredentials)
	}

	return e.NoContent(http.StatusOK)
}
开发者ID:zqzca,项目名称:back,代码行数:20,代码来源:create.go

示例4: Get

func (ee *EventEndpoints) Get(c echo.Context) error {
	eventID := c.Param("sg_event_id")

	cachedResponse := ee.CacheAdaptor.GetEvent(eventID)
	if cachedResponse != "" {
		log.Println("returning cached response")

		return c.JSONBlob(http.StatusOK, []byte(cachedResponse))
	}

	event, err := ee.DBAdaptor.GetEvent(eventID)
	if err != nil {
		log.Println("error returning data from cassandra: " + err.Error())

		return c.JSON(http.StatusInternalServerError, ControllerError{
			Message: "Something went wrong retrieving data from storage",
		})
	}

	return c.JSON(http.StatusOK, event)
}
开发者ID:efimovalex,项目名称:EventKitAPI,代码行数:21,代码来源:event_endpoints.go

示例5: appPatch

func appPatch(c echo.Context) error {
	data := []byte{}
	fmt.Println(data)
	return c.JSONBlob(http.StatusOK, data)
}
开发者ID:asyoume,项目名称:paas_srv,代码行数:5,代码来源:app.go

示例6: Get

func (ee *EventsEndpoints) Get(c echo.Context) error {
	headers := c.Response().Header()
	headers.Set("Cache-Control", "private, max-age=600")

	var nextPage string

	queryString := []byte(c.Request().URL().QueryString())

	cachedResponse := ee.CacheAdaptor.GetEventRequest(queryString)
	if cachedResponse != "" {
		log.Println("returning cached response")

		return c.JSONBlob(http.StatusOK, []byte(cachedResponse))
	}

	offsetID := c.QueryParam("offset_id")
	limit, err := strconv.Atoi(c.QueryParam("limit"))
	if err != nil || limit == 0 {
		limit = 50
	}

	fieldName := c.QueryParam("field_name")

	var events []database.Event
	var getErr error

	if fieldName == Timestamp {
		startValue := c.QueryParam("start_date")
		if startValue == "" {
			return c.JSON(http.StatusBadRequest, ControllerError{
				Message: "Start date is required for fieldValue = day",
			})
		}
		startDate, timeErr := time.Parse(date, startValue)
		if timeErr != nil {
			log.Println("Could not convert start date: " + timeErr.Error())

			return c.JSON(http.StatusBadRequest, ControllerError{
				Message: "Could not convert start date ",
			})
		}

		endValue := c.QueryParam("end_date")
		if endValue != "" {
			endDate, timeErr := time.Parse(date, endValue)
			if timeErr != nil {
				log.Println("Could not convert end date: " + timeErr.Error())

				return c.JSON(http.StatusBadRequest, ControllerError{
					Message: "Could not convert end date ",
				})
			}
			events, getErr = ee.DBAdaptor.GetEventsInInterval(startDate, endDate, limit, offsetID)

		} else {
			events, getErr = ee.DBAdaptor.GetEventsInInterval(startDate, time.Now(), limit, offsetID)
		}
	} else {
		fieldValue := c.QueryParam("field_value")
		events, getErr = ee.DBAdaptor.GetEvents(fieldName, fieldValue, limit, offsetID)

		if len(events) == limit-1 {
			nextPage = fmt.Sprintf("%s%s?field_name=%s&field_value=%s&limit=%d&offset_id=%s", URL, c.Get("route"), fieldName, fieldValue, limit, events[limit-1].SGEventID)
		}
	}

	if getErr != nil {
		log.Println("error returning data from cassandra: " + getErr.Error())

		return c.JSON(http.StatusInternalServerError, ControllerError{
			Message: "Something went wrong retrieving data from storage",
		})
	}

	var response common.ListResponse

	if len(events) < limit {
		response = common.ListResponse{
			Events: events}
	} else {
		response = common.ListResponse{
			Events:   events,
			NextPage: nextPage,
		}
	}

	ee.CacheAdaptor.SaveEventRequest(queryString, response)

	return c.JSON(http.StatusOK, response)
}
开发者ID:efimovalex,项目名称:EventKitAPI,代码行数:90,代码来源:events_endpoints.go


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