lang: Move StructTag const into lang/types

This constant value is strongly tied to the language, and little to do
with the engine. Move the definition into the lang/types package to
prevent circular imports between lang/types and engine/util.

Signed-off-by: Joe Groocock <me@frebib.net>
This commit is contained in:
Joe Groocock
2021-02-01 16:58:19 +00:00
parent 845d7ff188
commit c950568f1b
2 changed files with 6 additions and 3 deletions

View File

@@ -37,8 +37,6 @@ import (
) )
const ( const (
// StructTag is the key we use in struct field names for key mapping.
StructTag = "lang"
// DBusInterface is the dbus interface that contains genereal methods. // DBusInterface is the dbus interface that contains genereal methods.
DBusInterface = "org.freedesktop.DBus" DBusInterface = "org.freedesktop.DBus"
// DBusAddMatch is the dbus method to receive a subset of dbus broadcast // DBusAddMatch is the dbus method to receive a subset of dbus broadcast
@@ -133,7 +131,7 @@ func StructTagToFieldName(stptr interface{}) (map[string]string, error) {
field := st.Field(i) field := st.Field(i)
name := field.Name name := field.Name
// if !ok, then nothing is found // if !ok, then nothing is found
if alias, ok := field.Tag.Lookup(StructTag); ok { // golang 1.7+ if alias, ok := field.Tag.Lookup(types.StructTag); ok { // golang 1.7+
if val, exists := result[alias]; exists { if val, exists := result[alias]; exists {
return nil, fmt.Errorf("field `%s` uses the same key `%s` as field `%s`", name, alias, val) return nil, fmt.Errorf("field `%s` uses the same key `%s` as field `%s`", name, alias, val)
} }

View File

@@ -25,6 +25,11 @@ import (
"github.com/purpleidea/mgmt/util/errwrap" "github.com/purpleidea/mgmt/util/errwrap"
) )
const (
// StructTag is the key we use in struct field names for key mapping.
StructTag = "lang"
)
// Basic types defined here as a convenience for use with Type.Cmp(X). // Basic types defined here as a convenience for use with Type.Cmp(X).
var ( var (
TypeBool = NewType("bool") TypeBool = NewType("bool")