From c950568f1b99a30e5c488f9731fe7d7ad3cb868e Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Mon, 1 Feb 2021 16:58:19 +0000 Subject: [PATCH] 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 --- engine/util/util.go | 4 +--- lang/types/type.go | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/engine/util/util.go b/engine/util/util.go index 19b2eaa5..8a1fe9d3 100644 --- a/engine/util/util.go +++ b/engine/util/util.go @@ -37,8 +37,6 @@ import ( ) 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 = "org.freedesktop.DBus" // 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) name := field.Name // 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 { return nil, fmt.Errorf("field `%s` uses the same key `%s` as field `%s`", name, alias, val) } diff --git a/lang/types/type.go b/lang/types/type.go index e1ac1065..7e978f5e 100644 --- a/lang/types/type.go +++ b/lang/types/type.go @@ -25,6 +25,11 @@ import ( "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). var ( TypeBool = NewType("bool")