fw

module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT

README

FW

中文说明 / Chinese README

FW is a lightweight Go web framework for building APIs quickly with annotation-style routing, middleware binding, dependency injection, and automatic OpenAPI generation.

Features

  • Annotation-based routes such as @GET /users
  • Auto-registration for controllers, services, and middlewares
  • Global, controller-level, and method-level middleware
  • Automatic request binding for path, query, header, and body
  • Unified JSON response envelope
  • OpenAPI generation with Swagger UI
  • cmd/fw CLI for scaffolding and builds

Install

Add FW to your project:

go get github.com/linxlib/fw/v2

Install the CLI if needed:

go install github.com/linxlib/fw/v2/cmd/fw@latest

Quick Start

Create a new project:

fw init demo
cd demo
fw build
go run .

Typical startup:

package main

import (
	_ "embed"

	"github.com/linxlib/fw/v2/app"
)

//go:generate go run github.com/linxlib/fw/v2/astp/cmd/astp -exported .

//go:embed .astp.json
var astpData []byte

func main() {
	e, err := app.New("config/app.yaml")
	if err != nil {
		panic(err)
	}

	e.EmbedProject(astpData)

	if err := e.ListenAndServe(); err != nil {
		panic(err)
	}
}

Simple controller:

package controllers

import (
	"github.com/linxlib/fw/v2/context"
	"github.com/valyala/fasthttp"
)

// UserController handles user APIs.
// @Controller
// @Route /api/v1/users
type UserController struct{}

// Detail returns one user.
// @GET /:id
func (c *UserController) Detail(ctx context.Context, id string) error {
	return ctx.Respond(fasthttp.StatusOK, 0, "ok", map[string]any{"id": id})
}

Documentation

For coding agents:

CLI

Useful commands:

fw init myapp
fw build
fw create controller --name User --route /api/v1/users
fw create service --name User
fw create middleware --name Authorization

See the full CLI details in doc_en.md and doc_cn.md.

License

MIT

Directories

Path Synopsis
cmd/astp command
cmd
example command
Code generated by fw astp autoreg; DO NOT EDIT.
Code generated by fw astp autoreg; DO NOT EDIT.
fw command
Package inject provides utilities for mapping and injecting dependencies in various ways.
Package inject provides utilities for mapping and injecting dependencies in various ways.

Jump to

Keyboard shortcuts

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