github.com/go-swagger/go-swagger@v0.31.0/docs/reference/annotations/strfmt.md (about)

     1  ---
     2  title: strfmt
     3  date: 2023-01-01T01:01:01-08:00
     4  draft: true
     5  ---
     6  # swagger:strfmt
     7  
     8  A **swagger:strfmt** annotation names a type as a string formatter. The name is mandatory and that is
     9  what will be used as format name for this particular string format.
    10  String formats should only be used for **very** well known formats.
    11  
    12  <!-- more -->
    13  
    14  String formats are well-known items. These imply a common well-documented set of formats that can be validated. The toolkit allows for creating your own string formats too.
    15  
    16  To create a custom string format you need to create a type that implements the (Unm/M)arshalText interfaces and the sql Scan and sql Value interfaces.  The SQL interfaces are not strictly necessary but allow other people to use the string format in structs that are used with databases
    17  
    18  The default string formats for this toolkit are:
    19  
    20  * uuid, uuid3, uuid4, uuid5
    21  * email
    22  * uri (absolute)
    23  * hostname
    24  * ipv4
    25  * ipv6
    26  * credit card
    27  * isbn, isbn10, isbn13
    28  * social security number
    29  * hexcolor
    30  * rgbcolor
    31  * date
    32  * date-time
    33  * duration
    34  * password
    35  * custom string formats
    36  
    37  ##### Syntax
    38  
    39  ```go
    40  swagger:strfmt [name]
    41  ```
    42  
    43  ##### Example
    44  
    45  ```go
    46  func init() {
    47    eml := Email("")
    48    Default.Add("email", &eml, govalidator.IsEmail)
    49  }
    50  
    51  // Email represents the email string format as specified by the json schema spec
    52  //
    53  // swagger:strfmt email
    54  type Email string
    55  
    56  // MarshalText turns this instance into text
    57  func (e Email) MarshalText() ([]byte, error) {
    58  	return []byte(string(e)), nil
    59  }
    60  
    61  // UnmarshalText hydrates this instance from text
    62  func (e *Email) UnmarshalText(data []byte) error { // validation is performed later on
    63  	*e = Email(string(data))
    64  	return nil
    65  }
    66  
    67  func (b *Email) Scan(raw interface{}) error {
    68  	switch v := raw.(type) {
    69  	case []byte:
    70  		*b = Email(string(v))
    71  	case string:
    72  		*b = Email(v)
    73  	default:
    74  		return fmt.Errorf("cannot sql.Scan() strfmt.Email from: %#v", v)
    75  	}
    76  
    77  	return nil
    78  }
    79  
    80  func (b Email) Value() (driver.Value, error) {
    81  	return driver.Value(string(b)), nil
    82  }
    83  ```
    84  
    85  ##### Result
    86  
    87  ```yaml
    88  ```