huma/examples/test/service.go
2020-08-31 10:04:03 -07:00

27 lines
557 B
Go

package main
import (
"github.com/danielgtaylor/huma"
"github.com/danielgtaylor/huma/cli"
"github.com/danielgtaylor/huma/responses"
)
func routes(r *huma.Router) {
// Register a single test route that returns a text/plain response.
r.Resource("/test").Get("test", "Test route",
responses.OK().ContentType("text/plain"),
).Run(func(ctx huma.Context) {
ctx.Write([]byte("Hello, test!"))
})
}
func main() {
// Create the router.
app := cli.NewRouter("Test", "1.0.0")
// Register routes.
routes(app.Router)
// Run the service.
app.Run()
}