-
Notifications
You must be signed in to change notification settings - Fork 0
/
enum_geo_type.go
143 lines (134 loc) · 3.78 KB
/
enum_geo_type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package xgeo
// GeoType Generate by https://goclub.run/?k=enum
// ---------------------- DO NOT EDIT (Begin) ----------------------
import (
"fmt"
xerr "github.com/goclub/error"
)
// GeoType
// Source enums:
// {"name":"GeoType","type":"string","items":[{"field":"Point","value":"Point","tailed":", ","label":"点"},{"field":"LineString","value":"LineString","label":"线","tailed":", "},{"field":"Polygon","value":"Polygon","label":"面","tailed":", "},{"field":"MultiPoint","value":"MultiPoint","label":"多点","tailed":", "},{"field":"MultiLineString","value":"MultiLineString","label":"多线","tailed":", "},{"field":"MultiPolygon","value":"MultiPolygon","label":"多面"}]}
type GeoType string
// NewGeoType Create GeoType by string
func NewGeoType(v string) (geoType GeoType, err error) {
geoType = GeoType(v)
err = geoType.Validator()
return
}
// String return GeoType basic types
func (v GeoType) String() string { return string(v) }
// EnumGeoType Example: if geoType == EnumGeoType().xxx {...}
func EnumGeoType() (e struct {
Point GeoType
LineString GeoType
Polygon GeoType
MultiPoint GeoType
MultiLineString GeoType
MultiPolygon GeoType
}) {
e.Point = "Point"
e.LineString = "LineString"
e.Polygon = "Polygon"
e.MultiPoint = "MultiPoint"
e.MultiLineString = "MultiLineString"
e.MultiPolygon = "MultiPolygon"
return
}
func EnumGeoTypeExampleSwitch() {
_ = `
switch point, lineString, polygon, multiPoint, multiLineString, multiPolygon := m.EnumGeoTypeSwitch(); v {
case point.Point:
// @TODO write some code
case lineString.LineString:
// @TODO write some code
case polygon.Polygon:
// @TODO write some code
case multiPoint.MultiPoint:
// @TODO write some code
case multiLineString.MultiLineString:
// @TODO write some code
case multiPolygon.MultiPolygon:
// @TODO write some code
default:
err = xerr.New(fmt.Sprintf("GeoType can not be %v", v))
return
}
`
}
// EnumGeoTypeSwitch safe switch of all values
// example: m.EnumGeoTypeExampleSwitch()
func EnumGeoTypeSwitch() (
point struct{ Point GeoType },
lineString struct{ LineString GeoType },
polygon struct{ Polygon GeoType },
multiPoint struct{ MultiPoint GeoType },
multiLineString struct{ MultiLineString GeoType },
multiPolygon struct{ MultiPolygon GeoType },
) {
e := EnumGeoType()
point.Point = e.Point
lineString.LineString = e.LineString
polygon.Polygon = e.Polygon
multiPoint.MultiPoint = e.MultiPoint
multiLineString.MultiLineString = e.MultiLineString
multiPolygon.MultiPolygon = e.MultiPolygon
return
}
// Validator Verify data
func (v GeoType) Validator(custom ...error) error {
outError := xerr.New(fmt.Sprintf("GeoType can not be %v", v))
if len(custom) != 0 {
outError = custom[0]
}
switch point, lineString, polygon, multiPoint, multiLineString, multiPolygon := EnumGeoTypeSwitch(); v {
case point.Point:
case lineString.LineString:
case polygon.Polygon:
case multiPoint.MultiPoint:
case multiLineString.MultiLineString:
case multiPolygon.MultiPolygon:
default:
return outError
}
return nil
}
// IsZero
func (v GeoType) IsZero() bool {
return v == ""
}
// JavaScript code for https://github.com/2type/admin#_enum
/*
TA.enum.geoType = [
{
key: "Point",
value: "Point",
label: "点",
},
{
key: "LineString",
value: "LineString",
label: "线",
},
{
key: "Polygon",
value: "Polygon",
label: "面",
},
{
key: "MultiPoint",
value: "MultiPoint",
label: "多点",
},
{
key: "MultiLineString",
value: "MultiLineString",
label: "多线",
},
{
key: "MultiPolygon",
value: "MultiPolygon",
label: "多面",
},
]
*/
// ---------------------- DO NOT EDIT (End) ----------------------