Skip to content
/ webh Public

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

License

Notifications You must be signed in to change notification settings

tomiok/webh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

f76e5ea · May 21, 2024

History

35 Commits
Jul 15, 2023
Jun 24, 2023
Jul 15, 2023
Jul 15, 2023
Jul 8, 2023
Jul 18, 2023
Nov 29, 2023
Jul 15, 2023
May 21, 2024
May 21, 2024
May 21, 2024
May 21, 2024
Jul 14, 2023

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 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

go get -u github.com/tomiok/webh

Create and start the server with one endpoint.

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.

package web

import (
	"fmt"
	"net/http"
)

func HelloHandler(w http.ResponseWriter, r *http.Request) error {
	_, err := fmt.Fprint(w, "hello")
	return err
}
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()
}

About

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

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published