example

package
v4.0.7 Latest Latest
Warning

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

Go to latest
Published: May 31, 2025 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const IgnoreThisItem, AndThis = 741, "quack"

preamble const declarations are ignored by the enumeration tool

View Source
const (
	// One is ignored by the enumeration tool too
	One = 1
)

Variables

View Source
var AllBaseEnums = enum.FloatEnums{
	A, C, G, T,
}

AllBaseEnums lists all 4 values in order.

View Source
var AllBases = []Base{
	A, C, G, T,
}

AllBases lists all 4 values in order.

View Source
var AllCountries = []Country{}/* 247 elements not displayed */

AllCountries lists all 247 values in order.

AllDays lists all 7 values in order.

AllGreekAlphabets lists all 24 values in order.

View Source
var AllMethodEnums = enum.IntEnums{
	HEAD, GET, PUT, POST,
	PATCH, DELETE,
}

AllMethodEnums lists all 6 values in order.

View Source
var AllMethods = []Method{
	HEAD, GET, PUT, POST,
	PATCH, DELETE,
}

AllMethods lists all 6 values in order.

AllMonths lists all 12 values in order.

AllPets lists all 5 values in order.

View Source
var AllSalesChannelEnums = enum.IntEnums{
	OnlineSales, InstoreSales, TelephoneSales,
}

AllSalesChannelEnums lists all 3 values in order.

AllSalesChannels lists all 3 values in order.

Functions

This section is empty.

Types

type Base

type Base float32

Base example demonstrates using floating point values instead of integers. These are float32 but could be float64; the only other restriction is that no two values can be the same number.

const A Base = 331.2

Nucleotide Molecular Weights, g/mol

const C Base = 307.2
const G Base = 347.2
const T Base = 322.2

func AsBase

func AsBase(s string) (Base, error)

AsBase parses a string to find the corresponding Base, accepting either one of the string values or a number. It wraps Parse.

func BaseOf

func BaseOf(v int) Base

BaseOf returns a Base based on an ordinal number. This is the inverse of Ordinal. If the ordinal is out of range, an invalid Base is returned.

func MustParseBase

func MustParseBase(s string) Base

MustParseBase is similar to AsBase except that it panics on error.

func (Base) Float

func (v Base) Float() float64

Float returns the float64 value. It serves to facilitate polymorphism (see enum.FloatEnum).

func (Base) IsValid

func (v Base) IsValid() bool

IsValid determines whether a Base is one of the defined constants.

func (Base) Ordinal

func (v Base) Ordinal() int

Ordinal returns the ordinal number of a Base. This is an integer counting from zero. It is *not* the same as the const number assigned to the value.

func (*Base) Parse

func (v *Base) Parse(in string) error

Parse parses a string to find the corresponding Base, accepting one of the string values or a number. It is used by AsBase.

Usage Example

v := new(Base)
err := v.Parse(s)
...  etc

func (Base) String

func (v Base) String() string

String returns the literal string representation of a Base, which is the same as the const identifier but without prefix or suffix.

type Country

type Country int

Country example shows use of the '-plural' option to set the name of plural collections. Because of '-ic', the parser ignores case. Because of '-unsnake', the parser treats underscores and spaces alike.

When generating JSON & SQL values, the 2-letter ISO-3166 country codes are used. This is determined by the `all` tags in comments. The 2-letter codes are also accepted when parsing.

The '-alias' option also allows 3-letter ISO-3166 tags to be parsed as their corresponding country using the map iso3166_3LetterCodes.

const (
	Afghanistan                                  Country = iota // all:"af"
	Åland_Islands                                               // all:"ax"
	Albania                                                     // all:"al"
	Algeria                                                     // all:"dz"
	American_Samoa                                              // all:"as"
	Andorra                                                     // all:"ad"
	Angola                                                      // all:"ao"
	Anguilla                                                    // all:"ai"
	Antarctica                                                  // all:"aq"
	Antigua_and_Barbuda                                         // all:"ag"
	Argentina                                                   // all:"ar"
	Armenia                                                     // all:"am"
	Aruba                                                       // all:"aw"
	Australia                                                   // all:"au"
	Austria                                                     // all:"at"
	Azerbaijan                                                  // all:"az"
	Bahamas                                                     // all:"bs"
	Bahrain                                                     // all:"bh"
	Bangladesh                                                  // all:"bd"
	Barbados                                                    // all:"bb"
	Belarus                                                     // all:"by"
	Belgium                                                     // all:"be"
	Belize                                                      // all:"bz"
	Benin                                                       // all:"bj"
	Bermuda                                                     // all:"bm"
	Bhutan                                                      // all:"bt"
	Bolivia                                                     // all:"bo"
	Bosnia_and_Herzegovina                                      // all:"ba"
	Botswana                                                    // all:"bw"
	Bouvet_Island                                               // all:"bv"
	Brazil                                                      // all:"br"
	British_Virgin_Islands                                      // all:"vg"
	British_Indian_Ocean_Territory                              // all:"io"
	Brunei_Darussalam                                           // all:"dn"
	Bulgaria                                                    // all:"bg"
	Burkina_Faso                                                // all:"bf"
	Burundi                                                     // all:"bi"
	Cambodia                                                    // all:"kh"
	Cameroon                                                    // all:"cm"
	Canada                                                      // all:"ca"
	Cape_Verde                                                  // all:"cv"
	Cayman_Islands                                              // all:"ky"
	Central_African_Republic                                    // all:"cf"
	Chad                                                        // all:"td"
	Chile                                                       // all:"cl"
	China                                                       // all:"cn"
	Hong_Kong                                                   // all:"hk" -- Special Administrative Region of China
	Macao                                                       // all:"mo" -- Special Administrative Region of China
	Christmas_Island                                            // all:"cx"
	Cocos_Islands                                               // all:"cc" -- Cocos (Keeling) Islands
	Colombia                                                    // all:"co"
	Comoros                                                     // all:"km"
	Congo_Brazzaville                                           // all:"cg" -- Congo (Brazzaville)
	Congo_DRC                                                   // all:"cd" -- Democratic Republic of the Congo
	Cook_Islands                                                // all:"ck"
	Costa_Rica                                                  // all:"cr"
	Côte_dIvoire                                                // all:"ci" -- Côte_d’Ivoire
	Croatia                                                     // all:"hr"
	Cuba                                                        // all:"cu"
	Cyprus                                                      // all:"cy"
	Czechia                                                     // all:"cz"
	Denmark                                                     // all:"dk"
	Djibouti                                                    // all:"dj"
	Dominica                                                    // all:"dm"
	Dominican_Republic                                          // all:"do"
	Ecuador                                                     // all:"ec"
	Egypt                                                       // all:"eg"
	El_Salvador                                                 // all:"sv"
	Equatorial_Guinea                                           // all:"gq"
	Eritrea                                                     // all:"er"
	Estonia                                                     // all:"ee"
	Ethiopia                                                    // all:"et"
	Falkland_Islands                                            // all:"fk" -- Falkland Islands (Malvinas)
	Faroe_Islands                                               // all:"fo"
	Fiji                                                        // all:"fj"
	Finland                                                     // all:"fi"
	France                                                      // all:"fr"
	French_Guiana                                               // all:"gf"
	French_Polynesia                                            // all:"pf"
	French_Southern_Territories                                 // all:"tf"
	Gabon                                                       // all:"ga"
	Gambia                                                      // all:"gm"
	Georgia                                                     // all:"ge"
	Germany                                                     // all:"de"
	Ghana                                                       // all:"gh"
	Gibraltar                                                   // all:"gi"
	Greece                                                      // all:"gr"
	Greenland                                                   // all:"gl"
	Grenada                                                     // all:"gd"
	Guadeloupe                                                  // all:"gp"
	Guam                                                        // all:"gu"
	Guatemala                                                   // all:"gt"
	Guernsey                                                    // all:"gg"
	Guinea                                                      // all:"gn"
	Guinea_Bissau                                               // all:"gw"
	Guyana                                                      // all:"gy"
	Haiti                                                       // all:"ht"
	Heard_Island_and_Mcdonald_Islands                           // all:"hm"
	Holy_See                                                    // all:"va" -- Vatican City State
	Honduras                                                    // all:"hn"
	Hungary                                                     // all:"hu"
	Iceland                                                     // all:"is"
	India                                                       // all:"in"
	Indonesia                                                   // all:"id"
	Iran                                                        // all:"ir" -- Islamic Republic of Iran
	Iraq                                                        // all:"iq"
	Ireland                                                     // all:"ie"
	Isle_of_Man                                                 // all:"im"
	Israel                                                      // all:"il"
	Italy                                                       // all:"it"
	Jamaica                                                     // all:"jm"
	Japan                                                       // all:"jp"
	Jersey                                                      // all:"je"
	Jordan                                                      // all:"jo"
	Kazakhstan                                                  // all:"kz"
	Kenya                                                       // all:"ke"
	Kiribati                                                    // all:"ki"
	Democratic_Peoples_Republic_of_Korea                        // all:"kp" -- Democratic People’s Republic of Korea
	South_Korea                                                 // all:"kr" -- Republic of Korea
	Kuwait                                                      // all:"kw"
	Kyrgyzstan                                                  // all:"kg"
	Lao_PDR                                                     // all:"la"
	Latvia                                                      // all:"lv"
	Lebanon                                                     // all:"lb"
	Lesotho                                                     // all:"ls"
	Liberia                                                     // all:"lr"
	Libya                                                       // all:"ly"
	Liechtenstein                                               // all:"li"
	Lithuania                                                   // all:"lt"
	Luxembourg                                                  // all:"lu"
	North_Macedonia                                             // all:"mk" -- Republic of North_Macedonia
	Madagascar                                                  // all:"mg"
	Malawi                                                      // all:"mw"
	Malaysia                                                    // all:"my"
	Maldives                                                    // all:"mv"
	Mali                                                        // all:"ml"
	Malta                                                       // all:"mt"
	Marshall_Islands                                            // all:"mh"
	Martinique                                                  // all:"mq"
	Mauritania                                                  // all:"mr"
	Mauritius                                                   // all:"mu"
	Mayotte                                                     // all:"yt"
	Mexico                                                      // all:"mx"
	Micronesia                                                  // all:"fm" -- Federated States of Micronesia
	Moldova                                                     // all:"md"
	Monaco                                                      // all:"mc"
	Mongolia                                                    // all:"mn"
	Montenegro                                                  // all:"me"
	Montserrat                                                  // all:"ms"
	Morocco                                                     // all:"ma"
	Mozambique                                                  // all:"mz"
	Myanmar                                                     // all:"mm"
	Namibia                                                     // all:"na"
	Nauru                                                       // all:"nr"
	Nepal                                                       // all:"np"
	Netherlands                                                 // all:"nl",
	Netherlands_Antilles                                        // all:"an" -- obsolete
	New_Caledonia                                               // all:"nc",
	New_Zealand                                                 // all:"nz",
	Nicaragua                                                   // all:"ni",
	Niger                                                       // all:"ne",
	Nigeria                                                     // all:"ng",
	Niue                                                        // all:"nu",
	Norfolk_Island                                              // all:"nf",
	Northern_Mariana_Islands                                    // all:"mp",
	Norway                                                      // all:"no",
	Oman                                                        // all:"om",
	Pakistan                                                    // all:"pk",
	Palau                                                       // all:"pw",
	Palestinian_Territory                                       // all:"ps", -- Palestinian Territory, Occupied
	Panama                                                      // all:"pa",
	Papua_New_Guinea                                            // all:"pg",
	Paraguay                                                    // all:"py",
	Peru                                                        // all:"pe",
	Philippines                                                 // all:"ph",
	Pitcairn                                                    // all:"pn",
	Poland                                                      // all:"pl",
	Portugal                                                    // all:"pt",
	Puerto_Rico                                                 // all:"pr",
	Qatar                                                       // all:"qa",
	Réunion                                                     // all:"re",
	Romania                                                     // all:"ro",
	Russian_Federation                                          // all:"ru",
	Rwanda                                                      // all:"rw",
	Saint_Barthélemy                                            // all:"bl",
	Saint_Helena                                                // all:"sh",
	Saint_Kitts_and_Nevis                                       // all:"kn",
	Saint_Lucia                                                 // all:"lc"
	Saint_Martin                                                // all:"mf" -- Saint-Martin (French part)
	Saint_Pierre_and_Miquelon                                   // all:"pm"
	Saint_Vincent_and_Grenadines                                // all:"vc"
	Samoa                                                       // all:"ws"
	San_Marino                                                  // all:"sm"
	Sao_Tome_and_Principe                                       // all:"st"
	Saudi_Arabia                                                // all:"sa"
	Senegal                                                     // all:"sn"
	Serbia                                                      // all:"rs"
	Seychelles                                                  // all:"sc"
	Sierra_Leone                                                // all:"sl"
	Singapore                                                   // all:"sg"
	Slovakia                                                    // all:"sk"
	Slovenia                                                    // all:"si"
	Solomon_Islands                                             // all:"sb"
	Somalia                                                     // all:"so"
	South_Africa                                                // all:"za"
	South_Georgia_and_the_South_Sandwich_Islands                // all:"gs"
	South_Sudan                                                 // all:"ss"
	Spain                                                       // all:"es"
	Sri_Lanka                                                   // all:"lk"
	Sudan                                                       // all:"sd"
	Suriname                                                    // all:"sr"
	Svalbard_and_Jan_Mayen_Islands                              // all:"sj"
	Swaziland                                                   // all:"sz" -- Eswatini
	Sweden                                                      // all:"se"
	Switzerland                                                 // all:"ch"
	Syria                                                       // all:"sy" -- Syrian Arab Republic
	Taiwan                                                      // all:"tw" -- Taiwan, Republic of China
	Tajikistan                                                  // all:"tj"
	Tanzania                                                    // all:"tz" -- United Republic of Tanzania
	Thailand                                                    // all:"th"
	Timor_Leste                                                 // all:"tl"
	Togo                                                        // all:"tg"
	Tokelau                                                     // all:"tk"
	Tonga                                                       // all:"to"
	Trinidad_and_Tobago                                         // all:"tt"
	Tunisia                                                     // all:"tn"
	Türkiye                                                     // all:"tr"
	Turkmenistan                                                // all:"tm"
	Turks_and_Caicos_Islands                                    // all:"tc"
	Tuvalu                                                      // all:"tv"
	Uganda                                                      // all:"ug"
	Ukraine                                                     // all:"ua"
	United_Arab_Emirates                                        // all:"ae"
	United_Kingdom                                              // all:"gb"
	United_States_of_America                                    // all:"us"
	United_States_Minor_Outlying_Islands                        // all:"um"
	Uruguay                                                     // all:"uy"
	Uzbekistan                                                  // all:"uz"
	Vanuatu                                                     // all:"vu"
	Venezuela                                                   // all:"ve" -- Bolivarian Republic of Venezuela
	Viet_Nam                                                    // all:"vn"
	Virgin_Islands                                              // all:"vi"
	Wallis_and_Futuna_Islands                                   // all:"wf"
	Western_Sahara                                              // all:"eh"
	Yemen                                                       // all:"ye"
	Zambia                                                      // all:"zm"
	Zimbabwe                                                    // all:"zw"
)

func AsCountry

func AsCountry(s string) (Country, error)

AsCountry parses a string to find the corresponding Country, accepting either one of the string values or a number. It wraps Parse. The input case does not matter.

func CountryOf

func CountryOf(v int) Country

CountryOf returns a Country based on an ordinal number. This is the inverse of Ordinal. If the ordinal is out of range, an invalid Country is returned.

func MustParseCountry

func MustParseCountry(s string) Country

MustParseCountry is similar to AsCountry except that it panics on error. The input case does not matter.

func (Country) Int

func (v Country) Int() int

Int returns the int value, which is not necessarily the same as the ordinal. This facilitates polymorphism (see enum.IntEnum).

func (Country) IsValid

func (v Country) IsValid() bool

IsValid determines whether a Country is one of the defined constants.

func (Country) JSON

func (v Country) JSON() string

JSON returns an approximation to the representation used for transmission via JSON. However, strings are not quoted.

func (Country) MarshalJSON

func (v Country) MarshalJSON() ([]byte, error)

MarshalJSON converts values to bytes suitable for transmission via JSON. The representation is chosen according to 'json' struct tags.

func (Country) MarshalText

func (v Country) MarshalText() ([]byte, error)

MarshalText converts values to bytes suitable for transmission via XML, JSON etc.

func (Country) Ordinal

func (v Country) Ordinal() int

Ordinal returns the ordinal number of a Country. This is an integer counting from zero. It is *not* the same as the const number assigned to the value.

func (*Country) Parse

func (v *Country) Parse(in string) error

Parse parses a string to find the corresponding Country, accepting one of the string values or a number. It is used by AsCountry. The input case does not matter.

Usage Example

v := new(Country)
err := v.Parse(s)
...  etc

func (*Country) Scan

func (v *Country) Scan(value interface{}) error

Scan parses some value, which can be a number, a string or []byte. It implements sql.Scanner, https://golang.org/pkg/database/sql/#Scanner

func (Country) String

func (v Country) String() string

String returns the literal string representation of a Country, which is the same as the const identifier but without prefix or suffix.

func (Country) Text

func (v Country) Text() string

Text returns the representation used for transmission via XML, JSON etc.

func (*Country) UnmarshalJSON

func (v *Country) UnmarshalJSON(text []byte) error

UnmarshalJSON converts transmitted JSON values to ordinary values. It allows both ordinals and strings to represent the values.

func (*Country) UnmarshalText

func (v *Country) UnmarshalText(bs []byte) error

UnmarshalText converts transmitted values to ordinary values.

func (Country) Value

func (v Country) Value() (driver.Value, error)

Value converts the Country to a string. The representation is chosen according to 'sql' struct tags. It implements driver.Valuer, https://golang.org/pkg/database/sql/driver/#Valuer

type Day

type Day uint

Day simple example also shows that more than one 'const' block can be used provided that the integer values are all distinct.

const (
	Sunday Day
	Monday
	Tuesday
	Wednesday
)
const (
	Thursday Day = iota + 5
	Friday
	Saturday
)

It is allowable to break the constant blocks (although it's a bit unnecessary here). However, the numeric values *must* all be distinct, otherwise the generated enum will not compile.

func AsDay

func AsDay(s string) (Day, error)

AsDay parses a string to find the corresponding Day, accepting either one of the string values or a number. It wraps Parse.

func DayOf

func DayOf(v int) Day

DayOf returns a Day based on an ordinal number. This is the inverse of Ordinal. If the ordinal is out of range, an invalid Day is returned.

func MustParseDay

func MustParseDay(s string) Day

MustParseDay is similar to AsDay except that it panics on error.

func (Day) Int

func (v Day) Int() int

Int returns the int value, which is not necessarily the same as the ordinal. This facilitates polymorphism (see enum.IntEnum).

func (Day) IsValid

func (v Day) IsValid() bool

IsValid determines whether a Day is one of the defined constants.

func (Day) Ordinal

func (v Day) Ordinal() int

Ordinal returns the ordinal number of a Day. This is an integer counting from zero. It is *not* the same as the const number assigned to the value.

func (*Day) Parse

func (v *Day) Parse(in string) error

Parse parses a string to find the corresponding Day, accepting one of the string values or a number. It is used by AsDay.

Usage Example

v := new(Day)
err := v.Parse(s)
...  etc

func (Day) String

func (v Day) String() string

String returns the literal string representation of a Day, which is the same as the const identifier but without prefix or suffix.

type GreekAlphabet

type GreekAlphabet int

GreekAlphabet example shows non-ASCII characters in use. There is also a cross-mapping table specified via the '-using' option. So the parser recognises inputs from both sets of strings.

See also https://unicode.org/charts/PDF/U0370.pdf https://en.wikipedia.org/wiki/Greek_alphabet

const (
	Αλφα    GreekAlphabet = iota + 1 // text:"alpha"   sql:"\u0391" = Α
	Βήτα                             // text:"beta"    sql:"\u0392"
	Γάμμα                            // text:"gamma"   sql:"\u0393"
	Δέλτα                            // text:"delta"   sql:"\u0394"
	Εψιλον                           // text:"epsilon" sql:"\u0395"
	Ζήτα                             // text:"zeta"    sql:"\u0396"
	Ητα                              // text:"eta"     sql:"\u0397"
	Θήτα                             // text:"theta"   sql:"\u0398"
	Ιώτα                             // text:"iota"    sql:"\u0399"
	Κάππα                            // text:"kappa"   sql:"\u039A"
	Λάμβδα                           // text:"lambda"  sql:"\u039B"
	Μυ                               // text:"mu"      sql:"\u039C"
	Νυ                               // text:"nu"      sql:"\u039D"
	Ξι                               // text:"xi"      sql:"\u039E"
	Ομικρον                          // text:"omicron" sql:"\u039F"
	Πι                               // text:"pi"      sql:"\u03A0"
	Ρώ                               // text:"rho"     sql:"\u03A1"
	Σίγμα                            // text:"sigma"   sql:"\u03A3"
	Ταυ                              // text:"tau"     sql:"\u03A4"
	Υψιλον                           // text:"upsilon" sql:"\u03A5"
	Φι                               // text:"phi"     sql:"\u03A6"
	Χι                               // text:"chi"     sql:"\u03A7"
	Ψι                               // text:"psi"     sql:"\u03A8"
	Ωμέγα                            // text:"omega"   sql:"\u03A9"

)

func AsGreekAlphabet

func AsGreekAlphabet(s string) (GreekAlphabet, error)

AsGreekAlphabet parses a string to find the corresponding GreekAlphabet, accepting either one of the string values or a number. It wraps Parse.

func GreekAlphabetOf

func GreekAlphabetOf(v int) GreekAlphabet

GreekAlphabetOf returns a GreekAlphabet based on an ordinal number. This is the inverse of Ordinal. If the ordinal is out of range, an invalid GreekAlphabet is returned.

func MustParseGreekAlphabet

func MustParseGreekAlphabet(s string) GreekAlphabet

MustParseGreekAlphabet is similar to AsGreekAlphabet except that it panics on error.

func (GreekAlphabet) Int

func (v GreekAlphabet) Int() int

Int returns the int value, which is not necessarily the same as the ordinal. This facilitates polymorphism (see enum.IntEnum).

func (GreekAlphabet) IsValid

func (v GreekAlphabet) IsValid() bool

IsValid determines whether a GreekAlphabet is one of the defined constants.

func (GreekAlphabet) MarshalText

func (v GreekAlphabet) MarshalText() ([]byte, error)

MarshalText converts values to bytes suitable for transmission via XML, JSON etc.

func (GreekAlphabet) Ordinal

func (v GreekAlphabet) Ordinal() int

Ordinal returns the ordinal number of a GreekAlphabet. This is an integer counting from zero. It is *not* the same as the const number assigned to the value.

func (*GreekAlphabet) Parse

func (v *GreekAlphabet) Parse(in string) error

Parse parses a string to find the corresponding GreekAlphabet, accepting one of the string values or a number. It is used by AsGreekAlphabet.

Usage Example

v := new(GreekAlphabet)
err := v.Parse(s)
...  etc

func (*GreekAlphabet) Scan

func (v *GreekAlphabet) Scan(value interface{}) error

Scan parses some value, which can be a number, a string or []byte. It implements sql.Scanner, https://golang.org/pkg/database/sql/#Scanner

func (GreekAlphabet) String

func (v GreekAlphabet) String() string

String returns the literal string representation of a GreekAlphabet, which is the same as the const identifier but without prefix or suffix.

func (GreekAlphabet) Text

func (v GreekAlphabet) Text() string

Text returns the representation used for transmission via XML, JSON etc.

func (*GreekAlphabet) UnmarshalText

func (v *GreekAlphabet) UnmarshalText(bs []byte) error

UnmarshalText converts transmitted values to ordinary values.

func (GreekAlphabet) Value

func (v GreekAlphabet) Value() (driver.Value, error)

Value converts the GreekAlphabet to a string. The representation is chosen according to 'sql' struct tags. It implements driver.Valuer, https://golang.org/pkg/database/sql/driver/#Valuer

type Method

type Method uint

Method example has json tags that control the JSON representations. So the parser recognises inputs from thes and the identifiers too. The '-ic' option means the parser ignores the case of its inputs.

See also SalesChannel.

const (
	HEAD   Method = iota // json:"HE"
	GET                  // json:"GE"
	PUT                  // json:"PU"
	POST                 // json:"PO"
	PATCH                // json:"PA"
	DELETE               // json:"DE"
)

func AsMethod

func AsMethod(s string) (Method, error)

AsMethod parses a string to find the corresponding Method, accepting either one of the string values or a number. It wraps Parse. The input case does not matter.

func MethodOf

func MethodOf(v int) Method

MethodOf returns a Method based on an ordinal number. This is the inverse of Ordinal. If the ordinal is out of range, an invalid Method is returned.

func MustParseMethod

func MustParseMethod(s string) Method

MustParseMethod is similar to AsMethod except that it panics on error. The input case does not matter.

func (Method) Int

func (v Method) Int() int

Int returns the int value, which is not necessarily the same as the ordinal. This facilitates polymorphism (see enum.IntEnum).

func (Method) IsValid

func (v Method) IsValid() bool

IsValid determines whether a Method is one of the defined constants.

func (Method) JSON

func (v Method) JSON() string

JSON returns an approximation to the representation used for transmission via JSON. However, strings are not quoted.

func (Method) MarshalJSON

func (v Method) MarshalJSON() ([]byte, error)

MarshalJSON converts values to bytes suitable for transmission via JSON. The representation is chosen according to 'json' struct tags.

func (Method) Ordinal

func (v Method) Ordinal() int

Ordinal returns the ordinal number of a Method. This is an integer counting from zero. It is *not* the same as the const number assigned to the value.

func (*Method) Parse

func (v *Method) Parse(in string) error

Parse parses a string to find the corresponding Method, accepting one of the string values or a number. It is used by AsMethod. The input case does not matter.

Usage Example

v := new(Method)
err := v.Parse(s)
...  etc

func (*Method) Scan

func (v *Method) Scan(value interface{}) error

Scan parses some value, which can be a number, a string or []byte. It implements sql.Scanner, https://golang.org/pkg/database/sql/#Scanner

func (Method) String

func (v Method) String() string

String returns the literal string representation of a Method, which is the same as the const identifier but without prefix or suffix.

func (*Method) UnmarshalJSON

func (v *Method) UnmarshalJSON(text []byte) error

UnmarshalJSON converts transmitted JSON values to ordinary values. It allows both ordinals and strings to represent the values.

func (Method) Value

func (v Method) Value() (driver.Value, error)

Value converts the Method to a number (based on '-store number'). It implements driver.Valuer, https://golang.org/pkg/database/sql/driver/#Valuer

type Month

type Month uint

Month example shows that several comma-separated enumeration constants can be on each line, and they can have explicit values. The '-ic' option means the parser ignores the case of its inputs.

const (
	January, February, March    Month = 1, 2, 3
	April, May, June            Month = 4, 5, 6
	July, August, September     Month = 7, 8, 9
	October, November, December Month = 10, 11, 12
)

func AsMonth

func AsMonth(s string) (Month, error)

AsMonth parses a string to find the corresponding Month, accepting either one of the string values or a number. The input representation is determined by monthMarshalTextRep. It wraps Parse. The input case does not matter.

func MonthOf

func MonthOf(v int) Month

MonthOf returns a Month based on an ordinal number. This is the inverse of Ordinal. If the ordinal is out of range, an invalid Month is returned.

func MustParseMonth

func MustParseMonth(s string) Month

MustParseMonth is similar to AsMonth except that it panics on error. The input case does not matter.

func (Month) Int

func (v Month) Int() int

Int returns the int value, which is not necessarily the same as the ordinal. This facilitates polymorphism (see enum.IntEnum).

func (Month) IsValid

func (v Month) IsValid() bool

IsValid determines whether a Month is one of the defined constants.

func (Month) MarshalText

func (v Month) MarshalText() ([]byte, error)

MarshalText converts values to bytes suitable for transmission via XML, JSON etc.

func (Month) Ordinal

func (v Month) Ordinal() int

Ordinal returns the ordinal number of a Month. This is an integer counting from zero. It is *not* the same as the const number assigned to the value.

func (*Month) Parse

func (v *Month) Parse(in string) error

Parse parses a string to find the corresponding Month, accepting one of the string values or a number. The input representation is determined by Identifier. It is used by AsMonth. The input case does not matter.

Usage Example

v := new(Month)
err := v.Parse(s)
...  etc

func (Month) String

func (v Month) String() string

String returns the literal string representation of a Month, which is the same as the const identifier but without prefix or suffix.

func (Month) Text

func (v Month) Text() string

Text returns the representation used for transmission via XML, JSON etc.

func (*Month) UnmarshalText

func (v *Month) UnmarshalText(bs []byte) error

UnmarshalText converts transmitted values to ordinary values.

type Pet

type Pet uint16

Pet example has a cross-mapping table specified via the 'text' tags. So the parser recognises inputs from both sets of strings. Also:

  • The '-lc' option means the parser expects lowercase inputs and the String method gives lowercase values.

  • The -prefix option means each identifer, MyCat etc, is stored in the enumeration as just "cat" without the "My" prefix.

  • Because of '-unsnake', underscores are replaced with spaces so "MyKoala_Bear" is treated as "koala bear".

  • Because of the '-lenient' option, the parser will allow numbers outside the valid range 0 to 4.

const (
	MyCat        Pet = iota // text:"Felis Catus"
	MyDog                   // text:"Canis Lupus"
	MyMouse                 // text:"Mus Musculus"
	MyElephant              // text:"Loxodonta Africana"
	MyKoala_Bear            // text:"Phascolarctos Cinereus"
)

These all have prefix "My", which is stripped from the String representation.

func AsPet

func AsPet(s string) (Pet, error)

AsPet parses a string to find the corresponding Pet, accepting either one of the string values or a number. It wraps Parse.

func MustParsePet

func MustParsePet(s string) Pet

MustParsePet is similar to AsPet except that it panics on error.

func PetOf

func PetOf(v int) Pet

PetOf returns a Pet based on an ordinal number. This is the inverse of Ordinal. If the ordinal is out of range, an invalid Pet is returned.

func (Pet) Int

func (v Pet) Int() int

Int returns the int value, which is not necessarily the same as the ordinal. This facilitates polymorphism (see enum.IntEnum).

func (Pet) IsValid

func (v Pet) IsValid() bool

IsValid determines whether a Pet is one of the defined constants.

func (Pet) MarshalText

func (v Pet) MarshalText() ([]byte, error)

MarshalText converts values to bytes suitable for transmission via XML, JSON etc.

func (Pet) Ordinal

func (v Pet) Ordinal() int

Ordinal returns the ordinal number of a Pet. This is an integer counting from zero. It is *not* the same as the const number assigned to the value.

func (*Pet) Parse

func (v *Pet) Parse(in string) error

Parse parses a string to find the corresponding Pet, accepting one of the string values or a number. It is used by AsPet.

Usage Example

v := new(Pet)
err := v.Parse(s)
...  etc

func (Pet) String

func (v Pet) String() string

String returns the literal string representation of a Pet, which is the same as the const identifier but without prefix or suffix.

func (Pet) Text

func (v Pet) Text() string

Text returns the representation used for transmission via XML, JSON etc.

func (*Pet) UnmarshalText

func (v *Pet) UnmarshalText(bs []byte) error

UnmarshalText converts transmitted values to ordinary values.

type SalesChannel

type SalesChannel int

SalesChannel example demonstrates the removing of a suffix string from the identifiers when their string equivalent is accessed.

The `json` tags in comments control values used for JSON marshalling. The `sql` tags in comments control values used for SQL storage.

const (
	OnlineSales    SalesChannel = 3 // json:"webshop" sql:"o" -- String() is "online"
	InstoreSales   SalesChannel = 5 // json:"store"   sql:"s" -- String() is "instore"
	TelephoneSales SalesChannel = 7 // json:"phone"   sql:"t" -- String() is "telephone"
)

func AsSalesChannel

func AsSalesChannel(s string) (SalesChannel, error)

AsSalesChannel parses a string to find the corresponding SalesChannel, accepting either one of the string values or a number. It wraps Parse.

func MustParseSalesChannel

func MustParseSalesChannel(s string) SalesChannel

MustParseSalesChannel is similar to AsSalesChannel except that it panics on error.

func SalesChannelOf

func SalesChannelOf(v int) SalesChannel

SalesChannelOf returns a SalesChannel based on an ordinal number. This is the inverse of Ordinal. If the ordinal is out of range, an invalid SalesChannel is returned.

func (SalesChannel) Int

func (v SalesChannel) Int() int

Int returns the int value, which is not necessarily the same as the ordinal. This facilitates polymorphism (see enum.IntEnum).

func (SalesChannel) IsValid

func (v SalesChannel) IsValid() bool

IsValid determines whether a SalesChannel is one of the defined constants.

func (SalesChannel) JSON

func (v SalesChannel) JSON() string

JSON returns an approximation to the representation used for transmission via JSON. However, strings are not quoted.

func (SalesChannel) MarshalJSON

func (v SalesChannel) MarshalJSON() ([]byte, error)

MarshalJSON converts values to bytes suitable for transmission via JSON. The representation is chosen according to 'json' struct tags.

func (SalesChannel) Ordinal

func (v SalesChannel) Ordinal() int

Ordinal returns the ordinal number of a SalesChannel. This is an integer counting from zero. It is *not* the same as the const number assigned to the value.

func (*SalesChannel) Parse

func (v *SalesChannel) Parse(in string) error

Parse parses a string to find the corresponding SalesChannel, accepting one of the string values or a number. It is used by AsSalesChannel.

Usage Example

v := new(SalesChannel)
err := v.Parse(s)
...  etc

func (*SalesChannel) Scan

func (v *SalesChannel) Scan(value interface{}) error

Scan parses some value, which can be a number, a string or []byte. It implements sql.Scanner, https://golang.org/pkg/database/sql/#Scanner

func (SalesChannel) String

func (v SalesChannel) String() string

String returns the literal string representation of a SalesChannel, which is the same as the const identifier but without prefix or suffix.

func (*SalesChannel) UnmarshalJSON

func (v *SalesChannel) UnmarshalJSON(text []byte) error

UnmarshalJSON converts transmitted JSON values to ordinary values. It allows both ordinals and strings to represent the values.

func (SalesChannel) Value

func (v SalesChannel) Value() (driver.Value, error)

Value converts the SalesChannel to a string. The representation is chosen according to 'sql' struct tags. It implements driver.Valuer, https://golang.org/pkg/database/sql/driver/#Valuer

Jump to

Keyboard shortcuts

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