这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [1.21, 1.22, 1.23]
go: [1.23, 1.24]
name: Build & Test
steps:
- uses: actions/checkout@v4
Expand All @@ -17,9 +17,9 @@ jobs:
with:
go-version: ${{ matrix.go }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v8
with:
version: v1.60.1
version: v2.1.6
- run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- uses: codecov/codecov-action@v4
with:
Expand Down
26 changes: 22 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
version: "2"
linters:
disable:
- errcheck
enable:
- dupword
- misspell
- musttag
- nolintlint
- perfsprint
- prealloc
- tenv
- testifylint
- unparam
- unconvert
- unparam
- wastedassign
disable:
- errcheck
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ A big thank you to our current & former sponsors!

# Install

Install via `go get`. Note that Go 1.21 or newer is required.
Install via `go get`. Note that Go 1.23 or newer is required.

```sh
# After: go mod init ...
Expand Down
14 changes: 1 addition & 13 deletions adapters/humago/humago.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,7 @@ func (c *goContext) URL() url.URL {
}

func (c *goContext) Param(name string) string {
// For now, support Go 1.22+ while still compiling in older versions by
// checking for the existence of the new method.
// TODO: eventually remove when the minimum Go version goes to 1.22.
var v any = c.r
if pv, ok := v.(interface{ PathValue(string) string }); ok {
return pv.PathValue(name)
}
panic("requires Go 1.22+")
return c.r.PathValue(name)
}

func (c *goContext) Query(name string) string {
Expand Down Expand Up @@ -169,11 +162,6 @@ func NewAdapter(m Mux, prefix string) huma.Adapter {
// mux := http.NewServeMux()
// api := humago.New(mux, huma.DefaultConfig("My API", "1.0.0"))
func New(m Mux, config huma.Config) huma.API {
// Panic if Go version is less than 1.22
var v any = &http.Request{}
if _, ok := v.(interface{ PathValue(string) string }); !ok {
panic("This adapter requires Go 1.22+")
}
return huma.NewAPI(config, &goAdapter{m, ""})
}

Expand Down
10 changes: 5 additions & 5 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,12 @@ func NewAPI(config Config, a Adapter) API {
config.OpenAPI.OpenAPI = "3.1.0"
}

if config.OpenAPI.Components == nil {
config.OpenAPI.Components = &Components{}
if config.Components == nil {
config.Components = &Components{}
}

if config.OpenAPI.Components.Schemas == nil {
config.OpenAPI.Components.Schemas = NewMapRegistry("#/components/schemas/", DefaultSchemaNamer)
if config.Components.Schemas == nil {
config.Components.Schemas = NewMapRegistry("#/components/schemas/", DefaultSchemaNamer)
}

if config.DefaultFormat == "" && config.Formats["application/json"].Marshal != nil {
Expand Down Expand Up @@ -495,7 +495,7 @@ func NewAPI(config Config, a Adapter) API {
// Some routers dislike a path param+suffix, so we strip it here instead.
schema := strings.TrimSuffix(ctx.Param("schema"), ".json")
ctx.SetHeader("Content-Type", "application/json")
b, _ := json.Marshal(config.OpenAPI.Components.Schemas.Map()[schema])
b, _ := json.Marshal(config.Components.Schemas.Map()[schema])
b = rxSchema.ReplaceAll(b, []byte(config.SchemasPath+`/$1.json`))
ctx.BodyWriter().Write(b)
})
Expand Down
2 changes: 1 addition & 1 deletion casing/casing.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func Camel(value string, transform ...TransformFunc) string {
if transform == nil {
transform = []TransformFunc{strings.ToLower}
}
t := append(transform, strings.Title)
t := append(transform, strings.Title) //nolint:staticcheck
return Join(Split(value), "", t...)
}

Expand Down
2 changes: 1 addition & 1 deletion defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func DefaultConfig(title, version string) Config {
// Schema that describes the response structure.
// This is a create hook so we get the latest schema path setting.
linkTransformer := NewSchemaLinkTransformer(schemaPrefix, c.SchemasPath)
c.OpenAPI.OnAddOperation = append(c.OpenAPI.OnAddOperation, linkTransformer.OnAddOperation)
c.OnAddOperation = append(c.OnAddOperation, linkTransformer.OnAddOperation)
c.Transformers = append(c.Transformers, linkTransformer.Transform)
return c
},
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/features/bring-your-own-router.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Adapters are in the [`adapters`](https://github.com/danielgtaylor/huma/tree/main
- [Echo](https://echo.labstack.com/) via [`humaecho`](https://pkg.go.dev/github.com/danielgtaylor/huma/v2/adapters/humaecho)
- [Fiber](https://gofiber.io/) via [`humafiber`](https://pkg.go.dev/github.com/danielgtaylor/huma/v2/adapters/humafiber)
- [gin](https://gin-gonic.com/) via [`humagin`](https://pkg.go.dev/github.com/danielgtaylor/huma/v2/adapters/humagin)
- [Go 1.22+ `http.ServeMux`](https://pkg.go.dev/net/http@master#ServeMux) via [`humago`](https://pkg.go.dev/github.com/danielgtaylor/huma/v2/adapters/humago) (requires `go 1.22` in `go.mod`)
- [Go 1.22+ `http.ServeMux`](https://pkg.go.dev/net/http@master#ServeMux) via [`humago`](https://pkg.go.dev/github.com/danielgtaylor/huma/v2/adapters/humago) (requires `go 1.22` or newer in `go.mod`)
- [gorilla/mux](https://github.com/gorilla/mux) via [`humamux`](https://pkg.go.dev/github.com/danielgtaylor/huma/v2/adapters/humamux)
- [httprouter](https://github.com/julienschmidt/httprouter) via [`humahttprouter`](https://pkg.go.dev/github.com/danielgtaylor/huma/v2/adapters/humahttprouter)

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/tutorial/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Learn how to install Huma and create your first API.

## Prerequisites

Huma requires [Go 1.21 or newer](https://go.dev/dl/), so install that first. You'll also want some kind of [text editor or IDE](https://code.visualstudio.com/) to write code and a terminal to run commands.
Huma requires [Go 1.23 or newer](https://go.dev/dl/), so install that first. You'll also want some kind of [text editor or IDE](https://code.visualstudio.com/) to write code and a terminal to run commands.

## Project Setup

Expand Down
67 changes: 35 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,69 +1,72 @@
module github.com/danielgtaylor/huma/v2

go 1.22
go 1.23.0

toolchain go1.22.0
toolchain go1.24.1

require (
github.com/danielgtaylor/shorthand/v2 v2.2.0
github.com/evanphx/json-patch/v5 v5.9.0
github.com/fxamacker/cbor/v2 v2.7.0
github.com/evanphx/json-patch/v5 v5.9.11
github.com/fxamacker/cbor/v2 v2.8.0
github.com/gin-gonic/gin v1.10.0
github.com/go-chi/chi/v5 v5.1.0
github.com/gofiber/fiber/v2 v2.52.5
github.com/go-chi/chi/v5 v5.2.1
github.com/gofiber/fiber/v2 v2.52.6
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
github.com/julienschmidt/httprouter v1.3.0
github.com/labstack/echo/v4 v4.12.0
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
github.com/uptrace/bunrouter v1.0.22
github.com/labstack/echo/v4 v4.13.3
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.10.0
github.com/uptrace/bunrouter v1.0.23
)

require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/bytedance/sonic v1.12.3 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/bytedance/sonic v1.13.2 // indirect
github.com/bytedance/sonic/loader v0.2.4 // indirect
github.com/cloudwego/base64x v0.1.5 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/danielgtaylor/mexpr v1.9.0 // indirect
github.com/danielgtaylor/mexpr v1.9.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.1 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/go-playground/validator/v10 v10.26.0 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.10 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
github.com/knz/go-libedit v1.10.1 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.56.0 // indirect
github.com/valyala/fasthttp v1.62.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/arch v0.11.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.35.1 // indirect
golang.org/x/arch v0.17.0 // indirect
golang.org/x/crypto v0.38.0 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.25.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading