Skip to content

Validate enum types #421

Description

@lgfa29

Overview

Enum types often have specific values they can take. For example, DiskBackendType can only be "local" or "distributed". When receiving external input, it is useful to validate that a value is actually a valid enum variant, so the SDK could provide validation methods like:

func (v DiskBackendType) Valid() bool {
	switch v {
	case DiskBackendTypeLocal, DiskBackendTypeDistributed:
		return true
	}
	return false
}

Now users can just cast an input and have the SDK validate it:

t := oxide.DiskBackendType(input)
if !t.Valid() {
    return fmt.Errorf("invalid disk type")
}

Implementation details

No response

Anything else you would like to add?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementImprovements to the current code that are not breaking current functionalityGo SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions