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

add mux.HandlePath method (v2) #1449

Merged
merged 2 commits into from
Jun 9, 2020
Merged

add mux.HandlePath method (v2) #1449

merged 2 commits into from
Jun 9, 2020

Conversation

ti
Copy link
Contributor

@ti ti commented Jun 9, 2020

in v2, we can not use internal/httprule from outside, so we need add this new method for add custom pattern from out side.

Brief description of what is fixed or changed

with this feature, People can add custom pattern From outsiede

exmaple

mux.HandlePath("GET", "/v1/user/{user_id}/data", ...)

Other comments

in v1 we can use bellow code, but in v2 the httprule in internal, we can not use it from outside

// HandlePath associates "h" to the pair of HTTP method and path pattern.
func HandlePath(method string, path string, h runtime.HandlerFunc) {
	compiler, err := httprule.Parse(path)
	if err != nil {
		log.Fatalf("Parse path to compiler failed: %v", err)
	}
	tp := compiler.Compile()
	pattern := runtime.MustPattern(runtime.NewPattern(tp.Version, tp.OpCodes, tp.Pool, tp.Verb))
	mux.Handle(method, pattern, h)
}
// exmaple
HandlePath("GET", "/v1/user/{user_id}/data", ...)

@codecov-commenter
Copy link

Codecov Report

Merging #1449 into v2 will increase coverage by 0.05%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##               v2    #1449      +/-   ##
==========================================
+ Coverage   59.05%   59.11%   +0.05%     
==========================================
  Files          32       32              
  Lines        3903     3913      +10     
==========================================
+ Hits         2305     2313       +8     
- Misses       1344     1345       +1     
- Partials      254      255       +1     
Impacted Files Coverage Δ
runtime/mux.go 60.68% <80.00%> (+1.80%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e3513c9...5699091. Read the comment docs.

@ti
Copy link
Contributor Author

ti commented Jun 9, 2020

@johanbrandhorst
sorry for I lost some data when rebase from v2, I create a new patch with all the codes and docs from the previous merge request

refer : #1440

@johanbrandhorst johanbrandhorst merged commit c4b0f84 into grpc-ecosystem:v2 Jun 9, 2020
@johanbrandhorst
Copy link
Collaborator

Thank you for your contribution!

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.

4 participants