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


Golang Render.JSON方法代码示例

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


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

示例1: AdminGetModels

func AdminGetModels(params martini.Params, r render.Render) {
	var itemList []string
	for k, _ := range models {
		itemList = append(itemList, k)
	}
	r.JSON(200, map[string]interface{}{"models": itemList})
}
开发者ID:ronlobo,项目名称:gae-go-starter-martini,代码行数:7,代码来源:admin.go

示例2: MediaCreate

func MediaCreate(db gorm.DB, r render.Render, media models.Media) {
	if err := db.Save(&media).Error; err != nil {
		r.JSON(http.StatusConflict, map[string]interface{}{"error": "Media conflict"})
		return
	}
	r.JSON(http.StatusCreated, media)
}
开发者ID:RadioTerminal,项目名称:podcaster,代码行数:7,代码来源:media.go

示例3: ReadListQnA

func ReadListQnA(req *http.Request, r render.Render, db *mgo.Database) {
	appid := req.Header.Get("Application-Id")
	if appid == "" {
		r.JSON(handlers.HttpErr(http.StatusNotFound, "insert to Application-Id"))
		return
	}
	////
	colQuerier := bson.M{}
	change := bson.M{"$set": bson.M{"reception": true}}
	CollectionName := handlers.CollectionNameQnA(appid)
	if _, err := db.C(CollectionName).UpdateAll(colQuerier, change); err != nil {
		r.JSON(handlers.HttpErr(http.StatusNotFound, err.Error()))
		return
	}
	var qnas []QnA
	if err := db.C(CollectionName).Find(bson.M{}).Sort("-time").All(&qnas); err != nil {
		r.JSON(handlers.HttpErr(http.StatusNotFound, err.Error()))
		return
	}

	if qnas == nil {
		r.JSON(http.StatusOK, map[string]interface{}{"return": bson.D{}})
		return
	}

	r.JSON(http.StatusOK, map[string]interface{}{"return": qnas})
}
开发者ID:haruio,项目名称:haru-golang-helpcenter,代码行数:27,代码来源:QnAController.go

示例4: ListBuckets

func ListBuckets(r render.Render, db database.Database) {
	if buckets, err := db.ListBuckets(); err != nil {
		JsonErrorf(r, http.StatusBadRequest, err.Error())
	} else {
		r.JSON(http.StatusOK, buckets)
	}
}
开发者ID:aroravishal,项目名称:changes-artifacts,代码行数:7,代码来源:buckethandler.go

示例5: GetAllRelations

//Get /users/:user_id/relationships
func (u *UserHandler) GetAllRelations(request *http.Request, rd render.Render, params martini.Params) {
	// 获取 url 参数
	userid, err := strconv.ParseInt(params["user_id"], 10, 64)
	if err != nil {
		rd.Text(400, "The request cannot be fulfilled due to bad syntax.")
		return
	}

	//验证 user 是否存在
	_, err = u.userService.GetUser(userid)
	if err != nil {
		if err == pg.ErrNoRows {
			rd.Text(400, fmt.Sprintln("user", userid, "not exist"))
		} else {
			rd.Text(500, err.Error())
		}
		return
	}

	rs, err := u.userService.GetUserRelations(userid)
	if err != nil {
		rd.Text(500, err.Error())
		return
	}

	relations := make([]interface{}, 0, 0)
	for _, r := range rs {
		relations = append(relations, fmtRelationShip(r))
	}

	rd.JSON(200, relations)
}
开发者ID:Arthurli,项目名称:RestfulDemo,代码行数:33,代码来源:user.go

示例6: CollectionResponse

func CollectionResponse(r render.Render, collection []interface{}, err error) {
	if err != nil {
		r.JSON(404, nil)
	} else {
		r.JSON(200, collection)
	}
}
开发者ID:jartek,项目名称:meh,代码行数:7,代码来源:server.go

示例7: createUser

func createUser(r render.Render, re *http.Request, f *fishhub.DBService, userForm user.UserForm) {
	userExistError := binding.Error{
		Message:        "is already taken",
		FieldNames:     []string{"email"},
		Classification: "UserExistError",
	}
	errors := binding.Errors{userExistError}
	if userExist(f, userForm.UserId) {
		r.JSON(400, errors)
		return
	}

	d := f.DB.Copy()
	defer d.Close()

	query := bson.M{"userid": userForm.UserId}
	update := bson.M{"$set": userForm}
	updated, _ := d.Upsert("users", query, nil, update, true)

	if updated == true {
		r.JSON(200, map[string]interface{}{
			"message": "User profile is successfully created.",
		})
		return
	}

	displayUnknownError(r)
}
开发者ID:greensolutionsonly,项目名称:fishhub,代码行数:28,代码来源:user.go

示例8: Vote

func Vote(db model.Model, req *http.Request, r render.Render, params martini.Params) {
	id, err := strconv.Atoi(params["id"])
	if err != nil {
		r.JSON(404, ErrorEnv{"invalid quote id"})
		return
	}

	count, err := strconv.Atoi(req.FormValue("count"))
	if err != nil {
		r.JSON(404, ErrorEnv{"invalid vote count"})
		return
	}

	err = db.VoteQuote(id, count)
	if err != nil {
		r.JSON(500, ErrorEnv{"unable to vote quote"})
		return
	}

	quote, err := db.GetQuote(id)
	if err != nil {
		r.JSON(404, ErrorEnv{"quote not found"})
		return
	}

	env := struct {
		Score int `json:"score"`
	}{quote.Score}
	r.JSON(200, env)
}
开发者ID:firba1,项目名称:irq,代码行数:30,代码来源:vote.go

示例9: Index

func Index(r render.Render) {
	type homeStats struct {
		RepoCount  int
		IssueCount int
		UserCount  int
		IssueLangs []string
	}

	stats := homeStats{}

	c.DB.Model(c.Repository{}).Count(&stats.RepoCount)
	c.DB.Model(c.Issue{}).Count(&stats.IssueCount)
	c.DB.Model(c.User{}).Count(&stats.UserCount)

	rows := c.DB.Raw(`select distinct language
		from issues
		inner join repositories on repositories.id = issues.repository_id
		where language != ''
		order by language
	`)

	rows.Pluck("language", &stats.IssueLangs)

	r.JSON(200, stats)
}
开发者ID:jakeporter,项目名称:govcode.org,代码行数:25,代码来源:main.go

示例10: Random

func Random(db model.Model, r render.Render, req *http.Request, isJson IsJson) {
	qs := req.URL.Query()

	search := qs.Get("query")

	maxLines, err := strconv.Atoi(qs.Get("max-lines"))
	if err != nil || maxLines < 1 {
		maxLines = 0
	}

	quotes, err := db.GetQuotes(model.Query{
		Limit:       1,
		Search:      search,
		MaxLines:    maxLines,
		OrderBy:     []string{"rand()"},
		IncludeTags: qs["tags"],
		ExcludeTags: qs["exclude-tags"],
	})

	if err != nil || len(quotes) == 0 {
		RenderError(r, 500, isJson, fmt.Sprint("quote not found", err))
		return
	}

	quote := quotes[0]

	if isJson {
		r.JSON(200, quote)
	} else {
		r.Redirect(fmt.Sprintf("/quote/%d", quote.ID))
	}
}
开发者ID:firba1,项目名称:irq,代码行数:32,代码来源:random.go

示例11: LoginHandler

func LoginHandler(r render.Render, user model.User, appx *appx.Datastore) {
	response := model.Response{
		ErrorCode: http.StatusOK,
		Message:   []string{},
		Data:      nil,
	}

	isValid, validationErr := user.IsValid()

	if !isValid {
		response.ErrorCode = http.StatusBadRequest
		response.Message = validationErr
	} else {
		err := appx.Save(&user)

		if err != nil {
			log.Printf("Error: %v", err)
			response.ErrorCode = http.StatusInternalServerError
			response.Message = append(response.Message, err.Error())
		} else {
			response.Data = user
		}
	}

	r.JSON(200, response)

}
开发者ID:BearchInc,项目名称:fala-com-meu-carro,代码行数:27,代码来源:login_handler.go

示例12: PostIdeaHandler

func PostIdeaHandler(req *http.Request, render render.Render, log *log.Logger) {
	log.Println("Receive post data.")
	name := req.FormValue("name")
	email := req.FormValue("email")
	link := req.FormValue("link")
	content := req.FormValue("content")
	log.Println("Name: " + name)
	log.Println("Email: " + email)
	log.Println("Link: " + link)
	log.Println("Content: " + content)
	if len(name) == 0 {
		render.JSON(400, map[string]interface{}{"error": 1, "message": "Empty name."})
		return
	}
	if len(email) == 0 {
		render.JSON(400, map[string]interface{}{"error": 2, "message": "Empty email."})
		return
	}
	if len(content) == 0 {
		render.JSON(400, map[string]interface{}{"error": 3, "message": "Empty content."})
		return
	}
	AddIdea(name, email, link, content)
	render.JSON(200, map[string]interface{}{"error": 0})
}
开发者ID:imdreamrunner,项目名称:orz,代码行数:25,代码来源:main.go

示例13: request

func (this *EurekaRequestGet) request(data interface{}, r render.Render, req *http.Request) {
	if req.URL.Query().Get("json") != "" {
		r.JSON(200, data)
	} else {
		r.XML(200, data)
	}
}
开发者ID:ArthurHlt,项目名称:microcos,代码行数:7,代码来源:eureka_request_get.go

示例14: ListBuckets

func ListBuckets(ctx context.Context, r render.Render, db database.Database) {
	if buckets, err := db.ListBuckets(); err != nil {
		LogAndRespondWithError(ctx, r, http.StatusBadRequest, err)
	} else {
		r.JSON(http.StatusOK, buckets)
	}
}
开发者ID:dropbox,项目名称:changes-artifacts,代码行数:7,代码来源:buckethandler.go

示例15: UpdateQuestion

/**
更新
**/
func UpdateQuestion(r render.Render, req *http.Request) {
	c := appengine.NewContext(req)
	id, _ := strconv.Atoi(req.FormValue("Key"))
	key := datastore.NewKey(c, "Question", "", int64(id), nil)
	var question Question
	if err := datastore.Get(c, key, &question); err != nil {
		c.Criticalf(err.Error())
	}
	question.Content = req.FormValue("Content")
	question.LargeCategoryKey = req.FormValue("LargeCategoryKey")
	question.MediumCategoryKey = req.FormValue("MediumCategoryKey")
	question.SmallCategoryKey = req.FormValue("SmallCategoryKey")
	question.Rubric = req.FormValue("Rubric")
	question.Percentage, _ = strconv.ParseFloat(req.FormValue("Percentage"), 64)
	question.Status = req.FormValue("Status")
	question.Level = req.FormValue("Level")
	question.UserKey = req.FormValue("UserKey")
	_, err := datastore.Put(c, key, &question)
	if err != nil {
		c.Criticalf("%s", err)
		r.JSON(400, err)
	} else {
		r.JSON(200, question)
	}
}
开发者ID:KojiTakahara,项目名称:dragon-formula,代码行数:28,代码来源:questionController.go


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