Skip to content

harrydayexe/GoWebUtilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoWebUtilities

Go Reference Go Report Card Test License: MIT

A Go library providing reusable utilities for building web applications.

Installation

go get github.com/harrydayexe/GoWebUtilities

Available Modules

Middleware

Composable HTTP middleware following Go's standard net/http pattern. All middleware follow the signature:

type Middleware func(h http.Handler) http.Handler

Available middleware:

  • Logging - Request logging with structured logging (log/slog)
  • MaxBytesReader - Request body size limiting
  • SetContentType - Response Content-Type header setting

Example:

package main

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

    "github.com/harrydayexe/GoWebUtilities/middleware"
)

func main() {
    logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))

    handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte(`{"status":"ok"}`))
    })

    stack := middleware.CreateStack(
        middleware.NewLoggingMiddleware(logger),
        middleware.NewMaxBytesReader(1024*1024), // 1MB limit
        middleware.NewSetContentTypeJSON(),
    )

    http.ListenAndServe(":8080", stack(handler))
}

Documentation

For detailed documentation, use go doc:

# View package documentation
go doc github.com/harrydayexe/GoWebUtilities/middleware

# View specific function documentation
go doc github.com/harrydayexe/GoWebUtilities/middleware.NewLoggingMiddleware

Full documentation is also available on pkg.go.dev.

Testing

# Run all tests
go test ./...

# Run with coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out

Contributing

Contributions are welcome! Please ensure all tests pass and code follows Go conventions.

About

A collection of utilities I find helpful when writing web applications in GoLang

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages