本文整理匯總了Golang中github.com/gin-gonic/gin.Context.Render方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Render方法的具體用法?Golang Context.Render怎麽用?Golang Context.Render使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gin-gonic/gin.Context
的用法示例。
在下文中一共展示了Context.Render方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Index
func (r *StatesResource) Index(c *gin.Context) {
var s []*models.State
search := bson.M{}
err := r.DB.Find(search, GetLimit(c.Request), 1, "-updatedat", &s)
if err != nil {
c.JSON(500, gin.H{"error": "500", "message": err.Error()})
} else {
if len(s) == 0 {
c.JSON(200, gin.H{"states": []string{}})
return
}
for i, _ := range s {
s[i].Capital = r.getCapital(s[i].CapitalId)
s[i].Links = r.getStateLinks(*s[i])
}
data := gin.H{
"states": s,
}
render := &DataRender{c.Request, data}
c.Render(200, render)
}
}
示例2: Lines
func (self TrainsSpResource) Lines(c *gin.Context) {
var l []*models.Line
err := self.DB.Find(bson.M{}, GetLimit(c.Request), 1, "linenumber", &l)
if err != nil {
c.JSON(500, gin.H{"error": "500", "message": err.Error()})
} else {
done := make(chan bool)
go func() {
self.setLinks(l)
self.setStatus(l)
done <- true
}()
<-done
data := gin.H{
"lines": l,
"paging": pagination(
"v1/sp/metro/lines",
self.DB,
GetLimit(c.Request),
1,
models.Line{},
bson.M{},
),
}
render := &DataRender{c.Request, data}
c.Render(200, render)
}
}
示例3: Get
func (r *ParliamentarianResource) Get(c *gin.Context) {
uri := c.Params.ByName("uri")
var p models.Parliamentarian
err := r.DB.FindOne(bson.M{"id": uri}, &p)
done := make(chan bool)
go func() {
p.Links = r.getLink(p.Id)
p.Memberships = r.getMemberships(p.Id)
done <- true
}()
<-done
if err != nil {
c.JSON(404, gin.H{"error": "404", "message": err.Error()})
} else {
render := &DataRender{c.Request, gin.H{"parliamentarian": p}}
c.Render(200, render)
}
}
示例4: Index
func (r *ParliamentarianResource) Index(c *gin.Context) {
var p []*models.Parliamentarian
search := bson.M{}
query := c.Request.URL.Query()
identifier := query.Get("identifier")
if identifier != "" {
search["identifiers"] = bson.M{
"$elemMatch": bson.M{
"identifier": identifier,
},
}
}
pageS := query.Get("page")
if pageS == "" {
pageS = "1"
}
page, _ := strconv.Atoi(pageS)
err := r.DB.Find(search, GetLimit(c.Request), page, "-updatedat", &p)
if err != nil {
c.JSON(500, gin.H{"error": "500", "message": err.Error()})
} else {
if len(p) == 0 {
c.JSON(200, gin.H{"parliamentarians": []string{}})
return
}
done := make(chan bool)
go func() {
r.setLinks(p)
r.setMemberships(p)
done <- true
}()
<-done
data := gin.H{
"parliamentarians": p,
"paging": pagination(
"v1/parliamentarians",
r.DB,
GetLimit(c.Request),
page,
models.Parliamentarian{},
search,
),
}
render := &DataRender{c.Request, data}
c.Render(200, render)
}
}
示例5: Get
func (r *PartyResource) Get(c *gin.Context) {
uri := c.Params.ByName("uri")
var p models.Party
err := r.DB.FindOne(bson.M{"id": uri}, &p)
if err != nil {
c.JSON(404, gin.H{"error": "404", "message": err.Error()})
} else {
c.Render(200, DataRender{c.Request}, gin.H{"party": p})
}
}
示例6: Get
func (r *StatesResource) Get(c *gin.Context) {
uri := c.Params.ByName("uri")
var s models.State
err := r.DB.FindOne(bson.M{"id": uri}, &s)
if err != nil {
c.JSON(404, gin.H{"error": "404", "message": err.Error()})
} else {
s.Capital = r.getCapital(s.CapitalId)
s.Links = r.getStateLinks(s)
c.Render(200, DataRender{c.Request}, gin.H{"state": s})
}
}
示例7: Cities
func (s *StatesResource) Cities(c *gin.Context) {
var ci []*models.City
stateUri := c.Params.ByName("uri")
query := c.Request.URL.Query()
search := bson.M{"stateid": stateUri}
pageS := query.Get("page")
if pageS == "" {
pageS = "1"
}
page, _ := strconv.Atoi(pageS)
err := s.DB.Find(search, GetLimit(c.Request), page, "-updatedat", &ci)
if err != nil {
c.JSON(500, gin.H{"error": "500", "message": err.Error()})
} else {
if len(ci) == 0 {
c.JSON(200, gin.H{"cities": []string{}})
return
}
done := make(chan bool)
go func() {
s.setCitiesLinks(ci)
done <- true
}()
<-done
data := gin.H{
"cities": ci,
"paging": pagination(
"v1/states/"+stateUri+"/cities",
s.DB,
GetLimit(c.Request),
page,
models.City{},
search,
),
}
render := &DataRender{c.Request, data}
c.Render(200, render)
}
}
示例8: GetLineStatuses
func (self TrainsSpResource) GetLineStatuses(c *gin.Context) {
uri := c.Params.ByName("line_uri")
var s []*models.Status
err := self.DB.Find(bson.M{"line_id": uri}, GetLimit(c.Request), 1, &s)
if err != nil {
c.JSON(404, gin.H{"error": "404", "message": err.Error()})
} else {
done := make(chan bool)
go func() {
self.setStatusLinks(s)
done <- true
}()
<-done
c.Render(200, DataRender{c.Request}, gin.H{"statuses": s})
}
}
示例9: GetLineStatus
func (self TrainsSpResource) GetLineStatus(c *gin.Context) {
uri := c.Params.ByName("line_uri")
statusId := bson.ObjectIdHex(c.Params.ByName("status_id"))
var status models.Status
err := self.DB.FindOne(bson.M{"line_id": uri, "_id": statusId}, &status)
if err != nil {
c.JSON(404, gin.H{"error": "404", "message": err.Error()})
} else {
done := make(chan bool)
go func() {
status.Links = self.getStatusLink(uri, status.Id)
done <- true
}()
<-done
c.Render(200, DataRender{c.Request}, gin.H{"status": status})
}
}
示例10: GetCity
func (s *StatesResource) GetCity(c *gin.Context) {
var city models.City
stateUri := c.Params.ByName("uri")
cityUri := c.Params.ByName("city_uri")
q := bson.M{"stateid": stateUri, "id": cityUri}
err := s.DB.FindOne(q, &city)
if err != nil {
c.JSON(404, gin.H{"error": "404", "message": err.Error()})
} else {
done := make(chan bool)
go func() {
city.Links = s.setCityLinks(city)
done <- true
}()
<-done
c.Render(200, DataRender{c.Request}, gin.H{"city": city})
}
}
示例11: Index
func (r *ReservoirSpResource) Index(c *gin.Context) {
var rv []struct {
Id string `bson:"_id" json:"granularity"`
Reservoirs []models.Reservoir `json:"reservoirs"`
}
search := bson.M{}
err := r.DB.FindAndGroupBy("granularity", search, &rv, models.Reservoir{})
if err != nil {
c.JSON(500, gin.H{"error": "500", "message": err.Error()})
} else {
data := make(map[string][]models.Reservoir, 0)
for _, item := range rv {
data[item.Id] = item.Reservoirs
}
c.Render(200, DataRender{c.Request}, data)
}
}
示例12: GetLine
func (self TrainsSpResource) GetLine(c *gin.Context) {
uri := c.Params.ByName("line_uri")
var l models.Line
err := self.DB.FindOne(bson.M{"id": uri}, &l)
if err != nil {
c.JSON(404, gin.H{"error": "404", "message": err.Error()})
} else {
done := make(chan bool)
go func() {
l.Links = self.getLink(l.Id, l.CannonicalUri)
l.Status = self.getStatus(l.CannonicalUri)
done <- true
}()
<-done
c.Render(200, DataRender{c.Request}, gin.H{"line": l})
}
}
示例13: Index
func (r *PartyResource) Index(c *gin.Context) {
var p []*models.Party
search := bson.M{}
query := c.Request.URL.Query()
pageS := query.Get("page")
if pageS == "" {
pageS = "1"
}
page, _ := strconv.Atoi(pageS)
err := r.DB.Find(search, GetLimit(c.Request), page, "-updatedat", &p)
if err != nil {
c.JSON(500, gin.H{"error": "500", "message": err.Error()})
} else {
if len(p) == 0 {
c.JSON(200, gin.H{"parties": []string{}})
return
}
data := gin.H{
"parties": p,
"paging": pagination(
"v1/parties",
r.DB,
GetLimit(c.Request),
page,
models.Party{},
search,
),
}
render := &DataRender{c.Request, data}
c.Render(200, render)
}
}