當前位置: 首頁>>代碼示例>>Golang>>正文


Golang binding.Json函數代碼示例

本文整理匯總了Golang中github.com/martini-contrib/binding.Json函數的典型用法代碼示例。如果您正苦於以下問題:Golang Json函數的具體用法?Golang Json怎麽用?Golang Json使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Json函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/martini-contrib/binding.Json函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。