-
Notifications
You must be signed in to change notification settings - Fork 689
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
47 additions
and
1 deletion.
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,33 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"log" | ||
"net/http" | ||
|
||
restful "github.com/emicklei/go-restful/v3" | ||
) | ||
|
||
// This example shows how to handle different casing of path template. | ||
// | ||
// GET http://localhost:8080/hola/Juan | ||
// GET http://localhost:8080/HOLA/Juan | ||
// GET http://localhost:8080/Hola/Juan | ||
|
||
func main() { | ||
ws := new(restful.WebService) | ||
|
||
// hola is path template, to accept different casing of hola, we use regex matching with syntax {name:regex} | ||
// - {: is nesserary to trigger the regex matching. | ||
// - (?i) is to make the regex case-insensitive. | ||
// it seems solve the issue, but there is a issue you might hit: https://github.com/emicklei/go-restful/issues/545 | ||
// to avoid partial matching, another regex pattern | ||
// - ^$ is needed to match the whole route token. | ||
ws.Route(ws.GET("/{:(?i)^hola$}/{name:*}").To(hola)) | ||
restful.Add(ws) | ||
log.Fatal(http.ListenAndServe(":8080", nil)) | ||
} | ||
|
||
func hola(req *restful.Request, resp *restful.Response) { | ||
io.WriteString(resp, "hola "+req.PathParameter("name")) | ||
} |
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,5 @@ | ||
module github.com/emicklei/go-restful/examples/pathtemplatecasing | ||
|
||
go 1.14 | ||
|
||
require github.com/emicklei/go-restful/v3 v3.12.0 |
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,2 @@ | ||
github.com/emicklei/go-restful/v3 v3.12.0 h1:y2DdzBAURM29NFF94q6RaY4vjIH1rtwDapwQtU84iWk= | ||
github.com/emicklei/go-restful/v3 v3.12.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= |
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,3 @@ | ||
GET http://localhost:8080/hola/Juan | ||
GET http://localhost:8080/HOLA/Juan | ||
GET http://localhost:8080/Hola/Juan |