本文整理汇总了Golang中github.com/martini-contrib/binding.Json函数的典型用法代码示例。如果您正苦于以下问题:Golang Json函数的具体用法?Golang Json怎么用?Golang Json使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Json函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
app := martini.Classic()
app.Use(db.DB())
app.Use(martini.Static("public"))
app.Use(render.Renderer(render.Options{
Directory: "views",
Layout: "layout",
Extensions: []string{".html"},
}))
app.Get("/", handlers.IndexHandler)
app.Group("/api", func(route martini.Router) {
route.Get("/info", handlers.GetInfoHandler)
route.Get("/items", handlers.GetItemsHandler)
route.Get("/items/:id", handlers.GetItemHandler)
route.Post("/items", binding.Json(types.Item{}), handlers.PostItemHandler)
route.Delete("/items/:id", handlers.DeleteItemHandler)
route.Put("/items/:id", binding.Json(types.Item{}), handlers.UpdateItemHandler)
})
http.ListenAndServe(config.Get("dev").Port, app)
}
开发者ID:roman01la,项目名称:go-rest-server,代码行数:26,代码来源:server.go
示例2: apiv1
func apiv1() {
url := "/api/v1"
m.Group(url+"/workplace", func(router martini.Router) {
router.Post("/auth", binding.Json(controllers.InputWorkplaceAuth{}), controllers.WorkplaceAuth)
//router.Post("/test", binding.Json(controllers.Test{}), controllers.WorkplacePing)
//router.Post("/add", binding.Json(controllers.Add{}), controllers.WorkplaceAdd)
//update
//delete
//import
}, render.Renderer())
m.Group(url+"/promocode", func(router martini.Router) {
router.Post("/calc", binding.Json(controllers.InputPromocodeCalc{}), controllers.PromocodeCalc)
//update
//delete
//import
}, render.Renderer())
m.Group(url+"/document", func(router martini.Router) {
router.Post("/add", binding.Json(controllers.InputDocumentAdd{}), controllers.DocumentAdd)
//update
//delete
//import
}, render.Renderer())
}
开发者ID:Ch16uR,项目名称:go-cls,代码行数:31,代码来源:route.go
示例3: UseApi
func (m *myClassic) UseApi(option ApiOption) error {
aipOption = option
m.Get("/api/v1/collections/:collectionId", getCollectionHandler)
m.Put("/api/v1/collections/:collectionId", updateCollectionHandler)
m.Delete("/api/v1/collections/:collectionId", deleteCollectionHandler)
m.Get("/api/v1/collections", getCollectionsHandler)
m.Post("/api/v1/collections", binding.Json(Collection{}), binding.ErrorHandler, createCollectionHandler)
m.Get("/api/v1/products/:productId", getProductHandler)
m.Post("/api/v1/products", binding.Json(Product{}), binding.ErrorHandler, createProductHandler)
m.Get("/api/v1/themes/:themeName", getThemeHandler)
m.Get("/api/v1/themes", getThemesHandler)
m.Post("/api/v1/themes", binding.Json(Theme{}), binding.ErrorHandler, createThemeHandler)
m.Get("/api/v1/pages", getPageHandler)
m.Post("/api/v1/pages", binding.Json(Page{}), binding.ErrorHandler, createPageHandler)
m.Get("/api/v1/templates/:templateName", getTemplateHandler)
m.Get("/api/v1/templates", getTemplatesHandler)
m.Post("/api/v1/templates", binding.Json(Template{}), binding.ErrorHandler, createTemplateHandler)
return nil
}
开发者ID:JasonSoft,项目名称:MyGo,代码行数:26,代码来源:api.go
示例4: route
// martini router
func route(m *martini.ClassicMartini) {
// regist a device
m.Post("/v1/devices/registration", binding.Json(DeviceRegisterArgs{}), RegisterDevice)
// auth device
m.Post("/v1/devices/authentication", binding.Json(DeviceAuthArgs{}), AuthDevice)
}
开发者ID:lg0491986,项目名称:pando-cloud,代码行数:9,代码来源:router.go
示例5: createHttpHandler
func createHttpHandler() http.Handler {
m := martini.Classic()
m.Use(render.Renderer())
// Make sure server is still responsive
m.Get("/ping", func() (int, string) {
return http.StatusOK, "pong"
})
m.Get("/v1/citizens", func(params martini.Params, r render.Render) {
citizens := cases.FindCitizens()
response := make([]Citizen, len(citizens), len(citizens))
for i, citizen := range citizens {
response[i].from(citizen)
}
r.JSON(http.StatusOK, response)
})
m.Post("/v1/citizens", binding.Json(Citizen{}), func(citizen Citizen, r render.Render) {
if citizen, err := cases.CreateCitizen(citizen.UID, citizen.Secret); err != nil {
r.JSON(http.StatusBadRequest, err)
} else {
response := Citizen{}
response.from(citizen)
r.JSON(http.StatusOK, response)
}
})
m.Patch("/v1/citizens/:uid", binding.Json(Citizen{}), func(params martini.Params, attributes Citizen, r render.Render) {
if citizen, err := cases.UpdateCitizen(params["uid"], attributes.to()); err != nil {
r.JSON(http.StatusBadRequest, err)
} else {
response := Citizen{}
response.from(citizen)
r.JSON(http.StatusOK, response)
}
})
m.Get("/v1/citizens/:uid", func(params martini.Params, r render.Render) {
if citizen, err := cases.FindCitizen(params["uid"]); err != nil {
r.JSON(http.StatusBadRequest, err)
} else {
response := Citizen{}
response.from(citizen)
r.JSON(http.StatusOK, response)
}
})
m.Put("/v1/identify", func(params martini.Params) (int, string) {
if token, err := cases.LoginCitizen(params["uid"], params["secret"]); err != nil {
return http.StatusInternalServerError, ""
} else {
return http.StatusOK, token
}
})
return m
}
开发者ID:vynetic,项目名称:citizens,代码行数:57,代码来源:rest.go
示例6: BindTaskApi
func BindTaskApi(m *martini.ClassicMartini) {
m.Get("/admin/task/list", binding.Form(tasklistForm{}), adminErrorHandler, tasklistHandler)
m.Get("/admin/task/timeline", binding.Form(userTaskForm{}), adminErrorHandler, userTaskHandler)
//m.Get("/admin/task/timeline", binding.Form(taskTimelineForm{}), adminErrorHandler, taskTimelineHandler)
m.Post("/admin/task/auth", binding.Json(taskAuthForm{}), adminErrorHandler, taskAuthHandler)
m.Options("/admin/task/auth", optionsHandler)
m.Post("/admin/task/auth_list", binding.Json(taskAuthListForm{}), adminErrorHandler, taskAuthListHandler)
m.Options("/admin/task/auth_list", optionsHandler)
}
开发者ID:shevilangle,项目名称:sports,代码行数:9,代码来源:task.go
示例7: NewTestServer
func NewTestServer() *httptest.Server {
m := createServer()
// Errors
m.Get("/throw400", throw400)
m.Get("/throw401", throw401)
m.Get("/throw404", throw404)
// Charges
m.Post("/charges", binding.Json(Charge{}), createCharge)
m.Get("/charges/:chargeId", getCharge)
m.Post("/charges/:chargeId/refund", refundCharge)
// Customers
m.Post("/customers", binding.Json(Customer{}), createCustomer)
m.Put("/customers/:customerId", binding.Json(Customer{}), updateCustomer)
m.Delete("/customers/:customerId", deleteCustomer)
m.Post("/customers/:customerId/cards", binding.Json(CreditCard{}), createCard)
m.Put("/customers/:customerId/cards/:cardId", binding.Json(CreditCard{}), updateCard)
m.Delete("/customers/:customerId/cards/:cardId", deleteCard)
m.Post("/customers/:customerId/subscription", binding.Json(Subscription{}), createSubscription)
m.Put("/customers/:customerId/subscription", binding.Json(Subscription{}), updateSubscription)
m.Post("/customers/:customerId/subscription/pause", pauseSubscription)
m.Post("/customers/:customerId/subscription/resume", resumeSubscription)
m.Post("/customers/:customerId/subscription/cancel", cancelSubscription)
// Plans
m.Post("/plans", binding.Json(Plan{}), createPlan)
m.Put("/plans/:planId", binding.Json(Plan{}), updatePlan)
m.Delete("/plans/:planId", deletePlan)
return httptest.NewServer(m)
}
开发者ID:mishudark,项目名称:conekta-go,代码行数:33,代码来源:conekta_suite_test.go
示例8: BindArticleApi
func BindArticleApi(m *martini.ClassicMartini) {
m.Get("/admin/article/info", binding.Form(articleInfoForm{}), adminErrorHandler, articleInfoHandler)
m.Get("/admin/article/list", binding.Form(articleListForm{}), adminErrorHandler, articleListHandler)
m.Get("/admin/article/timeline", binding.Form(articleListForm{}), adminErrorHandler, articleTimelineHandler)
m.Get("/admin/article/comments", binding.Form(articleListForm{}), adminErrorHandler, articleCommentsHandler)
m.Options("/admin/article/post", articlePostOptionsHandler)
m.Post("/admin/article/post", binding.Json(postForm{}), adminErrorHandler, articlePostHandler)
m.Post("/admin/article/delete", binding.Json(delArticleForm{}), adminErrorHandler, delArticleHandler)
m.Get("/admin/article/search", binding.Form(articleSearchForm{}), adminErrorHandler, articleSearchHandler)
m.Post("/admin/article/update", binding.Json(articleUpdateForm{}), adminErrorHandler, articleUpdateHandler)
}
开发者ID:shevilangle,项目名称:sports,代码行数:11,代码来源:article.go
示例9: BindArticleApi
func BindArticleApi(m *martini.ClassicMartini) {
m.Post("/1/article/new",
binding.Json(newArticleForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
checkLimitHandler,
newArticleHandler)
m.Post("/1/article/delete",
binding.Json(deleteArticleForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
checkLimitHandler,
deleteArticleHandler)
m.Post("/1/article/thumb",
binding.Json(articleThumbForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
checkLimitHandler,
articleThumbHandler)
m.Get("/1/article/is_thumbed",
binding.Form(articleIsThumbedForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
articleIsThumbedHandler)
m.Get("/1/article/timelines",
binding.Form(articleListForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
articleListHandler)
m.Get("/1/article/get",
binding.Form(articleInfoForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
articleInfoHandler)
m.Post("/1/article/comments",
binding.Json(articleCommentsForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
articleCommentsHandler)
m.Get("/1/aritcle/thumbList",
binding.Form(thumbersForm{}),
thumbersHandler)
m.Get("/1/article/news",
binding.Form(articleNewsForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
articleNewsHandler)
}
开发者ID:shevilangle,项目名称:sports,代码行数:51,代码来源:article.go
示例10: BindTaskApi
func BindTaskApi(m *martini.ClassicMartini) {
m.Get("/1/tasks/get",
binding.Form(getTaskForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
getTaskHandler)
m.Get("/1/tasks/getList",
binding.Form(getTasksForm{}),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
getTasksHandler)
m.Get("/1/tasks/getInfo",
binding.Form(getTaskInfoForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
//loadUserHandler,
getTaskInfoHandler)
m.Get("/1/tasks/result",
binding.Form(getTaskResultForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
//loadUserHandler,
getTaskResultHandler)
m.Post("/1/tasks/execute",
binding.Json(completeTaskForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
checkLimitHandler,
completeTaskHandler)
m.Get("/1/tasks/referrals",
binding.Form(taskReferralForm{}),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
taskReferralsHandler)
m.Post("/1/tasks/share",
binding.Json(taskShareForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
taskShareHandler)
m.Post("/1/tasks/shared",
binding.Json(taskSharedForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
taskSharedHandler)
}
开发者ID:shevilangle,项目名称:sports,代码行数:51,代码来源:task.go
示例11: main
func main() {
m := martini.Classic()
m.Use(render.Renderer())
m.Get("/tasks", ListTasks)
m.Get("/tasks/:id", GetTask)
m.Post("/tasks", binding.Json(Task{}), AddTask)
m.Put("/tasks/:id", binding.Json(Task{}), UpdateTask)
m.Map(initDb("dev.db"))
m.Run()
}
开发者ID:jmptrader,项目名称:martini-gorp-bootstrap,代码行数:14,代码来源:server.go
示例12: BindUserApi
func BindUserApi(m *martini.ClassicMartini) {
m.Post("/1/user/send_device_token",
binding.Json(sendDevForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
sendDevHandler)
m.Post("/1/user/set_push_enable",
binding.Json(setPushForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
setPushHandler)
m.Get("/1/user/is_push_enabled",
binding.Form(pushStatusForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
pushStatusHandler)
m.Post("/1/user/enableAttention",
binding.Json(relationshipForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
checkLimitHandler,
followHandler)
m.Post("/1/user/enableDefriend",
binding.Json(relationshipForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
checkLimitHandler,
blacklistHandler)
m.Get("/1/user/getAttentionFriendsList",
binding.Form(getFollowsForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
getFollowsHandler)
m.Get("/1/user/getAttentedMembersList",
binding.Form(getFollowsForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
getFollowersHandler)
m.Get("/1/user/getJoinedGroupsList",
binding.Form(getFollowsForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
getGroupsHandler)
m.Get("/1/user/getRelatedMembersList",
binding.Form(socialListForm{}),
ErrorHandler,
socialListHandler)
}
开发者ID:shevilangle,项目名称:sports,代码行数:50,代码来源:user.go
示例13: main
func main() {
//lol if you don't already use swiftly
username := os.Getenv("SWIFTLY_AUTH_USER")
apikey := os.Getenv("SWIFTLY_AUTH_KEY")
authurl := os.Getenv("SWIFTLY_AUTH_URL")
region := os.Getenv("SWIFTLY_REGION")
snet := os.Getenv("SWIFTLY_SNET")
dockerized := os.Getenv("DOCKERIZED")
memcacheOverride := os.Getenv("MEMCACHEADDR")
if strings.ToLower(dockerized) == "true" {
memcacheOverride = fmt.Sprintf("%s:%s", os.Getenv("MEMCACHED_PORT_11211_TCP_ADDR"), os.Getenv("MEMCACHED_PORT_11211_TCP_PORT"))
}
memcacheAddr := "127.0.0.1:11211"
if memcacheOverride != "" {
memcacheAddr = memcacheOverride
}
internal := false
if strings.ToLower(snet) == "true" {
internal = true
}
//martini looks for a HOST and PORT env var to determine what to listen on
m := martini.Classic()
cf := swift.Connection{
UserName: username,
ApiKey: apikey,
AuthUrl: authurl,
Region: region,
Internal: internal,
}
// Authenticate
err := cf.Authenticate()
PanicIf(err)
m.Map(&cf)
log.Println(os.Environ())
log.Println(memcacheAddr)
mc := memcache.New(memcacheAddr)
m.Map(mc)
m.Use(render.Renderer())
m.Get("/", IndexPage)
m.Get("/history", GetHistory)
m.Get("/:pasteid", GetPaste)
m.Get("/:pasteid/:format", GetPaste)
m.Post("/paste", binding.Json(Paste{}), binding.ErrorHandler, SavePaste)
m.Put("/paste", binding.Json(Paste{}), binding.ErrorHandler, SavePaste)
m.Run()
}
开发者ID:pandemicsyn,项目名称:cfpaste,代码行数:49,代码来源:cfpaste.go
示例14: StartServerMultiplesBotsHostPort
func StartServerMultiplesBotsHostPort(uri string, pathl string, host string, port string, newrelic *RelicConfig, bots ...*TgBot) {
var puri *url.URL
if uri != "" {
tmpuri, err := url.Parse(uri)
if err != nil {
fmt.Printf("Bad URL %s", uri)
return
}
puri = tmpuri
}
botsmap := make(map[string]*TgBot)
for _, bot := range bots {
tokendiv := strings.Split(bot.Token, ":")
if len(tokendiv) != 2 {
return
}
tokenpath := fmt.Sprintf("%s%s", tokendiv[0], tokendiv[1])
botpathl := path.Join(pathl, tokenpath)
nuri, _ := puri.Parse(botpathl)
remoteuri := nuri.String()
res, error := bot.SetWebhook(remoteuri)
if error != nil {
ec := res.ErrorCode
fmt.Printf("Error setting the webhook: \nError code: %d\nDescription: %s\n", &ec, res.Description)
continue
}
if bot.MainListener == nil {
bot.StartMainListener()
}
botsmap[tokenpath] = bot
}
pathtolisten := path.Join(pathl, "(?P<token>[a-zA-Z0-9-_]+)")
m := martini.Classic()
m.Post(pathtolisten, binding.Json(MessageWithUpdateID{}), func(params martini.Params, msg MessageWithUpdateID) {
bot, ok := botsmap[params["token"]]
if ok && msg.UpdateID > 0 && msg.Msg.ID > 0 {
bot.MainListener <- msg
} else {
fmt.Println("Someone tried with: ", params["token"], msg)
}
})
if newrelic != nil {
gorelic.InitNewrelicAgent(newrelic.Token, newrelic.Name, false)
m.Use(gorelic.Handler)
}
if host == "" || port == "" {
m.Run()
} else {
m.RunOnAddr(host + ":" + port)
}
}
开发者ID:joseluiscd,项目名称:go-tgbot,代码行数:60,代码来源:utils.go
示例15: BindRecordApi
func BindRecordApi(m *martini.ClassicMartini) {
m.Post("/1/record/new",
binding.Json(newRecordForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
checkLimitHandler,
newRecordHandler)
m.Get("/1/record/get",
binding.Form(getRecordForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
getRecordHandler)
m.Get("/1/record/timeline",
binding.Form(recTimelineForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
recTimelineHandler)
m.Get("/1/record/statistics",
binding.Form(userRecStatForm{}),
ErrorHandler,
userRecStatHandler)
m.Get("/1/leaderboard/list",
binding.Form(leaderboardForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
leaderboardHandler)
m.Get("/1/leaderboard/gameList",
binding.Form(gamelbForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
gamelbHandler,
)
}
开发者ID:shevilangle,项目名称:sports,代码行数:35,代码来源:record.go
示例16: SetupRoutes
func SetupRoutes(m *martini.ClassicMartini) {
m.Get("/", Leaderboard)
m.Get("/leaders", GetLeaders)
m.Get("/leaders/:page", GetLeaders)
m.Get("/leader/:name", GetLeader)
m.Post("/leader", binding.Json(Leader{}), binding.ErrorHandler, PostLeader)
}
开发者ID:nghiangodinh,项目名称:sample-go-webapp,代码行数:7,代码来源:routes.go
示例17: setupRoutes
func (srv *httpServer) setupRoutes(m *martini.ClassicMartini) {
m.Get(`/`, func() string { return "every day" })
m.Get(`/pusher/info`, srv.getPusherInfo)
m.Post(`/apps/:app_id/events`, binding.Json(Event{}), srv.createAppEvents)
m.Get(`/timeline/:id`, handleStatsJSONP)
log.Printf("Set up HTTP Server routes on %#v\n", m)
}
开发者ID:joshk,项目名称:hustle,代码行数:7,代码来源:http_server.go
示例18: BindWalletApi
func BindWalletApi(m *martini.ClassicMartini) {
m.Get("/1/wallet/get",
binding.Form(walletForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
getWalletHandler)
m.Get("/1/wallet/balance",
binding.Form(walletForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
balanceHandler)
m.Get("/1/wallet/newaddr",
binding.Form(walletForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
newAddrHandler)
m.Post("/1/wallet/send",
binding.Json(txForm{}, (*Parameter)(nil)),
ErrorHandler,
checkTokenHandler,
loadUserHandler,
checkLimitHandler,
txHandler)
m.Get("/1/wallet/txs",
binding.Form(addrTxsForm{}),
addrTxsHandler)
}
开发者ID:shevilangle,项目名称:sports,代码行数:30,代码来源:wallet.go
示例19: PutRequestNoAuth
func PutRequestNoAuth(method string, route string, handler martini.Handler, body io.Reader, params martini.Params, skeleton interface{}) *httptest.ResponseRecorder {
r.Put(route, binding.Json(skeleton), handler)
request, _ := http.NewRequest(method, route, body)
request.Header.Set("Content-Type", "application/json")
response = httptest.NewRecorder()
m.ServeHTTP(response, request)
return response
} // func
开发者ID:centricconsulting,项目名称:devops-slack-hook-push,代码行数:8,代码来源:spicoli_suite_test.go
示例20: setup
func setup(router martini.Router) {
router.Get("/user/:id", controllers.UserGet)
router.Put("/user/:id",
binding.Json(models.User{}),
binding.ErrorHandler,
controllers.UserPut)
}
开发者ID:kosuda,项目名称:martini-test,代码行数:8,代码来源:router.go
注:本文中的github.com/martini-contrib/binding.Json函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论