ronantakizawa/codereview-bench huggingface dataset:
Repository: go-chi/chi
File: middleware/wrap_writer.go (Go)

Code before:
	discard     bool
}

func (b *basicWriter) WriteHeader(code int) {
	if !b.wroteHeader {
		b.code = code
		b.wroteHeader = true
		b.ResponseWriter.WriteHeader(code)
	}
}

func (b *basicWriter) Write(buf []byte) (n int, err error) {
	b.maybeWriteHeader()
	if !b.discard {
		n, err = b.ResponseWriter.Write(buf)
		if b.tee != nil {
			_, err2 := b.tee.Write(buf[:n])
			// Prefer errors generated by the proxied writer.
			if err == nil {
				err = err2
			}
		}
	} else if b.tee != nil {
		n, err = b.tee.Write(buf)
	} else {
		n, err = io.Discard.Write(buf)
	}
	b.bytes += n
	return n, err
}

func (b *basicWriter) maybeWriteHeader() {
	if !b.wroteHeader {
		b.WriteHeader(http.StatusOK)
	}
}

func (b *basicWriter) Status() int {
	return b.code
}

func (b *basicWriter) BytesWritten() int {
	return b.bytes
}

func (b *basicWriter) Tee(w io.Writer) {
	b.tee = w
}

func (b *basicWriter) Unwrap() http.ResponseWriter {
	return b.ResponseWriter

Review comment (suggestion):
https://github.com/go-chi/chi/actions/runs/9712399165/job/26807549159?pr=926

Looks like we'll need to use `ioutil.Discard` because of backward-compatibility with older versions of Go

Code after:

func (b *basicWriter) WriteHeader(code int) {
	if !b.wroteHeader {
		b.code = code
		b.wroteHeader = true
		if !b.discard {
			b.ResponseWriter.WriteHeader(code)
		}
	}
}

func (b *basicWriter) Write(buf []byte) (n int, err error) {
	b.maybeWriteHeader()
	if !b.discard {
		n, err = b.ResponseWriter.Write(buf)
		if b.tee != nil {
			_, err2 := b.tee.Write(buf[:n])
			// Prefer errors generated by the proxied writer.
			if err == nil {
				err = err2
			}
		}
	} else if b.tee != nil {
		n, err = b.tee.Write(buf)
	} else {
		n, err = ioutil.Discard.Write(buf)
	}
	b.bytes += n
	return n, err
}

func (b *basicWriter) maybeWriteHeader() {
	if !b.wroteHeader {
		b.WriteHeader(http.StatusOK)
	}
}

func (b *basicWriter) Status() int {
	return b.code
}

func (b *basicWriter) BytesWritten() int {
	return b.bytes
}

func (b *basicWriter) Tee(w io.Writer) {
	b.tee = w
}

func (b *basicWriter) Unwrap() http.ResponseWriter {
	return b.ResponseWriter
Repository: go-playground/validator
File: doc.go (Go)

Code before:
		maintain and are not reusable, so it's as much a programming philosophy
		as anything.

		In place of this new validator functions should be created; a regex can
		be used within the validator function and even be precompiled for better
		efficiency within regexes.go.

		And the best reason, you can submit a pull request and we can keep on
		adding to the validation library of this package!

Panics

This package panics when bad input is provided, this is by design, bad code like
that should not make it to production.

	type Test struct {
		TestField string `validate:"nonexistantfunction=1"`
	}

	t := &Test{
		TestField: "Test"
	}

	validate.Struct(t) // this will panic

Non standard validators

	type Test struct {
		TestField string `validate:"yourtag"`
	}

	t := &Test{
		TestField: "Test"
	}

	validate := validator.New()
	validate.RegisterValidation("yourtag", validations.ValidatorName)

	NotBlank
		This validates that the value is not blank or with length zero.
		For strings ensures they do not contain only spaces. For channels, maps, slices and arrays
		ensures they don't have zero length. For others, a non empty value is required.

		Usage: notblank
*/
package validator


Review comment (suggestion):
If you could add a note here about what Non standard validations are and that you have to register them manually that would be amazing :)

Code after:
		maintain and are not reusable, so it's as much a programming philosophy
		as anything.

		In place of this new validator functions should be created; a regex can
		be used within the validator function and even be precompiled for better
		efficiency within regexes.go.

		And the best reason, you can submit a pull request and we can keep on
		adding to the validation library of this package!

Panics

This package panics when bad input is provided, this is by design, bad code like
that should not make it to production.

	type Test struct {
		TestField string `validate:"nonexistantfunction=1"`
	}

	t := &Test{
		TestField: "Test"
	}

	validate.Struct(t) // this will panic

Non standard validators

A collection of validation rules that are frequently needed but are more
complex than the ones found in the baked in validators.
A non standard validator must be registered manually using any tag you like.
See below examples of registration and use.

	type Test struct {
		TestField string `validate:"yourtag"`
	}

	t := &Test{
		TestField: "Test"
	}

	validate := validator.New()
	validate.RegisterValidation("yourtag", validations.ValidatorName)

	NotBlank
		This validates that the value is not blank or with length zero.
		For strings ensures they do not contain only spaces. For channels, maps, slices and arrays
		ensures they don't have zero length. For others, a non empty value is required.

		Usage: notblank
*/
package validator
Repository: go-playground/validator
File: baked_in.go (Go)

Code before:
func isHTMLEncoded(fl FieldLevel) bool {
	return hTMLEncodedRegex.MatchString(fl.Field().String())
}

func isHTML(fl FieldLevel) bool {
	return hTMLRegex.MatchString(fl.Field().String())
}

func isOneOf(fl FieldLevel) bool {
	vals := parseOneOfParam2(fl.Param())

	field := fl.Field()

	var v string
	switch field.Kind() {
	case reflect.String:
		v = field.String()
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		v = strconv.FormatInt(field.Int(), 10)
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		v = strconv.FormatUint(field.Uint(), 10)
	default:
		panic(fmt.Sprintf("Bad field type %T", field.Interface()))
	}
	for i := 0; i < len(vals); i++ {
		val := strings.Replace(vals[i], "'", "", -1)
		if val == v {
			return true
		}
	}
	return false
}

// isUnique is the validation function for validating if each array|slice|map value is unique
func isUnique(fl FieldLevel) bool {

	field := fl.Field()
	v := reflect.ValueOf(struct{}{})

	switch field.Kind() {
	case reflect.Slice, reflect.Array:
		m := reflect.MakeMap(reflect.MapOf(field.Type().Elem(), v.Type()))

		for i := 0; i < field.Len(); i++ {
			m.SetMapIndex(field.Index(i), v)
		}
		return field.Len() == m.Len()
	case reflect.Map:
		m := reflect.MakeMap(reflect.MapOf(field.Type().Elem(), v.Type()))

		for _, k := range field.MapKeys() {

Review comment (performance):
instead of separating this logic from the `parseOneOfParam2` function is it possible to do the replace before adding to the `oneofValsCache` cache, then the output of the function is constent and all other validations can benefit from the same changes 😄  eg. `required_with*`

Code after:

func isHTMLEncoded(fl FieldLevel) bool {
	return hTMLEncodedRegex.MatchString(fl.Field().String())
}

func isHTML(fl FieldLevel) bool {
	return hTMLRegex.MatchString(fl.Field().String())
}

func isOneOf(fl FieldLevel) bool {
	vals := parseOneOfParam2(fl.Param())

	field := fl.Field()

	var v string
	switch field.Kind() {
	case reflect.String:
		v = field.String()
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		v = strconv.FormatInt(field.Int(), 10)
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		v = strconv.FormatUint(field.Uint(), 10)
	default:
		panic(fmt.Sprintf("Bad field type %T", field.Interface()))
	}
	for i := 0; i < len(vals); i++ {
		if vals[i] == v {
			return true
		}
	}
	return false
}

// isUnique is the validation function for validating if each array|slice|map value is unique
func isUnique(fl FieldLevel) bool {

	field := fl.Field()
	v := reflect.ValueOf(struct{}{})

	switch field.Kind() {
	case reflect.Slice, reflect.Array:
		m := reflect.MakeMap(reflect.MapOf(field.Type().Elem(), v.Type()))

		for i := 0; i < field.Len(); i++ {
			m.SetMapIndex(field.Index(i), v)
		}
		return field.Len() == m.Len()
	case reflect.Map:
		m := reflect.MakeMap(reflect.MapOf(field.Type().Elem(), v.Type()))

		for _, k := range field.MapKeys() {
Repository: go-playground/validator
File: baked_in.go (Go)

Code before:

	return checksum%11 == 0
}

// IsEthereumAddress is the validation function for validating if the field's value is a valid Ethereum address.
func isEthereumAddress(fl FieldLevel) bool {
	address := fl.Field().String()

	if !ethAddressRegex.MatchString(address) {
		return false
	}

	if ethaddressRegexUpper.MatchString(address) || ethAddressRegexLower.MatchString(address) {
		return true
	}

	// Checksum validation. Reference: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md
	digitValue := map[byte]int{
		'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
		'5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
		'a': 10, 'b': 11, 'c': 12,
		'd': 13, 'e': 14, 'f': 15,
	}
	address = address[2:]
	h := sha3.NewLegacyKeccak256()
	h.Write([]byte(strings.ToLower(address)))
	hash := hex.EncodeToString(h.Sum(nil))

	for i := 0; i < len(address); i++ {
		if address[i] <= '9' {
			continue
		}
		nibble := digitValue[hash[i]]

		if nibble > 7 && address[i] >= 'a' || nibble <= 7 && address[i] < 'a' {
			return false
		}
	}

	return true
}

// IsBitcoinAddress is the validation function for validating if the field's value is a valid btc address
func isBitcoinAddress(fl FieldLevel) bool {
	address := fl.Field().String()

	if !btcAddressRegex.MatchString(address) {
		return false
	}

	alphabet := []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")

Review comment (suggestion):
`hash.Hash`'s `io.Writer` implementation says it never returns an error. https://golang.org/pkg/hash/#Hash

Code after:

	return checksum%11 == 0
}

// IsEthereumAddress is the validation function for validating if the field's value is a valid Ethereum address.
func isEthereumAddress(fl FieldLevel) bool {
	address := fl.Field().String()

	if !ethAddressRegex.MatchString(address) {
		return false
	}

	if ethaddressRegexUpper.MatchString(address) || ethAddressRegexLower.MatchString(address) {
		return true
	}

	// Checksum validation. Reference: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md
	address = address[2:] // Skip "0x" prefix.
	h := sha3.NewLegacyKeccak256()
	// hash.Hash's io.Writer implementation says it never returns an error. https://golang.org/pkg/hash/#Hash
	_, _ = h.Write([]byte(strings.ToLower(address)))
	hash := hex.EncodeToString(h.Sum(nil))

	for i := 0; i < len(address); i++ {
		if address[i] <= '9' { // Skip 0-9 digits: they don't have upper/lower-case.
			continue
		}
		if hash[i] > '7' && address[i] >= 'a' || hash[i] <= '7' && address[i] <= 'F' {
			return false
		}
	}

	return true
}

// IsBitcoinAddress is the validation function for validating if the field's value is a valid btc address
func isBitcoinAddress(fl FieldLevel) bool {
	address := fl.Field().String()

	if !btcAddressRegex.MatchString(address) {
		return false
	}

	alphabet := []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")

	decode := [25]byte{}

	for _, n := range []byte(address) {
		d := bytes.IndexByte(alphabet, n)

		for i := 24; i >= 0; i-- {
Repository: go-playground/validator
File: baked_in.go (Go)

Code before:
		checksum += 10 * int32(s[9]-'0')
	}

	return checksum%11 == 0
}

// IsEthereumAddress is the validation function for validating if the field's value is a valid Ethereum address.
func isEthereumAddress(fl FieldLevel) bool {
	address := fl.Field().String()

	if !ethAddressRegex.MatchString(address) {
		return false
	}

	if ethaddressRegexUpper.MatchString(address) || ethAddressRegexLower.MatchString(address) {
		return true
	}

	// Checksum validation. Reference: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md
	digitValue := map[byte]int{
		'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
		'5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
		'a': 10, 'b': 11, 'c': 12,
		'd': 13, 'e': 14, 'f': 15,
	}
	address = address[2:]
	h := sha3.NewLegacyKeccak256()
	h.Write([]byte(strings.ToLower(address)))
	hash := hex.EncodeToString(h.Sum(nil))

	for i := 0; i < len(address); i++ {
		if address[i] <= '9' {
			continue
		}
		nibble := digitValue[hash[i]]

		if nibble > 7 && address[i] >= 'a' || nibble <= 7 && address[i] < 'a' {
			return false
		}
	}

	return true
}

// IsBitcoinAddress is the validation function for validating if the field's value is a valid btc address
func isBitcoinAddress(fl FieldLevel) bool {
	address := fl.Field().String()

	if !btcAddressRegex.MatchString(address) {
		return false
	}

Review comment (suggestion):
Here `len(address)` definitely has value 40, but I preferred to write `len(address)` instead of `40`. Thus we keep the information that "Ethereum addresses have 40 hex digits" declared only in one place, in the `regexes.go` (`ethAddress{Upper,Lower,}RegexString`).

Let me know if otherwise

Code after:
		checksum += 10 * int32(s[9]-'0')
	}

	return checksum%11 == 0
}

// IsEthereumAddress is the validation function for validating if the field's value is a valid Ethereum address.
func isEthereumAddress(fl FieldLevel) bool {
	address := fl.Field().String()

	if !ethAddressRegex.MatchString(address) {
		return false
	}

	if ethaddressRegexUpper.MatchString(address) || ethAddressRegexLower.MatchString(address) {
		return true
	}

	// Checksum validation. Reference: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md
	address = address[2:] // Skip "0x" prefix.
	h := sha3.NewLegacyKeccak256()
	// hash.Hash's io.Writer implementation says it never returns an error. https://golang.org/pkg/hash/#Hash
	_, _ = h.Write([]byte(strings.ToLower(address)))
	hash := hex.EncodeToString(h.Sum(nil))

	for i := 0; i < len(address); i++ {
		if address[i] <= '9' { // Skip 0-9 digits: they don't have upper/lower-case.
			continue
		}
		if hash[i] > '7' && address[i] >= 'a' || hash[i] <= '7' && address[i] <= 'F' {
			return false
		}
	}

	return true
}

// IsBitcoinAddress is the validation function for validating if the field's value is a valid btc address
func isBitcoinAddress(fl FieldLevel) bool {
	address := fl.Field().String()

	if !btcAddressRegex.MatchString(address) {
		return false
	}

	alphabet := []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")

	decode := [25]byte{}

	for _, n := range []byte(address) {
		d := bytes.IndexByte(alphabet, n)
Repository: go-playground/validator
File: validator_test.go (Go)

Code before:
				t.Fatalf("Index: %d dns_rfc1035_label failed Error: %s", i, errs)
			}
		} else {
			if IsEqual(errs, nil) {
				t.Fatalf("Index: %d dns_rfc1035_label failed Error: %s", i, errs)
			} else {
				val := getError(errs, "", "")
				if val.Tag() != "dns_rfc1035_label" {
					t.Fatalf("Index: %d dns_rfc1035_label failed Error: %s", i, errs)
				}
			}
		}
	}
}

func TestPostCodeByIso3166Alpha2(t *testing.T) {
	tests := map[string][]struct {
		value    string
		expected bool
	}{
		"VN": {
			{"ABC", false},
			{"700000", true},
			{"A1", false},
		},
		"GB": {
			{"EC1A 1BB", true},
			{"CF10 1B1H", false},
		},
		"VI": {
			{"00803", true},
			{"1234567", false},
		},
		"LC": { // not support regexp for post code
			{"123456", false},
		},
		"XX": { // not support country
			{"123456", false},
		},
	}

	validate := New()

	for cc, ccTests := range tests {
		for i, test := range ccTests {
			errs := validate.Var(test.value, fmt.Sprintf("postcode_iso3166_alpha2=%s", cc))

			if test.expected {
				if !IsEqual(errs, nil) {
					t.Fatalf("Index: %d postcode_iso3166_alpha2=%s failed Error: %s", i, cc, errs)
				}

Review comment (bug):
Given that input may come from someone who has no idea what they're doing, what about some more obtuse edge cases like:
* `"abc-abc"`
* `"ABC-ABC"`
* `"123-abc"`
* `""`
?


Code after:
				t.Fatalf("Index: %d bic failed Error: %s", i, errs)
			}
		} else {
			if IsEqual(errs, nil) {
				t.Fatalf("Index: %d bic failed Error: %s", i, errs)
			} else {
				val := getError(errs, "", "")
				if val.Tag() != "bic" {
					t.Fatalf("Index: %d bic failed Error: %s", i, errs)
				}
			}
		}
	}
}

func TestRFC1035LabelFormatValidation(t *testing.T) {
	tests := []struct {
		value    string `validate:"dns_rfc1035_label"`
		tag      string
		expected bool
	}{
		{"abc", "dns_rfc1035_label", true},
		{"abc-", "dns_rfc1035_label", false},
		{"abc-123", "dns_rfc1035_label", true},
		{"ABC", "dns_rfc1035_label", false},
		{"ABC-123", "dns_rfc1035_label", false},
		{"abc-abc", "dns_rfc1035_label", true},
		{"ABC-ABC", "dns_rfc1035_label", false},
		{"123-abc", "dns_rfc1035_label", false},
		{"", "dns_rfc1035_label", false},
	}

	validate := New()

	for i, test := range tests {
		errs := validate.Var(test.value, test.tag)

		if test.expected {
			if !IsEqual(errs, nil) {
				t.Fatalf("Index: %d dns_rfc1035_label failed Error: %s", i, errs)
			}
		} else {
			if IsEqual(errs, nil) {
				t.Fatalf("Index: %d dns_rfc1035_label failed Error: %s", i, errs)
			} else {
				val := getError(errs, "", "")
				if val.Tag() != "dns_rfc1035_label" {
					t.Fatalf("Index: %d dns_rfc1035_label failed Error: %s", i, errs)
				}
			}
		}
Repository: go-playground/validator
File: validator_test.go (Go)

Code before:
				val := getError(errs, "", "")
				if val.Tag() != "bic" {
					t.Fatalf("Index: %d bic failed Error: %s", i, errs)
				}
			}
		}
	}
}

func TestRFC1035LabelFormatValidation(t *testing.T) {
	tests := []struct {
		value    string `validate:"dns_rfc1035_label"`
		tag      string
		expected bool
	}{
		{"abc", "dns_rfc1035_label", true},
		{"abc-", "dns_rfc1035_label", false},
		{"abc-123", "dns_rfc1035_label", true},
		{"ABC", "dns_rfc1035_label", false},
		{"ABC-123", "dns_rfc1035_label", false},
	}

	validate := New()

	for i, test := range tests {

		errs := validate.Var(test.value, test.tag)

		if test.expected {
			if !IsEqual(errs, nil) {
				t.Fatalf("Index: %d dns_rfc1035_label failed Error: %s", i, errs)
			}
		} else {
			if IsEqual(errs, nil) {
				t.Fatalf("Index: %d dns_rfc1035_label failed Error: %s", i, errs)
			} else {
				val := getError(errs, "", "")
				if val.Tag() != "dns_rfc1035_label" {
					t.Fatalf("Index: %d dns_rfc1035_label failed Error: %s", i, errs)
				}
			}
		}
	}
}

func TestPostCodeByIso3166Alpha2(t *testing.T) {
	tests := map[string][]struct {
		value    string
		expected bool
	}{
		"VN": {

Review comment (refactor):
nit: remove this blank line? Blank lines are good to denote section breaks for improved readability, but here IMO it just makes it so less LOC fit on a single screen, which actually reduces readability. So just maybe be not quite so quick to insert one.

Code after:
		_ = validate.Var(2, "bcp47_language_tag")
	}, "Bad field type int")
}

func TestBicIsoFormatValidation(t *testing.T) {
	tests := []struct {
		value    string `validate:"bic"`
		tag      string
		expected bool
	}{
		{"SBICKEN1345", "bic", true},
		{"SBICKEN1", "bic", true},
		{"SBICKENY", "bic", true},
		{"SBICKEN1YYP", "bic", true},
		{"SBIC23NXXX", "bic", false},
		{"S23CKENXXXX", "bic", false},
		{"SBICKENXX", "bic", false},
		{"SBICKENXX9", "bic", false},
		{"SBICKEN13458", "bic", false},
		{"SBICKEN", "bic", false},
	}

	validate := New()

	for i, test := range tests {

		errs := validate.Var(test.value, test.tag)

		if test.expected {
			if !IsEqual(errs, nil) {
				t.Fatalf("Index: %d bic failed Error: %s", i, errs)
			}
		} else {
			if IsEqual(errs, nil) {
				t.Fatalf("Index: %d bic failed Error: %s", i, errs)
			} else {
				val := getError(errs, "", "")
				if val.Tag() != "bic" {
					t.Fatalf("Index: %d bic failed Error: %s", i, errs)
				}
			}
		}
	}
}

func TestRFC1035LabelFormatValidation(t *testing.T) {
	tests := []struct {
		value    string `validate:"dns_rfc1035_label"`
		tag      string
		expected bool
	}{
Repository: go-playground/validator
File: baked_in.go (Go)

Code before:
		"image/x-icon": true,
		"image/x-portable-anymap": true,
		"image/x-portable-bitmap": true,
		"image/x-portable-graymap": true,
		"image/x-portable-pixmap": true,
		"image/x-rgb": true,
		"image/x-xbitmap": true,
		"image/x-xpixmap": true,
		"image/x-xwindowdump": true,
	}
	field := fl.Field()

	switch field.Kind() {
	case reflect.String:
		filePath := field.String()
		fileInfo, err := os.Stat(filePath)

		if err != nil {
			return false
		}

		if fileInfo.IsDir() {
			return false
		}

		file, err := os.OpenFile(filePath, os.O_RDWR, 0644)
		if err != nil {
			return false
		}
		defer file.Close()

		mime, err := mimetype.DetectReader(file)
		if err != nil {
			return false
		}

		_, err = file.Seek(0, io.SeekStart)
		if err != nil {
			panic(fmt.Sprintf("Could not reset seek start for file. Error: %s", err))
		}

		if _, ok := mimetypes[mime.String()]; ok {
			return true
		}

		return false
	}

	panic(fmt.Sprintf("Bad field type %T", field.Interface()))
}


Review comment (security):
No need to have write permissions that I can see and `os.Open(...)` uses `O_RDONLY`
```suggestion
		file, err := os.Open(filePath)
```

Code after:
			return false
		}

		url, err := url.ParseRequestURI(s)

		if err != nil || url.Scheme == "" {
			return false
		}

		return true
	}

	panic(fmt.Sprintf("Bad field type %T", field.Interface()))
}

// isHttpURL is the validation function for validating if the current field's value is a valid HTTP(s) URL.
func isHttpURL(fl FieldLevel) bool {
	if !isURL(fl) {
		return false
	}

	field := fl.Field()
	switch field.Kind() {
	case reflect.String:

		s := strings.ToLower(field.String())
		return strings.HasPrefix(s, "http://") || strings.HasPrefix(s, "https://")
	}

	panic(fmt.Sprintf("Bad field type %T", field.Interface()))
}

// isUrnRFC2141 is the validation function for validating if the current field's value is a valid URN as per RFC 2141.
func isUrnRFC2141(fl FieldLevel) bool {
	field := fl.Field()

	switch field.Kind() {
	case reflect.String:

		str := field.String()

		_, match := urn.Parse([]byte(str))

		return match
	}

	panic(fmt.Sprintf("Bad field type %T", field.Interface()))
}

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