Source File
email.go
Belonging Package
github.com/oapi-codegen/runtime/types
package types
import (
)
// ErrValidationEmail is the sentinel error returned when an email fails validation
var ErrValidationEmail = errors.New("email: failed to pass regex validation")
// Email represents an email address.
// It is a string type that must pass regex validation before being marshalled
// to JSON or unmarshalled from JSON.
type Email string
func ( Email) () ([]byte, error) {
if !emailRegex.MatchString(string()) {
return nil, ErrValidationEmail
}
return json.Marshal(string())
}
func ( *Email) ( []byte) error {
if == nil {
return nil
}
var string
if := json.Unmarshal(, &); != nil {
return
}
* = Email()
if !emailRegex.MatchString() {
return ErrValidationEmail
}
return nil
}
![]() |
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |