本文整理汇总了Golang中lib/server.App类的典型用法代码示例。如果您正苦于以下问题:Golang App类的具体用法?Golang App怎么用?Golang App使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了App类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setupAPIAPITokens
func setupAPIAPITokens(app *server.App) {
var API = app.API()
// --------------------------------------------------------------------------
// APIToken
API.GET("/api_tokens/",
middleware.EntityAll(entities.APIToken.Query()))
API.GET("/api_tokens/:token.json",
middleware.EntityGet(entities.APIToken.Get().Cache(true), "token"))
API.POST("/api_tokens/",
middleware.ParseForm(func(v *validators.FormValidator) {
v.Field("description").Required()
}),
middleware.EntityPost(entities.APIToken.Put()))
API.PUT("/api_tokens/:token.json",
middleware.ParseForm(func(v *validators.FormValidator) {
v.Field("description").Required()
}),
middleware.EntityPut(entities.APIToken.Put(), "token"))
API.DELETE("/api_tokens/:token.json",
middleware.EntityDelete(entities.APIToken.Delete(), "token"))
}
示例2: setupAPIStats
func setupAPIStats(app *server.App) {
var API = app.API()
// --------------------------------------------------------------------------
// Stats
API.GET("/stats/",
server.Handler(func(req *wcg.Request) response.Response {
stats, _ := runtime.Stats(gae.NewContext(req))
json := map[string]interface{}{
"version": lib.Commit,
"timestamp": lib.Timestamp,
"stats": stats,
"environment": lib.CurrentEnvironment(),
"envvars": lib.GetEnvVars(),
}
if _, dsStats, err := entities.DatastoreStat.Get().Key("total_entities_usage").One(req); err != nil {
json["datastore"] = dsStats
}
// use array response for API convention.
return response.NewJSONResponse(
[](map[string]interface{}){
json,
},
)
}))
}
示例3: setupAPIConfigs
func setupAPIConfigs(app *server.App) {
var API = app.API()
// --------------------------------------------------------------------------
// Sever Config
API.GET("/configs/",
server.Handler(func(req *wcg.Request) response.Response {
return response.NewJSONResponse(configs.GetAll(req))
}))
API.GET("/configs/:key.json",
server.Handler(func(req *wcg.Request) response.Response {
val := configs.Get(req, req.Param("key"))
if val == nil {
return response.NotFound(req)
} else {
return response.NewJSONResponse(val)
}
}),
)
API.PUT("/configs/:key.json",
middleware.ParseForm(func(v *validators.FormValidator) {
v.Field("value").Required()
}),
server.Handler(func(req *wcg.Request) response.Response {
val := configs.Get(req, req.Param("key"))
if val == nil {
return response.NotFound(req)
} else {
val.Value = req.Form("value")
configs.PutMulti(req, val)
return response.NewJSONResponse(val)
}
}))
}
示例4: setupAPIGates
func setupAPIGates(app *server.App) {
var API = app.API()
// --------------------------------------------------------------------------
// Gate
API.GET("/gates/",
server.Handler(func(req *wcg.Request) response.Response {
return response.NewJSONResponse(gates.GetAll(req))
}))
API.GET("/gates/:key.json",
server.Handler(func(req *wcg.Request) response.Response {
val := gates.Get(req, req.Param("key"))
if val == nil {
return response.NotFound(req)
} else {
return response.NewJSONResponse(val)
}
}))
API.PUT("/gates/:key.json",
middleware.ParseForm(nil),
server.Handler(func(req *wcg.Request) response.Response {
val := gates.Get(req, req.Param("key"))
if val == nil {
return response.NotFound(req)
} else {
val.UIDs = req.HTTPRequest().Form["uids"]
gates.PutMulti(req, val)
return response.NewJSONResponse(val)
}
}))
}
示例5: setupAPIMembers
func setupAPIMembers(app *server.App) {
var API = app.API()
API.GET("/:artist/members/",
handlers.ArtistHandler(
func(req *wcg.Request, artist *hplink.Artist) response.Response {
memberQuery := Member.Query().Order("Index").Filter("ArtistKey=", artist.Key).Cache(fmt.Sprintf(ckAllMembersTemplate, artist.Key))
return middleware.EntityAll(memberQuery)(req)
},
))
API.GET("/:artist/members/:member.json",
handlers.MemberHandler(
func(req *wcg.Request, member *hplink.Member) response.Response {
return response.NewJSONResponse(member)
},
),
)
API.PUT("/:artist/members/:member.json",
handlers.AdminGate,
middleware.ParseForm(func(v *validators.FormValidator) {
v.Field("color").Required()
}),
handlers.MemberHandler(
func(req *wcg.Request, member *hplink.Member) response.Response {
if err := Member.UpdateEntityFromForm(member, req.HTTPRequest().Form); err != nil {
req.Logger.Warnf("UpdateEntityFromForm returns and error: %#v", err)
return response.APIBadRequest(middleware.ErrInvalidFormParameters)
}
Member.Put().Cache(ckAllMembersTemplate).MustUpdate(req, member)
return response.NewJSONResponse(member)
},
),
)
}
示例6: setupCronIEPGDailyNotification
func setupCronIEPGDailyNotification(app *server.App) {
var Cron = app.Cron()
Cron.Define(
"/records/notificatoin/daily/",
"every day 08:00",
"Notification for recordings today",
func(req *wcg.Request) error {
var hasError = false
var email = configs.GetValue(req, "intern.pt.notification_email")
messengerConfigs, err := getMessengerNotificationOptInUsers(req, "Summary")
if err != nil {
return err
}
content, err := createDailyNotificationContent(req)
if err != nil {
return err
}
if email == "" {
req.Logger.Warnf(
"No notification email address is specified (SiteConfig: %q)",
"intern.pt.notification_email",
)
} else {
err := notifications.NewEmail(
email,
content.title,
strings.Join(content.lines, "\n"),
).Deliver(req)
if err != nil {
req.Logger.Errorf("Failed to deliver an email notification: %v", err)
hasError = true
} else {
req.Logger.Infof("Sent an email notification to %s", email)
}
}
if len(messengerConfigs) == 0 {
req.Logger.Infof("No messenger configuration is found. Skipped")
}
for _, cfg := range messengerConfigs {
client := messenger.NewMessengerClient(req)
client.UserID = cfg.UserID
err := client.SendText(content.title + "\n" + strings.Join(content.lines, "\n"))
if err != nil {
req.Logger.Errorf("Failed to deliver a messenger notification: %v", err)
hasError = true
} else {
req.Logger.Infof("Sent a messenger notification to %s", client.UserID)
}
}
if hasError {
return fmt.Errorf("Something wrong in daily notification cron. Check error logs.")
}
return nil
},
)
}
示例7: setupPage
func setupPage(app *server.App) {
var Page = app.Page()
Page.GET("/", page.Title("ダッシュボード"))
Page.GET("/configs.html", page.Title("サイト設定"))
Page.GET("/gates.html", page.Title("ゲート設定"))
Page.GET("/api_tokens.html", page.Title("APIトークン設定"))
Page.GET("/oauth2/", page.Title("OAuth2クライアント設定"))
}
示例8: setupPage
func setupPage(app *server.App) {
var Page = app.Page()
gate := server.NewPageInstanceHandler(middleware.Gate("family"))
Page.GET("/", gate, page.Title("テレビ予約一覧"))
Page.GET("/keywords.html", gate, page.Title("キーワード一覧"))
Page.GET("/exclusions.html", gate, page.Title("除外ルール一覧"))
Page.GET("/channels.html", gate, page.Title("チャンネル一覧"))
Page.GET("/configs.html", gate, page.Title("設定"))
}
示例9: setupAPIUsers
func setupAPIUsers(app *server.App) {
var API = app.API()
API.GET("/me/",
server.Handler(func(req *wcg.Request) response.Response {
if req.User == nil || request.ByGuest(req) {
return response.NewJSONResponse(nil)
}
return response.NewJSONResponse(req.User)
}))
API.POST("/me/gates/",
server.Handler(func(req *wcg.Request) response.Response {
keys := strings.Split(req.Form("keys"), ",")
result := gates.EvalKeys(req, keys...)
return response.NewJSONResponse(result)
}))
}
示例10: setupPage
func setupPage(app *server.App) {
var Page = app.Page()
Page.GET("/admin/", handlers.AdminGatePage, page.Title("アーティスト一覧"))
Page.GET("/admin/ameblo/", handlers.AdminGatePage, page.Title("Ameblo 設定"))
Page.GET("/admin/:artist/", handlers.AdminGatePage,
handlers.ArtistPageHandler(func(req *wcg.Request, pr *response.PageResponse, artist *hplink.Artist) *response.PageResponse {
pr.Title = artist.Name
pr.ReactModulePath = "/hplink/admin/artist.jsx"
return pr
}),
)
Page.GET("/admin/:artist/members/:member/", handlers.AdminGatePage,
handlers.MemberPageHandler(func(req *wcg.Request, pr *response.PageResponse, member *hplink.Member) *response.PageResponse {
pr.Title = fmt.Sprintf("%s / %s", member.Name, member.Artist.Name)
pr.ReactModulePath = "/hplink/admin/member.jsx"
return pr
}),
)
}
示例11: setupAPITasks
func setupAPITasks(app *server.App) {
var API = app.API()
API.GET("/tasks/", server.Handler(
middleware.EntityQuery(
entities.AsyncAPITask.Query().Filter(
"UpdatedAt >=",
request.Value(func(req *wcg.Request) interface{} {
return wcg.ParseDateOr(req.Query("since"), lib.Now().Add(-_TaskExpirationDays))
}),
).Filter(
"UpdatedAt <=",
request.Value(func(req *wcg.Request) interface{} {
return wcg.ParseDateOr(req.Query("until"), lib.Now())
}),
),
),
))
}
示例12: setupAPIIEPGExclusions
func setupAPIIEPGExclusions(app *server.App) {
var AsyncAPI = app.AsyncAPI()
var API = app.API()
API.GET("/iepg/exclusions/", middleware.EntityAll(IEPGExclusion.Query().Cache(_CacheAllIEPGExclusions)))
exclusionTask := AsyncAPI.Define("/iepg/exclusions/task/")
exclusionTask.Queue.Rate = "1/s"
exclusionTask.Queue.MaxConcurrentRequests = "1"
exclusionTask.OnTrigger(middleware.Gate("family"))
exclusionTask.OnMonitor(middleware.Gate("family"))
exclusionTask.OnProcess(server.AsyncTaskHandler(
func(req *wcg.Request, t *models.AsyncAPITask) (*models.AsyncAPITaskProgress, error) {
var list []*pt.IEPG
records := recentRecordsQuery().MustExecute(req).Data.([]pt.IEPG)
for i := range records {
list = append(list, &records[i])
}
if err := applyExclusions(req, list); err != nil {
return nil, err
}
IEPG.PutMulti().Cache(_CacheAllIEPGExclusions).MustUpdate(req, list)
return nil, nil
},
))
API.POST("/iepg/exclusions/",
middleware.Gate("family"),
middleware.ParseForm(func(v *validators.FormValidator) {
v.Field("cid").Required()
v.Field("sid").Required()
v.Field("weekday").Required()
v.Field("title_text").Required()
v.Field("title_text_type").Required()
}),
middleware.EntityPost(IEPGExclusion.Put().Cache(_CacheAllIEPGExclusions)),
)
API.DELETE("/iepg/exclusions/:id.json",
middleware.Gate("family"),
middleware.EntityDelete(IEPGExclusion.Delete().Cache(_CacheAllIEPGExclusions), "id"))
}
示例13: setupAPIChannels
func setupAPIChannels(app *server.App) {
var API = app.API()
API.GET("/channels/",
middleware.EntityAll(Channel.Query().Cache(_CacheAllChannels)))
API.POST("/channels/",
middleware.Gate("family"),
middleware.ParseForm(func(v *validators.FormValidator) {
v.Field("cid").Required()
v.Field("sid").Required()
v.Field("name").Required()
v.Field("iepg_station_id").Required()
}),
middleware.EntityPost(Channel.Put().Cache(_CacheAllChannels)))
API.DELETE("/channels/:id.json",
middleware.Gate("family"),
middleware.EntityDelete(Channel.Delete().Cache(_CacheAllChannels), "id"))
}
示例14: setupAPIArtist
func setupAPIArtist(app *server.App) {
var API = app.API()
API.GET("/",
server.Handler(func(req *wcg.Request) response.Response {
pArtists := entities.Artist.Query().Order("Index").Cache(ckAllArtits).MustExecute(req)
artist := pArtists.Data.([]hplink.Artist)
if req.Query("w") == "members" {
iterator.MustParallelSlice(artist, func(i int, a *hplink.Artist) error {
pMembers := entities.Member.Query().Order("Index").Filter("ArtistKey=", a.Key).Cache(fmt.Sprintf(ckAllMembersTemplate, a.Key)).MustExecute(req)
artist[i].Members = pMembers.Data.([]hplink.Member)
return nil
})
}
return response.NewJSONResponse(artist)
}),
)
API.GET("/:artist/",
middleware.EntityGet(entities.Artist.Get().Cache(true), "artist"))
}
示例15: setupAPIConfigs
func setupAPIConfigs(app *server.App) {
var API = app.API()
API.GET("/configs/:userid/messenger.json",
middleware.Gate("family"),
validateUserID,
requireMessengeOptIn,
server.Handler(
func(req *wcg.Request) response.Response {
_, one := MessengerNotification.Get().Key(req.Param("userid")).UseDefaultIfNil(true).Cache(true).MustOne(req)
return response.NewJSONResponse(one)
},
))
API.PUT("/configs/:userid/messenger.json",
middleware.Gate("family"),
validateUserID,
requireMessengeOptIn,
middleware.ParseForm(nil),
middleware.EntityPutOrCreate(MessengerNotification.Put(), "userid"))
API.POST("/configs/:userid/messenger/notify/",
middleware.Gate("family"),
validateUserID,
requireMessengeOptIn,
server.Handler(
func(req *wcg.Request) response.Response {
content, err := createDailyNotificationContent(req)
if err != nil {
return response.InternalServerError(req, err)
}
err = messenger.NewMessengerClient(req).SendText(content.title + "\n" + strings.Join(content.lines, "\n"))
if err != nil {
req.Logger.Errorf("Failed to notify a message to messenger: %v", err)
}
return response.NewJSONResponse(map[string]interface{}{
"ok": true,
})
},
))
}