本文整理匯總了Golang中github.com/gin-gonic/gin.RouterGroup.POST方法的典型用法代碼示例。如果您正苦於以下問題:Golang RouterGroup.POST方法的具體用法?Golang RouterGroup.POST怎麽用?Golang RouterGroup.POST使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gin-gonic/gin.RouterGroup
的用法示例。
在下文中一共展示了RouterGroup.POST方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Person
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)
}
示例2: api
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)),
})
}
})
}
示例3: Listen
// 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)
}
示例4: Use
// 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)
}
}
示例5: Setup
// 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))
}
}
示例6: NewBuildController
func NewBuildController(s *gin.RouterGroup) *BuildController {
ctl := &BuildController{}
s.POST("/apps/:id/builds", ctl.postBuild)
s.GET("/apps/:id/builds", ctl.getBuildList)
s.POST("/apps/:id/builds/:build_id/deploy", ctl.postBuildDeploy)
return ctl
}
示例7: Use
// Use is an exported function that
// define routing for user
func Use(r *gin.RouterGroup) {
r.Use()
{
r.GET("/user", getUsers)
r.GET("/user/:id", getUser)
r.POST("/user", postUser)
r.PATCH("/user/:id", updateUser)
r.DELETE("/user/:id", deleteUser)
}
}
示例8: NewConfigController
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
}
示例9: NewNodeController
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
}
示例10: RegisterRouterGroup
func (mm *ModuleManager) RegisterRouterGroup(group *gin.RouterGroup) {
group.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, (*mm).GetAllModules())
})
group.POST("/", func(c *gin.Context) {
var req shared.Module
err := c.BindJSON(&req)
if err != nil {
c.JSON(400, shared.HttpError{"Decoding HTTP body failed.", err})
return
}
if strings.TrimSpace(req.ModuleURL) == "" {
c.JSON(400, shared.HttpError{"Attribute 'module-url' is missing.", nil})
return
}
if mm.GetModule(req.Metadata.ID) != nil {
c.JSON(423, shared.HttpError{"Module already registered.", nil})
return
}
mm.AddModule(&req)
})
group.Any("/:module/proxy/*path", func(c *gin.Context) {
module := mm.GetModule(c.Param("module"))
if module == nil {
c.JSON(404, shared.HttpError{"Module not found.", nil})
return
}
target, err := url.Parse(module.ModuleURL)
if module == nil {
c.JSON(500, shared.HttpError{"Error connecting to module.", err})
return
}
oldPrefix := fmt.Sprintf("%s/%s/proxy", group.BasePath(), module.Metadata.ID)
newPrefix := "/module"
var handler http.Handler
handler = httputil.NewSingleHostReverseProxy(target)
handler = HTTPAddPrefix(newPrefix, handler)
handler = http.StripPrefix(oldPrefix, handler)
wrapper := gin.WrapH(handler)
wrapper(c)
})
}
示例11: UserRouter
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)
}
})
}
示例12: CRUD
// 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)
}
}
示例13: initRoutesUsers
// initRoutesUsers initialized routes for Users Controller
func initRoutesUsers(router *gin.RouterGroup, checkPassword gin.HandlerFunc) {
usersCtrl := &UsersController{}
gs := router.Group("/users")
gs.Use(checkPassword)
{
gs.GET("", usersCtrl.List)
}
g := router.Group("/user")
g.Use(checkPassword)
{
g.GET("/me", usersCtrl.Me)
g.GET("/me/contacts/:sinceSeconds", usersCtrl.Contacts)
g.POST("/me/contacts/:username", usersCtrl.AddContact)
g.DELETE("/me/contacts/:username", usersCtrl.RemoveContact)
g.POST("/me/topics/*topic", usersCtrl.AddFavoriteTopic)
g.DELETE("/me/topics/*topic", usersCtrl.RemoveFavoriteTopic)
g.POST("/me/tags/:tag", usersCtrl.AddFavoriteTag)
g.DELETE("/me/tags/:tag", usersCtrl.RemoveFavoriteTag)
g.POST("/me/enable/notifications/topics/*topic", usersCtrl.EnableNotificationsTopic)
g.POST("/me/disable/notifications/topics/*topic", usersCtrl.DisableNotificationsTopic)
g.POST("/me/enable/notifications/alltopics", usersCtrl.EnableNotificationsAllTopics)
g.POST("/me/disable/notifications/alltopics", usersCtrl.DisableNotificationsAllTopics)
}
admin := router.Group("/user")
admin.Use(checkPassword, CheckAdmin())
{
admin.PUT("/convert", usersCtrl.Convert)
admin.PUT("/archive", usersCtrl.Archive)
admin.PUT("/rename", usersCtrl.Rename)
admin.PUT("/update", usersCtrl.Update)
admin.PUT("/setadmin", usersCtrl.SetAdmin)
admin.PUT("/resetsystem", usersCtrl.ResetSystemUser)
admin.PUT("/updatesystem", usersCtrl.UpdateSystemUser)
admin.PUT("/check", usersCtrl.Check)
}
router.GET("/user/verify/:username/:tokenVerify", usersCtrl.Verify)
router.POST("/user/reset", usersCtrl.Reset)
router.POST("/user", usersCtrl.Create)
}
示例14: ConfigureRoutes
// ConfigureRoutes configures the routes for this controller
func (dc *DataController) ConfigureRoutes(route *gin.RouterGroup) {
route.POST("saveServer", dc.saveServer)
route.POST("deleteServer", dc.deleteServer)
route.GET("loadServers", dc.loadServers)
route.GET("loadSettings", dc.loadSettings)
route.POST("saveSettings", dc.saveSettings)
route.GET("findPackets", dc.findPackets)
route.GET("countPackets", dc.countPackets)
route.GET("loadLogFile", dc.loadLogFile)
route.GET("clearLogFile", dc.clearLogFile)
}
示例15: ConfigureRoutes
// ConfigureRoutes configures the routes for this controller
func (dc *DownloadsController) ConfigureRoutes(route *gin.RouterGroup) {
route.POST("downloadPacket", dc.downloadPacket)
route.POST("startDirectDownload", dc.startDirectDownload)
route.GET("listDownloads", dc.listDownloads)
route.POST("stopDownload", dc.stopDownload)
route.POST("cancelDownload", dc.cancelDownload)
route.POST("resumeDownload", dc.resumeDownload)
route.GET("loadFiles", dc.loadFiles)
route.POST("deleteFiles", dc.deleteFiles)
route.POST("moveFilesToMovies", dc.moveFilesToMovies)
}