Implement reflection and list facets
This commit is contained in:
@ -51,7 +51,14 @@ type Facet struct {
|
||||
func NewFacets(facets ...*Facet) *eiaapi.Facets {
|
||||
newFacets := make(map[string]interface{}, len(facets))
|
||||
for _, f := range facets {
|
||||
newFacets[fmt.Sprintf("facets[%s][]", f.Name)] = f.Data
|
||||
for i := 0; ; i++ {
|
||||
if _, set := newFacets[fmt.Sprintf("facets[%s][%d]", f.Name, i)]; set {
|
||||
continue
|
||||
}
|
||||
|
||||
newFacets[fmt.Sprintf("facets[%s][%d]", f.Name, i)] = f.Data
|
||||
break
|
||||
}
|
||||
}
|
||||
return &newFacets
|
||||
}
|
||||
|
25
pkg/eia/eia_reflection.go
Normal file
25
pkg/eia/eia_reflection.go
Normal file
@ -0,0 +1,25 @@
|
||||
package eia
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
eiaapi "gitea.libretechconsulting.com/50W/eia-api-go/api"
|
||||
)
|
||||
|
||||
func GetRoutes() []string {
|
||||
eiaClientInterface := new(eiaapi.ClientInterface)
|
||||
t := reflect.TypeOf(eiaClientInterface).Elem()
|
||||
|
||||
routes := make([]string, 0, t.NumMethod())
|
||||
|
||||
for i := 0; i < t.NumMethod(); i++ {
|
||||
method := t.Method(i)
|
||||
if strings.HasSuffix(method.Name, "Facet") {
|
||||
routes = append(routes, method.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return slices.Clip(routes)
|
||||
}
|
Reference in New Issue
Block a user