gin icon indicating copy to clipboard operation
gin copied to clipboard

feat(engine): Added methods that support OptionFunc

Open flc1125 opened this issue 2 months ago • 1 comments

Example:

package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {
	router := gin.New(
		// middleware
		gin.Use(gin.Recovery(), gin.Logger()),

		// routes
		gin.GET("/get", func(c *gin.Context) {}),
		gin.GET("/get/another", func(c *gin.Context) {}),
		gin.POST("/post", func(c *gin.Context) {}),
		gin.PUT("/put", func(c *gin.Context) {}),
		gin.DELETE("/delete", func(c *gin.Context) {}),
		gin.PATCH("/patch", func(c *gin.Context) {}),
		gin.HEAD("/head", func(c *gin.Context) {}),
		gin.OPTIONS("/options", func(c *gin.Context) {}),
		gin.Any("/any", func(c *gin.Context) {}),

		// group
		gin.Group("/group", func(group *gin.RouterGroup) {
			group.GET("/get", func(c *gin.Context) {})
			group.GET("/get/another", func(c *gin.Context) {})
		}),

		// route
		gin.Route("GET", "/route", func(c *gin.Context) {}),

		// no route
		gin.NoRoute(func(c *gin.Context) {}),

		// static
		gin.Static("/static", "/var/www"),
		gin.StaticFile("/favicon.ico", "/var/www/favicon.ico"),
		gin.StaticFS("/static", http.Dir("/var/www")),

		// custom
		router(),
	)

	router.Run(":8080")
}

func router() func(router *gin.Engine) {
	return func(router *gin.Engine) {
		router.GET("/custom", func(c *gin.Context) {})
	}
}

flc1125 avatar Mar 14 '24 06:03 flc1125

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.20%. Comparing base (3dc1cd6) to head (159d883). Report is 36 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3890      +/-   ##
==========================================
- Coverage   99.21%   99.20%   -0.02%     
==========================================
  Files          42       44       +2     
  Lines        3182     2756     -426     
==========================================
- Hits         3157     2734     -423     
+ Misses         17       12       -5     
- Partials        8       10       +2     
Flag Coverage Δ
?
-tags "sonic avx" 99.19% <100.00%> (?)
-tags go_json 99.19% <100.00%> (?)
-tags nomsgpack 99.18% <100.00%> (?)
go-1.18 99.12% <100.00%> (+<0.01%) :arrow_up:
go-1.19 99.20% <100.00%> (-0.02%) :arrow_down:
go-1.20 99.20% <100.00%> (-0.02%) :arrow_down:
go-1.21 99.20% <100.00%> (-0.02%) :arrow_down:
go-1.22 99.20% <100.00%> (?)
macos-latest 99.20% <100.00%> (-0.02%) :arrow_down:
ubuntu-latest 99.20% <100.00%> (-0.02%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Mar 14 '24 06:03 codecov[bot]