本文整理汇总了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)
}
示例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)
}
示例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)
}
示例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)
}
示例5: appPatch
func appPatch(c echo.Context) error {
data := []byte{}
fmt.Println(data)
return c.JSONBlob(http.StatusOK, data)
}
示例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)
}