https://github.com/vanng822/grbinder
Gin route binder
https://github.com/vanng822/grbinder
Last synced: 2 months ago
JSON representation
Gin route binder
- Host: GitHub
- URL: https://github.com/vanng822/grbinder
- Owner: vanng822
- License: mit
- Created: 2016-08-05T12:24:18.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-08-16T09:51:32.000Z (almost 6 years ago)
- Last Synced: 2025-01-18T05:27:33.048Z (over 1 year ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# grbinder
Gin route binder
# usage
```go
type statusHandler struct {
}
func (h *statusHandler) GET(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "OK"})
}
router := gin.Default()
grbinder.BindVerb(router.Group("/status"), &statusHandler{})
```
With lock
```go
func init() {
grbinder.InitDefaultLocker()
}
type calendarHandler struct {
}
func (h *calendarHandler) CreateHandler(c *gin.Context) {
// create calendar
c.JSON(http.StatusOK, gin.H{"status": "OK"})
}
func (h *calendarHandler) TakeHandler(c *gin.Context) {
// serve calendar
c.JSON(http.StatusOK, gin.H{"status": "OK"})
}
func (h *calendarHandler) UpdateHandler(c *gin.Context) {
// update calendar required lock
c.JSON(http.StatusOK, gin.H{"status": "OK"})
}
func (h *calendarHandler) DeleteHandler(c *gin.Context) {
// delete calendar required lock
c.JSON(http.StatusOK, gin.H{"status": "OK"})
}
router := gin.Default()
grbinder.CRUD(
router.Group("/calendar"),
&calendarHandler{},
grbinder.WithEntityLockEnable(true),
grbinder.WithEntityLockName("calendar"),
)
type calendarSubscribeHandler struct {
}
func (h *calendarSubscribeHandler) POST(c *gin.Context) {
// Lock when subscribing calendar
c.JSON(http.StatusOK, gin.H{"status": "OK"})
}
func (h *calendarSubscribeHandler) DELETE(c *gin.Context) {
// Lock when unsubscribing calendar
c.JSON(http.StatusOK, gin.H{"status": "OK"})
}
grbinder.BindVerb(
router.Group("/calendar/:id/subscribe"),
&calendarSubscribeHandler{},
grbinder.WithEntityLockEnable(true),
grbinder.WithEntityLockName("calendar"),
)
```