GoWebUtilities

module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT

README

GoWebUtilities

Go Reference Go Report Card Test

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.

Directories

Path Synopsis
Package config provides environment-based configuration management with validation.
Package config provides environment-based configuration management with validation.
Package middleware contains common middleware functions for use in web applications
Package middleware contains common middleware functions for use in web applications
Package server provides utilities for creating and running HTTP servers with environment-based configuration and graceful shutdown handling.
Package server provides utilities for creating and running HTTP servers with environment-based configuration and graceful shutdown handling.

Jump to

Keyboard shortcuts

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