Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
9730a91ad5
|
|||
8c16e4d982
|
|||
039a53a395
|
|||
2cf571579b
|
@@ -117,6 +117,20 @@ func (e {{.EnumTypeName}}) DescriptionMeta() enums.EnumDescriptionMetaValue {
|
||||
}
|
||||
{{end}}
|
||||
|
||||
{{if $hasData}}
|
||||
func (e {{.EnumTypeName}}) DataMeta() enums.EnumDataMetaValue {
|
||||
return enums.EnumDataMetaValue{
|
||||
VarName: e.VarName(),
|
||||
Value: e,
|
||||
{{if $hasDescr}} Description: langext.Ptr(e.Description()), {{else}} Description: nil, {{end}}
|
||||
Data: map[string]any{
|
||||
{{ range $datakey, $datatype := $enumdef | generalDataKeys }} "{{ $datakey }}": e.Data().{{ $datakey | godatakey }},
|
||||
{{ end }}
|
||||
},
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
|
||||
func Parse{{.EnumTypeName}}(vv string) ({{.EnumTypeName}}, bool) {
|
||||
for _, ev := range __{{.EnumTypeName}}Values {
|
||||
if string(ev) == vv {
|
||||
@@ -136,6 +150,12 @@ func {{.EnumTypeName}}ValuesMeta() []enums.EnumMetaValue {
|
||||
}
|
||||
}
|
||||
|
||||
func {{.EnumTypeName}}ValuesDataMeta() []enums.EnumMetaValue {
|
||||
return []enums.EnumDataMetaValue{ {{range .Values}}
|
||||
{{.VarName}}.DataMeta(), {{end}}
|
||||
}
|
||||
}
|
||||
|
||||
{{if $hasDescr}}
|
||||
func {{.EnumTypeName}}ValuesDescriptionMeta() []enums.EnumDescriptionMetaValue {
|
||||
return []enums.EnumDescriptionMetaValue{ {{range .Values}}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package enums
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type Enum interface {
|
||||
Valid() bool
|
||||
ValuesAny() []any
|
||||
@@ -31,3 +33,25 @@ type EnumDescriptionMetaValue struct {
|
||||
Value Enum `json:"value"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type EnumDataMetaValue struct {
|
||||
VarName string `json:"varName"`
|
||||
Value Enum `json:"value"`
|
||||
Description *string `json:"description"`
|
||||
|
||||
Data map[string]any `json:"-"` //handled by MarshalJSON
|
||||
}
|
||||
|
||||
func (v EnumDataMetaValue) MarshalJSON() ([]byte, error) {
|
||||
m := make(map[string]any, 8)
|
||||
|
||||
for k, dv := range v.Data {
|
||||
m[k] = dv
|
||||
}
|
||||
|
||||
m["varName"] = v.VarName
|
||||
m["value"] = v.Value
|
||||
m["description"] = v.Description
|
||||
|
||||
return json.Marshal(m)
|
||||
}
|
||||
|
4
go.mod
4
go.mod
@@ -48,7 +48,7 @@ require (
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/quic-go/qpack v0.5.1 // indirect
|
||||
github.com/quic-go/quic-go v0.54.0 // indirect
|
||||
github.com/quic-go/quic-go v0.55.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.3.0 // indirect
|
||||
@@ -62,7 +62,7 @@ require (
|
||||
golang.org/x/mod v0.28.0 // indirect
|
||||
golang.org/x/text v0.29.0 // indirect
|
||||
golang.org/x/tools v0.37.0 // indirect
|
||||
google.golang.org/protobuf v1.36.9 // indirect
|
||||
google.golang.org/protobuf v1.36.10 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
modernc.org/libc v1.37.6 // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
|
6
go.sum
6
go.sum
@@ -183,6 +183,10 @@ github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
|
||||
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
|
||||
github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=
|
||||
github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
|
||||
github.com/quic-go/quic-go v0.54.1 h1:4ZAWm0AhCb6+hE+l5Q1NAL0iRn/ZrMwqHRGQiFwj2eg=
|
||||
github.com/quic-go/quic-go v0.54.1/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
|
||||
github.com/quic-go/quic-go v0.55.0 h1:zccPQIqYCXDt5NmcEabyYvOnomjs8Tlwl7tISjJh9Mk=
|
||||
github.com/quic-go/quic-go v0.55.0/go.mod h1:DR51ilwU1uE164KuWXhinFcKWGlEjzys2l8zUl5Ss1U=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
@@ -475,6 +479,8 @@ google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyM
|
||||
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
||||
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
|
||||
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
||||
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
|
||||
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
@@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.604"
|
||||
const GoextVersion = "0.0.608"
|
||||
|
||||
const GoextVersionTimestamp = "2025-09-20T15:21:15+0200"
|
||||
const GoextVersionTimestamp = "2025-10-04T00:27:41+0200"
|
||||
|
@@ -27,11 +27,11 @@ func (r GoJsonRender) Render(w http.ResponseWriter) error {
|
||||
}
|
||||
jsonBytes, err := MarshalSafeCollections(r.Data, r.NilSafeSlices, r.NilSafeMaps, r.Indent, r.Filter)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
_, err = w.Write(jsonBytes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func (r GoJsonRender) Render(w http.ResponseWriter) error {
|
||||
func (r GoJsonRender) RenderString() (string, error) {
|
||||
jsonBytes, err := MarshalSafeCollections(r.Data, r.NilSafeSlices, r.NilSafeMaps, r.Indent, r.Filter)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return "", err
|
||||
}
|
||||
return string(jsonBytes), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user