-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pat: rename newWithMethods to NewWithMethods
In this commit newWithMethods is renamed to NewWithMethods. As a result it is publically accesible, and allows pat route with custom http methods to be constructed. One of the use case is to support LOCK HTTP method in RFC 2518. It looks like ``` mux.HandleFunc(NewWithMethods("/:name", "LOCK"), handlerFunc) ```
- Loading branch information
Showing
3 changed files
with
35 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,66 @@ | ||
package pat | ||
|
||
/* | ||
NewWithMethods returns a Pat route that matches http methods that are provided | ||
*/ | ||
func NewWithMethods(pat string, methods ...string) *Pattern { | ||
p := New(pat) | ||
|
||
methodSet := make(map[string]struct{}, len(methods)) | ||
for _, method := range methods { | ||
methodSet[method] = struct{}{} | ||
} | ||
p.methods = methodSet | ||
|
||
return p | ||
} | ||
|
||
/* | ||
Delete returns a Pat route that only matches the DELETE HTTP method. | ||
*/ | ||
func Delete(pat string) *Pattern { | ||
return newWithMethods(pat, "DELETE") | ||
return NewWithMethods(pat, "DELETE") | ||
} | ||
|
||
/* | ||
Get returns a Pat route that only matches the GET and HEAD HTTP method. HEAD | ||
requests are handled transparently by net/http. | ||
*/ | ||
func Get(pat string) *Pattern { | ||
return newWithMethods(pat, "GET", "HEAD") | ||
return NewWithMethods(pat, "GET", "HEAD") | ||
} | ||
|
||
/* | ||
Head returns a Pat route that only matches the HEAD HTTP method. | ||
*/ | ||
func Head(pat string) *Pattern { | ||
return newWithMethods(pat, "HEAD") | ||
return NewWithMethods(pat, "HEAD") | ||
} | ||
|
||
/* | ||
Options returns a Pat route that only matches the OPTIONS HTTP method. | ||
*/ | ||
func Options(pat string) *Pattern { | ||
return newWithMethods(pat, "OPTIONS") | ||
return NewWithMethods(pat, "OPTIONS") | ||
} | ||
|
||
/* | ||
Patch returns a Pat route that only matches the PATCH HTTP method. | ||
*/ | ||
func Patch(pat string) *Pattern { | ||
return newWithMethods(pat, "PATCH") | ||
return NewWithMethods(pat, "PATCH") | ||
} | ||
|
||
/* | ||
Post returns a Pat route that only matches the POST HTTP method. | ||
*/ | ||
func Post(pat string) *Pattern { | ||
return newWithMethods(pat, "POST") | ||
return NewWithMethods(pat, "POST") | ||
} | ||
|
||
/* | ||
Put returns a Pat route that only matches the PUT HTTP method. | ||
*/ | ||
func Put(pat string) *Pattern { | ||
return newWithMethods(pat, "PUT") | ||
return NewWithMethods(pat, "PUT") | ||
} |
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