https://github.com/tomiok/webh
Webh is a self contained library that has a production ready web server with all the capabilities, ready to use. Including safe start-shutdown, middlewares and handy error management
https://github.com/tomiok/webh
golang library mux-router server web
Last synced: 11 months ago
JSON representation
Webh is a self contained library that has a production ready web server with all the capabilities, ready to use. Including safe start-shutdown, middlewares and handy error management
- Host: GitHub
- URL: https://github.com/tomiok/webh
- Owner: tomiok
- License: gpl-3.0
- Created: 2023-06-24T23:13:54.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-05-21T19:52:45.000Z (about 2 years ago)
- Last Synced: 2024-06-07T16:36:33.056Z (about 2 years ago)
- Topics: golang, library, mux-router, server, web
- Language: Go
- Homepage:
- Size: 37.1 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
[](https://github.com/tomiok/webh/blob/master/LICENSE)
# webh, the web helper for Golang
## Include web code snippets for speed up the development.
This is a tiny yet powerful library was built for do not write every single
time the web server.
We provide several capabilities used in the industry like
middlewares, graceful shutdown, logging, ability to unwrap web handlers that return an
error in order to avoid weird returns.
A clean mechanism to log errors among the http requests.
Encoder and Decoder for JSON.
A custom error type for web purposes.
The Server is created on top of [chi](https://go-chi.io) web library, so will have all
the same features and ways to declare endpoints.
Heartbeat at `/ping` is already declared for you, among recover and logger. Do not worry to add them.
### Installation
```shell
go get -u github.com/tomiok/webh
```
### Create and start the server with one endpoint.
```go
s := webh.NewServer("8080", webh.WithLogger("hello"), webh.WithHeartbeat("/ping"))
s.Get("/hello", func(w http.ResponseWriter, r *http.Request){
//.....
})
s.Start()
```
or use a custom handler returning an error.
```go
package web
import (
"fmt"
"net/http"
)
func HelloHandler(w http.ResponseWriter, r *http.Request) error {
_, err := fmt.Fprint(w, "hello")
return err
}
```
```go
package main
import "github.com/tomiok/webh"
func main() {
s := webh.NewServer("8080", webh.WithLogger("hello"), webh.WithHeartbeat("/ping"))
s.Get("/hello", webh.Unwrap(HelloHandler))
s.Start()
}
```