weby

package module
v0.0.0-...-2aea054 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 1 Imported by: 0

README

Weby

Weby is a very simple server side web framework that intends to simply wrap the Go http library and leverage the routing functionality introduced in Go 1.22. It provides some basic middleware that would be commonly utilized and intends to stay completely compatible with the standard library rather than introducing framework specific interfaces and types like many other frameworks have had to do to introduce routers, contexts, and other features that are now part of the standard library.

Use

package main

import (
	"log"
	"log/slog"
	"net/http"
	"os"

	"github.com/jrozner/weby"
	"github.com/jrozner/weby/middleware"
	"github.com/jrozner/weby/rlog"
)

func main() {
	var handler slog.Handler = slog.NewTextHandler(os.Stdout, nil)
	handler = rlog.RequestIDHandler{handler}
	logger := slog.New(handler)
	mux := weby.NewServeMux()
	mux.Use(middleware.RequestID)
	mux.Use(middleware.WrapResponse)
	mux.Use(middleware.Logger(logger))
	mux.HandleFunc("/", root)

	log.Fatal(http.ListenAndServe(":8080", mux))
}

func root(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(http.StatusOK)
}

License

Weby is licensed under MIT though you probably shouldn't use it for your own projects.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ServeMux

type ServeMux struct {
	*http.ServeMux
	// contains filtered or unexported fields
}

func NewServeMux

func NewServeMux() *ServeMux

func (*ServeMux) ServeHTTP

func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*ServeMux) Use

func (s *ServeMux) Use(middleware func(http.Handler) http.Handler)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL