Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether the value is of type iota constant in Golang?

Tags:

People also ask

What type is iota Golang?

Iota is an identifier which is used with constant and which can simplify constant definitions that use auto increment numbers. The IOTA keyword represent integer constant starting from zero. So essentially it can be used to create effective constant in Go .

Is iota a constant?

Iota in Go is used to represent constant increasing sequences. When repeated in a constant, its value gets incremented after each specification.

How do you declare a constant in Golang?

To declare a constant and give it a name, the const keyword is used. Constants cannot be declared using the := syntax.

What is enum go?

An enum, or enumerator, is a data type consisting of a set of named constant values. Enums are a powerful feature with a wide range of uses. However, in Golang, they're implemented quite differently than most other programming languages.


I have the following type defined using iota in Golang.

type StatusType int

const (
    PENDING StatusType = iota
    APPROVED
    REJECTED
)

I want to restrict the value passed in REST-API to the StatusType. Such that the value should not exceed 0,1,2.