Skip to content

Commit

Permalink
Fix paths
Browse files Browse the repository at this point in the history
  • Loading branch information
vardius committed Jan 1, 2024
1 parent 94183f7 commit cc09601
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 23 deletions.
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ and can contain named wildcard placeholders *(e.g. {placeholder})* to match dyna
Take the following example:
import "github.com/ceriath/gorouter/v4/context"
import "github.com/vardius/gorouter/v4/context"
router.GET("/hello/{name:r([a-z]+)go}", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
params, _ := context.Parameters(r.Context())
Expand Down
3 changes: 1 addition & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (

"github.com/valyala/fasthttp"

"github.com/ceriath/gorouter/v4"
"github.com/ceriath/gorouter/v4/context"
"github.com/vardius/gorouter/v4/context"
)

func handleNetHTTPRequest(method, path string, handler http.Handler) {
Expand Down
6 changes: 3 additions & 3 deletions fasthttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package gorouter
import (
"strings"

pathutils "github.com/ceriath/gorouter/v4/path"
pathutils "github.com/vardius/gorouter/v4/path"

"github.com/valyala/fasthttp"

"github.com/ceriath/gorouter/v4/middleware"
"github.com/ceriath/gorouter/v4/mux"
"github.com/vardius/gorouter/v4/middleware"
"github.com/vardius/gorouter/v4/mux"
)

var allFasthttpMethods = []string{
Expand Down
2 changes: 1 addition & 1 deletion fasthttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/valyala/fasthttp"

"github.com/ceriath/gorouter/v4/context"
"github.com/vardius/gorouter/v4/context"
)

func buildFastHTTPRequestContext(method, path string) *fasthttp.RequestCtx {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/ceriath/gorouter/v4
module github.com/vardius/gorouter/v4

go 1.20

Expand Down
6 changes: 3 additions & 3 deletions mux/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package mux
import (
"regexp"

"github.com/ceriath/gorouter/v4/context"
"github.com/ceriath/gorouter/v4/middleware"
pathutils "github.com/ceriath/gorouter/v4/path"
"github.com/vardius/gorouter/v4/context"
"github.com/vardius/gorouter/v4/middleware"
pathutils "github.com/vardius/gorouter/v4/path"
)

// NewNode provides new mux Node
Expand Down
6 changes: 3 additions & 3 deletions mux/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"sort"
"strings"

"github.com/ceriath/gorouter/v4/context"
"github.com/ceriath/gorouter/v4/middleware"
pathutils "github.com/ceriath/gorouter/v4/path"
"github.com/vardius/gorouter/v4/context"
"github.com/vardius/gorouter/v4/middleware"
pathutils "github.com/vardius/gorouter/v4/path"
)

// NewTree provides new empty Tree
Expand Down
8 changes: 4 additions & 4 deletions nethttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"net/url"
"strings"

"github.com/ceriath/gorouter/v4/context"
"github.com/ceriath/gorouter/v4/middleware"
"github.com/ceriath/gorouter/v4/mux"
pathutils "github.com/ceriath/gorouter/v4/path"
"github.com/vardius/gorouter/v4/context"
"github.com/vardius/gorouter/v4/middleware"
"github.com/vardius/gorouter/v4/mux"
pathutils "github.com/vardius/gorouter/v4/path"
)

var allNethttpMethods = []string{
Expand Down
2 changes: 1 addition & 1 deletion nethttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/ceriath/gorouter/v4/context"
"github.com/vardius/gorouter/v4/context"
)

func TestInterface(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http/httptest"
"testing"

"github.com/ceriath/gorouter/v4/context"
"github.com/ceriath/gorouter/v4/middleware"
"github.com/vardius/gorouter/v4/context"
"github.com/vardius/gorouter/v4/middleware"
)

func TestRouter(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gorouter
import (
"net/http"

"github.com/ceriath/gorouter/v4/mux"
"github.com/vardius/gorouter/v4/mux"
)

func allowed(t mux.Tree, method, path string) (allow string) {
Expand Down
78 changes: 78 additions & 0 deletions website/docs/apphandler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
id: apphandler
title: App Handler
sidebar_label: App Handler
---

## Use custom handler type in your application

<!--DOCUSAURUS_CODE_TABS-->
<!--net/http-->

```go
package main

import (
"errors"
"fmt"
"log"
"net/http"

"github.com/vardius/gorouter/v4"
)

type AppHandlerFunc func(http.ResponseWriter, *http.Request) error

// ServeHTTP calls f(w, r) and handles error
func (f AppHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err := f(w, r); err != nil {
w.WriteHeader(http.StatusInternalServerError)
_, _ = fmt.Fprint(w, err.Error())
}
}

func Index(w http.ResponseWriter, r *http.Request) error {
return errors.New("I am app handler which can return error")
}

func main() {
router := gorouter.New()
router.GET("/", AppHandlerFunc(Index))

log.Fatal(http.ListenAndServe(":8080", router))
}
```
<!--valyala/fasthttp-->
```go
package main

import (
"errors"
"log"

"github.com/valyala/fasthttp"
"github.com/vardius/gorouter/v4"
)

type AppHandlerFunc func(ctx *fasthttp.RequestCtx) error

// HandleFastHTTP calls f(ctx) and handles error
func (f AppHandlerFunc) HandleFastHTTP(ctx *fasthttp.RequestCtx) {
if err := f(ctx); err != nil {
ctx.SetBody([]byte(err.Error()))
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
}
}

func index(_ *fasthttp.RequestCtx) error {
return errors.New("I am app handler which can return error")
}

func main() {
router := gorouter.NewFastHTTPRouter()
router.GET("/", AppHandlerFunc(index))

log.Fatal(fasthttp.ListenAndServe(":8080", router.HandleFastHTTP))
}
```
<!--END_DOCUSAURUS_CODE_TABS-->
3 changes: 2 additions & 1 deletion website/src/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"https",
"http2",
"multidomain",
"panic"
"panic",
"apphandler"
],
"Benchmark": ["benchmark"]
}
Expand Down

0 comments on commit cc09601

Please sign in to comment.