Minimal Go web framework built on net/http. The concept is a smallest-possible Go framework paired with a minimal flake.nix.
Languages: English | 日本語
- Simple routing with
:parampath parameters - Middleware pipeline (context-based)
- JSON and HTML helpers
- Static file handler (no-cache)
- Adapter to wrap
http.Handler/http.HandlerFunc
mkdir myapp
cd myapp
nix flake init -t github:tenelol/nixarRun:
nix rungo get github.com/tenelol/nixarpackage main
import (
"log"
"net/http"
"github.com/tenelol/nixar/framework"
)
func main() {
app := framework.NewApp()
app.Use(framework.Logging())
app.Get("/", func(ctx *framework.Context) {
ctx.JSON(http.StatusOK, map[string]any{"hello": "nixar"})
})
addr := ":8080"
log.Println("Listening on", addr)
log.Fatal(http.ListenAndServe(addr, app))
}app.Get("/users/:id", func(ctx *framework.Context) {
id := ctx.Param("id")
ctx.JSON(200, map[string]string{"id": id})
})staticHandler := http.StripPrefix("/static/", framework.Static("static"))
app.Get("/static/*filePath", framework.WrapHTTPHandler(staticHandler))static is just an example; you can serve any directory.
--port(default:8080)--pages-dir(default:apps/simple)--static-dir(default:static)
This repository includes a minimal flake.nix for building and running the example server.
Run the server:
nix runBuild the package:
nix buildEnter the dev shell:
nix developframework/core frameworkcmd/server/example server entryapps/simple/example app (minimal site + API)static/static assets for the sample servertemplate/starter template (Go + Nix flake)
Enable the module in your NixOS configuration and it will run the server as a systemd service. It also bundles the sample HTML and static assets and serves them automatically.
Example (flake-based):
{
inputs.nixar.url = "github:tenelol/nixar";
outputs = { self, nixar, nixpkgs, ... }: {
nixosConfigurations.my-host = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
nixar.nixosModules.nixar
{
services.nixar.enable = true;
services.nixar.port = 8080;
}
];
};
};
}MIT. See LICENSE.