Skip to content

How to compare enum which type is from another package? #235

@piratf

Description

@piratf

For example:

import (
    someapi "xxxx"
)

type SomeStruct struct {
    Type someapi.SomeType	
}

The expression I want to execute is to validate the value of an enumeration.

someStruct.Type == someapi.SomeType_TypeOne

errors encountered:
failed: unknown name someapi
This error is easy to understand, but I don't know how to import the "someapi" package into expr context.

I tried to convert the type to int32, but it didn't work

int32(someStruct.Type.Number())==1

failed: unknown func int32

The only solution I've found so far is to convert to string

someStruct.Type.String()=="Day"

This looks more expensive, so I want to seek the best practice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions