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


Golang binding.Bind函数代码示例

本文整理汇总了Golang中github.com/martini-contrib/binding.Bind函数的典型用法代码示例。如果您正苦于以下问题:Golang Bind函数的具体用法?Golang Bind怎么用?Golang Bind使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: main

func main() {
	LoadDatabase()
	StartAutoSave()

	m := martini.Classic()

	// API endpoints
	m.Get("/app/report/:host", GetReports)
	m.Post("/app/report", binding.Bind(InboundReport{}), FileReport)
	m.Get("/app/suggest/:prefix", SuggestHosts)

	// API endpoints for report actions
	m.Post("/app/update/:reportID/ack", binding.Bind(ActionMeta{}), Acknowledge)
	m.Post("/app/update/:reportID/fixed", binding.Bind(ActionMeta{}), Fixed)
	m.Post("/app/update/:reportID/reject", binding.Bind(ActionMeta{}), Reject)
	m.Post("/app/update/:reportID/delete", binding.Bind(ActionMeta{}), Delete)

	// Serve up the report page
	m.Get("/report/:host", func(req *http.Request, resp http.ResponseWriter) {
		http.ServeFile(resp, req, "public/report.html")
	})

	m.Get("/test", func() string { return "test successful" })

	m.Run()
}
开发者ID:SunSparc,项目名称:grammarlert,代码行数:26,代码来源:main.go

示例2: Run

func (h *Httpd) Run() {
	m := martini.Classic()
	m.Get("/", func() string { return "Hello, I'm Takosan!!1" })
	m.Post("/notice", binding.Bind(Param{}), messageHandler)
	m.Post("/privmsg", binding.Bind(Param{}), messageHandler)
	m.RunOnAddr(fmt.Sprintf("%s:%d", h.Host, h.Port))
}
开发者ID:intfrr,项目名称:takosan,代码行数:7,代码来源:httpd.go

示例3: main

func main() {

	// Initialize
	m := martini.Classic()

	// Connect to mongo
	m.Use(middlewares.Connect())

	// Templating support
	m.Use(middlewares.Templates())

	// Routes

	m.Get("/", func(r render.Render) {
		r.Redirect("/available")
	})

	m.Group("/available", func(r martini.Router) {
		r.Get("", available.List)
		r.Get("/new", available.New)
		r.Get("/:_id", available.Edit)
		r.Post("", binding.Bind(models.AvailableTopic{}), available.Create)
		r.Post("/:_id", binding.Bind(models.AvailableTopic{}), available.Update)
		r.Delete("/:_id", available.Delete)
	})

	// Start listening
	m.Run()
}
开发者ID:gitter-badger,项目名称:khabar-admin,代码行数:29,代码来源:main.go

示例4: main

func main() {
	var host string
	var port int
	flag.StringVar(&host, "host", "", "The address to bind to")
	flag.IntVar(&port, "port", 9999, "The port to listen at")

	m := martini.Classic()
	m.Use(func(c martini.Context, w http.ResponseWriter) {
		c.MapTo(encoder.JsonEncoder{PrettyPrint: false}, (*encoder.Encoder)(nil))
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
	})

	m.Get("/users", GetUsers)
	m.Post("/users", binding.Bind(User{}), CreateUser)
	m.Get("/users/:id", GetUser)
	m.Delete("/users/:id", DeleteUser)
	m.Get("/users/:id/teams", GetUserTeams)
	m.Get("/users/:id/goals", GetUserGoals)

	m.Get("/teams", GetTeams)
	m.Post("/teams", binding.Bind(Team{}), CreateTeam)
	m.Get("/teams/:id", GetTeam)
	m.Delete("/teams/:id", DeleteTeam)

	m.Put("/users/:uid/teams/:tid", AddUserToTeam)
	m.Delete("/users/:uid/teams/:tid", DeleteUserFromTeam)

	m.Post("/goals", binding.Bind(Goal{}), CreateGoal)
	m.Get("/goals/:id", GetGoal)
	m.Post("/goals/:id", binding.Bind(GoalCompleteParams{}), CompleteGoal)

	log.Fatal(http.ListenAndServe(":8080", m))
	m.Run()
}
开发者ID:FP7Collage,项目名称:GoalSetting,代码行数:34,代码来源:server.go

示例5: Routes

func Routes() http.Handler {
	// Middlewares are setup and run before each incoming request
	// the ones named like *Provider provide singleton instances
	// of injectable objects. For instance appx, logger, appengine context
	// can be injected in our routes handlers (a.k.a controllers)
	router := martini.Classic()

	router.Use(render.Renderer())
	router.Use(middlewares.AppengineContextProvider)
	router.Use(middlewares.LoggerProvider)
	router.Use(middlewares.AppxProvider)

	router.Post("/login", binding.Bind(controllers.LoginForm{}), controllers.Login)

	router.Group("/account", func(r martini.Router) {
		r.Post("/registerDropbox", binding.Bind(controllers.RegisterDropboxForm{}), controllers.RegisterDropbox)
		r.Post("/update", binding.Bind(controllers.AccountUpdateForm{}), controllers.UpdateAccount)

		r.Group("/dropbox", func(r martini.Router) {
			r.Post("/init", controllers.DropboxInit)
			r.Post("/delta", controllers.DropboxDelta)
		}, middlewares.ExternalServiceAuthorizationProvider)

		r.Group("/trails", func(r martini.Router) {
			r.Get("/next_evaluation", controllers.TrailNextEvaluation)
			r.Patch("/:trail_id/like", controllers.TrailLike)
			r.Patch("/:trail_id/dislike", controllers.TrailDislike)
			r.Get("/tags", controllers.Tags)
			r.Get("/tags/:tag_id", controllers.TagTrails)
		})
	}, middlewares.AuthorizationAccountProvider)

	return router
}
开发者ID:BearchInc,项目名称:trails-api,代码行数:34,代码来源:routes.go

示例6: Start

func (self *oprPrevSeasonRankCom) Start(peer netfw.IPeer) {

	m := peer.(martinihttp.IMartiniAcceptor).GetInterface()

	m.Get("/seasonrank", sessionauth.LoginRequired, binding.Bind(queryZone{}), func(r render.Render, msg queryZone) {

		var zones []zoneInfo

		dbopr.IterateShowDB(func(name, showname string) {
			zones = append(zones, zoneInfo{
				Name:     name,
				ShowName: showname,
			})
		})

		r.HTML(200, "index", nil)
		r.HTML(200, "seasonrank", zones)

	})

	m.Post("/rankdata", sessionauth.LoginRequired, binding.Bind(queryZone{}), func(r render.Render, msg queryZone) {

		res, err := dbopr.ExecuteSQL(msg.Zone, &dbLastSeason{}, "select $FIELD_NAME$ from tb_last_season")
		if err != nil {
			r.Data(200, []byte(err.Error()))
			return
		}

		r.JSON(200, res)

	})

}
开发者ID:chogaths,项目名称:robin,代码行数:33,代码来源:prevseasonrank.go

示例7: Route

// Route return the route handler for this
func (s ServiceRegistryWebService) Route() martini.Router {
	r := martini.NewRouter()
	r.Group("/apiversions/", func(r martini.Router) {
		r.Get("", s.getAPIVersions)
		r.Post("", binding.Bind(common.APIVersion{}), s.createAPIVersion)
	})

	r.Group("/apiversions/:version/", func(r martini.Router) {
		r.Get("", s.getAPIVersion)
		r.Get("services/", s.getAPIServices)
		r.Post("services/", binding.Bind(common.ServiceVersion{}), s.createAPIService)
	})

	r.Group("/services/", func(r martini.Router) {
		r.Get("", s.getServices)
		r.Post("", binding.Bind(common.ServiceDefinition{}), s.createService)
		r.Delete(":service/", s.dropService)
	})

	r.Group("/services/:service/versions", func(r martini.Router) {
		r.Get("", s.getServiceVersions)
		r.Post("", binding.Bind(common.ServiceVersion{}), s.createServiceVersion)
	})

	r.Group("/services/:service/:version/hosts/", func(r martini.Router) {
		r.Get("", s.getServiceHosts)
		r.Post("", binding.Bind(common.ServiceHost{}), s.attachServiceHost)
	})

	return r
}
开发者ID:enzian,项目名称:go-msf,代码行数:32,代码来源:ServiceRegistryWebService.go

示例8: main

func main() {
	m := martini.Classic()
	m.Post("/text", binding.Bind(DisplayMessage{}), createText)
	m.Post("/image", binding.MultipartForm(ImageMessage{}), createImage)
	m.Post("/display", binding.Bind(IDMessage{}), displayImage)
	m.Run()
}
开发者ID:raumzeitlabor,项目名称:pingied,代码行数:7,代码来源:pingied.go

示例9: main

func main() {

	config, err := config.Load()
	if err != nil {
		log.Fatal(err)
	}

	fishhubService, err := fishhub.NewService(config.MongoURL)
	if err != nil {
		log.Fatal(err)
	}

	sessionService, err := session.NewService(config.MongoURL)
	if err != nil {
		log.Fatal(err)
	}

	store := sessions.NewCookieStore([]byte("@!#$%^&*"))

	m := martini.Classic()

	m.Map(fishhubService)
	m.Map(sessionService)

	m.Use(sessions.Sessions("go_session", store))

	// Setup routes
	m.Get("/", home)

	m.Group("/users", func(r martini.Router) {
		r.Post("", binding.Bind(UserForm{}), NewUser)
		r.Get("/:id", GetUser)
		r.Put("/update/:id", UpdateUser)
		r.Delete("/delete/:id", DeleteUser)
	})

	m.Group("/login", func(r martini.Router) {
		r.Post("", binding.Bind(LoginForm{}), CheckCredential)
	})

	m.Handlers(
		render.Renderer(render.Options{
			Delims: render.Delims{"<%", "%>"},
		}),
		martini.Logger(),
		martini.Static("public"),
	)

	m.NotFound(func(r render.Render) {
		r.HTML(404, "404", nil)
	})

	err = http.ListenAndServe(":"+config.Port, m)
	if err != nil {
		log.Fatal(err)
	}

}
开发者ID:Alpa-vantage,项目名称:fishhub,代码行数:58,代码来源:main.go

示例10: SetupRoutes

func SetupRoutes(db *mgo.Database, m *martini.ClassicMartini) {
	m.Group("/oauth", func(r martini.Router) {
		r.Get("/register/:type", modules.Register)
		r.Get("/github", binding.Bind(models.GithubOAuth{}), modules.GithubOAuth)
	})

	m.Group("/api/user", func(r martini.Router) {
		r.Put("/", binding.Bind(models.User{}), api.RegisterUser)
	})
}
开发者ID:rickihastings,项目名称:codeprofile,代码行数:10,代码来源:webserver.go

示例11: init

func init() {
	// BASE_URL, AUTH_USER and AUTH_PASS, AWS_S3_BASE_URL are not required or else wercker tests would fail
	baseURL = os.Getenv("BASE_URL")
	authUser = os.Getenv("AUTH_USER")
	authPass = os.Getenv("AUTH_PASS")
	s3BaseURL = os.Getenv("AWS_S3_BASE_URL")

	if awsAuth, err := aws.EnvAuth(); err != nil {
		// not required or else wercker tests would fail
		log.Println(err)
	} else {
		// TODO(jrubin) allow region to be chosen by env variable
		s3Data := s3.New(awsAuth, aws.USWest2)
		s3Bucket = s3Data.Bucket(os.Getenv("AWS_S3_BUCKET_NAME"))
	}

	m = martini.Classic()

	m.Use(gzip.All())
	m.Use(render.Renderer())

	m.Get("/", func() string {
		return "hello, world"
	})

	m.Post(
		"/v1/transcribe",
		auth.Basic(authUser, authPass),
		strict.Accept("application/json"),
		strict.ContentType("application/x-www-form-urlencoded"),
		binding.Bind(transcribeData{}),
		binding.ErrorHandler,
		handleTranscribe,
	)

	m.Post(
		"/v1/transcribe/process",
		strict.ContentType("application/x-www-form-urlencoded"),
		binding.Bind(telapi.TranscribeCallbackData{}),
		binding.ErrorHandler,
		handleTranscribeProcess,
	)

	m.Post(
		"/v1/transcribe/upload",
		auth.Basic(authUser, authPass),
		strict.Accept("application/json"),
		binding.MultipartForm(transcribeUploadData{}),
		binding.ErrorHandler,
		handleTranscribeUpload,
	)

	m.Router.NotFound(strict.MethodNotAllowed, strict.NotFound)
}
开发者ID:joshuarubin,项目名称:goscribe,代码行数:54,代码来源:web.go

示例12: registerRoutes

func registerRoutes(server *martini.ClassicMartini) {
	// Box
	server.Post("/boxes", binding.Bind(request.CreateRequest{}), boxCreate)
	server.Put("/boxes/:name", binding.Bind(request.DeployRequest{}), boxDeploy)
	server.Get("/boxes", boxList)
	server.Get("/boxes/:name", boxInspect)
	server.Delete("/boxes/:name", boxDelete)

	// Domain
	server.Post("/boxes/:name/domain", binding.Bind(request.Domain{}), domainAdd)
	server.Delete("/boxes/:name/domain/:domain", domainDelete)
}
开发者ID:aramalipoor,项目名称:farmer,代码行数:12,代码来源:api.go

示例13: main

func main() {
	config := config.New()
	config.Load("config.json")
	cfbase := config.GetString("database", "sqlite3")
	cfconn := config.GetString("connection", "./app.db")
	db, err := gorm.Open(cfbase, cfconn)
	checkErr(err, "Database connection failed")
	db.AutoMigrate(&models.Blog{})
	db.AutoMigrate(&models.Classify{})
	defer db.Close()

	admin := &fun.Admins{Account: config.GetString("web_account", "admin"), Password: config.GetString("web_password", "admin")}

	jade := gojade.New()
	jade.ViewPath = "./jade"
	jade.RegisterFunction("date", fun.Date)
	jade.RegisterFunction("dateformat", fun.DateFormat)
	jade.RegisterFunction("compare", fun.Compare)
	jade.RegisterFunction("compare_not", fun.CompareNot)
	jade.RegisterFunction("substr", fun.Substr)
	jade.RegisterFunction("subtext", fun.Subtext)
	jade.RegisterFunction("img", fun.Img)
	jade.RegisterFunction("html2str", fun.HTML2str)
	jade.RegisterFunction("str2html", fun.Str2html)
	jade.RegisterFunction("htmlquote", fun.Htmlquote)
	jade.RegisterFunction("htmlunquote", fun.Htmlunquote)
	jade.RegisterFunction("map_get", fun.MapGet)

	m := martini.Classic()
	m.Map(db)
	m.Map(jade)
	m.Map(admin)
	m.Use(martini.Static("static"))
	m.Get("/", controllers.Home)
	m.Get("/:tag.html", controllers.Tag)
	m.Get("/view/:id.html", controllers.View)
	m.Get("/_login", controllers.Login)
	m.Get("/_logout", controllers.Logout)
	m.Get("/_add", controllers.Check, controllers.Create)
	m.Get("/_class", controllers.Check, controllers.Classify)
	m.Get("/_edit/:id", controllers.Check, controllers.Edit)
	m.Get("/_delete/:id", controllers.Check, controllers.Delete)

	m.Post("/_login", binding.Bind(models.Admin{}), controllers.LoginPost)
	m.Post("/_add", binding.Bind(models.Blog{}), controllers.CreatePost)
	m.Post("/_class", binding.Bind(models.Classify{}), controllers.ClassifyPost)
	m.Post("/_edit/:id", binding.Bind(models.Blog{}), controllers.UpdatePost)

	m.NotFound(controllers.NotFound)
	m.Run()
}
开发者ID:bishen,项目名称:blog,代码行数:51,代码来源:server.go

示例14: main

func main() {
	m := martini.Classic()

	m.Use(cors.Allow(&cors.Options{
		AllowOrigins:     []string{"*"},
		AllowMethods:     []string{"PUT", "PATCH", "GET", "POST", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "content-type"},
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,
	}))

	session, err := mgo.Dial("localhost")

	if err != nil {
		panic(err)
	}

	defer session.Close()

	m.Map(session)

	m.Group("/foods", func(r martini.Router) {
		r.Get("", GetFood)
		r.Get("/:id", GetFood)
		r.Get("/queries/:name", GetFoodByName)
		r.Post("/new", binding.Bind(d.Food{}), NewFood)
		r.Put("/update/:id", binding.Bind(d.Food{}), UpdateFood)
		r.Delete("/delete/:id", DeleteFood)
	})

	m.Group("/recipes", func(r martini.Router) {
		r.Get("", GetRecipe)
		r.Get("/:id", GetRecipe)
		r.Post("", binding.Bind(Recipe{}), NewRecipe)
		r.Put("/update/:id", binding.Bind(Recipe{}), UpdateRecipe)
		r.Delete("/delete/:id", DeleteRecipe)
	})

	m.Get("/foodGroup", func() []byte {
		foodGroupDB := session.DB("CNF").C("foodGroup")
		query := foodGroupDB.Find(nil)
		var result []d.FoodGroup
		query.All(&result)
		b, _ := json.Marshal(result)
		return b
	})

	m.Run()
}
开发者ID:EckoEdc,项目名称:cookBookAPI,代码行数:49,代码来源:main.go

示例15: main

func main() {
	m := martini.Classic()

	if envGet(ENV_RESTRICT_DOMAINS) == "" {
		m.Get("/qr", binding.Bind(meddler.Payload{}), presentQRCode)
		m.Post("/qr", binding.Bind(meddler.Payload{}), presentQRCode)
	}

	m.Get("/drive/qr", binding.Bind(meddler.Payload{}), googleDriveDomainRestrictedQRCode)
	m.Post("/drive/qr", binding.Bind(meddler.Payload{}), googleDriveDomainRestrictedQRCode)

	// m.Post("/gen", GenerateKeySet)

	m.Run() // m.RunOnAddr(envAddrInfo.ConnectionString())
}
开发者ID:lucmichalski,项目名称:qr-server,代码行数:15,代码来源:main.go


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