コード例 #1
9
ファイル: router.go プロジェクト: thedodd/api
// BindRoutes bind this package's routes to the given gin.RouterGroup at the given base URI.
func BindRoutes(baseRouter *gin.RouterGroup, baseURI string) {
	router := baseRouter.Group(baseURI)

	// Register routes.
	router.Use(common.BasicAuthRequired) // Protect these resources with basic auth.
	router.GET("/builds/", GetElasticsearchBuilds)
	router.POST("/builds/", common.BindJSON(&BuildModel{}), CreateElasticsearchBuild)
	router.GET("/builds/:id", GetElasticsearchBuildByID)
}
コード例 #2
3
ファイル: user.go プロジェクト: dots-the-game/beaver
func UserRouter(router *gin.RouterGroup, db gorm.DB) {

	router.GET("", func(ctx *gin.Context) {
		result := usermodel.Fetch(&db)
		fmt.Println(result)
		ctx.JSON(http.StatusOK, result.Value)
	})

	router.GET("/:id", func(ctx *gin.Context) {
		userId := ctx.Param("id")
		user := usermodel.FetchUserById(userId, &db)

		ctx.JSON(http.StatusOK, user.Value)
	})

	router.POST("", func(ctx *gin.Context) {
		user := usermodel.UserJSON{}
		ctx.BindJSON(&user)
		result := usermodel.Create(&user, &db)

		if result.Error != nil {
			ctx.JSON(http.StatusBadRequest, utils.HTTPError{Error: error(result.Error)})
		} else {
			ctx.JSON(http.StatusOK, result.Value)
		}
	})

	router.DELETE("/:id", func(ctx *gin.Context) {
		userId := ctx.Param("id")

		result := usermodel.Remove(userId, &db)

		if result.Error != nil {
			ctx.JSON(http.StatusBadRequest, utils.HTTPError{Error: error(result.Error)})
		} else {
			ctx.JSON(http.StatusOK, nil)
		}
	})

	router.PUT("/:id", func(ctx *gin.Context) {
		user := usermodel.UserJSON{}
		ctx.BindJSON(&user)
		result := usermodel.Update(ctx.Param("id"), &user, &db)

		if result.Error != nil {
			ctx.JSON(http.StatusBadRequest, utils.HTTPError{Error: error(result.Error)})
		} else {
			ctx.JSON(http.StatusOK, result.Value)
		}
	})
}
コード例 #3
2
func GetGroupHandler(router *gin.RouterGroup) {
	admin := router.Group("/admin").Use(jwt.GinJwtHandler).Use(jwt.GroupHandler("admin"))
	{
		admin.GET("/:prop", getProperty)
		admin.PUT("/:prop", setProperty)
	}
}
コード例 #4
0
ファイル: handlers.go プロジェクト: tiborv/hilbert-geohash
func api(api *gin.RouterGroup) {
	api.POST("/point", func(c *gin.Context) {
		p := point.Point{}
		err := c.Bind(&p)
		hash, err := hash.NewHashPoint(p)
		if err != nil || !p.IsValid() {
			c.JSON(http.StatusBadRequest, "Invalid point")
		} else {
			c.JSON(http.StatusOK, gin.H{
				"point":  p,
				"hash":   reverseString(hash.String),
				"zorder": reverseString(hash.GetZorder().HashString(32)),
			})
		}
	})

	api.POST("/hash", func(c *gin.Context) {
		hash := &hash.Hash{}
		err := c.Bind(&hash)
		hash.String = reverseString(hash.String)
		if err != nil || hash.InitFromString() != nil {
			c.JSON(http.StatusBadRequest, "Invalid hash")
		} else {
			c.JSON(http.StatusOK, gin.H{
				"hash":   reverseString(hash.String),
				"point":  hash.GenPoint(),
				"zorder": reverseString(hash.GetZorder().HashString(32)),
			})
		}
	})
}
コード例 #5
0
ファイル: users.go プロジェクト: wangmingjob/goyangi
// @Title Users
// @Description Users's router group.
func Users(parentRoute *gin.RouterGroup) {
	route := parentRoute.Group("/users")
	route.POST("", createUser)
	route.GET("/:id", retrieveUser)
	route.GET("", retrieveUsers)
	route.PUT("/:id", userPermission.AuthRequired(updateUser))
	route.DELETE("/:id", userPermission.AuthRequired(deleteUser))

	route.POST("/roles", userPermission.AdminRequired(addRoleToUser))
	route.DELETE(":id/roles/:roleId", userPermission.AdminRequired(removeRoleFromUser))

	route.POST("/likings", userPermission.AuthRequired(createLikingOnUser))
	route.GET("/:id/likings", retrieveLikingsOnUsers)
	route.DELETE("/:id/likings/:userId", userPermission.AuthRequired(deleteLikingOnUser))
	route.GET("/:id/liked", retrieveLikedOnUsers)

	route = parentRoute.Group("/user")
	route.GET("/current", retrieveCurrentUser)
	route.POST("/send/password/reset/token", sendPasswordResetToken)
	route.PUT("/reset/password", resetPassword)
	route.POST("/send/email/verification/token", sendEmailVerificationToken)
	route.PUT("/verify/email", verifyEmail)
	route.GET("/email/:email", retrieveUserByEmail)
	route.GET("/email/:email/list", retrieveUsersByEmail)
	route.GET("/username/:username", retrieveUserByUsername)
	route.GET("/admin/:id", userPermission.AdminRequired(retrieveUserForAdmin))
	route.GET("/admin", userPermission.AdminRequired(retrieveUsersForAdmin))
	route.PUT("/activate/:id", userPermission.AdminRequired(activateUser))
	route.GET("/test/send/email", sendTestEmail)
}
コード例 #6
0
ファイル: routes.go プロジェクト: jlertle/pgweb
func SetupMiddlewares(group *gin.RouterGroup) {
	if command.Opts.Debug {
		group.Use(requestInspectMiddleware())
	}

	group.Use(dbCheckMiddleware())
}
コード例 #7
0
ファイル: person.go プロジェクト: dynastymasra/GoGinThrift
func Person(router *gin.RouterGroup) {
	router.GET("/persons", handler.GetAll)
	router.GET("/person/:id", handler.GetById)
	router.POST("/person", handler.Create)
	router.PUT("/person", handler.Update)
	router.DELETE("/person", handler.Delete)
}
コード例 #8
0
ファイル: user-resource.go プロジェクト: SimiPro/letsgo
func (u *UserResource) Register(usergroup *gin.RouterGroup) {
	usergroup.OPTIONS("login")
	usergroup.GET("login", u.login)
	usergroup.GET("find/:user-id", u.findUser)
	usergroup.PUT("update/:user-id", u.updateUser)
	usergroup.DELETE("remove/:user-id", u.removeUser)
}
コード例 #9
0
ファイル: main.go プロジェクト: durango/gin-passport-facebook
func Routes(oauth *oauth2.Config, r *gin.RouterGroup) {
	passportOauth = oauth

	r.GET("/login", func(c *gin.Context) {
		Login(oauth, c)
	})
}
コード例 #10
0
ファイル: godmin.go プロジェクト: gpitfield/godmin
// set up the admin Routes, and add in the Authenticator middleware if present
func Routes(r *gin.RouterGroup) {
	// root level is list of admin models
	r.Handle("GET", "/", index)
	r.Handle("GET", "/:model/", list)
	r.Handle("POST", "/:model/", listUpdate)
	r.Handle("GET", "/:model/:pk", change)
	r.Handle("POST", "/:model/:pk", changeUpdate)
}
コード例 #11
0
ファイル: ssh_controller.go プロジェクト: KarhuTeam/Karhu
func NewSshController(s *gin.RouterGroup) *SshController {

	ctl := &SshController{}

	s.GET("/ssh/public-key", ctl.getPublicKey)

	return ctl
}
コード例 #12
0
ファイル: tasks.go プロジェクト: fmr/kanban
func taskRoutes(api *gin.RouterGroup, prefix string) {

	g := api.Group(prefix)
	{
		g.DELETE(":id", deleteTask)
		g.PUT(":id/move/:new_list_id", moveTask)
	}
}
コード例 #13
0
ファイル: api.go プロジェクト: bubblebox/server
// Setup will setup all API routes.
func Setup(group *gin.RouterGroup, db *db.DB) {
	group.Use()
	{
		group.GET("/items/:code", itemsShowHandler(db))
		group.DELETE("/items/:code", itemsDestroyHandler(db))
		group.GET("/items", itemsIndexHandler(db))
		group.POST("/items", itemsCreateHandler(db))
	}
}
コード例 #14
0
func NewDeploymentController(s *gin.RouterGroup) *DeploymentController {

	ctl := &DeploymentController{}

	s.GET("/apps/:id/deploy/:deploy_id", ctl.getDeployment)
	s.GET("/apps/:id/deploy", ctl.getDeploymentList)

	return ctl
}
コード例 #15
0
ファイル: upload.go プロジェクト: wangmingjob/goyangi
// @Title Upload
// @Description Upload's router group.
func Upload(parentRoute *gin.RouterGroup) {
	route := parentRoute.Group("/upload")
	route.POST("/images", userPermission.AuthRequired(uploadImages))

	route.POST("/files", userPermission.AuthRequired(createFile))
	route.POST("/files/all", userPermission.AuthRequired(createFiles))
	route.GET("/files/:id", retrieveFile)
	route.GET("/files", retrieveFiles)
	route.PUT("/files/:id", userPermission.AuthRequired(updateFile))
	route.DELETE("/files/:id", userPermission.AuthRequired(deleteFile))
}
コード例 #16
0
ファイル: show.go プロジェクト: widnyana/madara
func RealMain(routerGroup *gin.RouterGroup) {
	routerGroup.GET("/users", func(c *gin.Context) {
		data := User{
			ID:    1,
			Name:  "Widnyana",
			Email: "*****@*****.**",
		}

		c.JSON(200, data)
	})
}
コード例 #17
0
ファイル: setting.go プロジェクト: wangmingjob/goyangi
func Setting(parentRoute *gin.RouterGroup) {
	route := parentRoute
	route = parentRoute.Group("/setting")
	route.GET("", func(c *gin.Context) {
		sPARoute(c, "/setting")
	})
	route.GET("/:tab", func(c *gin.Context) {
		tab := c.Params.ByName("tab")
		sPARoute(c, "/setting/"+tab)
	})
}
コード例 #18
0
ファイル: cards.go プロジェクト: fmr/kanban
func cardRoutes(api *gin.RouterGroup, prefix string) {

	g := api.Group(prefix)
	{
		g.GET("", getCards)
		g.POST("", addCard)
		g.DELETE(":id", deleteCard)
		g.PUT(":id", updateCard)
		g.PUT(":id/move/:target_id", moveCard)
		g.POST(":id/add/", addTask)
	}

}
コード例 #19
0
ファイル: routes.go プロジェクト: ovh/tat
// initRoutesTopics initialized routes for Topics Controller
func initRoutesTopics(router *gin.RouterGroup, checkPassword gin.HandlerFunc) {
	topicsCtrl := &TopicsController{}

	g := router.Group("/")
	g.Use(checkPassword)
	{
		g.GET("/topics", topicsCtrl.List)
		g.POST("/topic", topicsCtrl.Create)
		g.DELETE("/topic/*topic", topicsCtrl.Delete)
		g.GET("/topic/*topic", topicsCtrl.OneTopic)

		g.PUT("/topic/add/parameter", topicsCtrl.AddParameter)
		g.PUT("/topic/remove/parameter", topicsCtrl.RemoveParameter)

		g.PUT("/topic/add/filter", topicsCtrl.AddFilter)
		g.PUT("/topic/remove/filter", topicsCtrl.RemoveFilter)
		g.PUT("/topic/update/filter", topicsCtrl.UpdateFilter)

		g.PUT("/topic/add/rouser", topicsCtrl.AddRoUser)
		g.PUT("/topic/remove/rouser", topicsCtrl.RemoveRoUser)
		g.PUT("/topic/add/rwuser", topicsCtrl.AddRwUser)
		g.PUT("/topic/remove/rwuser", topicsCtrl.RemoveRwUser)
		g.PUT("/topic/add/adminuser", topicsCtrl.AddAdminUser)
		g.PUT("/topic/remove/adminuser", topicsCtrl.RemoveAdminUser)

		g.PUT("/topic/compute/tags", topicsCtrl.ComputeTags)
		g.PUT("/topic/truncate/tags", topicsCtrl.TruncateTags)
		g.PUT("/topic/compute/labels", topicsCtrl.ComputeLabels)
		g.PUT("/topic/truncate/labels", topicsCtrl.TruncateLabels)
		g.PUT("/topic/truncate", topicsCtrl.Truncate)
		g.PUT("/topic/add/rogroup", topicsCtrl.AddRoGroup)
		g.PUT("/topic/remove/rogroup", topicsCtrl.RemoveRoGroup)
		g.PUT("/topic/add/rwgroup", topicsCtrl.AddRwGroup)
		g.PUT("/topic/remove/rwgroup", topicsCtrl.RemoveRwGroup)
		g.PUT("/topic/add/admingroup", topicsCtrl.AddAdminGroup)
		g.PUT("/topic/remove/admingroup", topicsCtrl.RemoveAdminGroup)
		g.PUT("/topic/param", topicsCtrl.SetParam)
	}

	admin := router.Group("/topics")
	admin.Use(checkPassword, CheckAdmin())
	{
		admin.PUT("/compute/tags", topicsCtrl.AllComputeTags)
		admin.PUT("/compute/labels", topicsCtrl.AllComputeLabels)
		admin.PUT("/compute/replies", topicsCtrl.AllComputeReplies)
		admin.PUT("/migrate/dedicated/*topic", topicsCtrl.MigrateToDedicatedTopic)
		admin.PUT("/migrate/dedicatedmessages/:limit/*topic", topicsCtrl.MigrateMessagesForDedicatedTopic)
		admin.PUT("/param", topicsCtrl.AllSetParam)
	}
}
コード例 #20
0
ファイル: image.go プロジェクト: HakabaV3/atami-go
// Use is a function
func Use(r *gin.RouterGroup) {
	r.Use()
	{
		r.GET("/image/all", getAllImages)
		r.GET("/image/search", getSearchImages)
		r.POST("/image", createImage)
	}
}
コード例 #21
0
ファイル: locations.go プロジェクト: wangmingjob/goyangi
// @Title Locations
// @Description Locations's router group.
func Locations(parentRoute *gin.RouterGroup) {
	route := parentRoute.Group("/locations")
	route.POST("", userPermission.AuthRequired(createLocation))
	route.GET("/:id", retrieveLocation)
	route.GET("", retrieveLocations)
	route.PUT("/:id", userPermission.AuthRequired(updateLocation))
	route.DELETE("/:id", userPermission.AuthRequired(deleteLocation))

	route.POST("/comments", userPermission.AuthRequired(createCommentOnLocation))
	route.GET("/:id/comments", retrieveCommentsOnLocation)
	route.PUT("/:id/comments/:commentId", userPermission.AuthRequired(updateCommentOnLocation))
	route.DELETE("/:id/comments/:commentId", userPermission.AuthRequired(deleteCommentOnLocation))

	route.POST("/likings", userPermission.AuthRequired(createLikingOnLocation))
	route.GET("/:id/likings", retrieveLikingsOnLocations)
	route.DELETE("/:id/likings/:userId", userPermission.AuthRequired(deleteLikingOnLocation))
}
コード例 #22
0
ファイル: rest.go プロジェクト: doubledutch/dd-vote
// It defines
//   POST: /path
//   GET:  /path
//   PUT:  /path/:id
//   POST: /path/:id
func CRUD(group *gin.RouterGroup, path string, resource interface{}) {
	if resource, ok := resource.(CreateSupported); ok {
		group.POST(path, resource.CreateHandler)
	}
	if resource, ok := resource.(ListSupported); ok {
		group.GET(path, resource.ListHandler)
	}
	if resource, ok := resource.(TakeSupported); ok {
		group.GET(path+"/:id", resource.TakeHandler)
	}
	if resource, ok := resource.(UpdateSupported); ok {
		group.PUT(path+"/:id", resource.UpdateHandler)
	}
	if resource, ok := resource.(DeleteSupported); ok {
		group.DELETE(path+"/:id", resource.DeleteHandler)
	}
}
コード例 #23
0
ファイル: api.go プロジェクト: Skullever/digo
// Listen Tells Gin API to start
func Listen(iface string, s *discordgo.Session, logger *logging.Logger) {
	// set the refs to point to main
	var v1 *gin.RouterGroup
	session = s
	c := config.Get()
	log = logger

	if c.LogLevel != "debug" {
		gin.SetMode(gin.ReleaseMode)
	}

	//r := gin.Default()
	r := gin.New()

	r.Use(loggerino())
	r.Use(gin.Recovery())

	if c.APIPassword != "" {
		log.Info("Basic Authentication enabled for API")
		v1 = r.Group("/v1", gin.BasicAuth(gin.Accounts{
			c.APIUsername: c.APIPassword,
		}))
	} else {
		log.Warning("DIGO_API_PASSWORD and DIGO_API_USERNAME are not set")
		log.Warning("The API is open to all requests")
		v1 = r.Group("/v1")
	}

	v1.GET("/version", versionV1)
	v1.GET("/channels", channelsV1)
	v1.POST("/message", messageV1)

	go r.Run(iface)
	log.Noticef("Digo API is listening on %s", c.APIInterface)
}
コード例 #24
0
ファイル: routes.go プロジェクト: ovh/tat
// initRoutesStats initialized routes for Stats Controller
func initRoutesStats(router *gin.RouterGroup, checkPassword gin.HandlerFunc) {
	statsCtrl := &StatsController{}

	admin := router.Group("/stats")
	admin.Use(checkPassword, CheckAdmin())
	{
		admin.GET("/count", statsCtrl.Count)
		admin.GET("/instance", statsCtrl.Instance)
		admin.GET("/distribution/topics", statsCtrl.DistributionTopics)
		admin.GET("/db/stats", statsCtrl.DBStats)
		admin.GET("/db/replSetGetConfig", statsCtrl.DBReplSetGetConfig)
		admin.GET("/db/serverStatus", statsCtrl.DBServerStatus)
		admin.GET("/db/replSetGetStatus", statsCtrl.DBReplSetGetStatus)
		admin.GET("/db/collections", statsCtrl.DBStatsCollections)
		admin.GET("/db/slowestQueries", statsCtrl.DBGetSlowestQueries)
		admin.GET("/checkHeaders", statsCtrl.CheckHeaders)
	}
}
コード例 #25
0
ファイル: node_controller.go プロジェクト: KarhuTeam/Karhu
func NewNodeController(s *gin.RouterGroup) *NodeController {

	ctl := &NodeController{}

	s.GET("/nodes/register.sh", ctl.getRegisterSH)
	s.POST("/nodes", ctl.postNode)
	s.GET("/nodes", ctl.getAllNode)
	s.GET("/nodes/config/:filename", ctl.getNodeConfig)

	return ctl
}
コード例 #26
0
ファイル: config_controller.go プロジェクト: KarhuTeam/Karhu
func NewConfigController(s *gin.RouterGroup) *ConfigController {

	ctl := &ConfigController{}

	s.POST("/apps/:id/configs", ctl.postConfig)
	s.PUT("/apps/:id/configs/:config_id", ctl.putConfig)
	s.GET("/apps/:id/configs", ctl.getConfigList)
	s.GET("/apps/:id/configs/:config_id", ctl.getConfig)

	return ctl
}
コード例 #27
0
ファイル: articles.go プロジェクト: tka/goyangi
// @Title Articles
// @Description Article's router group.
func Articles(parentRoute *gin.RouterGroup) {

	route := parentRoute.Group("/articles")
	route.POST("", userPermission.AuthRequired(createArticle))
	route.POST("/all", userPermission.AuthRequired(createArticles))
	route.GET("/:id", retrieveArticle)
	route.GET("", retrieveArticles)
	route.PUT("/:id", userPermission.AuthRequired(updateArticle))
	route.DELETE("/:id", userPermission.AuthRequired(deleteArticle))

	route.POST("/comments", userPermission.AuthRequired(createCommentOnArticle))
	route.GET("/:id/comments", retrieveCommentsOnArticle)
	route.PUT("/:id/comments/:commentId", userPermission.AuthRequired(updateCommentOnArticle))
	route.DELETE("/:id/comments/:commentId", userPermission.AuthRequired(deleteCommentOnArticle))

	route.POST("/likings", userPermission.AuthRequired(createLikingOnArticle))
	route.GET("/:id/likings", retrieveLikingsOnArticles)
	route.DELETE("/:id/likings/:userId", userPermission.AuthRequired(deleteLikingOnArticle))
}
コード例 #28
0
ファイル: routes.go プロジェクト: ovh/tat
// initRoutesPresences initialized routes for Presences Controller
func initRoutesPresences(router *gin.RouterGroup, checkPassword gin.HandlerFunc) {
	presencesCtrl := &PresencesController{}
	g := router.Group("/")
	g.Use(checkPassword)
	{
		// List Presences
		g.GET("presences", presencesCtrl.List)
		g.GET("presences/*topic", presencesCtrl.List)
		// Add a presence and get list
		g.POST("presenceget/*topic", presencesCtrl.CreateAndGet)
		// delete a presence
		g.DELETE("presences/*topic", presencesCtrl.Delete)
	}
	admin := router.Group("/presencesadmin")
	admin.Use(checkPassword, CheckAdmin())
	{
		admin.GET("/checkall", presencesCtrl.CheckAllPresences)
	}
}
コード例 #29
0
ファイル: admin.go プロジェクト: wangmingjob/goyangi
func Admin(parentRoute *gin.RouterGroup) {
	route := parentRoute
	route.GET("/log/access", func(c *gin.Context) {
		c.File(config.AccessLogFilePath + config.AccessLogFileExtension)
	})
	route.GET("log/error", func(c *gin.Context) {
		c.File(config.ErrorLogFilePath + config.ErrorLogFileExtension)
	})

	route = parentRoute.Group("/admin")
	route.GET("/:type", func(c *gin.Context) {
		typeName := c.Params.ByName("type")
		sPARoute(c, "/admin/"+typeName)
	})
	route.GET("/:type/:page", func(c *gin.Context) {
		typeName := c.Params.ByName("type")
		page := c.Params.ByName("page")
		sPARoute(c, "/admin/"+typeName+"/"+page)
	})
}
コード例 #30
-5
ファイル: roles.go プロジェクト: wangmingjob/goyangi
// @Title Roles
// @Description Roles's router group.
func Roles(parentRoute *gin.RouterGroup) {
	route := parentRoute.Group("/roles")
	route.POST("", userPermission.AdminRequired(createRole))
	route.GET("/:id", retrieveRole)
	route.GET("", retrieveRoles)
	route.PUT("/:id", userPermission.AdminRequired(updateRole))
	route.DELETE("/:id", userPermission.AdminRequired(deleteRole))
}