encore icon indicating copy to clipboard operation
encore copied to clipboard

Add a way to export enum-like types to generated clients

Open shixzie opened this issue 1 year ago • 0 comments

If you have a enum-like type

type Permissions int

const (
    PermAdmin Permissions = 1 << (iota + 1)

    PermListUsers Permissions = 1 << (iota +1)
    PermGetUser
    //. . .
)

and then generate a client encore gen client [project-id] -l [lang]

the generated client won't contain any of the available constants, I suggest a way to have an encore-type comment to tell the compiler to include the constants inside a certain block.

type Permissions int

//encore:gen [lang]     <-------------------
const (
    PermAdmin Permissions = 1 << (iota + 1)

    PermListUsers Permissions = 1 << (iota +1)
    PermGetUser
    //. . .
)

with the constants being included in all languages unless a language is specified.

shixzie avatar Nov 01 '22 21:11 shixzie