Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(engine): Added OptionFunc and With #3572

Merged
merged 8 commits into from
Mar 11, 2024
Merged

Conversation

flc1125
Copy link
Contributor

@flc1125 flc1125 commented Apr 19, 2023

I would like to add an OptionFunc to facilitate Gin configuration.

Note: This adjustment supports downward compatibility.

Before:

package main

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

func main() {
	r := gin.New()

	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})

	r.Run(":8002")
}

But now:

  • New Engine
package main

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

func main() {
	var fc = func(e *gin.Engine) {
		e.GET("/ping", func(c *gin.Context) {
			c.JSON(200, gin.H{
				"message": "pong",
			})
		})
		
		e.Use(gin.Recovery())
	}

	r := gin.New(fc)

	r.Run(":8002")
}
  • With Engine:
package main

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

func main() {
	r := gin.New()
	
	r.With(func(e *gin.Engine) {
		e.GET("/ping", func(c *gin.Context) {
			c.JSON(200, gin.H{
				"message": "pong",
			})
		})

		e.Use(gin.Recovery())
	})

	r.Run(":8002")
}

@appleboy appleboy added this to the v1.10 milestone Apr 26, 2023
@flc1125
Copy link
Contributor Author

flc1125 commented Apr 26, 2023

@appleboy Does lint information, unrelated to PR, need to be processed?

@flc1125 flc1125 mentioned this pull request Apr 26, 2023
@flc1125
Copy link
Contributor Author

flc1125 commented Apr 26, 2023

lint see #3584

@appleboy
Copy link
Member

appleboy commented Apr 27, 2023

already fixed in #3583, Please rebase the PR.

@flc1125
Copy link
Contributor Author

flc1125 commented Apr 27, 2023

already fixed in #3583, Please rebase the PR.

It's already done

@flc1125
Copy link
Contributor Author

flc1125 commented Apr 27, 2023

😢

@flc1125 flc1125 closed this Apr 27, 2023
@flc1125 flc1125 reopened this Apr 27, 2023
@flc1125
Copy link
Contributor Author

flc1125 commented May 4, 2023

@appleboy

@flc1125
Copy link
Contributor Author

flc1125 commented May 5, 2023

Okay, I'm tweaking related errors, this is devastating. 😂

Signed-off-by: Flc゛ <four_leaf_clover@foxmail.com>
@flc1125
Copy link
Contributor Author

flc1125 commented May 5, 2023

@appleboy Please try again. 3Q

@appleboy appleboy requested review from appleboy and thinkerou May 5, 2023 03:13
@codecov
Copy link

codecov bot commented May 5, 2023

Codecov Report

Merging #3572 (83dee28) into master (757a638) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3572   +/-   ##
=======================================
  Coverage   98.63%   98.63%           
=======================================
  Files          42       42           
  Lines        3151     3156    +5     
=======================================
+ Hits         3108     3113    +5     
  Misses         29       29           
  Partials       14       14           
Flag Coverage Δ
98.63% <100.00%> (+<0.01%) ⬆️
go-1.18 98.54% <100.00%> (+<0.01%) ⬆️
go-1.19 98.63% <100.00%> (+<0.01%) ⬆️
go-1.20 98.63% <100.00%> (+<0.01%) ⬆️
macos-latest 98.63% <100.00%> (+<0.01%) ⬆️
ubuntu-latest 98.63% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
gin.go 99.20% <100.00%> (+0.01%) ⬆️

@appleboy appleboy changed the title feat: Added OptionFunc and With feat(engine): Added OptionFunc and With Mar 11, 2024
@appleboy appleboy merged commit ac5e84d into gin-gonic:master Mar 11, 2024
@appleboy
Copy link
Member

@flc1125 Thanks.

@flc1125 flc1125 deleted the feat-with branch March 11, 2024 15:05
gin.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants