Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
covrom committed Aug 26, 2024
1 parent cc8c893 commit d80f947
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,61 @@
# stdchi
go 1.22+ standard http router wrapper like chi router
go 1.22+ standard http router wrapper with API like chi router.

Example:

```go
import chi "github.com/covrom/stdchi"

// ...

r := NewRouter()
r.Use(func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Route /sharing")
r.Write(os.Stdout)
h.ServeHTTP(w, r)
})
})

r.Get("/{hash}", func(w http.ResponseWriter, r *http.Request) {
v := r.PathValue("hash")
w.Write([]byte(fmt.Sprintf("/%s", v)))
fmt.Println("Done GET /{hash}")
})

r.Route("/{hash}/share", func(r Router) {
r.Use(func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Route /{hash}/share/")
r.Write(os.Stdout)
h.ServeHTTP(w, r)
})
})

r.Get("/{$}", func(w http.ResponseWriter, r *http.Request) {
v := r.PathValue("hash")
w.Write([]byte(fmt.Sprintf("/%s/share", v)))
fmt.Println("Done GET /{hash}/share/")
})
r.Get("/{network}", func(w http.ResponseWriter, r *http.Request) {
v := r.PathValue("hash")
n := r.PathValue("network")
w.Write([]byte(fmt.Sprintf("/%s/share/%s", v, n)))
fmt.Println("Done GET /{hash}/share/{network}")
})
})

m := NewRouter()
m.Mount("/sharing", r)
m.Use(func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Route /")
r.Write(os.Stdout)
h.ServeHTTP(w, r)
})
})

// ...

http.ListenAndServe(":8080", m)
```

0 comments on commit d80f947

Please sign in to comment.