//Define the type.
type metafieldType string
//Define the possible values.
const (
metafieldTypeBoolean metafieldType = "boolean"
metafieldTypeColor metafieldType = "color"
metafieldTypeSingleLineTextField metafieldType = "single_line_text_field"
//...
)
//Metafield type is changed to use the new type.
type Metafield struct {
//...
Type metafieldType `json:"type,omitempty"`
//...
}
Why? This makes it so code editors will suggest only possible values for this field. Right now, any string can be provided regardless of if it is a value Shopify will accept. This is really just to prevent typos.
For legacy purposes, string values will still be accepted when assigning to the Type field without issue. So this shouldn't break any existing code.
Would it be worth defining constants, and an associated type, for struct fields with well-known & defined possible values?
For example, the
Metafield
type has aType
field. TheType
field can only be one of the defined values listed at https://shopify.dev/docs/apps/custom-data/metafields/types#supported-types.I propose something like the following:
Why? This makes it so code editors will suggest only possible values for this field. Right now, any string can be provided regardless of if it is a value Shopify will accept. This is really just to prevent typos.
For legacy purposes,
string
values will still be accepted when assigning to theType
field without issue. So this shouldn't break any existing code.