-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/override-regexp-compile
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 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,35 @@ | ||
package mux_test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gorilla/mux" | ||
) | ||
|
||
// This example demonstrates building a dynamic URL using | ||
// required vars and values retrieve from another source | ||
func ExampleRoute_GetVarNames() { | ||
r := mux.NewRouter() | ||
|
||
route := r.Host("{domain}"). | ||
Path("/{group}/{item_id}"). | ||
Queries("some_data1", "{some_data1}"). | ||
Queries("some_data2_and_3", "{some_data2}.{some_data3}") | ||
|
||
dataSource := func(key string) string { | ||
return "my_value_for_" + key | ||
} | ||
|
||
varNames, _ := route.GetVarNames() | ||
|
||
pairs := make([]string, 0, len(varNames)*2) | ||
|
||
for _, varName := range varNames { | ||
pairs = append(pairs, varName, dataSource(varName)) | ||
} | ||
|
||
url, err := route.URL(pairs...) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(url.String()) | ||
} |
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