Skip to content
Proyek

Tentang

Simple and lightweight Go web framework inspired by koa

Pengembangan web dan aplikasi

Cara angka ini diukur

Pertumbuhan bintang terukur

dalam 24 jam
0
dalam 7 hari
0
dalam 15 hari
0
dalam 1 bulan
Mengumpulkan riwayat

Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.

README.md

Asli

VOX

Go Reference Build Status Codecov Go Report Card Maintainability Gitter chat

A Go web framework for humans, heavily inspired by Koa.

VoxLogo

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/.

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.

Jelajahi proyek terkait

Memuat…