feat: renamed goHTTPRouter to httprouter
BREAKING CHANGE: new package name git.martin-riedl.de/golang/httprouter
This commit is contained in:
parent
c0e04495a4
commit
2fb1b35713
8 changed files with 72 additions and 22 deletions
32
README.md
32
README.md
|
@ -1,17 +1,19 @@
|
||||||
# goHTTPRouter
|
# httprouter
|
||||||
|
|
||||||
|
[](https://git.martin-riedl.de/golang/httprouter/tags)
|
||||||
|
[](https://git.martin-riedl.de/golang/httprouter/actions)
|
||||||
[](https://godoc.org/gitlab.com/martinr92/gohttprouter)
|
[](https://godoc.org/gitlab.com/martinr92/gohttprouter)
|
||||||
[](https://gitlab.com/martinr92/gohttprouter/commits/master)
|
|
||||||
[](https://gitlab.com/martinr92/gohttprouter/commits/master)
|
|
||||||
[](https://codecov.io/gl/martinr92/gohttprouter)
|
|
||||||
[](https://goreportcard.com/report/gitlab.com/martinr92/gohttprouter)
|
[](https://goreportcard.com/report/gitlab.com/martinr92/gohttprouter)
|
||||||
|
|
||||||
goHTTPRouter is a framework used for HTTP request routing.
|
httprouter is a framework used for HTTP request routing.
|
||||||
|
|
||||||
# Examples
|
# Examples
|
||||||
|
|
||||||
## Simple Routing
|
## Simple Routing
|
||||||
|
|
||||||
Just replace the standard router of golang with this one:
|
Just replace the standard router of golang with this one:
|
||||||
```golang
|
```golang
|
||||||
import httprouter "gitlab.com/martinr92/gohttprouter/v3"
|
import "git.martin-riedl.de/golang/httprouter/v3"
|
||||||
```
|
```
|
||||||
```golang
|
```golang
|
||||||
router := httprouter.New()
|
router := httprouter.New()
|
||||||
|
@ -22,9 +24,10 @@ err := http.ListenAndServe("localhost:8080", router)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Routing with placeholder
|
## Routing with placeholder
|
||||||
|
|
||||||
A path can also contain placeholder (like :id). If then a request is sent to the url "/user/123" the method gets executed and the URL part (in this case "123") is passed as parameter into your handler function.
|
A path can also contain placeholder (like :id). If then a request is sent to the url "/user/123" the method gets executed and the URL part (in this case "123") is passed as parameter into your handler function.
|
||||||
```golang
|
```golang
|
||||||
import httprouter "gitlab.com/martinr92/gohttprouter/v3"
|
import "git.martin-riedl.de/golang/httprouter/v3"
|
||||||
```
|
```
|
||||||
```golang
|
```golang
|
||||||
router := httprouter.New()
|
router := httprouter.New()
|
||||||
|
@ -38,11 +41,12 @@ err := http.ListenAndServe("localhost:8080", router)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Serve Static Content
|
## Serve Static Content
|
||||||
|
|
||||||
Static files (like JavaScript or CSS) can be served automatically (including caching header and MIME type). It uses the `embed.FS` (since go 1.16) to serve static content.
|
Static files (like JavaScript or CSS) can be served automatically (including caching header and MIME type). It uses the `embed.FS` (since go 1.16) to serve static content.
|
||||||
```golang
|
```golang
|
||||||
import httprouter "gitlab.com/martinr92/gohttprouter/v3"
|
import "git.martin-riedl.de/golang/httprouter/v3"
|
||||||
|
|
||||||
//go:embed files/statc/*
|
//go:embed files/static/*
|
||||||
var staticFiles embed.FS
|
var staticFiles embed.FS
|
||||||
```
|
```
|
||||||
```golang
|
```golang
|
||||||
|
@ -51,9 +55,12 @@ router := httprouter.New()
|
||||||
router.Handle(http.MethodGet, "/static/*", staticFS)
|
router.Handle(http.MethodGet, "/static/*", staticFS)
|
||||||
```
|
```
|
||||||
|
|
||||||
For development purpose you can enable the local file serving additionally. The framework checks first, if the file exists locally and serves it directly. If not, the file is served from the `embed.FS`. This helps you during local development so you can modify a CSS file without recompiling everything.
|
For development purpose you can enable the local file serving additionally.
|
||||||
|
The framework checks first, if the file exists locally and serves it directly.
|
||||||
|
If not, the file is served from the `embed.FS`.
|
||||||
|
This helps you during local development so you can modify a CSS file without recompiling everything.
|
||||||
```golang
|
```golang
|
||||||
import httprouter "gitlab.com/martinr92/gohttprouter/v3"
|
import "git.martin-riedl.de/golang/httprouter/v3"
|
||||||
```
|
```
|
||||||
```golang
|
```golang
|
||||||
staticFS := httprouter.NewFS(&staticFiles)
|
staticFS := httprouter.NewFS(&staticFiles)
|
||||||
|
@ -62,8 +69,9 @@ staticFS.LocalFolderPrefix = "some/folder" // optional
|
||||||
```
|
```
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
```
|
```
|
||||||
Copyright 2018-2021 Martin Riedl
|
Copyright 2018-2025 Martin Riedl
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|
4
fs.go
4
fs.go
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2021 Martin Riedl
|
// Copyright 2021-2025 Martin Riedl
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package gohttprouter
|
package httprouter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
|
16
fs_test.go
16
fs_test.go
|
@ -1,4 +1,18 @@
|
||||||
package gohttprouter
|
// Copyright 2025 Martin Riedl
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package httprouter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,3 +1,3 @@
|
||||||
module gitlab.com/martinr92/gohttprouter/v3
|
module git.martin-riedl.de/golang/httprouter/v3
|
||||||
|
|
||||||
go 1.19
|
go 1.19
|
4
route.go
4
route.go
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2018-2021 Martin Riedl
|
// Copyright 2018-2025 Martin Riedl
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package gohttprouter
|
package httprouter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
|
@ -1,4 +1,18 @@
|
||||||
package gohttprouter
|
// Copyright 2025 Martin Riedl
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package httprouter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2018-2021 Martin Riedl
|
// Copyright 2018-2025 Martin Riedl
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package gohttprouter
|
package httprouter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
|
@ -1,4 +1,18 @@
|
||||||
package gohttprouter
|
// Copyright 2025 Martin Riedl
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package httprouter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
Loading…
Add table
Reference in a new issue