axyut commited on
Commit ·
e3988b5
1
Parent(s): e8e3c48
using huma?
Browse files
go.mod
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module github.com/axyut/lawops
|
| 2 |
+
|
| 3 |
+
go 1.24.2
|
| 4 |
+
|
| 5 |
+
require (
|
| 6 |
+
github.com/danielgtaylor/huma/v2 v2.32.0
|
| 7 |
+
github.com/go-chi/chi/v5 v5.1.0
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
require (
|
| 11 |
+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
|
| 12 |
+
github.com/x448/float16 v0.8.4 // indirect
|
| 13 |
+
)
|
go.sum
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
github.com/danielgtaylor/huma/v2 v2.32.0 h1:ytU9ExG/axC434+soXxwNzv0uaxOb3cyCgjj8y3PmBE=
|
| 2 |
+
github.com/danielgtaylor/huma/v2 v2.32.0/go.mod h1:9BxJwkeoPPDEJ2Bg4yPwL1mM1rYpAwCAWFKoo723spk=
|
| 3 |
+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
| 4 |
+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
| 5 |
+
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
|
| 6 |
+
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
|
| 7 |
+
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
|
| 8 |
+
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
| 9 |
+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
| 10 |
+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
| 11 |
+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
| 12 |
+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
| 13 |
+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
| 14 |
+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
| 15 |
+
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
| 16 |
+
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
| 17 |
+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
| 18 |
+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
main.go
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package main
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"context"
|
| 5 |
+
"fmt"
|
| 6 |
+
"net/http"
|
| 7 |
+
|
| 8 |
+
"github.com/danielgtaylor/huma/v2"
|
| 9 |
+
"github.com/danielgtaylor/huma/v2/adapters/humachi"
|
| 10 |
+
"github.com/go-chi/chi/v5"
|
| 11 |
+
|
| 12 |
+
_ "github.com/danielgtaylor/huma/v2/formats/cbor"
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
// GreetingOutput represents the greeting operation response.
|
| 16 |
+
type GreetingOutput struct {
|
| 17 |
+
Body struct {
|
| 18 |
+
Message string `json:"message" example:"Hello, world!" doc:"Greeting message"`
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
func main() {
|
| 23 |
+
// Create a new router & API.
|
| 24 |
+
router := chi.NewMux()
|
| 25 |
+
api := humachi.New(router, huma.DefaultConfig("My API", "1.0.0"))
|
| 26 |
+
|
| 27 |
+
// Register GET /greeting/{name} handler.
|
| 28 |
+
huma.Get(api, "/greeting/{name}", func(ctx context.Context, input *struct {
|
| 29 |
+
Name string `path:"name" maxLength:"30" example:"world" doc:"Name to greet"`
|
| 30 |
+
}) (*GreetingOutput, error) {
|
| 31 |
+
resp := &GreetingOutput{}
|
| 32 |
+
resp.Body.Message = fmt.Sprintf("Hello, %s!", input.Name)
|
| 33 |
+
return resp, nil
|
| 34 |
+
})
|
| 35 |
+
|
| 36 |
+
// Start the server!
|
| 37 |
+
http.ListenAndServe("127.0.0.1:8888", router)
|
| 38 |
+
}
|