Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Unanswered
piratf asked this question in Q&A
Discussion options

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.

You must be logged in to vote

Replies: 2 comments

Comment options

You can use Patch to override this part.

You must be logged in to vote
0 replies
Comment options

In order to use someapi it should be a struct.

Unfortunately Go’s reflect doesn’t support reflection on packages.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #235 on May 09, 2022 10:03.

AltStyle によって変換されたページ (->オリジナル) /