这是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
13 changes: 8 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go: [1.21, 1.22, 1.23]
name: Build & Test
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v1
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: ${{ matrix.go }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: v1.57.2
version: v1.60.1
- run: go test -coverprofile=coverage.txt -covermode=atomic ./...
- uses: codecov/codecov-action@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ A big thank you to our current & former sponsors!

# Install

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

```sh
# After: go mod init ...
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

# 安装

通过安装`go get`。请注意,需要 Go 1.20 或更高版本。
通过安装`go get`。请注意,需要 Go 1.21 或更高版本。

```sh
# After: go mod init ...
Expand Down
21 changes: 3 additions & 18 deletions adapters/humaflow/flow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,10 @@ import (
"net/http"
"net/url"
"regexp"
"slices"
"strings"
)

// slicesIndex returns the index of the first occurrence of v in s,
// or -1 if not present.
func slicesIndex[E comparable](s []E, v E) int {
for i := range s {
if v == s[i] {
return i
}
}
return -1
}

// slicesContains reports whether v is present in s.
func slicesContains[E comparable](s []E, v E) bool {
return slicesIndex(s, v) >= 0
}

// AllMethods is a slice containing all HTTP request methods.
var AllMethods = []string{http.MethodGet, http.MethodHead, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodConnect, http.MethodOptions, http.MethodTrace}

Expand Down Expand Up @@ -128,7 +113,7 @@ func New() *Mux {
// Handle registers a new handler for the given request path pattern and HTTP
// methods.
func (m *Mux) Handle(pattern string, handler http.Handler, methods ...string) {
if slicesContains(methods, http.MethodGet) && !slicesContains(methods, http.MethodHead) {
if slices.Contains(methods, http.MethodGet) && !slices.Contains(methods, http.MethodHead) {
methods = append(methods, http.MethodHead)
}

Expand Down Expand Up @@ -191,7 +176,7 @@ func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
route.handler.ServeHTTP(w, r.WithContext(ctx))
return
}
if !slicesContains(allowedMethods, route.method) {
if !slices.Contains(allowedMethods, route.method) {
allowedMethods = append(allowedMethods, route.method)
}
}
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) //nolint:staticcheck
t := append(transform, strings.Title)
return Join(Split(value), "", t...)
}

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

## Project Setup

Expand Down
4 changes: 2 additions & 2 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/danielgtaylor/huma/v2/examples

go 1.20
go 1.21

replace github.com/danielgtaylor/huma/v2 => ../

Expand Down Expand Up @@ -51,7 +51,7 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -549,7 +549,7 @@ golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy
golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -648,8 +648,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/danielgtaylor/huma/v2

go 1.20
go 1.21

require (
github.com/danielgtaylor/shorthand/v2 v2.2.0
Expand Down
21 changes: 3 additions & 18 deletions huma.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"net/http"
"reflect"
"regexp"
"slices"
"strconv"
"strings"
"sync"
Expand All @@ -33,22 +34,6 @@ var cookieType = reflect.TypeOf((*http.Cookie)(nil)).Elem()
var fmtStringerType = reflect.TypeOf((*fmt.Stringer)(nil)).Elem()
var stringType = reflect.TypeOf("")

// slicesIndex returns the index of the first occurrence of v in s,
// or -1 if not present.
func slicesIndex[E comparable](s []E, v E) int {
for i := range s {
if v == s[i] {
return i
}
}
return -1
}

// slicesContains reports whether v is present in s.
func slicesContains[E comparable](s []E, v E) bool {
return slicesIndex(s, v) >= 0
}

// SetReadDeadline is a utility to set the read deadline on a response writer,
// if possible. If not, it will not incur any allocations (unlike the stdlib
// `http.ResponseController`). This is mostly a convenience function for
Expand Down Expand Up @@ -141,7 +126,7 @@ func findParams(registry Registry, op *Operation, t reflect.Type) *findResult[*p
name = split[0]
// If `in` is `query` then `explode` defaults to true. Parsing is *much*
// easier if we use comma-separated values, so we disable explode by default.
if slicesContains(split[1:], "explode") {
if slices.Contains(split[1:], "explode") {
pfi.Explode = true
}
explode = &pfi.Explode
Expand Down Expand Up @@ -417,7 +402,7 @@ func _findInType[T comparable](t reflect.Type, path []int, result *findResult[T]
if !f.IsExported() {
continue
}
if slicesContains(ignore, f.Name) {
if slices.Contains(ignore, f.Name) {
continue
}
if ignoreAnonymous && f.Anonymous {
Expand Down
2 changes: 1 addition & 1 deletion registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (r *mapRegistry) Map() map[string]*Schema {
}

func (r *mapRegistry) MarshalJSON() ([]byte, error) {
return json.Marshal(r.schemas) //nolint:musttag
return json.Marshal(r.schemas)
}

func (r *mapRegistry) MarshalYAML() (interface{}, error) {
Expand Down
6 changes: 3 additions & 3 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1212,21 +1212,21 @@ func TestCustomUnmarshalType(t *testing.T) {

// Confirm the field works as expected when loading JSON.
o = O{}
err := json.Unmarshal([]byte(`{"field": 123}`), &o) //nolint:musttag
err := json.Unmarshal([]byte(`{"field": 123}`), &o)
require.NoError(t, err)
assert.True(t, o.Field.Sent)
assert.False(t, o.Field.Null)
assert.Equal(t, 123, o.Field.Value)

o = O{}
err = json.Unmarshal([]byte(`{"field": null}`), &o) //nolint:musttag
err = json.Unmarshal([]byte(`{"field": null}`), &o)
require.NoError(t, err)
assert.True(t, o.Field.Sent)
assert.True(t, o.Field.Null)
assert.Equal(t, 0, o.Field.Value)

o = O{}
err = json.Unmarshal([]byte(`{}`), &o) //nolint:musttag
err = json.Unmarshal([]byte(`{}`), &o)
require.NoError(t, err)
assert.False(t, o.Field.Sent)
assert.False(t, o.Field.Null)
Expand Down
2 changes: 1 addition & 1 deletion validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ func TestValidate(t *testing.T) {
errs := mapTo(res.Errors, func(e error) string {
return e.(*huma.ErrorDetail).Message
})
schemaJSON, _ := json.MarshalIndent(registry.Map(), "", " ") //nolint: musttag
schemaJSON, _ := json.MarshalIndent(registry.Map(), "", " ")
for _, err := range test.errs {
assert.Contains(t, errs, err, string(schemaJSON))
}
Expand Down