Skip to content

Commit

Permalink
format all code: remove empty lines, fix indent
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed May 16, 2024
1 parent e20b948 commit 2230739
Show file tree
Hide file tree
Showing 46 changed files with 168 additions and 800 deletions.
1 change: 0 additions & 1 deletion _examples/custom-validation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type MyStruct struct {
var validate *validator.Validate

func main() {

validate = validator.New()
validate.RegisterValidation("is-awesome", ValidateMyVal)

Expand Down
3 changes: 0 additions & 3 deletions _examples/custom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type DbBackedUser struct {
var validate *validator.Validate

func main() {

validate = validator.New()

// register all sql.Null* types to use the ValidateValuer CustomTypeFunc
Expand All @@ -29,15 +28,13 @@ func main() {
x := DbBackedUser{Name: sql.NullString{String: "", Valid: true}, Age: sql.NullInt64{Int64: 0, Valid: false}}

err := validate.Struct(x)

if err != nil {
fmt.Printf("Err(s):\n%+v\n", err)
}
}

// ValidateValuer implements validator.CustomTypeFunc
func ValidateValuer(field reflect.Value) interface{} {

if valuer, ok := field.Interface().(driver.Valuer); ok {

val, err := valuer.Value()
Expand Down
1 change: 0 additions & 1 deletion _examples/dive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type Test struct {
var validate *validator.Validate

func main() {

validate = validator.New()

// registering alias so we can see the differences between
Expand Down
1 change: 0 additions & 1 deletion _examples/gin-upgrading-overriding/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import "github.com/gin-gonic/gin/binding"

func main() {

binding.Validator = new(defaultValidator)

// regular gin logic
Expand Down
2 changes: 0 additions & 2 deletions _examples/gin-upgrading-overriding/v8_to_v9.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type defaultValidator struct {
var _ binding.StructValidator = &defaultValidator{}

func (v *defaultValidator) ValidateStruct(obj interface{}) error {

if kindOfData(obj) == reflect.Struct {

v.lazyinit()
Expand Down Expand Up @@ -44,7 +43,6 @@ func (v *defaultValidator) lazyinit() {
}

func kindOfData(data interface{}) reflect.Kind {

value := reflect.ValueOf(data)
valueType := value.Kind()

Expand Down
2 changes: 1 addition & 1 deletion _examples/map-validation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/go-playground/validator/v10"
)

Expand Down Expand Up @@ -38,7 +39,6 @@ func validateMap() {
}

func validateNestedMap() {

data := map[string]interface{}{
"name": "Arshiya Kiani",
"email": "zytel3301@gmail.com",
Expand Down
3 changes: 0 additions & 3 deletions _examples/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ type Address struct {
var validate *validator.Validate

func main() {

validate = validator.New(validator.WithRequiredStructEnabled())

validateStruct()
validateVariable()
}

func validateStruct() {

address := &Address{
Street: "Eavesdown Docks",
Planet: "Persphone",
Expand Down Expand Up @@ -89,7 +87,6 @@ func validateStruct() {
}

func validateVariable() {

myEmail := "joeybloggs.gmail.com"

errs := validate.Var(myEmail, "required,email")
Expand Down
2 changes: 0 additions & 2 deletions _examples/struct-level/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ type Address struct {
var validate *validator.Validate

func main() {

validate = validator.New()

// register function to get tag name from json tags.
Expand Down Expand Up @@ -160,7 +159,6 @@ func main() {
// hooks right into validator and you can combine with validation tags and still have a
// common error output format.
func UserStructLevelValidation(sl validator.StructLevel) {

user := sl.Current().Interface().(User)

if len(user.FirstName) == 0 && len(user.LastName) == 0 {
Expand Down
1 change: 1 addition & 0 deletions _examples/struct-map-rules-validation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/go-playground/validator/v10"
)

Expand Down
4 changes: 0 additions & 4 deletions _examples/translations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var (
)

func main() {

// NOTE: ommitting allot of error checking for brevity

en := en.New()
Expand All @@ -53,7 +52,6 @@ func main() {
}

func translateAll(trans ut.Translator) {

type User struct {
Username string `validate:"required"`
Tagline string `validate:"required,lt=10"`
Expand Down Expand Up @@ -81,7 +79,6 @@ func translateAll(trans ut.Translator) {
}

func translateIndividual(trans ut.Translator) {

type User struct {
Username string `validate:"required"`
}
Expand All @@ -101,7 +98,6 @@ func translateIndividual(trans ut.Translator) {
}

func translateOverride(trans ut.Translator) {

validate.RegisterTranslation("required", trans, func(ut ut.Translator) error {
return ut.Add("required", "{0} must have a value!", true) // see universal-translator for details
}, func(ut ut.Translator, fe validator.FieldError) string {
Expand Down
6 changes: 0 additions & 6 deletions baked_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,6 @@ func isEqIgnoreCase(fl FieldLevel) bool {
param := fl.Param()

switch field.Kind() {

case reflect.String:
return strings.EqualFold(field.String(), param)
}
Expand Down Expand Up @@ -1583,7 +1582,6 @@ func isImage(fl FieldLevel) bool {
case reflect.String:
filePath := field.String()
fileInfo, err := os.Stat(filePath)

if err != nil {
return false
}
Expand Down Expand Up @@ -1612,7 +1610,6 @@ func isImage(fl FieldLevel) bool {

// isFilePath is the validation function for validating if the current field's value is a valid file path.
func isFilePath(fl FieldLevel) bool {

var exists bool
var err error

Expand Down Expand Up @@ -2183,7 +2180,6 @@ func isGt(fl FieldLevel) bool {
case reflect.Struct:

if field.Type().ConvertibleTo(timeType) {

return field.Convert(timeType).Interface().(time.Time).After(time.Now().UTC())
}
}
Expand Down Expand Up @@ -2420,7 +2416,6 @@ func isLt(fl FieldLevel) bool {
case reflect.Struct:

if field.Type().ConvertibleTo(timeType) {

return field.Convert(timeType).Interface().(time.Time).Before(time.Now().UTC())
}
}
Expand Down Expand Up @@ -2600,7 +2595,6 @@ func isDir(fl FieldLevel) bool {

// isDirPath is the validation function for validating if the current field's value is a valid directory.
func isDirPath(fl FieldLevel) bool {

var exists bool
var err error

Expand Down
1 change: 1 addition & 0 deletions country_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ var iso3166_1_alpha3_eu = map[string]bool{
"POL": true, "PRT": true, "ROU": true, "SVK": true, "SVN": true,
"ESP": true, "SWE": true,
}

var iso3166_1_alpha_numeric = map[int]bool{
// see: https://www.iso.org/iso-3166-country-codes.html
4: true, 8: true, 12: true, 16: true, 20: true,
Expand Down
11 changes: 4 additions & 7 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type InvalidValidationError struct {

// Error returns InvalidValidationError message
func (e *InvalidValidationError) Error() string {

if e.Type == nil {
return "validator: (nil)"
}
Expand All @@ -41,7 +40,6 @@ type ValidationErrors []FieldError
// All information to create an error message specific to your application is contained within
// the FieldError found within the ValidationErrors array
func (ve ValidationErrors) Error() string {

buff := bytes.NewBufferString("")

for i := 0; i < len(ve); i++ {
Expand All @@ -55,7 +53,6 @@ func (ve ValidationErrors) Error() string {

// Translate translates all of the ValidationErrors
func (ve ValidationErrors) Translate(ut ut.Translator) ValidationErrorsTranslations {

trans := make(ValidationErrorsTranslations)

var fe *fieldError
Expand All @@ -78,7 +75,6 @@ func (ve ValidationErrors) Translate(ut ut.Translator) ValidationErrorsTranslati

// FieldError contains all functions to get error details
type FieldError interface {

// Tag returns the validation tag that failed. if the
// validation was an alias, this will return the
// alias name and not the underlying tag that failed.
Expand Down Expand Up @@ -158,8 +154,10 @@ type FieldError interface {
}

// compile time interface checks
var _ FieldError = new(fieldError)
var _ error = new(fieldError)
var (
_ FieldError = new(fieldError)
_ error = new(fieldError)
)

// fieldError contains a single field's validation error along
// with other properties that may be needed for error message creation
Expand Down Expand Up @@ -204,7 +202,6 @@ func (fe *fieldError) StructNamespace() string {
// Field returns the field's name with the tag name taking precedence over the
// field's actual name.
func (fe *fieldError) Field() string {

return fe.ns[len(fe.ns)-int(fe.fieldLen):]
// // return fe.field
// fld := fe.ns[len(fe.ns)-int(fe.fieldLen):]
Expand Down
1 change: 0 additions & 1 deletion field_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "reflect"
// FieldLevel contains all the information and helper functions
// to validate a field
type FieldLevel interface {

// Top returns the top level struct, if any
Top() reflect.Value

Expand Down
3 changes: 0 additions & 3 deletions struct_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func wrapStructLevelFunc(fn StructLevelFunc) StructLevelFuncCtx {
// StructLevel contains all the information and helper functions
// to validate a struct
type StructLevel interface {

// Validator returns the main validation object, in case one wants to call validations internally.
// this is so you don't have to use anonymous functions to get access to the validate
// instance.
Expand Down Expand Up @@ -107,7 +106,6 @@ func (v *validate) ExtractType(field reflect.Value) (reflect.Value, reflect.Kind

// ReportError reports an error just by passing the field and tag information
func (v *validate) ReportError(field interface{}, fieldName, structFieldName, tag, param string) {

fv, kind, _ := v.extractTypeInternal(reflect.ValueOf(field), false)

if len(structFieldName) == 0 {
Expand Down Expand Up @@ -161,7 +159,6 @@ func (v *validate) ReportError(field interface{}, fieldName, structFieldName, ta
//
// NOTE: this function prepends the current namespace to the relative ones.
func (v *validate) ReportValidationErrors(relativeNamespace, relativeStructNamespace string, errs ValidationErrors) {

var err *fieldError

for i := 0; i < len(errs); i++ {
Expand Down
4 changes: 2 additions & 2 deletions translations/ar/ar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestTranslations(t *testing.T) {
PostCode string `validate:"postcode_iso3166_alpha2=SG"`
PostCodeCountry string
PostCodeByField string `validate:"postcode_iso3166_alpha2_field=PostCodeCountry"`
Image string `validate:"image"`
Image string `validate:"image"`
}

var test Test
Expand Down Expand Up @@ -683,7 +683,7 @@ func TestTranslations(t *testing.T) {
expected: "لا يتطابق PostCodeByField مع تنسيق الرمز البريدي للبلد في حقل PostCodeCountry",
},
{
ns: "Test.Image",
ns: "Test.Image",
expected: "يجب أن تكون Image صورة صالحة",
},
}
Expand Down
Loading

0 comments on commit 2230739

Please sign in to comment.