Merge branch 'feature/form-name' into develop

This commit is contained in:
Simon Vieille 2025-08-01 18:05:55 +02:00
commit f1b45c7ad4
Signed by: deblan
GPG key ID: 579388D585F70417
5 changed files with 19 additions and 2 deletions

View file

@ -1,5 +1,9 @@
## [Unreleased]
### Added
- feat: add tag `field` to specify the naming strategy (case)
## v1.1.6
### Fixed

1
go.mod
View file

@ -9,6 +9,7 @@ require (
)
require (
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/samber/lo v1.51.0 // indirect
golang.org/x/text v0.22.0 // indirect
maragu.dev/gomponents v1.1.0 // indirect

2
go.sum
View file

@ -2,6 +2,8 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=

View file

@ -18,6 +18,8 @@ package util
import (
"errors"
"reflect"
"github.com/iancoleman/strcase"
)
func InspectStruct(input interface{}) (map[string]interface{}, error) {
@ -37,8 +39,16 @@ func InspectStruct(input interface{}) (map[string]interface{}, error) {
for i := 0; i < val.NumField(); i++ {
field := typ.Field(i)
value := val.Field(i)
tags := typ.Field(i).Tag
name := field.Name
result[field.Name] = value.Interface()
fieldTag := tags.Get("field")
if fieldTag == "lowerCamel" {
name = strcase.ToLowerCamel(name)
}
result[name] = value.Interface()
}
return result, nil

View file

@ -39,7 +39,7 @@ func (c NotBlank) Validate(data any) []Error {
v := reflect.ValueOf(data)
if v.IsZero() {
if data == nil || v.IsZero() {
errors = append(errors, Error(c.Message))
return errors