项目
在 GitHub 查看
aisk/vox
关于
Simple and lightweight Go web framework inspired by koa
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文VOX
A Go web framework for humans, heavily inspired by Koa.
Getting started
Installation
Requires Go 1.27 or later. Install with go get:
$ go get -u github.com/aisk/vox
Basic Web Application
package main
import (
"fmt"
"time"
"github.com/aisk/vox"
)
type CreateUser struct {
Name string `json:"name"`
}
type User struct {
ID int `json:"id"`
Name string `json:"name"`
}
func main() {
app := vox.New()
// custom middleware that adds an X-Response-Time header
app.Use(func(ctx *vox.Context, req *vox.BaseRequest, res *vox.BaseResponse) {
start := time.Now()
ctx.Next()
duration := time.Now().Sub(start)
res.Header.Set("X-Response-Time", fmt.Sprintf("%s", duration))
})
// router param
app.Get("/hello/{name}", func(ctx *vox.Context, req *vox.Request[vox.NoBody], res *vox.Response[string]) {
res.Body = "Hello, " + req.Params["name"] + "!"
})
app.Post("/users", func(ctx *vox.Context, req *vox.Request[CreateUser], res *vox.Response[User]) {
res.Status = 201
res.Body = User{ID: 1, Name: req.Body.Name}
})
app.Run("localhost:3000")
}
Route handlers declare their request and response body types in the function signature. Vox decodes request bodies as JSON; use Request[vox.NoBody] when no decoding is needed. Middleware receives BaseRequest and BaseResponse.
Documentation
The full documentation lives at https://aisk.github.io/vox/.
- Getting Started
- Routing, Route Handlers and Middleware
- Request, Response and Error Handling
- Static Files and Pprof middleware
- Recipes
Need Support?
If you need help for using vox, or have other questions, welcome to our gitter chat room.
About the Project
Vox is © 2016-2026 by aisk.
License
Vox is distributed by a MIT license.
探索相关项目
加载中…
