forked from mirror/enumer
Compare commits
59 Commits
docs-updat
...
master
Author | SHA1 | Date |
---|---|---|
re | e3c2a6fbb2 | |
Dan Markham | ff555f73ed | |
moritamori | ed2895e2a7 | |
Dan Markham | 71d3edd22d | |
Eduardo Solis | 49441931ac | |
Eduardo Solis | f8c85a7a99 | |
Dan Markham | 6e1910cc4f | |
Eduardo Solis | e79db5ce74 | |
Dan Markham | 0f231a24f5 | |
urso | 98641f4fd2 | |
Dan Markham | aa45c0d477 | |
Scott Leggett | df780b2a0e | |
Dan Markham | caff60ea13 | |
Dan Markham | 881cbb24bf | |
Dan Markham | b43356ef4a | |
Dan Markham | 3bf002e2f3 | |
Dan Markham | 28a1efd624 | |
Nir Haas | af60bb2988 | |
mieubrisse | a1605fba51 | |
Dan Markham | 585d6b237e | |
Menno | 67b1febc1d | |
Menno | 074b95bab8 | |
Menno | f80c486834 | |
Dan Markham | 328a338ddb | |
Dan Markham | 367f14bcb1 | |
Dan Markham | 9d0b7d4c67 | |
Dan Markham | b85f109b7f | |
Dan Markham | 677b61cc2c | |
Dan Markham | be4c11f837 | |
Dan Markham | 2479605aa2 | |
Dan Markham | b96c3ca7db | |
Kiril Vladimiroff | 67e4e9619f | |
Dan Markham | 67fb6efca7 | |
Dan Markham | eb484e6440 | |
Dan Markham | 0a1f0e6d70 | |
Dan Markham | be960ad5f1 | |
Dan Markham | 5c8e883cf6 | |
xescugc | cb6196db58 | |
xescugc | 20d9792920 | |
Dan Markham | 9741c5ae47 | |
Dan Markham | 017d714532 | |
Dan Markham | 3100ad138c | |
Kiril Vladimiroff | 78ada3fc29 | |
Dan Markham | d46c853929 | |
Dan Markham | 8d7221cc8a | |
Dan Markham | 9793e421ce | |
Dan Markham | 56342fda5f | |
Dan Markham | df8df69062 | |
Dan Markham | f6864bbebc | |
Dan Markham | 49fa643993 | |
Dan Markham | f93c6b0e0b | |
Dan Markham | cdbbf12521 | |
Quang Le | 1467a49eb3 | |
Quang Le | 0bc4e9e23e | |
Dan Markham | 2440b832e4 | |
Dan Markham | 14261a8f07 | |
Dan Markham | e080e58c1e | |
Dan Markham | 2a31c850ad | |
Dan Markham | f993037eaa |
|
@ -26,3 +26,6 @@ coverage.txt
|
||||||
*.prof
|
*.prof
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
enumer
|
||||||
|
|
|
@ -4,9 +4,8 @@ matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- go: master
|
- go: master
|
||||||
include:
|
include:
|
||||||
- go: 1.11.x
|
- go: 1.17.x
|
||||||
- go: 1.12.x
|
- go: 1.18.x
|
||||||
- go: master
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- GO111MODULE=on
|
- GO111MODULE=on
|
||||||
|
@ -21,9 +20,10 @@ deploy:
|
||||||
file:
|
file:
|
||||||
- cli/build/enumer.linux-amd64.tar.gz
|
- cli/build/enumer.linux-amd64.tar.gz
|
||||||
- cli/build/enumer.darwin-amd64.tar.gz
|
- cli/build/enumer.darwin-amd64.tar.gz
|
||||||
|
- cli/build/enumer.darwin-arm64.tar.gz
|
||||||
- cli/build/enumer.windows-amd64.exe.tar.gz
|
- cli/build/enumer.windows-amd64.exe.tar.gz
|
||||||
- cli/build/sha256sum.txt
|
- cli/build/sha256sum.txt
|
||||||
on:
|
on:
|
||||||
go: 1.12.x
|
go: 1.17.x
|
||||||
repo: dmarkham/enumer
|
repo: dmarkham/enumer
|
||||||
tags: true
|
tags: true
|
||||||
|
|
1
Makefile
1
Makefile
|
@ -7,6 +7,7 @@ build-cli: clean
|
||||||
-mkdir -p ./cli/build
|
-mkdir -p ./cli/build
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o ./cli/build/enumer.linux-amd64 .
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o ./cli/build/enumer.linux-amd64 .
|
||||||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -o ./cli/build/enumer.darwin-amd64 .
|
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a -o ./cli/build/enumer.darwin-amd64 .
|
||||||
|
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -a -o ./cli/build/enumer.darwin-arm64 .
|
||||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -o ./cli/build/enumer.windows-amd64.exe .
|
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -o ./cli/build/enumer.windows-amd64.exe .
|
||||||
cd ./cli/build && find . -name 'enumer*' | xargs -I{} tar czf {}.tar.gz {}
|
cd ./cli/build && find . -name 'enumer*' | xargs -I{} tar czf {}.tar.gz {}
|
||||||
cd ./cli/build && shasum -a 256 * > sha256sum.txt
|
cd ./cli/build && shasum -a 256 * > sha256sum.txt
|
||||||
|
|
22
README.md
22
README.md
|
@ -1,10 +1,10 @@
|
||||||
# Enumer [![GoDoc](https://godoc.org/github.com/dmarkham/enumer?status.svg)](https://godoc.org/github.com/dmarkham/enumer) [![Go Report Card](https://goreportcard.com/badge/github.com/dmarkham/enumer)](https://goreportcard.com/report/github.com/dmarkham/enumer) [![GitHub Release](https://img.shields.io/github/release/dmarkham/enumer.svg)](https://github.com/dmarkham/enumer/releases)[![Build Status](https://travis-ci.org/dmarkham/enumer.svg?branch=master)](https://travis-ci.org/dmarkham/enumer)
|
# Enumer [![GoDoc](https://godoc.org/git.internal/re/enumer?status.svg)](https://godoc.org/git.internal/re/enumer) [![Go Report Card](https://goreportcard.com/badge/git.internal/re/enumer)](https://goreportcard.com/report/git.internal/re/enumer) [![GitHub Release](https://img.shields.io/github/release/dmarkham/enumer.svg)](https://git.internal/re/enumer/releases)[![Build Status](https://travis-ci.com/dmarkham/enumer.svg?branch=master)](https://travis-ci.com/dmarkham/enumer)
|
||||||
|
|
||||||
|
|
||||||
Enumer is a tool to generate Go code that adds useful methods to Go enums (constants with a specific type).
|
Enumer is a tool to generate Go code that adds useful methods to Go enums (constants with a specific type).
|
||||||
It started as a fork of [Rob Pike’s Stringer tool](https://godoc.org/golang.org/x/tools/cmd/stringer)
|
It started as a fork of [Rob Pike’s Stringer tool](https://godoc.org/golang.org/x/tools/cmd/stringer)
|
||||||
maintained by [Álvaro López Espinosa](https://github.com/alvaroloes/enumer).
|
maintained by [Álvaro López Espinosa](https://github.com/alvaroloes/enumer).
|
||||||
This was again forked here as (https://github.com/dmarkham/enumer) picking up where Álvaro left off.
|
This was again forked here as (https://git.internal/re/enumer) picking up where Álvaro left off.
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -14,12 +14,14 @@ Usage of ./enumer:
|
||||||
Enumer [flags] -type T [directory]
|
Enumer [flags] -type T [directory]
|
||||||
Enumer [flags] -type T files... # Must be a single package
|
Enumer [flags] -type T files... # Must be a single package
|
||||||
For more information, see:
|
For more information, see:
|
||||||
http://godoc.org/github.com/dmarkham/enumer
|
http://godoc.org/git.internal/re/enumer
|
||||||
Flags:
|
Flags:
|
||||||
-addprefix string
|
-addprefix string
|
||||||
transform each item name by adding a prefix. Default: ""
|
transform each item name by adding a prefix. Default: ""
|
||||||
-comment value
|
-comment value
|
||||||
comments to include in generated code, can repeat. Default: ""
|
comments to include in generated code, can repeat. Default: ""
|
||||||
|
-gqlgen
|
||||||
|
if true, GraphQL marshaling methods for gqlgen will be generated. Default: false
|
||||||
-json
|
-json
|
||||||
if true, json marshaling methods will be generated. Default: false
|
if true, json marshaling methods will be generated. Default: false
|
||||||
-linecomment
|
-linecomment
|
||||||
|
@ -36,6 +38,8 @@ Flags:
|
||||||
transform each item name by removing a prefix. Default: ""
|
transform each item name by removing a prefix. Default: ""
|
||||||
-type string
|
-type string
|
||||||
comma-separated list of type names; must be set
|
comma-separated list of type names; must be set
|
||||||
|
-values
|
||||||
|
if true, alternative string values method will be generated. Default: false
|
||||||
-yaml
|
-yaml
|
||||||
if true, yaml marshaling methods will be generated. Default: false
|
if true, yaml marshaling methods will be generated. Default: false
|
||||||
```
|
```
|
||||||
|
@ -52,7 +56,7 @@ When Enumer is applied to a type, it will generate:
|
||||||
- Function `<Type>String(s string)`: returns the enum value from its string representation. This is useful
|
- Function `<Type>String(s string)`: returns the enum value from its string representation. This is useful
|
||||||
when you need to read enum values from command line arguments, from a configuration file, or
|
when you need to read enum values from command line arguments, from a configuration file, or
|
||||||
from a REST API request... In short, from those places where using the real enum value (an integer) would
|
from a REST API request... In short, from those places where using the real enum value (an integer) would
|
||||||
be almost meaningless or hard to trace or use by a human.
|
be almost meaningless or hard to trace or use by a human. `s` string is Case Insensitive.
|
||||||
- Function `<Type>Values()`: returns a slice with all the values of the enum
|
- Function `<Type>Values()`: returns a slice with all the values of the enum
|
||||||
- Function `<Type>Strings()`: returns a slice with all the Strings of the enum
|
- Function `<Type>Strings()`: returns a slice with all the Strings of the enum
|
||||||
- Method `IsA<Type>()`: returns true only if the current value is among the values of the enum. Useful for validations.
|
- Method `IsA<Type>()`: returns true only if the current value is among the values of the enum. Useful for validations.
|
||||||
|
@ -124,7 +128,7 @@ var aspirinString string = Aspirin.String()
|
||||||
fmt.Println("I need ", Paracetamol) // Will print "I need Paracetamol"
|
fmt.Println("I need ", Paracetamol) // Will print "I need Paracetamol"
|
||||||
|
|
||||||
// Convert a string with the enum name to the corresponding enum value
|
// Convert a string with the enum name to the corresponding enum value
|
||||||
pill, err := PillString("Ibuprofen")
|
pill, err := PillString("Ibuprofen") // "ibuprofen" will also work.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Unrecognized pill: ", err)
|
fmt.Println("Unrecognized pill: ", err)
|
||||||
return
|
return
|
||||||
|
@ -191,6 +195,12 @@ name := MyTypeValue.String() // name => "my_type_value"
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
|
For a module-aware repo with `enumer` in the `go.mod` file, generation can be called by adding the following to a `.go` source file:
|
||||||
|
|
||||||
|
```golang
|
||||||
|
//go:generate go run git.internal/re/enumer -type=YOURTYPE
|
||||||
|
```
|
||||||
|
|
||||||
There are four boolean flags: `json`, `text`, `yaml` and `sql`. You can use any combination of them (i.e. `enumer -type=Pill -json -text`),
|
There are four boolean flags: `json`, `text`, `yaml` and `sql`. You can use any combination of them (i.e. `enumer -type=Pill -json -text`),
|
||||||
|
|
||||||
For enum string representation transformation the `transform` and `trimprefix` flags
|
For enum string representation transformation the `transform` and `trimprefix` flags
|
||||||
|
@ -203,6 +213,8 @@ it is transformed). If a name doesn't have the prefix it will be passed unchange
|
||||||
|
|
||||||
If a prefix is provided via the `addprefix` flag, it will be added to the start of each name (after trimming and after transforming).
|
If a prefix is provided via the `addprefix` flag, it will be added to the start of each name (after trimming and after transforming).
|
||||||
|
|
||||||
|
The boolean flag `values` will additionally create an alternative string values method `Values() []string` to fullfill the `EnumValues` interface of [ent](https://entgo.io/docs/schema-fields/#enum-fields).
|
||||||
|
|
||||||
## Inspiring projects
|
## Inspiring projects
|
||||||
|
|
||||||
- [Álvaro López Espinosa](https://github.com/alvaroloes/enumer)
|
- [Álvaro López Espinosa](https://github.com/alvaroloes/enumer)
|
||||||
|
|
|
@ -65,7 +65,6 @@ func TestEndToEnd(t *testing.T) {
|
||||||
// Generate, compile, and run the test programs.
|
// Generate, compile, and run the test programs.
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
if !strings.HasSuffix(name, ".go") {
|
if !strings.HasSuffix(name, ".go") {
|
||||||
t.Errorf("%s is not a Go file", name)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if name == "cgo.go" && !build.Default.CgoEnabled {
|
if name == "cgo.go" && !build.Default.CgoEnabled {
|
||||||
|
|
23
enumer.go
23
enumer.go
|
@ -10,6 +10,10 @@ func %[1]sString(s string) (%[1]s, error) {
|
||||||
if val, ok := _%[1]sNameToValueMap[s]; ok {
|
if val, ok := _%[1]sNameToValueMap[s]; ok {
|
||||||
return val, nil
|
return val, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if val, ok := _%[1]sNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
return 0, fmt.Errorf("%%s does not belong to %[1]s values", s)
|
return 0, fmt.Errorf("%%s does not belong to %[1]s values", s)
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
@ -54,6 +58,18 @@ func (i %[1]s) IsA%[1]s() bool {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// Arguments to format are:
|
||||||
|
// [1]: type name
|
||||||
|
const altStringValuesMethod = `func (%[1]s) Values() []string {
|
||||||
|
return %[1]sStrings()
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
func (g *Generator) buildAltStringValuesMethod(typeName string) {
|
||||||
|
g.Printf("\n")
|
||||||
|
g.Printf(altStringValuesMethod, typeName)
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Generator) buildBasicExtras(runs [][]Value, typeName string, runsThreshold int) {
|
func (g *Generator) buildBasicExtras(runs [][]Value, typeName string, runsThreshold int) {
|
||||||
// At this moment, either "g.declareIndexAndNameVars()" or "g.declareNameVars()" has been called
|
// At this moment, either "g.declareIndexAndNameVars()" or "g.declareNameVars()" has been called
|
||||||
|
|
||||||
|
@ -61,7 +77,7 @@ func (g *Generator) buildBasicExtras(runs [][]Value, typeName string, runsThresh
|
||||||
g.Printf("\nvar _%sValues = []%s{", typeName, typeName)
|
g.Printf("\nvar _%sValues = []%s{", typeName, typeName)
|
||||||
for _, values := range runs {
|
for _, values := range runs {
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
g.Printf("\t%s, ", value.str)
|
g.Printf("\t%s, ", value.originalName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.Printf("}\n\n")
|
g.Printf("}\n\n")
|
||||||
|
@ -76,7 +92,7 @@ func (g *Generator) buildBasicExtras(runs [][]Value, typeName string, runsThresh
|
||||||
g.Printf(stringNameToValueMethod, typeName)
|
g.Printf(stringNameToValueMethod, typeName)
|
||||||
g.Printf(stringValuesMethod, typeName)
|
g.Printf(stringValuesMethod, typeName)
|
||||||
g.Printf(stringsMethod, typeName)
|
g.Printf(stringsMethod, typeName)
|
||||||
if len(runs) < runsThreshold {
|
if len(runs) <= runsThreshold {
|
||||||
g.Printf(stringBelongsMethodLoop, typeName)
|
g.Printf(stringBelongsMethodLoop, typeName)
|
||||||
} else { // There is a map of values, the code is simpler then
|
} else { // There is a map of values, the code is simpler then
|
||||||
g.Printf(stringBelongsMethodSet, typeName)
|
g.Printf(stringBelongsMethodSet, typeName)
|
||||||
|
@ -98,7 +114,8 @@ func (g *Generator) printValueMap(runs [][]Value, typeName string, runsThreshold
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
g.Printf("\t_%sName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), &value)
|
g.Printf("\t_%sName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), value.originalName)
|
||||||
|
g.Printf("\t_%sLowerName%s[%d:%d]: %s,\n", typeName, runID, n, n+len(value.name), value.originalName)
|
||||||
n += len(value.name)
|
n += len(value.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
## Steps
|
## Steps
|
||||||
|
|
||||||
1. Go get enumer `go get -u github.com/dmarkham/enumer`
|
1. Go get enumer `go get -u git.internal/re/enumer`
|
||||||
2. `go generate` This should create `pill_enumer.go`
|
2. `go generate` This should create `pill_enumer.go`
|
||||||
3. `go run *.go` to see it in action
|
3. `go run *.go` to see it in action
|
||||||
4. `go mod tidy` to remove the deps for `enumer` once your happy.
|
4. `go mod tidy` to remove the deps for `enumer` once your happy.
|
||||||
|
|
|
@ -2,7 +2,7 @@ package main
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
//go:generate go run github.com/dmarkham/enumer -type=Pill -json
|
//go:generate go run git.internal/re/enumer -type=Pill -json
|
||||||
type Pill int
|
type Pill int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
13
go.mod
13
go.mod
|
@ -1,6 +1,13 @@
|
||||||
module github.com/dmarkham/enumer
|
module git.internal/re/enumer
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1
|
github.com/pascaldekloe/name v1.0.0
|
||||||
golang.org/x/tools v0.0.0-20190404132500-923d25813098
|
golang.org/x/tools v0.1.12
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
|
||||||
|
)
|
||||||
|
|
||||||
|
go 1.17
|
||||||
|
|
30
go.sum
30
go.sum
|
@ -1,8 +1,28 @@
|
||||||
github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1 h1:/I3lTljEEDNYLho3/FUB7iD/oc2cEFgVmbHzV+O0PtU=
|
github.com/pascaldekloe/name v1.0.0 h1:n7LKFgHixETzxpRv2R77YgPUFo85QHGZKrdaYm7eY5U=
|
||||||
github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5JxqMiuNYyFNmyY9rkJ/slN8y59oEu4Ei7F8OoKWQ=
|
github.com/pascaldekloe/name v1.0.0/go.mod h1:Z//MfYJnH4jVpQ9wkclwu2I2MkHmXTlT9wR5UZScttM=
|
||||||
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/tools v0.0.0-20190404132500-923d25813098 h1:MtqjsZmyGRgMmLUgxnmMJ6RYdvd2ib8ipiayHhqSxs4=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/tools v0.0.0-20190404132500-923d25813098/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
|
1271
golden_test.go
1271
golden_test.go
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,26 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
// Arguments to format are:
|
||||||
|
// [1]: type name
|
||||||
|
const gqlgenMethods = `
|
||||||
|
// MarshalGQL implements the graphql.Marshaler interface for %[1]s
|
||||||
|
func (i %[1]s) MarshalGQL(w io.Writer) {
|
||||||
|
fmt.Fprint(w, strconv.Quote(i.String()))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalGQL implements the graphql.Unmarshaler interface for %[1]s
|
||||||
|
func (i *%[1]s) UnmarshalGQL(value interface{}) error {
|
||||||
|
str, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("%[1]s should be a string, got %%T", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
*i, err = %[1]sString(str)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
func (g *Generator) buildGQLGenMethods(runs [][]Value, typeName string) {
|
||||||
|
g.Printf(gqlgenMethods, typeName)
|
||||||
|
}
|
18
sql.go
18
sql.go
|
@ -12,14 +12,16 @@ const scanMethod = `func (i *%[1]s) Scan(value interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
str, ok := value.(string)
|
var str string
|
||||||
if !ok {
|
switch v := value.(type) {
|
||||||
bytes, ok := value.([]byte)
|
case []byte:
|
||||||
if !ok {
|
str = string(v)
|
||||||
return fmt.Errorf("value is not a byte slice")
|
case string:
|
||||||
}
|
str = v
|
||||||
|
case fmt.Stringer:
|
||||||
str = string(bytes[:])
|
str = v.String()
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid value of %[1]s: %%[1]T(%%[1]v)", value)
|
||||||
}
|
}
|
||||||
|
|
||||||
val, err := %[1]sString(str)
|
val, err := %[1]sString(str)
|
||||||
|
|
109
stringer.go
109
stringer.go
|
@ -5,7 +5,7 @@
|
||||||
// Enumer is a tool to generate Go code that adds useful methods to Go enums (constants with a specific type).
|
// Enumer is a tool to generate Go code that adds useful methods to Go enums (constants with a specific type).
|
||||||
// It started as a fork of Rob Pike’s Stringer tool
|
// It started as a fork of Rob Pike’s Stringer tool
|
||||||
//
|
//
|
||||||
// Please visit http://github.com/dmarkham/enumer for a comprehensive documentation
|
// Please visit http://git.internal/re/enumer for a comprehensive documentation
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -49,6 +49,8 @@ var (
|
||||||
json = flag.Bool("json", false, "if true, json marshaling methods will be generated. Default: false")
|
json = flag.Bool("json", false, "if true, json marshaling methods will be generated. Default: false")
|
||||||
yaml = flag.Bool("yaml", false, "if true, yaml marshaling methods will be generated. Default: false")
|
yaml = flag.Bool("yaml", false, "if true, yaml marshaling methods will be generated. Default: false")
|
||||||
text = flag.Bool("text", false, "if true, text marshaling methods will be generated. Default: false")
|
text = flag.Bool("text", false, "if true, text marshaling methods will be generated. Default: false")
|
||||||
|
gqlgen = flag.Bool("gqlgen", false, "if true, GraphQL marshaling methods for gqlgen will be generated. Default: false")
|
||||||
|
altValuesFunc = flag.Bool("values", false, "if true, alternative string values method will be generated. Default: false")
|
||||||
output = flag.String("output", "", "output file name; default srcdir/<type>_string.go")
|
output = flag.String("output", "", "output file name; default srcdir/<type>_string.go")
|
||||||
transformMethod = flag.String("transform", "noop", "enum item name transformation method. Default: noop")
|
transformMethod = flag.String("transform", "noop", "enum item name transformation method. Default: noop")
|
||||||
trimPrefix = flag.String("trimprefix", "", "transform each item name by removing a prefix. Default: \"\"")
|
trimPrefix = flag.String("trimprefix", "", "transform each item name by removing a prefix. Default: \"\"")
|
||||||
|
@ -69,7 +71,7 @@ func Usage() {
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "\tEnumer [flags] -type T [directory]\n")
|
_, _ = fmt.Fprintf(os.Stderr, "\tEnumer [flags] -type T [directory]\n")
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "\tEnumer [flags] -type T files... # Must be a single package\n")
|
_, _ = fmt.Fprintf(os.Stderr, "\tEnumer [flags] -type T files... # Must be a single package\n")
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "For more information, see:\n")
|
_, _ = fmt.Fprintf(os.Stderr, "For more information, see:\n")
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "\thttp://godoc.org/github.com/dmarkham/enumer\n")
|
_, _ = fmt.Fprintf(os.Stderr, "\thttp://godoc.org/git.internal/re/enumer\n")
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "Flags:\n")
|
_, _ = fmt.Fprintf(os.Stderr, "Flags:\n")
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
|
@ -118,17 +120,22 @@ func main() {
|
||||||
g.Printf("\n")
|
g.Printf("\n")
|
||||||
g.Printf("import (\n")
|
g.Printf("import (\n")
|
||||||
g.Printf("\t\"fmt\"\n")
|
g.Printf("\t\"fmt\"\n")
|
||||||
|
g.Printf("\t\"strings\"\n")
|
||||||
if *sql {
|
if *sql {
|
||||||
g.Printf("\t\"database/sql/driver\"\n")
|
g.Printf("\t\"database/sql/driver\"\n")
|
||||||
}
|
}
|
||||||
if *json {
|
if *json {
|
||||||
g.Printf("\t\"encoding/json\"\n")
|
g.Printf("\t\"encoding/json\"\n")
|
||||||
}
|
}
|
||||||
|
if *gqlgen {
|
||||||
|
g.Printf("\t\"io\"\n")
|
||||||
|
g.Printf("\t\"strconv\"\n")
|
||||||
|
}
|
||||||
g.Printf(")\n")
|
g.Printf(")\n")
|
||||||
|
|
||||||
// Run generate for each type.
|
// Run generate for each type.
|
||||||
for _, typeName := range typs {
|
for _, typeName := range typs {
|
||||||
g.generate(typeName, *json, *yaml, *sql, *text, *transformMethod, *trimPrefix, *addPrefix, *linecomment)
|
g.generate(typeName, *json, *yaml, *sql, *text, *gqlgen, *transformMethod, *trimPrefix, *addPrefix, *linecomment, *altValuesFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the output.
|
// Format the output.
|
||||||
|
@ -377,8 +384,17 @@ func (g *Generator) transformValueNames(values []Value, transformMethod string)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range values {
|
for i, v := range values {
|
||||||
values[i].name = fn(values[i].name)
|
after := fn(v.name)
|
||||||
|
// If the original one was "" or the one before the transformation
|
||||||
|
// was "" (most commonly if linecomment defines it as empty) we
|
||||||
|
// do not care if it's empty.
|
||||||
|
// But if any of them was not empty before then it means that
|
||||||
|
// the transformed emptied the value
|
||||||
|
if v.originalName != "" && v.name != "" && after == "" {
|
||||||
|
log.Fatalf("transformation of %q (%s) got an empty result", v.name, v.originalName)
|
||||||
|
}
|
||||||
|
values[i].name = after
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,8 +413,9 @@ func (g *Generator) prefixValueNames(values []Value, prefix string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate produces the String method for the named type.
|
// generate produces the String method for the named type.
|
||||||
func (g *Generator) generate(typeName string, includeJSON, includeYAML, includeSQL, includeText bool,
|
func (g *Generator) generate(typeName string,
|
||||||
transformMethod string, trimPrefix string, addPrefix string, lineComment bool) {
|
includeJSON, includeYAML, includeSQL, includeText, includeGQLGen bool,
|
||||||
|
transformMethod string, trimPrefix string, addPrefix string, lineComment bool, includeValuesMethod bool) {
|
||||||
values := make([]Value, 0, 100)
|
values := make([]Value, 0, 100)
|
||||||
for _, file := range g.pkg.files {
|
for _, file := range g.pkg.files {
|
||||||
file.lineComment = lineComment
|
file.lineComment = lineComment
|
||||||
|
@ -415,7 +432,9 @@ func (g *Generator) generate(typeName string, includeJSON, includeYAML, includeS
|
||||||
log.Fatalf("no values defined for type %s", typeName)
|
log.Fatalf("no values defined for type %s", typeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
g.trimValueNames(values, trimPrefix)
|
for _, prefix := range strings.Split(trimPrefix, ",") {
|
||||||
|
g.trimValueNames(values, prefix)
|
||||||
|
}
|
||||||
|
|
||||||
g.transformValueNames(values, transformMethod)
|
g.transformValueNames(values, transformMethod)
|
||||||
|
|
||||||
|
@ -443,6 +462,11 @@ func (g *Generator) generate(typeName string, includeJSON, includeYAML, includeS
|
||||||
default:
|
default:
|
||||||
g.buildMap(runs, typeName)
|
g.buildMap(runs, typeName)
|
||||||
}
|
}
|
||||||
|
if includeValuesMethod {
|
||||||
|
g.buildAltStringValuesMethod(typeName)
|
||||||
|
}
|
||||||
|
|
||||||
|
g.buildNoOpOrderChangeDetect(runs, typeName)
|
||||||
|
|
||||||
g.buildBasicExtras(runs, typeName, runsThreshold)
|
g.buildBasicExtras(runs, typeName, runsThreshold)
|
||||||
if includeJSON {
|
if includeJSON {
|
||||||
|
@ -457,6 +481,9 @@ func (g *Generator) generate(typeName string, includeJSON, includeYAML, includeS
|
||||||
if includeSQL {
|
if includeSQL {
|
||||||
g.addValueAndScanMethod(typeName)
|
g.addValueAndScanMethod(typeName)
|
||||||
}
|
}
|
||||||
|
if includeGQLGen {
|
||||||
|
g.buildGQLGenMethods(runs, typeName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// splitIntoRuns breaks the values into runs of contiguous sequences.
|
// splitIntoRuns breaks the values into runs of contiguous sequences.
|
||||||
|
@ -506,7 +533,8 @@ func (g *Generator) format() []byte {
|
||||||
|
|
||||||
// Value represents a declared constant.
|
// Value represents a declared constant.
|
||||||
type Value struct {
|
type Value struct {
|
||||||
name string // The name of the constant after transformation (i.e. camel case => snake case)
|
originalName string // The name of the constant before transformation
|
||||||
|
name string // The name of the constant after transformation (i.e. camel case => snake case)
|
||||||
// The value is stored as a bit pattern alone. The boolean tells us
|
// The value is stored as a bit pattern alone. The boolean tells us
|
||||||
// whether to interpret it as an int64 or a uint64; the only place
|
// whether to interpret it as an int64 or a uint64; the only place
|
||||||
// this matters is when sorting.
|
// this matters is when sorting.
|
||||||
|
@ -600,10 +628,11 @@ func (f *File) genDecl(node ast.Node) bool {
|
||||||
u64 = uint64(i64)
|
u64 = uint64(i64)
|
||||||
}
|
}
|
||||||
v := Value{
|
v := Value{
|
||||||
name: n.Name,
|
originalName: n.Name,
|
||||||
value: u64,
|
name: n.Name,
|
||||||
signed: info&types.IsUnsigned == 0,
|
value: u64,
|
||||||
str: value.String(),
|
signed: info&types.IsUnsigned == 0,
|
||||||
|
str: value.String(),
|
||||||
}
|
}
|
||||||
if c := vspec.Comment; f.lineComment && c != nil && len(c.List) == 1 {
|
if c := vspec.Comment; f.lineComment && c != nil && len(c.List) == 1 {
|
||||||
v.name = strings.TrimSpace(c.Text())
|
v.name = strings.TrimSpace(c.Text())
|
||||||
|
@ -640,6 +669,8 @@ func (g *Generator) declareIndexAndNameVars(runs [][]Value, typeName string) {
|
||||||
index, n := g.createIndexAndNameDecl(run, typeName, fmt.Sprintf("_%d", i))
|
index, n := g.createIndexAndNameDecl(run, typeName, fmt.Sprintf("_%d", i))
|
||||||
indexes = append(indexes, index)
|
indexes = append(indexes, index)
|
||||||
names = append(names, n)
|
names = append(names, n)
|
||||||
|
_, n = g.createLowerIndexAndNameDecl(run, typeName, fmt.Sprintf("_%d", i))
|
||||||
|
names = append(names, n)
|
||||||
}
|
}
|
||||||
g.Printf("const (\n")
|
g.Printf("const (\n")
|
||||||
for _, n := range names {
|
for _, n := range names {
|
||||||
|
@ -658,6 +689,31 @@ func (g *Generator) declareIndexAndNameVar(run []Value, typeName string) {
|
||||||
index, n := g.createIndexAndNameDecl(run, typeName, "")
|
index, n := g.createIndexAndNameDecl(run, typeName, "")
|
||||||
g.Printf("const %s\n", n)
|
g.Printf("const %s\n", n)
|
||||||
g.Printf("var %s\n", index)
|
g.Printf("var %s\n", index)
|
||||||
|
index, n = g.createLowerIndexAndNameDecl(run, typeName, "")
|
||||||
|
g.Printf("const %s\n", n)
|
||||||
|
//g.Printf("var %s\n", index)
|
||||||
|
}
|
||||||
|
|
||||||
|
// createIndexAndNameDecl returns the pair of declarations for the run. The caller will add "const" and "var".
|
||||||
|
func (g *Generator) createLowerIndexAndNameDecl(run []Value, typeName string, suffix string) (string, string) {
|
||||||
|
b := new(bytes.Buffer)
|
||||||
|
indexes := make([]int, len(run))
|
||||||
|
for i := range run {
|
||||||
|
b.WriteString(strings.ToLower(run[i].name))
|
||||||
|
indexes[i] = b.Len()
|
||||||
|
}
|
||||||
|
nameConst := fmt.Sprintf("_%sLowerName%s = %q", typeName, suffix, b.String())
|
||||||
|
nameLen := b.Len()
|
||||||
|
b.Reset()
|
||||||
|
_, _ = fmt.Fprintf(b, "_%sLowerIndex%s = [...]uint%d{0, ", typeName, suffix, usize(nameLen))
|
||||||
|
for i, v := range indexes {
|
||||||
|
if i > 0 {
|
||||||
|
_, _ = fmt.Fprintf(b, ", ")
|
||||||
|
}
|
||||||
|
_, _ = fmt.Fprintf(b, "%d", v)
|
||||||
|
}
|
||||||
|
_, _ = fmt.Fprintf(b, "}")
|
||||||
|
return b.String(), nameConst
|
||||||
}
|
}
|
||||||
|
|
||||||
// createIndexAndNameDecl returns the pair of declarations for the run. The caller will add "const" and "var".
|
// createIndexAndNameDecl returns the pair of declarations for the run. The caller will add "const" and "var".
|
||||||
|
@ -691,6 +747,13 @@ func (g *Generator) declareNameVars(runs [][]Value, typeName string, suffix stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.Printf("\"\n")
|
g.Printf("\"\n")
|
||||||
|
g.Printf("const _%sLowerName%s = \"", typeName, suffix)
|
||||||
|
for _, run := range runs {
|
||||||
|
for i := range run {
|
||||||
|
g.Printf("%s", strings.ToLower(run[i].name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g.Printf("\"\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildOneRun generates the variables and String method for a single run of contiguous values.
|
// buildOneRun generates the variables and String method for a single run of contiguous values.
|
||||||
|
@ -727,8 +790,6 @@ const stringOneRun = `func (i %[1]s) String() string {
|
||||||
// [2]: lowest defined value for type, as a string
|
// [2]: lowest defined value for type, as a string
|
||||||
// [3]: size of index element (8 for uint8 etc.)
|
// [3]: size of index element (8 for uint8 etc.)
|
||||||
// [4]: less than zero check (for signed types)
|
// [4]: less than zero check (for signed types)
|
||||||
/*
|
|
||||||
*/
|
|
||||||
const stringOneRunWithOffset = `func (i %[1]s) String() string {
|
const stringOneRunWithOffset = `func (i %[1]s) String() string {
|
||||||
i -= %[2]s
|
i -= %[2]s
|
||||||
if %[4]si >= %[1]s(len(_%[1]sIndex)-1) {
|
if %[4]si >= %[1]s(len(_%[1]sIndex)-1) {
|
||||||
|
@ -781,6 +842,24 @@ func (g *Generator) buildMap(runs [][]Value, typeName string) {
|
||||||
g.Printf(stringMap, typeName)
|
g.Printf(stringMap, typeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buildNoOpOrderChangeDetect try to let the compiler and the user know if the order/value of the ENUMS have changed.
|
||||||
|
func (g *Generator) buildNoOpOrderChangeDetect(runs [][]Value, typeName string) {
|
||||||
|
g.Printf("\n")
|
||||||
|
|
||||||
|
g.Printf(`
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
`)
|
||||||
|
g.Printf("func _%sNoOp (){ ", typeName)
|
||||||
|
g.Printf("\n var x [1]struct{}\n")
|
||||||
|
for _, values := range runs {
|
||||||
|
for _, value := range values {
|
||||||
|
g.Printf("\t_ = x[%s-(%s)]\n", value.originalName, value.str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g.Printf("}\n\n")
|
||||||
|
}
|
||||||
|
|
||||||
// Argument to format is the type name.
|
// Argument to format is the type name.
|
||||||
const stringMap = `func (i %[1]s) String() string {
|
const stringMap = `func (i %[1]s) String() string {
|
||||||
if str, ok := _%[1]sMap[i]; ok {
|
if str, ok := _%[1]sMap[i]; ok {
|
||||||
|
|
|
@ -30,6 +30,9 @@ func main() {
|
||||||
ck(Sunday, "Sunday")
|
ck(Sunday, "Sunday")
|
||||||
ck(-127, "Day(-127)")
|
ck(-127, "Day(-127)")
|
||||||
ck(127, "Day(127)")
|
ck(127, "Day(127)")
|
||||||
|
ckDayString(Sunday, "Sunday")
|
||||||
|
ckDayString(Sunday, "sunday")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ck(day Day, str string) {
|
func ck(day Day, str string) {
|
||||||
|
@ -37,3 +40,14 @@ func ck(day Day, str string) {
|
||||||
panic("day.go: " + str)
|
panic("day.go: " + str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ckDayString(day Day, str string) {
|
||||||
|
d, err := DayString(str)
|
||||||
|
if err != nil {
|
||||||
|
panic("day.go: " + err.Error())
|
||||||
|
}
|
||||||
|
if d != day {
|
||||||
|
panic("day.go: " + str)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
|
||||||
|
const _DayName = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"
|
||||||
|
|
||||||
|
var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50}
|
||||||
|
|
||||||
|
const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday"
|
||||||
|
|
||||||
|
func (i Day) String() string {
|
||||||
|
if i < 0 || i >= Day(len(_DayIndex)-1) {
|
||||||
|
return fmt.Sprintf("Day(%d)", i)
|
||||||
|
}
|
||||||
|
return _DayName[_DayIndex[i]:_DayIndex[i+1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Day) Values() []string {
|
||||||
|
return DayStrings()
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _DayNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[Monday-(0)]
|
||||||
|
_ = x[Tuesday-(1)]
|
||||||
|
_ = x[Wednesday-(2)]
|
||||||
|
_ = x[Thursday-(3)]
|
||||||
|
_ = x[Friday-(4)]
|
||||||
|
_ = x[Saturday-(5)]
|
||||||
|
_ = x[Sunday-(6)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}
|
||||||
|
|
||||||
|
var _DayNameToValueMap = map[string]Day{
|
||||||
|
_DayName[0:6]: Monday,
|
||||||
|
_DayLowerName[0:6]: Monday,
|
||||||
|
_DayName[6:13]: Tuesday,
|
||||||
|
_DayLowerName[6:13]: Tuesday,
|
||||||
|
_DayName[13:22]: Wednesday,
|
||||||
|
_DayLowerName[13:22]: Wednesday,
|
||||||
|
_DayName[22:30]: Thursday,
|
||||||
|
_DayLowerName[22:30]: Thursday,
|
||||||
|
_DayName[30:36]: Friday,
|
||||||
|
_DayLowerName[30:36]: Friday,
|
||||||
|
_DayName[36:44]: Saturday,
|
||||||
|
_DayLowerName[36:44]: Saturday,
|
||||||
|
_DayName[44:50]: Sunday,
|
||||||
|
_DayLowerName[44:50]: Sunday,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DayNames = []string{
|
||||||
|
_DayName[0:6],
|
||||||
|
_DayName[6:13],
|
||||||
|
_DayName[13:22],
|
||||||
|
_DayName[22:30],
|
||||||
|
_DayName[30:36],
|
||||||
|
_DayName[36:44],
|
||||||
|
_DayName[44:50],
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func DayString(s string) (Day, error) {
|
||||||
|
if val, ok := _DayNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Day values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayValues returns all values of the enum
|
||||||
|
func DayValues() []Day {
|
||||||
|
return _DayValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayStrings returns a slice of all String values of the enum
|
||||||
|
func DayStrings() []string {
|
||||||
|
strs := make([]string, len(_DayNames))
|
||||||
|
copy(strs, _DayNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Day) IsADay() bool {
|
||||||
|
for _, v := range _DayValues {
|
||||||
|
if i == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
|
||||||
|
const _DayName = "NightMondayNightTuesdayNightWednesdayNightThursdayNightFridayNightSaturdayNightSunday"
|
||||||
|
|
||||||
|
var _DayIndex = [...]uint8{0, 11, 23, 37, 50, 61, 74, 85}
|
||||||
|
|
||||||
|
const _DayLowerName = "nightmondaynighttuesdaynightwednesdaynightthursdaynightfridaynightsaturdaynightsunday"
|
||||||
|
|
||||||
|
func (i Day) String() string {
|
||||||
|
if i < 0 || i >= Day(len(_DayIndex)-1) {
|
||||||
|
return fmt.Sprintf("Day(%d)", i)
|
||||||
|
}
|
||||||
|
return _DayName[_DayIndex[i]:_DayIndex[i+1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _DayNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[DayMonday-(0)]
|
||||||
|
_ = x[DayTuesday-(1)]
|
||||||
|
_ = x[DayWednesday-(2)]
|
||||||
|
_ = x[DayThursday-(3)]
|
||||||
|
_ = x[DayFriday-(4)]
|
||||||
|
_ = x[DaySaturday-(5)]
|
||||||
|
_ = x[DaySunday-(6)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DayValues = []Day{DayMonday, DayTuesday, DayWednesday, DayThursday, DayFriday, DaySaturday, DaySunday}
|
||||||
|
|
||||||
|
var _DayNameToValueMap = map[string]Day{
|
||||||
|
_DayName[0:11]: DayMonday,
|
||||||
|
_DayLowerName[0:11]: DayMonday,
|
||||||
|
_DayName[11:23]: DayTuesday,
|
||||||
|
_DayLowerName[11:23]: DayTuesday,
|
||||||
|
_DayName[23:37]: DayWednesday,
|
||||||
|
_DayLowerName[23:37]: DayWednesday,
|
||||||
|
_DayName[37:50]: DayThursday,
|
||||||
|
_DayLowerName[37:50]: DayThursday,
|
||||||
|
_DayName[50:61]: DayFriday,
|
||||||
|
_DayLowerName[50:61]: DayFriday,
|
||||||
|
_DayName[61:74]: DaySaturday,
|
||||||
|
_DayLowerName[61:74]: DaySaturday,
|
||||||
|
_DayName[74:85]: DaySunday,
|
||||||
|
_DayLowerName[74:85]: DaySunday,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DayNames = []string{
|
||||||
|
_DayName[0:11],
|
||||||
|
_DayName[11:23],
|
||||||
|
_DayName[23:37],
|
||||||
|
_DayName[37:50],
|
||||||
|
_DayName[50:61],
|
||||||
|
_DayName[61:74],
|
||||||
|
_DayName[74:85],
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func DayString(s string) (Day, error) {
|
||||||
|
if val, ok := _DayNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Day values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayValues returns all values of the enum
|
||||||
|
func DayValues() []Day {
|
||||||
|
return _DayValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayStrings returns a slice of all String values of the enum
|
||||||
|
func DayStrings() []string {
|
||||||
|
strs := make([]string, len(_DayNames))
|
||||||
|
copy(strs, _DayNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Day) IsADay() bool {
|
||||||
|
for _, v := range _DayValues {
|
||||||
|
if i == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
|
||||||
|
const _DayName = "lunesTuesdayWednesdayThursdayviernesSaturdaySunday"
|
||||||
|
|
||||||
|
var _DayIndex = [...]uint8{0, 5, 12, 21, 29, 36, 44, 50}
|
||||||
|
|
||||||
|
const _DayLowerName = "lunestuesdaywednesdaythursdayviernessaturdaysunday"
|
||||||
|
|
||||||
|
func (i Day) String() string {
|
||||||
|
if i < 0 || i >= Day(len(_DayIndex)-1) {
|
||||||
|
return fmt.Sprintf("Day(%d)", i)
|
||||||
|
}
|
||||||
|
return _DayName[_DayIndex[i]:_DayIndex[i+1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _DayNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[Monday-(0)]
|
||||||
|
_ = x[Tuesday-(1)]
|
||||||
|
_ = x[Wednesday-(2)]
|
||||||
|
_ = x[Thursday-(3)]
|
||||||
|
_ = x[Friday-(4)]
|
||||||
|
_ = x[Saturday-(5)]
|
||||||
|
_ = x[Sunday-(6)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}
|
||||||
|
|
||||||
|
var _DayNameToValueMap = map[string]Day{
|
||||||
|
_DayName[0:5]: Monday,
|
||||||
|
_DayLowerName[0:5]: Monday,
|
||||||
|
_DayName[5:12]: Tuesday,
|
||||||
|
_DayLowerName[5:12]: Tuesday,
|
||||||
|
_DayName[12:21]: Wednesday,
|
||||||
|
_DayLowerName[12:21]: Wednesday,
|
||||||
|
_DayName[21:29]: Thursday,
|
||||||
|
_DayLowerName[21:29]: Thursday,
|
||||||
|
_DayName[29:36]: Friday,
|
||||||
|
_DayLowerName[29:36]: Friday,
|
||||||
|
_DayName[36:44]: Saturday,
|
||||||
|
_DayLowerName[36:44]: Saturday,
|
||||||
|
_DayName[44:50]: Sunday,
|
||||||
|
_DayLowerName[44:50]: Sunday,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DayNames = []string{
|
||||||
|
_DayName[0:5],
|
||||||
|
_DayName[5:12],
|
||||||
|
_DayName[12:21],
|
||||||
|
_DayName[21:29],
|
||||||
|
_DayName[29:36],
|
||||||
|
_DayName[36:44],
|
||||||
|
_DayName[44:50],
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func DayString(s string) (Day, error) {
|
||||||
|
if val, ok := _DayNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Day values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayValues returns all values of the enum
|
||||||
|
func DayValues() []Day {
|
||||||
|
return _DayValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayStrings returns a slice of all String values of the enum
|
||||||
|
func DayStrings() []string {
|
||||||
|
strs := make([]string, len(_DayNames))
|
||||||
|
copy(strs, _DayNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Day) IsADay() bool {
|
||||||
|
for _, v := range _DayValues {
|
||||||
|
if i == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
|
||||||
|
const _DayName = "DayMondayDayTuesdayDayWednesdayDayThursdayDayFridayDaySaturdayDaySunday"
|
||||||
|
|
||||||
|
var _DayIndex = [...]uint8{0, 9, 19, 31, 42, 51, 62, 71}
|
||||||
|
|
||||||
|
const _DayLowerName = "daymondaydaytuesdaydaywednesdaydaythursdaydayfridaydaysaturdaydaysunday"
|
||||||
|
|
||||||
|
func (i Day) String() string {
|
||||||
|
if i < 0 || i >= Day(len(_DayIndex)-1) {
|
||||||
|
return fmt.Sprintf("Day(%d)", i)
|
||||||
|
}
|
||||||
|
return _DayName[_DayIndex[i]:_DayIndex[i+1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _DayNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[Monday-(0)]
|
||||||
|
_ = x[Tuesday-(1)]
|
||||||
|
_ = x[Wednesday-(2)]
|
||||||
|
_ = x[Thursday-(3)]
|
||||||
|
_ = x[Friday-(4)]
|
||||||
|
_ = x[Saturday-(5)]
|
||||||
|
_ = x[Sunday-(6)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DayValues = []Day{Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}
|
||||||
|
|
||||||
|
var _DayNameToValueMap = map[string]Day{
|
||||||
|
_DayName[0:9]: Monday,
|
||||||
|
_DayLowerName[0:9]: Monday,
|
||||||
|
_DayName[9:19]: Tuesday,
|
||||||
|
_DayLowerName[9:19]: Tuesday,
|
||||||
|
_DayName[19:31]: Wednesday,
|
||||||
|
_DayLowerName[19:31]: Wednesday,
|
||||||
|
_DayName[31:42]: Thursday,
|
||||||
|
_DayLowerName[31:42]: Thursday,
|
||||||
|
_DayName[42:51]: Friday,
|
||||||
|
_DayLowerName[42:51]: Friday,
|
||||||
|
_DayName[51:62]: Saturday,
|
||||||
|
_DayLowerName[51:62]: Saturday,
|
||||||
|
_DayName[62:71]: Sunday,
|
||||||
|
_DayLowerName[62:71]: Sunday,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DayNames = []string{
|
||||||
|
_DayName[0:9],
|
||||||
|
_DayName[9:19],
|
||||||
|
_DayName[19:31],
|
||||||
|
_DayName[31:42],
|
||||||
|
_DayName[42:51],
|
||||||
|
_DayName[51:62],
|
||||||
|
_DayName[62:71],
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func DayString(s string) (Day, error) {
|
||||||
|
if val, ok := _DayNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Day values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayValues returns all values of the enum
|
||||||
|
func DayValues() []Day {
|
||||||
|
return _DayValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayStrings returns a slice of all String values of the enum
|
||||||
|
func DayStrings() []string {
|
||||||
|
strs := make([]string, len(_DayNames))
|
||||||
|
copy(strs, _DayNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Day) IsADay() bool {
|
||||||
|
for _, v := range _DayValues {
|
||||||
|
if i == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -0,0 +1,115 @@
|
||||||
|
|
||||||
|
const (
|
||||||
|
_GapName_0 = "TwoThree"
|
||||||
|
_GapLowerName_0 = "twothree"
|
||||||
|
_GapName_1 = "FiveSixSevenEightNine"
|
||||||
|
_GapLowerName_1 = "fivesixseveneightnine"
|
||||||
|
_GapName_2 = "Eleven"
|
||||||
|
_GapLowerName_2 = "eleven"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_GapIndex_0 = [...]uint8{0, 3, 8}
|
||||||
|
_GapIndex_1 = [...]uint8{0, 4, 7, 12, 17, 21}
|
||||||
|
_GapIndex_2 = [...]uint8{0, 6}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i Gap) String() string {
|
||||||
|
switch {
|
||||||
|
case 2 <= i && i <= 3:
|
||||||
|
i -= 2
|
||||||
|
return _GapName_0[_GapIndex_0[i]:_GapIndex_0[i+1]]
|
||||||
|
case 5 <= i && i <= 9:
|
||||||
|
i -= 5
|
||||||
|
return _GapName_1[_GapIndex_1[i]:_GapIndex_1[i+1]]
|
||||||
|
case i == 11:
|
||||||
|
return _GapName_2
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("Gap(%d)", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Gap) Values() []string {
|
||||||
|
return GapStrings()
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _GapNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[Two-(2)]
|
||||||
|
_ = x[Three-(3)]
|
||||||
|
_ = x[Five-(5)]
|
||||||
|
_ = x[Six-(6)]
|
||||||
|
_ = x[Seven-(7)]
|
||||||
|
_ = x[Eight-(8)]
|
||||||
|
_ = x[Nine-(9)]
|
||||||
|
_ = x[Eleven-(11)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _GapValues = []Gap{Two, Three, Five, Six, Seven, Eight, Nine, Eleven}
|
||||||
|
|
||||||
|
var _GapNameToValueMap = map[string]Gap{
|
||||||
|
_GapName_0[0:3]: Two,
|
||||||
|
_GapLowerName_0[0:3]: Two,
|
||||||
|
_GapName_0[3:8]: Three,
|
||||||
|
_GapLowerName_0[3:8]: Three,
|
||||||
|
_GapName_1[0:4]: Five,
|
||||||
|
_GapLowerName_1[0:4]: Five,
|
||||||
|
_GapName_1[4:7]: Six,
|
||||||
|
_GapLowerName_1[4:7]: Six,
|
||||||
|
_GapName_1[7:12]: Seven,
|
||||||
|
_GapLowerName_1[7:12]: Seven,
|
||||||
|
_GapName_1[12:17]: Eight,
|
||||||
|
_GapLowerName_1[12:17]: Eight,
|
||||||
|
_GapName_1[17:21]: Nine,
|
||||||
|
_GapLowerName_1[17:21]: Nine,
|
||||||
|
_GapName_2[0:6]: Eleven,
|
||||||
|
_GapLowerName_2[0:6]: Eleven,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _GapNames = []string{
|
||||||
|
_GapName_0[0:3],
|
||||||
|
_GapName_0[3:8],
|
||||||
|
_GapName_1[0:4],
|
||||||
|
_GapName_1[4:7],
|
||||||
|
_GapName_1[7:12],
|
||||||
|
_GapName_1[12:17],
|
||||||
|
_GapName_1[17:21],
|
||||||
|
_GapName_2[0:6],
|
||||||
|
}
|
||||||
|
|
||||||
|
// GapString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func GapString(s string) (Gap, error) {
|
||||||
|
if val, ok := _GapNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _GapNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Gap values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GapValues returns all values of the enum
|
||||||
|
func GapValues() []Gap {
|
||||||
|
return _GapValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// GapStrings returns a slice of all String values of the enum
|
||||||
|
func GapStrings() []string {
|
||||||
|
strs := make([]string, len(_GapNames))
|
||||||
|
copy(strs, _GapNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAGap returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Gap) IsAGap() bool {
|
||||||
|
for _, v := range _GapValues {
|
||||||
|
if i == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
|
||||||
|
const _NumName = "m_2m_1m0m1m2"
|
||||||
|
|
||||||
|
var _NumIndex = [...]uint8{0, 3, 6, 8, 10, 12}
|
||||||
|
|
||||||
|
const _NumLowerName = "m_2m_1m0m1m2"
|
||||||
|
|
||||||
|
func (i Num) String() string {
|
||||||
|
i -= -2
|
||||||
|
if i < 0 || i >= Num(len(_NumIndex)-1) {
|
||||||
|
return fmt.Sprintf("Num(%d)", i+-2)
|
||||||
|
}
|
||||||
|
return _NumName[_NumIndex[i]:_NumIndex[i+1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Num) Values() []string {
|
||||||
|
return NumStrings()
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _NumNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[m_2-(-2)]
|
||||||
|
_ = x[m_1-(-1)]
|
||||||
|
_ = x[m0-(0)]
|
||||||
|
_ = x[m1-(1)]
|
||||||
|
_ = x[m2-(2)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _NumValues = []Num{m_2, m_1, m0, m1, m2}
|
||||||
|
|
||||||
|
var _NumNameToValueMap = map[string]Num{
|
||||||
|
_NumName[0:3]: m_2,
|
||||||
|
_NumLowerName[0:3]: m_2,
|
||||||
|
_NumName[3:6]: m_1,
|
||||||
|
_NumLowerName[3:6]: m_1,
|
||||||
|
_NumName[6:8]: m0,
|
||||||
|
_NumLowerName[6:8]: m0,
|
||||||
|
_NumName[8:10]: m1,
|
||||||
|
_NumLowerName[8:10]: m1,
|
||||||
|
_NumName[10:12]: m2,
|
||||||
|
_NumLowerName[10:12]: m2,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _NumNames = []string{
|
||||||
|
_NumName[0:3],
|
||||||
|
_NumName[3:6],
|
||||||
|
_NumName[6:8],
|
||||||
|
_NumName[8:10],
|
||||||
|
_NumName[10:12],
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func NumString(s string) (Num, error) {
|
||||||
|
if val, ok := _NumNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _NumNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Num values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumValues returns all values of the enum
|
||||||
|
func NumValues() []Num {
|
||||||
|
return _NumValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumStrings returns a slice of all String values of the enum
|
||||||
|
func NumStrings() []string {
|
||||||
|
strs := make([]string, len(_NumNames))
|
||||||
|
copy(strs, _NumNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsANum returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Num) IsANum() bool {
|
||||||
|
for _, v := range _NumValues {
|
||||||
|
if i == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
|
||||||
|
const _NumberName = "OneTwoThree"
|
||||||
|
|
||||||
|
var _NumberIndex = [...]uint8{0, 3, 6, 11}
|
||||||
|
|
||||||
|
const _NumberLowerName = "onetwothree"
|
||||||
|
|
||||||
|
func (i Number) String() string {
|
||||||
|
i -= 1
|
||||||
|
if i < 0 || i >= Number(len(_NumberIndex)-1) {
|
||||||
|
return fmt.Sprintf("Number(%d)", i+1)
|
||||||
|
}
|
||||||
|
return _NumberName[_NumberIndex[i]:_NumberIndex[i+1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Number) Values() []string {
|
||||||
|
return NumberStrings()
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _NumberNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[One-(1)]
|
||||||
|
_ = x[Two-(2)]
|
||||||
|
_ = x[Three-(3)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _NumberValues = []Number{One, Two, Three}
|
||||||
|
|
||||||
|
var _NumberNameToValueMap = map[string]Number{
|
||||||
|
_NumberName[0:3]: One,
|
||||||
|
_NumberLowerName[0:3]: One,
|
||||||
|
_NumberName[3:6]: Two,
|
||||||
|
_NumberLowerName[3:6]: Two,
|
||||||
|
_NumberName[6:11]: Three,
|
||||||
|
_NumberLowerName[6:11]: Three,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _NumberNames = []string{
|
||||||
|
_NumberName[0:3],
|
||||||
|
_NumberName[3:6],
|
||||||
|
_NumberName[6:11],
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumberString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func NumberString(s string) (Number, error) {
|
||||||
|
if val, ok := _NumberNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _NumberNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Number values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumberValues returns all values of the enum
|
||||||
|
func NumberValues() []Number {
|
||||||
|
return _NumberValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// NumberStrings returns a slice of all String values of the enum
|
||||||
|
func NumberStrings() []string {
|
||||||
|
strs := make([]string, len(_NumberNames))
|
||||||
|
copy(strs, _NumberNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsANumber returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Number) IsANumber() bool {
|
||||||
|
for _, v := range _NumberValues {
|
||||||
|
if i == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -0,0 +1,127 @@
|
||||||
|
|
||||||
|
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
|
||||||
|
var _PrimeMap = map[Prime]string{
|
||||||
|
2: _PrimeName[0:2],
|
||||||
|
3: _PrimeName[2:4],
|
||||||
|
5: _PrimeName[4:6],
|
||||||
|
7: _PrimeName[6:8],
|
||||||
|
11: _PrimeName[8:11],
|
||||||
|
13: _PrimeName[11:14],
|
||||||
|
17: _PrimeName[14:17],
|
||||||
|
19: _PrimeName[17:20],
|
||||||
|
23: _PrimeName[20:23],
|
||||||
|
29: _PrimeName[23:26],
|
||||||
|
31: _PrimeName[26:29],
|
||||||
|
41: _PrimeName[29:32],
|
||||||
|
43: _PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Prime) String() string {
|
||||||
|
if str, ok := _PrimeMap[i]; ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("Prime(%d)", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Prime) Values() []string {
|
||||||
|
return PrimeStrings()
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _PrimeNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[p2-(2)]
|
||||||
|
_ = x[p3-(3)]
|
||||||
|
_ = x[p5-(5)]
|
||||||
|
_ = x[p7-(7)]
|
||||||
|
_ = x[p11-(11)]
|
||||||
|
_ = x[p13-(13)]
|
||||||
|
_ = x[p17-(17)]
|
||||||
|
_ = x[p19-(19)]
|
||||||
|
_ = x[p23-(23)]
|
||||||
|
_ = x[p29-(29)]
|
||||||
|
_ = x[p37-(31)]
|
||||||
|
_ = x[p41-(41)]
|
||||||
|
_ = x[p43-(43)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43}
|
||||||
|
|
||||||
|
var _PrimeNameToValueMap = map[string]Prime{
|
||||||
|
_PrimeName[0:2]: p2,
|
||||||
|
_PrimeLowerName[0:2]: p2,
|
||||||
|
_PrimeName[2:4]: p3,
|
||||||
|
_PrimeLowerName[2:4]: p3,
|
||||||
|
_PrimeName[4:6]: p5,
|
||||||
|
_PrimeLowerName[4:6]: p5,
|
||||||
|
_PrimeName[6:8]: p7,
|
||||||
|
_PrimeLowerName[6:8]: p7,
|
||||||
|
_PrimeName[8:11]: p11,
|
||||||
|
_PrimeLowerName[8:11]: p11,
|
||||||
|
_PrimeName[11:14]: p13,
|
||||||
|
_PrimeLowerName[11:14]: p13,
|
||||||
|
_PrimeName[14:17]: p17,
|
||||||
|
_PrimeLowerName[14:17]: p17,
|
||||||
|
_PrimeName[17:20]: p19,
|
||||||
|
_PrimeLowerName[17:20]: p19,
|
||||||
|
_PrimeName[20:23]: p23,
|
||||||
|
_PrimeLowerName[20:23]: p23,
|
||||||
|
_PrimeName[23:26]: p29,
|
||||||
|
_PrimeLowerName[23:26]: p29,
|
||||||
|
_PrimeName[26:29]: p37,
|
||||||
|
_PrimeLowerName[26:29]: p37,
|
||||||
|
_PrimeName[29:32]: p41,
|
||||||
|
_PrimeLowerName[29:32]: p41,
|
||||||
|
_PrimeName[32:35]: p43,
|
||||||
|
_PrimeLowerName[32:35]: p43,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeNames = []string{
|
||||||
|
_PrimeName[0:2],
|
||||||
|
_PrimeName[2:4],
|
||||||
|
_PrimeName[4:6],
|
||||||
|
_PrimeName[6:8],
|
||||||
|
_PrimeName[8:11],
|
||||||
|
_PrimeName[11:14],
|
||||||
|
_PrimeName[14:17],
|
||||||
|
_PrimeName[17:20],
|
||||||
|
_PrimeName[20:23],
|
||||||
|
_PrimeName[23:26],
|
||||||
|
_PrimeName[26:29],
|
||||||
|
_PrimeName[29:32],
|
||||||
|
_PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func PrimeString(s string) (Prime, error) {
|
||||||
|
if val, ok := _PrimeNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeValues returns all values of the enum
|
||||||
|
func PrimeValues() []Prime {
|
||||||
|
return _PrimeValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeStrings returns a slice of all String values of the enum
|
||||||
|
func PrimeStrings() []string {
|
||||||
|
strs := make([]string, len(_PrimeNames))
|
||||||
|
copy(strs, _PrimeNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Prime) IsAPrime() bool {
|
||||||
|
_, ok := _PrimeMap[i]
|
||||||
|
return ok
|
||||||
|
}
|
|
@ -0,0 +1,140 @@
|
||||||
|
|
||||||
|
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
|
||||||
|
var _PrimeMap = map[Prime]string{
|
||||||
|
2: _PrimeName[0:2],
|
||||||
|
3: _PrimeName[2:4],
|
||||||
|
5: _PrimeName[4:6],
|
||||||
|
7: _PrimeName[6:8],
|
||||||
|
11: _PrimeName[8:11],
|
||||||
|
13: _PrimeName[11:14],
|
||||||
|
17: _PrimeName[14:17],
|
||||||
|
19: _PrimeName[17:20],
|
||||||
|
23: _PrimeName[20:23],
|
||||||
|
29: _PrimeName[23:26],
|
||||||
|
31: _PrimeName[26:29],
|
||||||
|
41: _PrimeName[29:32],
|
||||||
|
43: _PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Prime) String() string {
|
||||||
|
if str, ok := _PrimeMap[i]; ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("Prime(%d)", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _PrimeNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[p2-(2)]
|
||||||
|
_ = x[p3-(3)]
|
||||||
|
_ = x[p5-(5)]
|
||||||
|
_ = x[p7-(7)]
|
||||||
|
_ = x[p11-(11)]
|
||||||
|
_ = x[p13-(13)]
|
||||||
|
_ = x[p17-(17)]
|
||||||
|
_ = x[p19-(19)]
|
||||||
|
_ = x[p23-(23)]
|
||||||
|
_ = x[p29-(29)]
|
||||||
|
_ = x[p37-(31)]
|
||||||
|
_ = x[p41-(41)]
|
||||||
|
_ = x[p43-(43)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43}
|
||||||
|
|
||||||
|
var _PrimeNameToValueMap = map[string]Prime{
|
||||||
|
_PrimeName[0:2]: p2,
|
||||||
|
_PrimeLowerName[0:2]: p2,
|
||||||
|
_PrimeName[2:4]: p3,
|
||||||
|
_PrimeLowerName[2:4]: p3,
|
||||||
|
_PrimeName[4:6]: p5,
|
||||||
|
_PrimeLowerName[4:6]: p5,
|
||||||
|
_PrimeName[6:8]: p7,
|
||||||
|
_PrimeLowerName[6:8]: p7,
|
||||||
|
_PrimeName[8:11]: p11,
|
||||||
|
_PrimeLowerName[8:11]: p11,
|
||||||
|
_PrimeName[11:14]: p13,
|
||||||
|
_PrimeLowerName[11:14]: p13,
|
||||||
|
_PrimeName[14:17]: p17,
|
||||||
|
_PrimeLowerName[14:17]: p17,
|
||||||
|
_PrimeName[17:20]: p19,
|
||||||
|
_PrimeLowerName[17:20]: p19,
|
||||||
|
_PrimeName[20:23]: p23,
|
||||||
|
_PrimeLowerName[20:23]: p23,
|
||||||
|
_PrimeName[23:26]: p29,
|
||||||
|
_PrimeLowerName[23:26]: p29,
|
||||||
|
_PrimeName[26:29]: p37,
|
||||||
|
_PrimeLowerName[26:29]: p37,
|
||||||
|
_PrimeName[29:32]: p41,
|
||||||
|
_PrimeLowerName[29:32]: p41,
|
||||||
|
_PrimeName[32:35]: p43,
|
||||||
|
_PrimeLowerName[32:35]: p43,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeNames = []string{
|
||||||
|
_PrimeName[0:2],
|
||||||
|
_PrimeName[2:4],
|
||||||
|
_PrimeName[4:6],
|
||||||
|
_PrimeName[6:8],
|
||||||
|
_PrimeName[8:11],
|
||||||
|
_PrimeName[11:14],
|
||||||
|
_PrimeName[14:17],
|
||||||
|
_PrimeName[17:20],
|
||||||
|
_PrimeName[20:23],
|
||||||
|
_PrimeName[23:26],
|
||||||
|
_PrimeName[26:29],
|
||||||
|
_PrimeName[29:32],
|
||||||
|
_PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func PrimeString(s string) (Prime, error) {
|
||||||
|
if val, ok := _PrimeNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeValues returns all values of the enum
|
||||||
|
func PrimeValues() []Prime {
|
||||||
|
return _PrimeValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeStrings returns a slice of all String values of the enum
|
||||||
|
func PrimeStrings() []string {
|
||||||
|
strs := make([]string, len(_PrimeNames))
|
||||||
|
copy(strs, _PrimeNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Prime) IsAPrime() bool {
|
||||||
|
_, ok := _PrimeMap[i]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalGQL implements the graphql.Marshaler interface for Prime
|
||||||
|
func (i Prime) MarshalGQL(w io.Writer) {
|
||||||
|
fmt.Fprint(w, strconv.Quote(i.String()))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalGQL implements the graphql.Unmarshaler interface for Prime
|
||||||
|
func (i *Prime) UnmarshalGQL(value interface{}) error {
|
||||||
|
str, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Prime should be a string, got %T", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
*i, err = PrimeString(str)
|
||||||
|
return err
|
||||||
|
}
|
|
@ -0,0 +1,140 @@
|
||||||
|
|
||||||
|
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
|
||||||
|
var _PrimeMap = map[Prime]string{
|
||||||
|
2: _PrimeName[0:2],
|
||||||
|
3: _PrimeName[2:4],
|
||||||
|
5: _PrimeName[4:6],
|
||||||
|
7: _PrimeName[6:8],
|
||||||
|
11: _PrimeName[8:11],
|
||||||
|
13: _PrimeName[11:14],
|
||||||
|
17: _PrimeName[14:17],
|
||||||
|
19: _PrimeName[17:20],
|
||||||
|
23: _PrimeName[20:23],
|
||||||
|
29: _PrimeName[23:26],
|
||||||
|
31: _PrimeName[26:29],
|
||||||
|
41: _PrimeName[29:32],
|
||||||
|
43: _PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Prime) String() string {
|
||||||
|
if str, ok := _PrimeMap[i]; ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("Prime(%d)", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _PrimeNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[p2-(2)]
|
||||||
|
_ = x[p3-(3)]
|
||||||
|
_ = x[p5-(5)]
|
||||||
|
_ = x[p7-(7)]
|
||||||
|
_ = x[p11-(11)]
|
||||||
|
_ = x[p13-(13)]
|
||||||
|
_ = x[p17-(17)]
|
||||||
|
_ = x[p19-(19)]
|
||||||
|
_ = x[p23-(23)]
|
||||||
|
_ = x[p29-(29)]
|
||||||
|
_ = x[p37-(31)]
|
||||||
|
_ = x[p41-(41)]
|
||||||
|
_ = x[p43-(43)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43}
|
||||||
|
|
||||||
|
var _PrimeNameToValueMap = map[string]Prime{
|
||||||
|
_PrimeName[0:2]: p2,
|
||||||
|
_PrimeLowerName[0:2]: p2,
|
||||||
|
_PrimeName[2:4]: p3,
|
||||||
|
_PrimeLowerName[2:4]: p3,
|
||||||
|
_PrimeName[4:6]: p5,
|
||||||
|
_PrimeLowerName[4:6]: p5,
|
||||||
|
_PrimeName[6:8]: p7,
|
||||||
|
_PrimeLowerName[6:8]: p7,
|
||||||
|
_PrimeName[8:11]: p11,
|
||||||
|
_PrimeLowerName[8:11]: p11,
|
||||||
|
_PrimeName[11:14]: p13,
|
||||||
|
_PrimeLowerName[11:14]: p13,
|
||||||
|
_PrimeName[14:17]: p17,
|
||||||
|
_PrimeLowerName[14:17]: p17,
|
||||||
|
_PrimeName[17:20]: p19,
|
||||||
|
_PrimeLowerName[17:20]: p19,
|
||||||
|
_PrimeName[20:23]: p23,
|
||||||
|
_PrimeLowerName[20:23]: p23,
|
||||||
|
_PrimeName[23:26]: p29,
|
||||||
|
_PrimeLowerName[23:26]: p29,
|
||||||
|
_PrimeName[26:29]: p37,
|
||||||
|
_PrimeLowerName[26:29]: p37,
|
||||||
|
_PrimeName[29:32]: p41,
|
||||||
|
_PrimeLowerName[29:32]: p41,
|
||||||
|
_PrimeName[32:35]: p43,
|
||||||
|
_PrimeLowerName[32:35]: p43,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeNames = []string{
|
||||||
|
_PrimeName[0:2],
|
||||||
|
_PrimeName[2:4],
|
||||||
|
_PrimeName[4:6],
|
||||||
|
_PrimeName[6:8],
|
||||||
|
_PrimeName[8:11],
|
||||||
|
_PrimeName[11:14],
|
||||||
|
_PrimeName[14:17],
|
||||||
|
_PrimeName[17:20],
|
||||||
|
_PrimeName[20:23],
|
||||||
|
_PrimeName[23:26],
|
||||||
|
_PrimeName[26:29],
|
||||||
|
_PrimeName[29:32],
|
||||||
|
_PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func PrimeString(s string) (Prime, error) {
|
||||||
|
if val, ok := _PrimeNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeValues returns all values of the enum
|
||||||
|
func PrimeValues() []Prime {
|
||||||
|
return _PrimeValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeStrings returns a slice of all String values of the enum
|
||||||
|
func PrimeStrings() []string {
|
||||||
|
strs := make([]string, len(_PrimeNames))
|
||||||
|
copy(strs, _PrimeNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Prime) IsAPrime() bool {
|
||||||
|
_, ok := _PrimeMap[i]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON implements the json.Marshaler interface for Prime
|
||||||
|
func (i Prime) MarshalJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(i.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON implements the json.Unmarshaler interface for Prime
|
||||||
|
func (i *Prime) UnmarshalJSON(data []byte) error {
|
||||||
|
var s string
|
||||||
|
if err := json.Unmarshal(data, &s); err != nil {
|
||||||
|
return fmt.Errorf("Prime should be a string, got %s", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
*i, err = PrimeString(s)
|
||||||
|
return err
|
||||||
|
}
|
|
@ -0,0 +1,170 @@
|
||||||
|
|
||||||
|
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
|
||||||
|
var _PrimeMap = map[Prime]string{
|
||||||
|
2: _PrimeName[0:2],
|
||||||
|
3: _PrimeName[2:4],
|
||||||
|
5: _PrimeName[4:6],
|
||||||
|
7: _PrimeName[6:8],
|
||||||
|
11: _PrimeName[8:11],
|
||||||
|
13: _PrimeName[11:14],
|
||||||
|
17: _PrimeName[14:17],
|
||||||
|
19: _PrimeName[17:20],
|
||||||
|
23: _PrimeName[20:23],
|
||||||
|
29: _PrimeName[23:26],
|
||||||
|
31: _PrimeName[26:29],
|
||||||
|
41: _PrimeName[29:32],
|
||||||
|
43: _PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Prime) String() string {
|
||||||
|
if str, ok := _PrimeMap[i]; ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("Prime(%d)", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _PrimeNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[p2-(2)]
|
||||||
|
_ = x[p3-(3)]
|
||||||
|
_ = x[p5-(5)]
|
||||||
|
_ = x[p7-(7)]
|
||||||
|
_ = x[p11-(11)]
|
||||||
|
_ = x[p13-(13)]
|
||||||
|
_ = x[p17-(17)]
|
||||||
|
_ = x[p19-(19)]
|
||||||
|
_ = x[p23-(23)]
|
||||||
|
_ = x[p29-(29)]
|
||||||
|
_ = x[p37-(31)]
|
||||||
|
_ = x[p41-(41)]
|
||||||
|
_ = x[p43-(43)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43}
|
||||||
|
|
||||||
|
var _PrimeNameToValueMap = map[string]Prime{
|
||||||
|
_PrimeName[0:2]: p2,
|
||||||
|
_PrimeLowerName[0:2]: p2,
|
||||||
|
_PrimeName[2:4]: p3,
|
||||||
|
_PrimeLowerName[2:4]: p3,
|
||||||
|
_PrimeName[4:6]: p5,
|
||||||
|
_PrimeLowerName[4:6]: p5,
|
||||||
|
_PrimeName[6:8]: p7,
|
||||||
|
_PrimeLowerName[6:8]: p7,
|
||||||
|
_PrimeName[8:11]: p11,
|
||||||
|
_PrimeLowerName[8:11]: p11,
|
||||||
|
_PrimeName[11:14]: p13,
|
||||||
|
_PrimeLowerName[11:14]: p13,
|
||||||
|
_PrimeName[14:17]: p17,
|
||||||
|
_PrimeLowerName[14:17]: p17,
|
||||||
|
_PrimeName[17:20]: p19,
|
||||||
|
_PrimeLowerName[17:20]: p19,
|
||||||
|
_PrimeName[20:23]: p23,
|
||||||
|
_PrimeLowerName[20:23]: p23,
|
||||||
|
_PrimeName[23:26]: p29,
|
||||||
|
_PrimeLowerName[23:26]: p29,
|
||||||
|
_PrimeName[26:29]: p37,
|
||||||
|
_PrimeLowerName[26:29]: p37,
|
||||||
|
_PrimeName[29:32]: p41,
|
||||||
|
_PrimeLowerName[29:32]: p41,
|
||||||
|
_PrimeName[32:35]: p43,
|
||||||
|
_PrimeLowerName[32:35]: p43,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeNames = []string{
|
||||||
|
_PrimeName[0:2],
|
||||||
|
_PrimeName[2:4],
|
||||||
|
_PrimeName[4:6],
|
||||||
|
_PrimeName[6:8],
|
||||||
|
_PrimeName[8:11],
|
||||||
|
_PrimeName[11:14],
|
||||||
|
_PrimeName[14:17],
|
||||||
|
_PrimeName[17:20],
|
||||||
|
_PrimeName[20:23],
|
||||||
|
_PrimeName[23:26],
|
||||||
|
_PrimeName[26:29],
|
||||||
|
_PrimeName[29:32],
|
||||||
|
_PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func PrimeString(s string) (Prime, error) {
|
||||||
|
if val, ok := _PrimeNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeValues returns all values of the enum
|
||||||
|
func PrimeValues() []Prime {
|
||||||
|
return _PrimeValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeStrings returns a slice of all String values of the enum
|
||||||
|
func PrimeStrings() []string {
|
||||||
|
strs := make([]string, len(_PrimeNames))
|
||||||
|
copy(strs, _PrimeNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Prime) IsAPrime() bool {
|
||||||
|
_, ok := _PrimeMap[i]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON implements the json.Marshaler interface for Prime
|
||||||
|
func (i Prime) MarshalJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(i.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON implements the json.Unmarshaler interface for Prime
|
||||||
|
func (i *Prime) UnmarshalJSON(data []byte) error {
|
||||||
|
var s string
|
||||||
|
if err := json.Unmarshal(data, &s); err != nil {
|
||||||
|
return fmt.Errorf("Prime should be a string, got %s", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
*i, err = PrimeString(s)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Prime) Value() (driver.Value, error) {
|
||||||
|
return i.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Prime) Scan(value interface{}) error {
|
||||||
|
if value == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var str string
|
||||||
|
switch v := value.(type) {
|
||||||
|
case []byte:
|
||||||
|
str = string(v)
|
||||||
|
case string:
|
||||||
|
str = v
|
||||||
|
case fmt.Stringer:
|
||||||
|
str = v.String()
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid value of Prime: %[1]T(%[1]v)", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
val, err := PrimeString(str)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*i = val
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,153 @@
|
||||||
|
|
||||||
|
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
|
||||||
|
var _PrimeMap = map[Prime]string{
|
||||||
|
2: _PrimeName[0:2],
|
||||||
|
3: _PrimeName[2:4],
|
||||||
|
5: _PrimeName[4:6],
|
||||||
|
7: _PrimeName[6:8],
|
||||||
|
11: _PrimeName[8:11],
|
||||||
|
13: _PrimeName[11:14],
|
||||||
|
17: _PrimeName[14:17],
|
||||||
|
19: _PrimeName[17:20],
|
||||||
|
23: _PrimeName[20:23],
|
||||||
|
29: _PrimeName[23:26],
|
||||||
|
31: _PrimeName[26:29],
|
||||||
|
41: _PrimeName[29:32],
|
||||||
|
43: _PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Prime) String() string {
|
||||||
|
if str, ok := _PrimeMap[i]; ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("Prime(%d)", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _PrimeNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[p2-(2)]
|
||||||
|
_ = x[p3-(3)]
|
||||||
|
_ = x[p5-(5)]
|
||||||
|
_ = x[p7-(7)]
|
||||||
|
_ = x[p11-(11)]
|
||||||
|
_ = x[p13-(13)]
|
||||||
|
_ = x[p17-(17)]
|
||||||
|
_ = x[p19-(19)]
|
||||||
|
_ = x[p23-(23)]
|
||||||
|
_ = x[p29-(29)]
|
||||||
|
_ = x[p37-(31)]
|
||||||
|
_ = x[p41-(41)]
|
||||||
|
_ = x[p43-(43)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43}
|
||||||
|
|
||||||
|
var _PrimeNameToValueMap = map[string]Prime{
|
||||||
|
_PrimeName[0:2]: p2,
|
||||||
|
_PrimeLowerName[0:2]: p2,
|
||||||
|
_PrimeName[2:4]: p3,
|
||||||
|
_PrimeLowerName[2:4]: p3,
|
||||||
|
_PrimeName[4:6]: p5,
|
||||||
|
_PrimeLowerName[4:6]: p5,
|
||||||
|
_PrimeName[6:8]: p7,
|
||||||
|
_PrimeLowerName[6:8]: p7,
|
||||||
|
_PrimeName[8:11]: p11,
|
||||||
|
_PrimeLowerName[8:11]: p11,
|
||||||
|
_PrimeName[11:14]: p13,
|
||||||
|
_PrimeLowerName[11:14]: p13,
|
||||||
|
_PrimeName[14:17]: p17,
|
||||||
|
_PrimeLowerName[14:17]: p17,
|
||||||
|
_PrimeName[17:20]: p19,
|
||||||
|
_PrimeLowerName[17:20]: p19,
|
||||||
|
_PrimeName[20:23]: p23,
|
||||||
|
_PrimeLowerName[20:23]: p23,
|
||||||
|
_PrimeName[23:26]: p29,
|
||||||
|
_PrimeLowerName[23:26]: p29,
|
||||||
|
_PrimeName[26:29]: p37,
|
||||||
|
_PrimeLowerName[26:29]: p37,
|
||||||
|
_PrimeName[29:32]: p41,
|
||||||
|
_PrimeLowerName[29:32]: p41,
|
||||||
|
_PrimeName[32:35]: p43,
|
||||||
|
_PrimeLowerName[32:35]: p43,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeNames = []string{
|
||||||
|
_PrimeName[0:2],
|
||||||
|
_PrimeName[2:4],
|
||||||
|
_PrimeName[4:6],
|
||||||
|
_PrimeName[6:8],
|
||||||
|
_PrimeName[8:11],
|
||||||
|
_PrimeName[11:14],
|
||||||
|
_PrimeName[14:17],
|
||||||
|
_PrimeName[17:20],
|
||||||
|
_PrimeName[20:23],
|
||||||
|
_PrimeName[23:26],
|
||||||
|
_PrimeName[26:29],
|
||||||
|
_PrimeName[29:32],
|
||||||
|
_PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func PrimeString(s string) (Prime, error) {
|
||||||
|
if val, ok := _PrimeNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeValues returns all values of the enum
|
||||||
|
func PrimeValues() []Prime {
|
||||||
|
return _PrimeValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeStrings returns a slice of all String values of the enum
|
||||||
|
func PrimeStrings() []string {
|
||||||
|
strs := make([]string, len(_PrimeNames))
|
||||||
|
copy(strs, _PrimeNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Prime) IsAPrime() bool {
|
||||||
|
_, ok := _PrimeMap[i]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Prime) Value() (driver.Value, error) {
|
||||||
|
return i.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *Prime) Scan(value interface{}) error {
|
||||||
|
if value == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var str string
|
||||||
|
switch v := value.(type) {
|
||||||
|
case []byte:
|
||||||
|
str = string(v)
|
||||||
|
case string:
|
||||||
|
str = v
|
||||||
|
case fmt.Stringer:
|
||||||
|
str = v.String()
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid value of Prime: %[1]T(%[1]v)", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
val, err := PrimeString(str)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*i = val
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -0,0 +1,135 @@
|
||||||
|
|
||||||
|
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
|
||||||
|
var _PrimeMap = map[Prime]string{
|
||||||
|
2: _PrimeName[0:2],
|
||||||
|
3: _PrimeName[2:4],
|
||||||
|
5: _PrimeName[4:6],
|
||||||
|
7: _PrimeName[6:8],
|
||||||
|
11: _PrimeName[8:11],
|
||||||
|
13: _PrimeName[11:14],
|
||||||
|
17: _PrimeName[14:17],
|
||||||
|
19: _PrimeName[17:20],
|
||||||
|
23: _PrimeName[20:23],
|
||||||
|
29: _PrimeName[23:26],
|
||||||
|
31: _PrimeName[26:29],
|
||||||
|
41: _PrimeName[29:32],
|
||||||
|
43: _PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Prime) String() string {
|
||||||
|
if str, ok := _PrimeMap[i]; ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("Prime(%d)", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _PrimeNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[p2-(2)]
|
||||||
|
_ = x[p3-(3)]
|
||||||
|
_ = x[p5-(5)]
|
||||||
|
_ = x[p7-(7)]
|
||||||
|
_ = x[p11-(11)]
|
||||||
|
_ = x[p13-(13)]
|
||||||
|
_ = x[p17-(17)]
|
||||||
|
_ = x[p19-(19)]
|
||||||
|
_ = x[p23-(23)]
|
||||||
|
_ = x[p29-(29)]
|
||||||
|
_ = x[p37-(31)]
|
||||||
|
_ = x[p41-(41)]
|
||||||
|
_ = x[p43-(43)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43}
|
||||||
|
|
||||||
|
var _PrimeNameToValueMap = map[string]Prime{
|
||||||
|
_PrimeName[0:2]: p2,
|
||||||
|
_PrimeLowerName[0:2]: p2,
|
||||||
|
_PrimeName[2:4]: p3,
|
||||||
|
_PrimeLowerName[2:4]: p3,
|
||||||
|
_PrimeName[4:6]: p5,
|
||||||
|
_PrimeLowerName[4:6]: p5,
|
||||||
|
_PrimeName[6:8]: p7,
|
||||||
|
_PrimeLowerName[6:8]: p7,
|
||||||
|
_PrimeName[8:11]: p11,
|
||||||
|
_PrimeLowerName[8:11]: p11,
|
||||||
|
_PrimeName[11:14]: p13,
|
||||||
|
_PrimeLowerName[11:14]: p13,
|
||||||
|
_PrimeName[14:17]: p17,
|
||||||
|
_PrimeLowerName[14:17]: p17,
|
||||||
|
_PrimeName[17:20]: p19,
|
||||||
|
_PrimeLowerName[17:20]: p19,
|
||||||
|
_PrimeName[20:23]: p23,
|
||||||
|
_PrimeLowerName[20:23]: p23,
|
||||||
|
_PrimeName[23:26]: p29,
|
||||||
|
_PrimeLowerName[23:26]: p29,
|
||||||
|
_PrimeName[26:29]: p37,
|
||||||
|
_PrimeLowerName[26:29]: p37,
|
||||||
|
_PrimeName[29:32]: p41,
|
||||||
|
_PrimeLowerName[29:32]: p41,
|
||||||
|
_PrimeName[32:35]: p43,
|
||||||
|
_PrimeLowerName[32:35]: p43,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeNames = []string{
|
||||||
|
_PrimeName[0:2],
|
||||||
|
_PrimeName[2:4],
|
||||||
|
_PrimeName[4:6],
|
||||||
|
_PrimeName[6:8],
|
||||||
|
_PrimeName[8:11],
|
||||||
|
_PrimeName[11:14],
|
||||||
|
_PrimeName[14:17],
|
||||||
|
_PrimeName[17:20],
|
||||||
|
_PrimeName[20:23],
|
||||||
|
_PrimeName[23:26],
|
||||||
|
_PrimeName[26:29],
|
||||||
|
_PrimeName[29:32],
|
||||||
|
_PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func PrimeString(s string) (Prime, error) {
|
||||||
|
if val, ok := _PrimeNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeValues returns all values of the enum
|
||||||
|
func PrimeValues() []Prime {
|
||||||
|
return _PrimeValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeStrings returns a slice of all String values of the enum
|
||||||
|
func PrimeStrings() []string {
|
||||||
|
strs := make([]string, len(_PrimeNames))
|
||||||
|
copy(strs, _PrimeNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Prime) IsAPrime() bool {
|
||||||
|
_, ok := _PrimeMap[i]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalText implements the encoding.TextMarshaler interface for Prime
|
||||||
|
func (i Prime) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(i.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalText implements the encoding.TextUnmarshaler interface for Prime
|
||||||
|
func (i *Prime) UnmarshalText(text []byte) error {
|
||||||
|
var err error
|
||||||
|
*i, err = PrimeString(string(text))
|
||||||
|
return err
|
||||||
|
}
|
|
@ -0,0 +1,140 @@
|
||||||
|
|
||||||
|
const _PrimeName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
const _PrimeLowerName = "p2p3p5p7p11p13p17p19p23p29p37p41p43"
|
||||||
|
|
||||||
|
var _PrimeMap = map[Prime]string{
|
||||||
|
2: _PrimeName[0:2],
|
||||||
|
3: _PrimeName[2:4],
|
||||||
|
5: _PrimeName[4:6],
|
||||||
|
7: _PrimeName[6:8],
|
||||||
|
11: _PrimeName[8:11],
|
||||||
|
13: _PrimeName[11:14],
|
||||||
|
17: _PrimeName[14:17],
|
||||||
|
19: _PrimeName[17:20],
|
||||||
|
23: _PrimeName[20:23],
|
||||||
|
29: _PrimeName[23:26],
|
||||||
|
31: _PrimeName[26:29],
|
||||||
|
41: _PrimeName[29:32],
|
||||||
|
43: _PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Prime) String() string {
|
||||||
|
if str, ok := _PrimeMap[i]; ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("Prime(%d)", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _PrimeNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[p2-(2)]
|
||||||
|
_ = x[p3-(3)]
|
||||||
|
_ = x[p5-(5)]
|
||||||
|
_ = x[p7-(7)]
|
||||||
|
_ = x[p11-(11)]
|
||||||
|
_ = x[p13-(13)]
|
||||||
|
_ = x[p17-(17)]
|
||||||
|
_ = x[p19-(19)]
|
||||||
|
_ = x[p23-(23)]
|
||||||
|
_ = x[p29-(29)]
|
||||||
|
_ = x[p37-(31)]
|
||||||
|
_ = x[p41-(41)]
|
||||||
|
_ = x[p43-(43)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeValues = []Prime{p2, p3, p5, p7, p11, p13, p17, p19, p23, p29, p37, p41, p43}
|
||||||
|
|
||||||
|
var _PrimeNameToValueMap = map[string]Prime{
|
||||||
|
_PrimeName[0:2]: p2,
|
||||||
|
_PrimeLowerName[0:2]: p2,
|
||||||
|
_PrimeName[2:4]: p3,
|
||||||
|
_PrimeLowerName[2:4]: p3,
|
||||||
|
_PrimeName[4:6]: p5,
|
||||||
|
_PrimeLowerName[4:6]: p5,
|
||||||
|
_PrimeName[6:8]: p7,
|
||||||
|
_PrimeLowerName[6:8]: p7,
|
||||||
|
_PrimeName[8:11]: p11,
|
||||||
|
_PrimeLowerName[8:11]: p11,
|
||||||
|
_PrimeName[11:14]: p13,
|
||||||
|
_PrimeLowerName[11:14]: p13,
|
||||||
|
_PrimeName[14:17]: p17,
|
||||||
|
_PrimeLowerName[14:17]: p17,
|
||||||
|
_PrimeName[17:20]: p19,
|
||||||
|
_PrimeLowerName[17:20]: p19,
|
||||||
|
_PrimeName[20:23]: p23,
|
||||||
|
_PrimeLowerName[20:23]: p23,
|
||||||
|
_PrimeName[23:26]: p29,
|
||||||
|
_PrimeLowerName[23:26]: p29,
|
||||||
|
_PrimeName[26:29]: p37,
|
||||||
|
_PrimeLowerName[26:29]: p37,
|
||||||
|
_PrimeName[29:32]: p41,
|
||||||
|
_PrimeLowerName[29:32]: p41,
|
||||||
|
_PrimeName[32:35]: p43,
|
||||||
|
_PrimeLowerName[32:35]: p43,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PrimeNames = []string{
|
||||||
|
_PrimeName[0:2],
|
||||||
|
_PrimeName[2:4],
|
||||||
|
_PrimeName[4:6],
|
||||||
|
_PrimeName[6:8],
|
||||||
|
_PrimeName[8:11],
|
||||||
|
_PrimeName[11:14],
|
||||||
|
_PrimeName[14:17],
|
||||||
|
_PrimeName[17:20],
|
||||||
|
_PrimeName[20:23],
|
||||||
|
_PrimeName[23:26],
|
||||||
|
_PrimeName[26:29],
|
||||||
|
_PrimeName[29:32],
|
||||||
|
_PrimeName[32:35],
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func PrimeString(s string) (Prime, error) {
|
||||||
|
if val, ok := _PrimeNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _PrimeNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Prime values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeValues returns all values of the enum
|
||||||
|
func PrimeValues() []Prime {
|
||||||
|
return _PrimeValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrimeStrings returns a slice of all String values of the enum
|
||||||
|
func PrimeStrings() []string {
|
||||||
|
strs := make([]string, len(_PrimeNames))
|
||||||
|
copy(strs, _PrimeNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAPrime returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Prime) IsAPrime() bool {
|
||||||
|
_, ok := _PrimeMap[i]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalYAML implements a YAML Marshaler for Prime
|
||||||
|
func (i Prime) MarshalYAML() (interface{}, error) {
|
||||||
|
return i.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalYAML implements a YAML Unmarshaler for Prime
|
||||||
|
func (i *Prime) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
var s string
|
||||||
|
if err := unmarshal(&s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
*i, err = PrimeString(s)
|
||||||
|
return err
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type Thresholdeq int
|
||||||
|
|
||||||
|
const (
|
||||||
|
req1 Thresholdeq = 2
|
||||||
|
req2 Thresholdeq = 4
|
||||||
|
req3 Thresholdeq = 6
|
||||||
|
req4 Thresholdeq = 8
|
||||||
|
req5 Thresholdeq = 10
|
||||||
|
req6 Thresholdeq = 12
|
||||||
|
req7 Thresholdeq = 14
|
||||||
|
req8 Thresholdeq = 16
|
||||||
|
req9 Thresholdeq = 18
|
||||||
|
req10 Thresholdeq = 20
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ck(1, "Thresholdeq(1)")
|
||||||
|
ck(req1, "req1")
|
||||||
|
ck(3, "Thresholdeq(3)")
|
||||||
|
ck(req2, "req2")
|
||||||
|
ck(5, "Thresholdeq(5)")
|
||||||
|
ck(req3, "req3")
|
||||||
|
ck(7, "Thresholdeq(7)")
|
||||||
|
ck(req4, "req4")
|
||||||
|
ck(9, "Thresholdeq(9)")
|
||||||
|
ck(req5, "req5")
|
||||||
|
ck(11, "Thresholdeq(11)")
|
||||||
|
ck(req6, "req6")
|
||||||
|
ck(13, "Thresholdeq(13)")
|
||||||
|
ck(req7, "req7")
|
||||||
|
ck(15, "Thresholdeq(15)")
|
||||||
|
ck(req8, "req8")
|
||||||
|
ck(17, "Thresholdeq(17)")
|
||||||
|
ck(req9, "req9")
|
||||||
|
ck(19, "Thresholdeq(19)")
|
||||||
|
ck(req10, "req10")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ck(thresholdeq Thresholdeq, str string) {
|
||||||
|
if fmt.Sprint(thresholdeq) != str {
|
||||||
|
panic("thresholdeq.go: " + str)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type Thresholdgt int
|
||||||
|
|
||||||
|
const (
|
||||||
|
rgt1 Thresholdgt = 2
|
||||||
|
rgt2 Thresholdgt = 4
|
||||||
|
rgt3 Thresholdgt = 6
|
||||||
|
rgt4 Thresholdgt = 8
|
||||||
|
rgt5 Thresholdgt = 10
|
||||||
|
rgt6 Thresholdgt = 12
|
||||||
|
rgt7 Thresholdgt = 14
|
||||||
|
rgt8 Thresholdgt = 16
|
||||||
|
rgt9 Thresholdgt = 18
|
||||||
|
rgt10 Thresholdgt = 20
|
||||||
|
rgt11 Thresholdgt = 22
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ck(1, "Thresholdgt(1)")
|
||||||
|
ck(rgt1, "rgt1")
|
||||||
|
ck(3, "Thresholdgt(3)")
|
||||||
|
ck(rgt2, "rgt2")
|
||||||
|
ck(5, "Thresholdgt(5)")
|
||||||
|
ck(rgt3, "rgt3")
|
||||||
|
ck(7, "Thresholdgt(7)")
|
||||||
|
ck(rgt4, "rgt4")
|
||||||
|
ck(9, "Thresholdgt(9)")
|
||||||
|
ck(rgt5, "rgt5")
|
||||||
|
ck(11, "Thresholdgt(11)")
|
||||||
|
ck(rgt6, "rgt6")
|
||||||
|
ck(13, "Thresholdgt(13)")
|
||||||
|
ck(rgt7, "rgt7")
|
||||||
|
ck(15, "Thresholdgt(15)")
|
||||||
|
ck(rgt8, "rgt8")
|
||||||
|
ck(17, "Thresholdgt(17)")
|
||||||
|
ck(rgt9, "rgt9")
|
||||||
|
ck(19, "Thresholdgt(19)")
|
||||||
|
ck(rgt10, "rgt10")
|
||||||
|
ck(21, "Thresholdgt(21)")
|
||||||
|
ck(rgt11, "rgt11")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ck(thresholdgt Thresholdgt, str string) {
|
||||||
|
if fmt.Sprint(thresholdgt) != str {
|
||||||
|
panic("thresholdgt.go: " + str)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type Thresholdlt int
|
||||||
|
|
||||||
|
const (
|
||||||
|
rlt1 Thresholdlt = 2
|
||||||
|
rlt2 Thresholdlt = 4
|
||||||
|
rlt3 Thresholdlt = 6
|
||||||
|
rlt4 Thresholdlt = 8
|
||||||
|
rlt5 Thresholdlt = 10
|
||||||
|
rlt6 Thresholdlt = 12
|
||||||
|
rlt7 Thresholdlt = 14
|
||||||
|
rlt8 Thresholdlt = 16
|
||||||
|
rlt9 Thresholdlt = 18
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ck(1, "Thresholdlt(1)")
|
||||||
|
ck(rlt1, "rlt1")
|
||||||
|
ck(3, "Thresholdlt(3)")
|
||||||
|
ck(rlt2, "rlt2")
|
||||||
|
ck(5, "Thresholdlt(5)")
|
||||||
|
ck(rlt3, "rlt3")
|
||||||
|
ck(7, "Thresholdlt(7)")
|
||||||
|
ck(rlt4, "rlt4")
|
||||||
|
ck(9, "Thresholdlt(9)")
|
||||||
|
ck(rlt5, "rlt5")
|
||||||
|
ck(11, "Thresholdlt(11)")
|
||||||
|
ck(rlt6, "rlt6")
|
||||||
|
ck(13, "Thresholdlt(13)")
|
||||||
|
ck(rlt7, "rlt7")
|
||||||
|
ck(15, "Thresholdlt(15)")
|
||||||
|
ck(rlt8, "rlt8")
|
||||||
|
ck(17, "Thresholdlt(17)")
|
||||||
|
ck(rlt9, "rlt9")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ck(thresholdlt Thresholdlt, str string) {
|
||||||
|
if fmt.Sprint(thresholdlt) != str {
|
||||||
|
panic("thresholdlt.go: " + str)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
|
||||||
|
const _DayName = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"
|
||||||
|
|
||||||
|
var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50}
|
||||||
|
|
||||||
|
const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday"
|
||||||
|
|
||||||
|
func (i Day) String() string {
|
||||||
|
if i < 0 || i >= Day(len(_DayIndex)-1) {
|
||||||
|
return fmt.Sprintf("Day(%d)", i)
|
||||||
|
}
|
||||||
|
return _DayName[_DayIndex[i]:_DayIndex[i+1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _DayNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[DayMonday-(0)]
|
||||||
|
_ = x[DayTuesday-(1)]
|
||||||
|
_ = x[DayWednesday-(2)]
|
||||||
|
_ = x[DayThursday-(3)]
|
||||||
|
_ = x[DayFriday-(4)]
|
||||||
|
_ = x[DaySaturday-(5)]
|
||||||
|
_ = x[DaySunday-(6)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DayValues = []Day{DayMonday, DayTuesday, DayWednesday, DayThursday, DayFriday, DaySaturday, DaySunday}
|
||||||
|
|
||||||
|
var _DayNameToValueMap = map[string]Day{
|
||||||
|
_DayName[0:6]: DayMonday,
|
||||||
|
_DayLowerName[0:6]: DayMonday,
|
||||||
|
_DayName[6:13]: DayTuesday,
|
||||||
|
_DayLowerName[6:13]: DayTuesday,
|
||||||
|
_DayName[13:22]: DayWednesday,
|
||||||
|
_DayLowerName[13:22]: DayWednesday,
|
||||||
|
_DayName[22:30]: DayThursday,
|
||||||
|
_DayLowerName[22:30]: DayThursday,
|
||||||
|
_DayName[30:36]: DayFriday,
|
||||||
|
_DayLowerName[30:36]: DayFriday,
|
||||||
|
_DayName[36:44]: DaySaturday,
|
||||||
|
_DayLowerName[36:44]: DaySaturday,
|
||||||
|
_DayName[44:50]: DaySunday,
|
||||||
|
_DayLowerName[44:50]: DaySunday,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DayNames = []string{
|
||||||
|
_DayName[0:6],
|
||||||
|
_DayName[6:13],
|
||||||
|
_DayName[13:22],
|
||||||
|
_DayName[22:30],
|
||||||
|
_DayName[30:36],
|
||||||
|
_DayName[36:44],
|
||||||
|
_DayName[44:50],
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func DayString(s string) (Day, error) {
|
||||||
|
if val, ok := _DayNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Day values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayValues returns all values of the enum
|
||||||
|
func DayValues() []Day {
|
||||||
|
return _DayValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayStrings returns a slice of all String values of the enum
|
||||||
|
func DayStrings() []string {
|
||||||
|
strs := make([]string, len(_DayNames))
|
||||||
|
copy(strs, _DayNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Day) IsADay() bool {
|
||||||
|
for _, v := range _DayValues {
|
||||||
|
if i == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
|
||||||
|
const _DayName = "MondayTuesdayWednesdayThursdayFridaySaturdaySunday"
|
||||||
|
|
||||||
|
var _DayIndex = [...]uint8{0, 6, 13, 22, 30, 36, 44, 50}
|
||||||
|
|
||||||
|
const _DayLowerName = "mondaytuesdaywednesdaythursdayfridaysaturdaysunday"
|
||||||
|
|
||||||
|
func (i Day) String() string {
|
||||||
|
if i < 0 || i >= Day(len(_DayIndex)-1) {
|
||||||
|
return fmt.Sprintf("Day(%d)", i)
|
||||||
|
}
|
||||||
|
return _DayName[_DayIndex[i]:_DayIndex[i+1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _DayNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[DayMonday-(0)]
|
||||||
|
_ = x[NightTuesday-(1)]
|
||||||
|
_ = x[DayWednesday-(2)]
|
||||||
|
_ = x[NightThursday-(3)]
|
||||||
|
_ = x[DayFriday-(4)]
|
||||||
|
_ = x[NightSaturday-(5)]
|
||||||
|
_ = x[DaySunday-(6)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DayValues = []Day{DayMonday, NightTuesday, DayWednesday, NightThursday, DayFriday, NightSaturday, DaySunday}
|
||||||
|
|
||||||
|
var _DayNameToValueMap = map[string]Day{
|
||||||
|
_DayName[0:6]: DayMonday,
|
||||||
|
_DayLowerName[0:6]: DayMonday,
|
||||||
|
_DayName[6:13]: NightTuesday,
|
||||||
|
_DayLowerName[6:13]: NightTuesday,
|
||||||
|
_DayName[13:22]: DayWednesday,
|
||||||
|
_DayLowerName[13:22]: DayWednesday,
|
||||||
|
_DayName[22:30]: NightThursday,
|
||||||
|
_DayLowerName[22:30]: NightThursday,
|
||||||
|
_DayName[30:36]: DayFriday,
|
||||||
|
_DayLowerName[30:36]: DayFriday,
|
||||||
|
_DayName[36:44]: NightSaturday,
|
||||||
|
_DayLowerName[36:44]: NightSaturday,
|
||||||
|
_DayName[44:50]: DaySunday,
|
||||||
|
_DayLowerName[44:50]: DaySunday,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _DayNames = []string{
|
||||||
|
_DayName[0:6],
|
||||||
|
_DayName[6:13],
|
||||||
|
_DayName[13:22],
|
||||||
|
_DayName[22:30],
|
||||||
|
_DayName[30:36],
|
||||||
|
_DayName[36:44],
|
||||||
|
_DayName[44:50],
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func DayString(s string) (Day, error) {
|
||||||
|
if val, ok := _DayNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _DayNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Day values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayValues returns all values of the enum
|
||||||
|
func DayValues() []Day {
|
||||||
|
return _DayValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// DayStrings returns a slice of all String values of the enum
|
||||||
|
func DayStrings() []string {
|
||||||
|
strs := make([]string, len(_DayNames))
|
||||||
|
copy(strs, _DayNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsADay returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Day) IsADay() bool {
|
||||||
|
for _, v := range _DayValues {
|
||||||
|
if i == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
|
||||||
|
const (
|
||||||
|
_UnumName_0 = "m0m1m2"
|
||||||
|
_UnumLowerName_0 = "m0m1m2"
|
||||||
|
_UnumName_1 = "m_2m_1"
|
||||||
|
_UnumLowerName_1 = "m_2m_1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_UnumIndex_0 = [...]uint8{0, 2, 4, 6}
|
||||||
|
_UnumIndex_1 = [...]uint8{0, 3, 6}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (i Unum) String() string {
|
||||||
|
switch {
|
||||||
|
case 0 <= i && i <= 2:
|
||||||
|
return _UnumName_0[_UnumIndex_0[i]:_UnumIndex_0[i+1]]
|
||||||
|
case 253 <= i && i <= 254:
|
||||||
|
i -= 253
|
||||||
|
return _UnumName_1[_UnumIndex_1[i]:_UnumIndex_1[i+1]]
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("Unum(%d)", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Unum) Values() []string {
|
||||||
|
return UnumStrings()
|
||||||
|
}
|
||||||
|
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
func _UnumNoOp() {
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[m0-(0)]
|
||||||
|
_ = x[m1-(1)]
|
||||||
|
_ = x[m2-(2)]
|
||||||
|
_ = x[m_2-(253)]
|
||||||
|
_ = x[m_1-(254)]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _UnumValues = []Unum{m0, m1, m2, m_2, m_1}
|
||||||
|
|
||||||
|
var _UnumNameToValueMap = map[string]Unum{
|
||||||
|
_UnumName_0[0:2]: m0,
|
||||||
|
_UnumLowerName_0[0:2]: m0,
|
||||||
|
_UnumName_0[2:4]: m1,
|
||||||
|
_UnumLowerName_0[2:4]: m1,
|
||||||
|
_UnumName_0[4:6]: m2,
|
||||||
|
_UnumLowerName_0[4:6]: m2,
|
||||||
|
_UnumName_1[0:3]: m_2,
|
||||||
|
_UnumLowerName_1[0:3]: m_2,
|
||||||
|
_UnumName_1[3:6]: m_1,
|
||||||
|
_UnumLowerName_1[3:6]: m_1,
|
||||||
|
}
|
||||||
|
|
||||||
|
var _UnumNames = []string{
|
||||||
|
_UnumName_0[0:2],
|
||||||
|
_UnumName_0[2:4],
|
||||||
|
_UnumName_0[4:6],
|
||||||
|
_UnumName_1[0:3],
|
||||||
|
_UnumName_1[3:6],
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnumString retrieves an enum value from the enum constants string name.
|
||||||
|
// Throws an error if the param is not part of the enum.
|
||||||
|
func UnumString(s string) (Unum, error) {
|
||||||
|
if val, ok := _UnumNameToValueMap[s]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := _UnumNameToValueMap[strings.ToLower(s)]; ok {
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("%s does not belong to Unum values", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnumValues returns all values of the enum
|
||||||
|
func UnumValues() []Unum {
|
||||||
|
return _UnumValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnumStrings returns a slice of all String values of the enum
|
||||||
|
func UnumStrings() []string {
|
||||||
|
strs := make([]string, len(_UnumNames))
|
||||||
|
copy(strs, _UnumNames)
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsAUnum returns "true" if the value is listed in the enum definition. "false" otherwise
|
||||||
|
func (i Unum) IsAUnum() bool {
|
||||||
|
for _, v := range _UnumValues {
|
||||||
|
if i == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
|
@ -54,7 +54,7 @@ Outer:
|
||||||
for n, test := range splitTests {
|
for n, test := range splitTests {
|
||||||
values := make([]Value, len(test.input))
|
values := make([]Value, len(test.input))
|
||||||
for i, v := range test.input {
|
for i, v := range test.input {
|
||||||
values[i] = Value{"", v, test.signed, fmt.Sprint(v)}
|
values[i] = Value{"", "", v, test.signed, fmt.Sprint(v)}
|
||||||
}
|
}
|
||||||
runs := splitIntoRuns(values)
|
runs := splitIntoRuns(values)
|
||||||
if len(runs) != len(test.output) {
|
if len(runs) != len(test.output) {
|
||||||
|
|
Loading…
Reference in New Issue