golpher

package module
v0.0.0-...-212534a Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 15 Imported by: 0

README

CI Coverage codecov Govulncheck Go Reference Go Report Card MIT License Issues

[!WARNING] Golpher has not reached a stable release yet. For production applications today, we recommend using one of the mature frameworks that inspire this project, such as Fiber, Gin, or the Go standard library directly with net/http.


Golpher

A net/http-first Go microframework with Express/Fiber-like DX.
Explore the API docs »

Getting Started · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Documentation
  5. Roadmap
  6. Star History
  7. Contributing
  8. License
  9. Contact
  10. Acknowledgments

About The Project

Golpher is a small Go web framework designed for teams that want modern routing ergonomics without giving up the standard library boundary.

It is inspired by the developer experience of Fiber, Express, Gin, and Zinc, while keeping core Go primitives at the center: http.Handler, http.ResponseWriter, *http.Request, request cancellation, observability middleware, and ordinary net/http deployment.

Golpher is built for applications that need framework convenience while remaining interoperable with the broader Go HTTP ecosystem.

(back to top)

Why Golpher?

  • Standard-library native: *golpher.App implements http.Handler.
  • Modern routing DX: app.GET, app.POST, route groups, and :params.
  • Middleware chain: global, group, route, and stdlib func(http.Handler) http.Handler middleware.
  • Interop by design: mount existing http.Handler values with FromHTTPHandler.
  • HTTP/2 ready: works through Go's net/http TLS/ALPN support.
  • HTTP/3 future-proof: core stays transport-agnostic so an HTTP/3 adapter can be added later without breaking the API.
  • Security-minded defaults: server timeouts, Recover, and BodyLimit are available from the start.

(back to top)

Built With

(back to top)

Status

Golpher is early-stage. The core API is being shaped through spec-driven development and TDD. Expect rapid iteration before a stable v1.

(back to top)

Getting Started

Follow these steps to install Golpher and run a minimal application.

Prerequisites

  • Go 1.23.6 or newer.

Check your Go version:

go version

Installation

Install the module in your Go project:

go get github.com/go-golpher/golpher

Then import it:

import "github.com/go-golpher/golpher"

(back to top)

Usage

Quick start

package main

import (
  "net/http"

  "github.com/go-golpher/golpher"
)

func main() {
  app := golpher.New()

  app.Use(golpher.Recover())
  app.Use(golpher.BodyLimit(2 << 20)) // 2 MB

  app.GET("/", func(req *golpher.Request, res *golpher.Response) error {
    return res.JSON(map[string]string{"message": "hello, golpher"})
  })

  app.GET("/users/:id", func(req *golpher.Request, res *golpher.Response) error {
    return res.Status(http.StatusOK).JSON(map[string]string{
      "id": req.Param("id"),
    })
  })

  app.Listen()
}

Standard net/http middleware

app.UseHTTP(func(next http.Handler) http.Handler {
  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("X-Powered-By", "golpher")
    next.ServeHTTP(w, r)
  })
})

Mount an existing http.Handler

app.Handle(http.MethodGet, "/healthz", golpher.FromHTTPHandler(
  http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    w.WriteHeader(http.StatusOK)
    _, _ = w.Write([]byte("ok"))
  }),
))

For more examples, see the Documentation.

(back to top)

Documentation

(back to top)

Roadmap

See ROADMAP.md for planned work and open issues for proposed features and known issues.

(back to top)

Star History

Star History Chart

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make Golpher better, please fork the repository and create a pull request. You can also open an issue with the enhancement label.

  1. Fork the project.
  2. Create your feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes using Conventional Commits (git commit -m 'feat: add amazing feature').
  4. Push to the branch (git push origin feature/amazing-feature).
  5. Open a pull request.

For project-specific guidance, see CONTRIBUTING.md.

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

Project Link: https://github.com/go-golpher/golpher

(back to top)

Acknowledgments

(back to top)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	ErrorHandler ErrorHandlerFunc
	Router       *Router
	Config       AppConfig
	// contains filtered or unexported fields
}

func New

func New(configs ...AppConfig) *App

func (*App) DELETE

func (app *App) DELETE(pattern string, handler HandlerFunc, middlewares ...MiddlewareFunc)

func (*App) DELETEContext

func (app *App) DELETEContext(pattern string, handler ContextHandlerFunc, middlewares ...MiddlewareFunc)

func (*App) Delete

func (app *App) Delete(pattern string, handler Handler, middlewares ...MiddlewareFunc)

func (*App) GET

func (app *App) GET(pattern string, handler HandlerFunc, middlewares ...MiddlewareFunc)

func (*App) GETContext

func (app *App) GETContext(pattern string, handler ContextHandlerFunc, middlewares ...MiddlewareFunc)

func (*App) Get

func (app *App) Get(pattern string, handler Handler, middlewares ...MiddlewareFunc)

func (*App) Group

func (app *App) Group(prefix string, middlewares ...MiddlewareFunc) *Group

func (*App) Handle

func (app *App) Handle(method, pattern string, handler HandlerFunc, middlewares ...MiddlewareFunc)

func (*App) HandleContext

func (app *App) HandleContext(method, pattern string, handler ContextHandlerFunc, middlewares ...MiddlewareFunc)

func (*App) HandleCtx

func (app *App) HandleCtx(method, pattern string, handler Handler, middlewares ...MiddlewareFunc)

func (*App) Listen

func (app *App) Listen(configs ...ListenConfig)

func (*App) PATCH

func (app *App) PATCH(pattern string, handler HandlerFunc, middlewares ...MiddlewareFunc)

func (*App) PATCHContext

func (app *App) PATCHContext(pattern string, handler ContextHandlerFunc, middlewares ...MiddlewareFunc)

func (*App) POST

func (app *App) POST(pattern string, handler HandlerFunc, middlewares ...MiddlewareFunc)

func (*App) POSTContext

func (app *App) POSTContext(pattern string, handler ContextHandlerFunc, middlewares ...MiddlewareFunc)

func (*App) PUT

func (app *App) PUT(pattern string, handler HandlerFunc, middlewares ...MiddlewareFunc)

func (*App) PUTContext

func (app *App) PUTContext(pattern string, handler ContextHandlerFunc, middlewares ...MiddlewareFunc)

func (*App) Patch

func (app *App) Patch(pattern string, handler Handler, middlewares ...MiddlewareFunc)

func (*App) Post

func (app *App) Post(pattern string, handler Handler, middlewares ...MiddlewareFunc)

func (*App) Put

func (app *App) Put(pattern string, handler Handler, middlewares ...MiddlewareFunc)

func (*App) Raw

func (app *App) Raw(method, pattern string, handler RawHandlerFunc)

func (*App) Serve

func (app *App) Serve(listener net.Listener) error

func (*App) ServeHTTP

func (app *App) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*App) Server

func (app *App) Server(addr string) *http.Server

func (*App) Shutdown

func (app *App) Shutdown(ctx context.Context, server *http.Server) error

func (*App) Use

func (app *App) Use(middlewares ...MiddlewareFunc)

func (*App) UseHTTP

func (app *App) UseHTTP(middlewares ...func(http.Handler) http.Handler)

type AppConfig

type AppConfig struct {
	ErrorHandler      ErrorHandlerFunc
	Port              int
	ReadHeaderTimeout time.Duration
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
	MaxHeaderBytes    int
	// DisableResponseBodyCapture skips storing bytes written through Response.Send
	// and Response.String. It is intended for latency-sensitive services that do
	// not inspect Response.Body() from middleware or tests.
	DisableResponseBodyCapture bool
	// DisableBanner skips the startup banner printed by Listen.
	DisableBanner bool
}

type Body

type Body struct {
	// contains filtered or unexported fields
}

func (*Body) Bytes

func (body *Body) Bytes() []byte

func (*Body) JSON

func (body *Body) JSON(v interface{}) error

func (*Body) XML

func (body *Body) XML(v interface{}) error

type Context

type Context struct {
	Request  *Request
	Response *Response
}

func (*Context) NewError

func (ctx *Context) NewError(status int, err string) error

type ContextHandlerFunc

type ContextHandlerFunc func(*Ctx, *Request, *Response) error

type Ctx

type Ctx struct {
	// contains filtered or unexported fields
}

func (*Ctx) Bytes

func (ctx *Ctx) Bytes(status int, contentType string, body []byte) error

func (*Ctx) JSONBytes

func (ctx *Ctx) JSONBytes(body []byte) error

func (*Ctx) Param

func (ctx *Ctx) Param(name string) string

func (*Ctx) RawRequest

func (ctx *Ctx) RawRequest() *http.Request

func (*Ctx) RawResponse

func (ctx *Ctx) RawResponse() http.ResponseWriter

func (*Ctx) RequestRef

func (ctx *Ctx) RequestRef() *Request

func (*Ctx) ResponseRef

func (ctx *Ctx) ResponseRef() *Response

func (*Ctx) Send

func (ctx *Ctx) Send(body []byte) error

func (*Ctx) Status

func (ctx *Ctx) Status(code int) *Ctx

func (*Ctx) String

func (ctx *Ctx) String(body string) error

type ErrorGolpher

type ErrorGolpher struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (ErrorGolpher) Error

func (e ErrorGolpher) Error() string

type ErrorHandlerFunc

type ErrorHandlerFunc func(ctx *Context, err error)

type Group

type Group struct {
	// contains filtered or unexported fields
}

func (*Group) DELETE

func (group *Group) DELETE(pattern string, handler HandlerFunc, middlewares ...MiddlewareFunc)

func (*Group) GET

func (group *Group) GET(pattern string, handler HandlerFunc, middlewares ...MiddlewareFunc)

func (*Group) Handle

func (group *Group) Handle(method, pattern string, handler HandlerFunc, middlewares ...MiddlewareFunc)

func (*Group) PATCH

func (group *Group) PATCH(pattern string, handler HandlerFunc, middlewares ...MiddlewareFunc)

func (*Group) POST

func (group *Group) POST(pattern string, handler HandlerFunc, middlewares ...MiddlewareFunc)

func (*Group) PUT

func (group *Group) PUT(pattern string, handler HandlerFunc, middlewares ...MiddlewareFunc)

func (*Group) Use

func (group *Group) Use(middlewares ...MiddlewareFunc)

type Handler

type Handler func(*Ctx) error

type HandlerFunc

type HandlerFunc func(Request *Request, Response *Response) error

func FromHTTPHandler

func FromHTTPHandler(handler http.Handler) HandlerFunc

func FromHTTPHandlerFunc

func FromHTTPHandlerFunc(handler http.HandlerFunc) HandlerFunc

type ListenConfig

type ListenConfig struct {
	Silent bool
}

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc) HandlerFunc

func BodyLimit

func BodyLimit(maxBytes int64) MiddlewareFunc

func Recover

func Recover() MiddlewareFunc

type RawHandlerFunc

type RawHandlerFunc func(http.ResponseWriter, *http.Request)

type Request

type Request struct {
	// contains filtered or unexported fields
}

func (*Request) Body

func (request *Request) Body() *Body

func (*Request) Context

func (request *Request) Context() context.Context

func (*Request) Headers

func (request *Request) Headers() map[string][]string

func (*Request) NewError

func (request *Request) NewError(status int, err string) error

func (*Request) Param

func (request *Request) Param(name string) string

func (*Request) Query

func (request *Request) Query(name string) string

func (*Request) Raw

func (request *Request) Raw() *http.Request

func (*Request) SetContext

func (request *Request) SetContext(ctx context.Context)

type Response

type Response struct {
	// contains filtered or unexported fields
}

func (*Response) Body

func (response *Response) Body() []byte

func (*Response) BodyString

func (response *Response) BodyString() string

func (*Response) Bytes

func (response *Response) Bytes(status int, contentType string, body []byte) error

func (*Response) Header

func (response *Response) Header() http.Header

func (*Response) JSON

func (response *Response) JSON(obj interface{}) error

func (*Response) JSONBytes

func (response *Response) JSONBytes(body []byte) error

func (*Response) Raw

func (response *Response) Raw() http.ResponseWriter

func (*Response) Redirect

func (response *Response) Redirect(url string, codes ...int) error

func (*Response) Send

func (response *Response) Send(body []byte) error

func (*Response) Status

func (response *Response) Status(code int) *Response

func (*Response) String

func (response *Response) String(body string) error

func (*Response) XML

func (response *Response) XML(obj interface{}) error

type Router

type Router struct {
	// contains filtered or unexported fields
}

func (*Router) DELETE

func (r *Router) DELETE(pattern string, handler HandlerFunc)

func (*Router) GET

func (r *Router) GET(pattern string, handler HandlerFunc)

func (*Router) PATCH

func (r *Router) PATCH(pattern string, handler HandlerFunc)

func (*Router) POST

func (r *Router) POST(pattern string, handler HandlerFunc)

func (*Router) PUT

func (r *Router) PUT(pattern string, handler HandlerFunc)

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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