-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from usama-tariq1/Update
Update -> create controller with model , create middleware with cli ,…
- Loading branch information
Showing
8 changed files
with
114 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package middlewares | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func {{.Name}}() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
t := time.Now() | ||
|
||
// Set example variable | ||
c.Set("example", "12345") | ||
// get the value in controller with | ||
// example := c.MustGet("example").(string) | ||
|
||
// before request | ||
|
||
c.Next() | ||
|
||
// after request | ||
latency := time.Since(t) | ||
log.Print(latency) | ||
|
||
// access the status we are sending | ||
status := c.Writer.Status() | ||
log.Println(status) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package routers | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"{{.ModName}}/controllers" | ||
|
||
) | ||
|
||
type {{ .Name }} struct { | ||
} | ||
|
||
|
||
func ({{ .Name }} {{ .Name }} ) handle(router *gin.RouterGroup) { | ||
var {{.ControllerName}} controllers.{{.ControllerName}} | ||
// router.Use(middlewares.Sample()) | ||
|
||
router.GET("", {{.ControllerName}}.Index) | ||
router.POST("", {{.ControllerName}}.Create) | ||
router.GET("/:id", {{.ControllerName}}.Read) | ||
router.PATCH("/:id", {{.ControllerName}}.Update) | ||
router.DELETE("/:id", {{.ControllerName}}.Delete) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package middlewares | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func Sample() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
t := time.Now() | ||
|
||
// Set example variable | ||
c.Set("example", "12345") | ||
// get the value in controller with | ||
// example := c.MustGet("example").(string) | ||
|
||
// before request | ||
|
||
c.Next() | ||
|
||
// after request | ||
latency := time.Since(t) | ||
log.Print(latency) | ||
|
||
// access the status we are sending | ||
status := c.Writer.Status() | ||
log.Println(status) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters