forked from acoshift/httprouter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more/improved documentation; tests converted to Gomega
- Loading branch information
Showing
7 changed files
with
232 additions
and
310 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,32 @@ | ||
package httprouter_test | ||
|
||
import ( | ||
"github.com/rickb777/httprouter/v3" | ||
"github.com/rickb777/servefiles/v3" | ||
"log" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func ExampleRouter_SubRouter_usingAnAssetHandler() { | ||
// This is a webserver using the asset handler provided by | ||
// github.com/rickb777/servefiles/v3, which has enhanced | ||
// HTTP expiry, cache control, compression etc. | ||
// 'Normal' bespoke handlers are included as needed. | ||
|
||
// where the assets are stored (replace as required) | ||
localPath := "./assets" | ||
|
||
// how long we allow user agents to cache assets | ||
// (this is in addition to conditional requests, see | ||
// RFC7234 https://tools.ietf.org/html/rfc7234#section-5.2.2.8) | ||
maxAge := time.Hour | ||
|
||
h := servefiles.NewAssetHandler(localPath).WithMaxAge(maxAge) | ||
|
||
router := httprouter.New() | ||
// ... add other routes / handlers as required | ||
router.SubRouter("/files/*", h, http.MethodGet, http.MethodHead) | ||
|
||
log.Fatal(http.ListenAndServe(":8080", router)) | ||
} |
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
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
Oops, something went wrong.