set generated strings to the line comment values

- keeps the name consistent with what is being looked up in the map
This commit is contained in:
Matthew Stobbs 2024-09-24 17:10:39 -06:00
parent 4d6d785924
commit c8ff16ec22
4 changed files with 17 additions and 14 deletions

View File

@ -1,5 +1,5 @@
/* /*
Copyright © 2024 NAME HERE <EMAIL ADDRESS> Copyright © 2024 Matthew Stobbs <matthew@stobbs.ca>
*/ */
package cmd package cmd

View File

@ -18,7 +18,7 @@ type ReservationV4 struct {
func ReserveV4MacAddr(identifierType string, identifier string, addr string, hostname string, subnet int) *ReservationV4 { func ReserveV4MacAddr(identifierType string, identifier string, addr string, hostname string, subnet int) *ReservationV4 {
r := &ReservationV4{ r := &ReservationV4{
IdentifierType: types.Lookup(identifierType), IdentifierType: types.LookupIdentifier(identifierType),
SubnetID: subnet, SubnetID: subnet,
Identifier: identifier, Identifier: identifier,
Ipv4: addr, Ipv4: addr,

View File

@ -1,4 +1,4 @@
// Code generated by "stringer -type=Identifier"; DO NOT EDIT. // Code generated by "stringer -linecomment -type=Identifier"; DO NOT EDIT.
package types package types
@ -17,12 +17,12 @@ func _() {
} }
const ( const (
_Identifier_name_0 = "HwAddressDuIDCircuitIdClientIdFlexId" _Identifier_name_0 = "hwaddrduidcircuit-idclient-idflex-id"
_Identifier_name_1 = "Invalid" _Identifier_name_1 = "invalid"
) )
var ( var (
_Identifier_index_0 = [...]uint8{0, 9, 13, 22, 30, 36} _Identifier_index_0 = [...]uint8{0, 6, 10, 20, 29, 36}
) )
func (i Identifier) String() string { func (i Identifier) String() string {

View File

@ -2,22 +2,25 @@ package types
import "strings" import "strings"
// Identifier as defined by the kea database entries. Values are hardcoded from
// a running instance of schema version 22.1
type Identifier int type Identifier int
func (i Identifier) Int() int { func (i Identifier) Int() int {
return int(i) return int(i)
} }
//go:generate stringer -type=Identifier //go:generate stringer -linecomment -type=Identifier
const ( const (
HwAddress Identifier = 0 HwAddress Identifier = 0 // hwaddr
DuID Identifier = 1 DuID Identifier = 1 // duid
CircuitId Identifier = 2 CircuitId Identifier = 2 // circuit-id
ClientId Identifier = 3 ClientId Identifier = 3 // client-id
FlexId Identifier = 4 FlexId Identifier = 4 // flex-id
Invalid Identifier = 255 Invalid Identifier = 255 // invalid
) )
// TODO: is there a generator that can create the lookup table for me?
var types = map[string]Identifier{ var types = map[string]Identifier{
"macaddr": HwAddress, "macaddr": HwAddress,
"hwaddr": HwAddress, "hwaddr": HwAddress,
@ -28,7 +31,7 @@ var types = map[string]Identifier{
"invalid": Invalid, "invalid": Invalid,
} }
func Lookup(rtype string) Identifier { func LookupIdentifier(rtype string) Identifier {
rtype = strings.ToLower(rtype) rtype = strings.ToLower(rtype)
if t, ok := types[rtype]; ok == true { if t, ok := types[rtype]; ok == true {
return t return t