strfmt

package
v0.0.0-...-0e3049a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2015 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package strfmt contains custom string formats

TODO: add info on how to define and register a custom format

Index

Constants

View Source
const (
	// RFC3339FullDate represents a full-date as specified by RFC3339
	// See: http://goo.gl/xXOvVd
	RFC3339FullDate = "2006-01-02"
	// DatePattern pattern to match for the date format from http://tools.ietf.org/html/rfc3339#section-5.6
	DatePattern = `^([0-9]{4})-([0-9]{2})-([0-9]{2})`
)
View Source
const (
	// RFC3339Millis represents a ISO8601 format to millis instead of to nanos
	RFC3339Millis = "2006-01-02T15:04:05.000Z07:00"
	// DateTimePattern pattern to match for the date-time format from http://tools.ietf.org/html/rfc3339#section-5.6
	DateTimePattern = `^([0-9]{2}):([0-9]{2}):([0-9]{2})(.[0-9]+)?(z|([+-][0-9]{2}:[0-9]{2}))$`
)
View Source
const (
	// HostnamePattern http://json-schema.org/latest/json-schema-validation.html#anchor114
	//  A string instance is valid against this attribute if it is a valid
	//  representation for an Internet host name, as defined by RFC 1034, section 3.1 [RFC1034].
	//  http://tools.ietf.org/html/rfc1034#section-3.5
	//  <digit> ::= any one of the ten digits 0 through 9
	//  var digit = /[0-9]/;
	//  <letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case
	//  var letter = /[a-zA-Z]/;
	//  <let-dig> ::= <letter> | <digit>
	//  var letDig = /[0-9a-zA-Z]/;
	//  <let-dig-hyp> ::= <let-dig> | "-"
	//  var letDigHyp = /[-0-9a-zA-Z]/;
	//  <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
	//  var ldhStr = /[-0-9a-zA-Z]+/;
	//  <label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]
	//  var label = /[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?/;
	//  <subdomain> ::= <label> | <subdomain> "." <label>
	//  var subdomain = /^[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?(\.[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?)*$/;
	//  <domain> ::= <subdomain> | " "
	HostnamePattern = `^[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?(\.[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?)*$`
)

Variables

Default is the default formats registry

Functions

func DefaultNameNormalizer

func DefaultNameNormalizer(name string) string

DefaultNameNormalizer removes all dashes

func IsDate

func IsDate(str string) bool

IsDate returns true when the string is a valid date

func IsDateTime

func IsDateTime(str string) bool

IsDateTime returns true when the string is a valid date-time

func IsDuration

func IsDuration(str string) bool

IsDuration returns true if the provided string is a valid duration

func IsHostname

func IsHostname(str string) bool

IsHostname returns true when the string is a valid hostname

func IsStrictURI

func IsStrictURI(str string) bool

IsStrictURI returns true when the string is an absolute URI

func ParseDuration

func ParseDuration(cand string) (time.Duration, error)

ParseDuration parses a duration from a string, compatible with scala duration syntax

Types

type Base64

type Base64 []byte

Base64 represents a base64 encoded string

swagger:strfmt byte

func (Base64) MarshalText

func (b Base64) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*Base64) Scan

func (b *Base64) Scan(raw interface{}) error

Scan read a value from a database driver

func (*Base64) UnmarshalText

func (b *Base64) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (Base64) Value

func (b Base64) Value() (driver.Value, error)

Value converts a value to a database driver value

type CreditCard

type CreditCard string

CreditCard represents a credit card string format

swagger:strfmt creditcard

func (CreditCard) MarshalText

func (u CreditCard) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*CreditCard) Scan

func (u *CreditCard) Scan(raw interface{}) error

Scan read a value from a database driver

func (*CreditCard) UnmarshalText

func (u *CreditCard) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (CreditCard) Value

func (u CreditCard) Value() (driver.Value, error)

Value converts a value to a database driver value

type Date

type Date struct {
	time.Time
}

Date represents a date from the API

swagger:strfmt date

func (Date) MarshalText

func (d Date) MarshalText() ([]byte, error)

MarshalText serializes this date type to string

func (*Date) Scan

func (d *Date) Scan(raw interface{}) error

Scan scans a Date value from database driver type.

func (Date) String

func (d Date) String() string

String converts this date into a string

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(text []byte) error

UnmarshalText parses a text representation into a date type

func (Date) Value

func (d Date) Value() (driver.Value, error)

Value converts Date to a primitive value ready to written to a database.

type DateTime

type DateTime struct {
	time.Time
}

DateTime is a time but it serializes to ISO8601 format with millis It knows how to read 3 different variations of a RFC3339 date time. Most API's we encounter want either millisecond or second precision times. This just tries to make it worry-free.

swagger:strfmt date-time

func ParseDateTime

func ParseDateTime(data string) (DateTime, error)

ParseDateTime parses a string that represents an ISO8601 time or a unix epoch

func (DateTime) MarshalText

func (t DateTime) MarshalText() ([]byte, error)

MarshalText implements the text marshaller interface

func (*DateTime) Scan

func (t *DateTime) Scan(raw interface{}) error

Scan scans a DateTime value from database driver type.

func (DateTime) String

func (t DateTime) String() string

func (*DateTime) UnmarshalText

func (t *DateTime) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller interface

func (DateTime) Value

func (t DateTime) Value() (driver.Value, error)

Value converts DateTime to a primitive value ready to written to a database.

type Duration

type Duration time.Duration

Duration represents a duration

swagger:strfmt duration

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*Duration) Scan

func (d *Duration) Scan(raw interface{}) error

Scan reads a Duration value from database driver type.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (Duration) Value

func (d Duration) Value() (driver.Value, error)

Value converts Duration to a primitive value ready to written to a database.

type Email

type Email string

Email represents the email string format as specified by the json schema spec

swagger:strfmt email

func (Email) MarshalText

func (e Email) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*Email) Scan

func (e *Email) Scan(raw interface{}) error

Scan read a value from a database driver

func (*Email) UnmarshalText

func (e *Email) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (Email) Value

func (e Email) Value() (driver.Value, error)

Value converts a value to a database driver value

type Format

type Format interface {
	encoding.TextMarshaler
	encoding.TextUnmarshaler
}

Format represents a string format

type HexColor

type HexColor string

HexColor represents a hex color string format

swagger:strfmt hexcolor

func (HexColor) MarshalText

func (h HexColor) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*HexColor) Scan

func (h *HexColor) Scan(raw interface{}) error

Scan read a value from a database driver

func (*HexColor) UnmarshalText

func (h *HexColor) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (HexColor) Value

func (h HexColor) Value() (driver.Value, error)

Value converts a value to a database driver value

type Hostname

type Hostname string

Hostname represents the hostname string format as specified by the json schema spec

swagger:strfmt hostname

func (Hostname) MarshalText

func (h Hostname) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*Hostname) Scan

func (h *Hostname) Scan(raw interface{}) error

Scan read a value from a database driver

func (*Hostname) UnmarshalText

func (h *Hostname) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (Hostname) Value

func (h Hostname) Value() (driver.Value, error)

Value converts a value to a database driver value

type IPv4

type IPv4 string

IPv4 represents an IP v4 address

swagger:strfmt ipv4

func (IPv4) MarshalText

func (u IPv4) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*IPv4) Scan

func (u *IPv4) Scan(raw interface{}) error

Scan read a value from a database driver

func (*IPv4) UnmarshalText

func (u *IPv4) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (IPv4) Value

func (u IPv4) Value() (driver.Value, error)

Value converts a value to a database driver value

type IPv6

type IPv6 string

IPv6 represents an IP v6 address

swagger:strfmt ipv6

func (IPv6) MarshalText

func (u IPv6) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*IPv6) Scan

func (u *IPv6) Scan(raw interface{}) error

Scan read a value from a database driver

func (*IPv6) UnmarshalText

func (u *IPv6) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (IPv6) Value

func (u IPv6) Value() (driver.Value, error)

Value converts a value to a database driver value

type ISBN

type ISBN string

ISBN represents an isbn string format

swagger:strfmt isbn

func (ISBN) MarshalText

func (u ISBN) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*ISBN) Scan

func (u *ISBN) Scan(raw interface{}) error

Scan read a value from a database driver

func (*ISBN) UnmarshalText

func (u *ISBN) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (ISBN) Value

func (u ISBN) Value() (driver.Value, error)

Value converts a value to a database driver value

type ISBN10

type ISBN10 string

ISBN10 represents an isbn 10 string format

swagger:strfmt isbn10

func (ISBN10) MarshalText

func (u ISBN10) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*ISBN10) Scan

func (u *ISBN10) Scan(raw interface{}) error

Scan read a value from a database driver

func (*ISBN10) UnmarshalText

func (u *ISBN10) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (ISBN10) Value

func (u ISBN10) Value() (driver.Value, error)

Value converts a value to a database driver value

type ISBN13

type ISBN13 string

ISBN13 represents an isbn 13 string format

swagger:strfmt isbn13

func (ISBN13) MarshalText

func (u ISBN13) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*ISBN13) Scan

func (u *ISBN13) Scan(raw interface{}) error

Scan read a value from a database driver

func (*ISBN13) UnmarshalText

func (u *ISBN13) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (ISBN13) Value

func (u ISBN13) Value() (driver.Value, error)

Value converts a value to a database driver value

type NameNormalizer

type NameNormalizer func(string) string

NameNormalizer is a function that normalizes a format name

type Password

type Password string

Password represents a password. This has no validations and is mainly used as a marker for UI components.

swagger:strfmt password

func (Password) MarshalText

func (r Password) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*Password) Scan

func (r *Password) Scan(raw interface{}) error

Scan read a value from a database driver

func (*Password) UnmarshalText

func (r *Password) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (Password) Value

func (r Password) Value() (driver.Value, error)

Value converts a value to a database driver value

type RGBColor

type RGBColor string

RGBColor represents a RGB color string format

swagger:strfmt rgbcolor

func (RGBColor) MarshalText

func (r RGBColor) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*RGBColor) Scan

func (r *RGBColor) Scan(raw interface{}) error

Scan read a value from a database driver

func (*RGBColor) UnmarshalText

func (r *RGBColor) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (RGBColor) Value

func (r RGBColor) Value() (driver.Value, error)

Value converts a value to a database driver value

type Registry

type Registry interface {
	Add(string, Format, Validator) bool
	DelByName(string) bool
	GetType(string) (reflect.Type, bool)
	ContainsName(string) bool
	Validates(string, string) bool
	Parse(string, string) (interface{}, error)
}

Registry is a registry of string formats

func NewFormats

func NewFormats() Registry

NewFormats creates a new formats registry seeded with the values from the default

func NewSeededFormats

func NewSeededFormats(seeds []knownFormat, normalizer NameNormalizer) Registry

NewSeededFormats creates a new formats registry

type SSN

type SSN string

SSN represents a social security string format

swagger:strfmt ssn

func (SSN) MarshalText

func (u SSN) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*SSN) Scan

func (u *SSN) Scan(raw interface{}) error

Scan read a value from a database driver

func (*SSN) UnmarshalText

func (u *SSN) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (SSN) Value

func (u SSN) Value() (driver.Value, error)

Value converts a value to a database driver value

type URI

type URI string

URI represents the uri string format as specified by the json schema spec

swagger:strfmt uri

func (URI) MarshalText

func (u URI) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*URI) Scan

func (u *URI) Scan(raw interface{}) error

Scan read a value from a database driver

func (*URI) UnmarshalText

func (u *URI) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (URI) Value

func (u URI) Value() (driver.Value, error)

Value converts a value to a database driver value

type UUID

type UUID string

UUID represents a uuid string format

swagger:strfmt uuid

func (UUID) MarshalText

func (u UUID) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*UUID) Scan

func (u *UUID) Scan(raw interface{}) error

Scan read a value from a database driver

func (*UUID) UnmarshalText

func (u *UUID) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (UUID) Value

func (u UUID) Value() (driver.Value, error)

Value converts a value to a database driver value

type UUID3

type UUID3 string

UUID3 represents a uuid3 string format

swagger:strfmt uuid3

func (UUID3) MarshalText

func (u UUID3) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*UUID3) Scan

func (u *UUID3) Scan(raw interface{}) error

Scan read a value from a database driver

func (*UUID3) UnmarshalText

func (u *UUID3) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (UUID3) Value

func (u UUID3) Value() (driver.Value, error)

Value converts a value to a database driver value

type UUID4

type UUID4 string

UUID4 represents a uuid4 string format

swagger:strfmt uuid4

func (UUID4) MarshalText

func (u UUID4) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*UUID4) Scan

func (u *UUID4) Scan(raw interface{}) error

Scan read a value from a database driver

func (*UUID4) UnmarshalText

func (u *UUID4) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (UUID4) Value

func (u UUID4) Value() (driver.Value, error)

Value converts a value to a database driver value

type UUID5

type UUID5 string

UUID5 represents a uuid5 string format

swagger:strfmt uuid5

func (UUID5) MarshalText

func (u UUID5) MarshalText() ([]byte, error)

MarshalText turns this instance into text

func (*UUID5) Scan

func (u *UUID5) Scan(raw interface{}) error

Scan read a value from a database driver

func (*UUID5) UnmarshalText

func (u *UUID5) UnmarshalText(data []byte) error

UnmarshalText hydrates this instance from text

func (UUID5) Value

func (u UUID5) Value() (driver.Value, error)

Value converts a value to a database driver value

type Validator

type Validator func(string) bool

Validator represents a validator for a string format

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL