跳转到正文
Mino

快速开始

用一个标准 HTTP handler,运行第一个 Mino 服务。

Read in English ↗

需要 Go 1.23+。

安装

mkdir mino-hello
cd mino-hello
go mod init example.com/mino-hello
go get github.com/hainuoli/mino/rest/httpx

创建服务

保存为 main.go:

main.go
package main

import (
	"log"
	"net/http"

	"github.com/hainuoli/mino/rest"
	"github.com/hainuoli/mino/rest/httpx"
)

func main() {
	mux := rest.NewMux()

	mux.Get("/", func(w http.ResponseWriter, r *http.Request) {
		httpx.OkJSON(w, "Hello, Mino!")
	})

	log.Fatal(http.ListenAndServe(":8080", mux))
}

运行

go run .

在另一个终端请求服务:

curl http://localhost:8080/
# "Hello, Mino!"

mux 实现 http.Handler,handler 使用标准库签名。httpx.OkJSON 直接将值输出为 JSON。

下一步

渐进式使用展示如何加入绑定、验证和路由分组;已有标准库项目可直接阅读迁移指南。

仓库内的可执行版本见 examples/hello。运行前按源码准备放好两个仓库。

源码准备

仅运行仓库内的示例与基准时,需要相邻的两个 checkout:

git clone https://github.com/hainuoli/mino.git
git clone https://github.com/hainuoli/mino-doc.git
cd mino-doc
workspace/
├── mino/
└── mino-doc/

开发模块通过 replace github.com/hainuoli/mino => ../../mino 引用本地源码。

cd examples
go run ./hello

本页目录