Getting started
Requirements
Section titled “Requirements”Go 1.26 or newer. Gas is pre-1.0, so minor versions may contain breaking changes; see the changelog.
Your first app
Section titled “Your first app”-
Install the core package.
Terminal window go get github.com/gasmod/gas -
Serve a route.
main.go import ("log""net/http""github.com/gasmod/gas")func main() {app := gas.NewApp()app.Router().Handle("", http.MethodGet, "/", func(ctx gas.Context) error {return ctx.Text(http.StatusOK, "Hello, World!")})if err := app.Run(); err != nil {log.Fatal(err)}} -
Run it.
Terminal window go run .# listening on 0.0.0.0:8080
gas.NewApp builds a router, an event bus, and a DI container. Run initializes
every registered service, applies pending migrations, executes ready hooks,
starts the HTTP server, and blocks until a shutdown signal arrives. On shutdown
it closes services in reverse initialization order.
Adding a module
Section titled “Adding a module”Modules are registered as services. Most of them ask the container for a
gas.ConfigProvider and a gas.Logger, so those go in first.
cfg := config.New(config.WithProvider(providers.NewEnvProvider()))if err := cfg.Load(); err != nil { log.Fatal(err)}app := gas.NewApp( // Infrastructure every module draws on. gas.WithServiceInstance[gas.ConfigProvider](cfg), gas.WithSingletonService[gas.Logger](gaslog.NewSlogLogger()),
// Modules, registered under the provider interface your services inject. gas.WithSingletonService[gas.StorageProvider](storages3.New()),)Where to go next
Section titled “Where to go next”- Concepts explains services, lifetimes, and ownership tracking.
- Modules lists everything you can bolt on.
- Examples has five runnable applications, from a bare hello world to a full API server.
- pkg.go.dev is the API reference.