當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。