modulepackage
0.0.0-20241224003634-a782910659cb
Repository: https://github.com/thepuffproject/puff.git
Documentation: pkg.go.dev
# README
Puff
An extensible, performant, and reliable framework inspired by FastAPI.
Features
- Automatic OpenAPI documentation generation and hosting.
- Tree-style structure Routers to group APIs.
- Extensible default middlewares.
- Customizable logger with structured and prettier logging.
- Adheres to standards set by net/http, and RFC-compliant.
- Simplicity where possible and build upon the goated stdlib when possible.
- Only has 2 external dependencies!
Quickstart
Installation
go get -u github.com/ThePuffProject/puff
Creating a new server using Puff is simple:
import "puff"
app := puff.DefaultApp("Cool Demo App")
app.Use(middleware.Tracing())
app.Use(middleware.Logging())
app.Get("/health", nil, func(c *puff.Context) {
c.SendResponse(puff.GenericResponse{Content: "Server is Healthy!"})
})
app.ListenAndServe(":8000")
This will begin the application and serve the docs at http://localhost:8000/docs
.
The DefaultApp sets up some great defaults, but you can specify a custom config with puff.App()
.
We also recommend setting up your own logger:
app.Logger = puff.NewLogger(puff.LoggerConfig{
Level: slog.LevelDebug,
Colorize: true,
UseJSON: false,
TimeFormat: time.DateTime,
})
View the roadmap
TODO: improve docs with example on creating a simple router, and contribution docs.
# Packages
No description provided by the author
Package middleware provides middlewares for handling common web application requirements.
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
DefaultLogger returns a slog.Logger which will use the default json logger.
DefaultLogger returns a slog.Logger which will use the default text logger.
DefineResponse creates a ResponseDefinition mapping an HTTP status code to the corresponding response type for a route.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewLogger creates a new *slog.Logger provided the LoggerConfig.
No description provided by the author
NewRouter creates a new router provided router name and path prefix.
NewSlogHandler returns a new puff.SlogHandler given a LoggerConfig and slog.Handler.
RandomNanoID generates a random NanoID with format LLLL-NNNN.
RandomToken generates a crytographically secure random base64 token with the provided length.
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
AppConfig defines PuffApp parameters.
Components struct holds reusable objects for different aspects of the OAS.
Contact struct contains contact information for the API.
Context provides functionality for the route.
No description provided by the author
No description provided by the author
ExternalDocumentation struct provides external documentation for the API.
No description provided by the author
FileResponse represents a response that sends a file.
GenericResponse represents a response with plain text content.
No description provided by the author
HTMLResponse represents a response with HTML content.
Info struct provides metadata about the API.
JSONResponse represents a response with JSON content.
License struct contains license information for the API.
No description provided by the author
LoggerConfig is used to dictate logger behavior.
MediaType struct describes a media type object in OpenAPI.
OpenAPI struct represents the root of the OpenAPI document.
OpenAPIResponse struct describes possible responses in OpenAPI.
Operation struct describes an operation in a PathItem.
Parameter struct describes a parameter in OpenAPI.
PathItem struct describes operations available on a single path.
Property defines a property in the OpenAPI spec that defines information about a property (parameters, definitions, etc).
No description provided by the author
RedirectResponse represents a response that sends a redirect to the client.
No description provided by the author
RequestBodyOrReference is a union type representing either a Request Body Object or a Reference Object.
ResponseDefinition represents a definition of a response for a specific HTTP status code.
No description provided by the author
Router defines a group of routes that share the same prefix and middlewares.
Schema struct represents a schema object in OpenAPI.
Server struct represents a server object in OpenAPI.
No description provided by the author
No description provided by the author
SlogHandler is puff's implementation of structured logging.
StreamingResponse represents a response that streams content.
SwaggerUIConfig is the subset of the SwaggerUI configurables that Puff supports.
Tag struct represents a tag used by the OpenAPI document.
# Interfaces
Response is an interface that all response types should implement.
# Type aliases
aliases.
No description provided by the author
No description provided by the author
No description provided by the author
Responses type maps together the HTTPStatusCode with a function returning the reflect.Type.
No description provided by the author
No description provided by the author