Improve route inspection
This commit is contained in:
@ -41,6 +41,34 @@ var defaultMethodSubs = MethodSubs{
|
||||
},
|
||||
}
|
||||
|
||||
//go:generate stringer -type=RouteType
|
||||
type RouteType uint8
|
||||
|
||||
const (
|
||||
RouteTypeRoutes RouteType = iota
|
||||
RouteTypeFinal
|
||||
RouteTypeFacets
|
||||
RouteTypeNotFound
|
||||
RouteTypeError
|
||||
)
|
||||
|
||||
// Checks the route to see if it returns a facet, a list of routes,
|
||||
// or a final route
|
||||
func (client *Client) GetRouteType(ctx context.Context, route string, subs *MethodSubs) (RouteType, error) {
|
||||
if facets, err := client.GetFacets(ctx, route, subs); err == nil && facets != nil {
|
||||
return RouteTypeFacets, nil
|
||||
}
|
||||
|
||||
finalRoute, routes, err := client.GetRoutesOrFinalRoute(ctx, route, subs)
|
||||
if finalRoute != nil {
|
||||
return RouteTypeFinal, nil
|
||||
} else if routes != nil {
|
||||
return RouteTypeRoutes, nil
|
||||
}
|
||||
|
||||
return RouteTypeNotFound, err
|
||||
}
|
||||
|
||||
// Retrieve information for a named Route (e.g. GetAeoV2Route1)
|
||||
// Returns a *eiaapi.Routes if this is not a final route, otherwise returns
|
||||
// a final route response
|
||||
|
27
pkg/eia/routetype_string.go
Normal file
27
pkg/eia/routetype_string.go
Normal file
@ -0,0 +1,27 @@
|
||||
// Code generated by "stringer -type=RouteType"; DO NOT EDIT.
|
||||
|
||||
package eia
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[RouteTypeRoutes-0]
|
||||
_ = x[RouteTypeFinal-1]
|
||||
_ = x[RouteTypeFacets-2]
|
||||
_ = x[RouteTypeNotFound-3]
|
||||
_ = x[RouteTypeError-4]
|
||||
}
|
||||
|
||||
const _RouteType_name = "RouteTypeRoutesRouteTypeFinalRouteTypeFacetsRouteTypeNotFoundRouteTypeError"
|
||||
|
||||
var _RouteType_index = [...]uint8{0, 15, 29, 44, 61, 75}
|
||||
|
||||
func (i RouteType) String() string {
|
||||
if i >= RouteType(len(_RouteType_index)-1) {
|
||||
return "RouteType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _RouteType_name[_RouteType_index[i]:_RouteType_index[i+1]]
|
||||
}
|
Reference in New Issue
Block a user