Let’s see what kind of operations we can do on primitive types like int or string.

Get the type

https://codeeval.dev/gist/c8f9e8354ada14fa3275d64be59f69cc

In real code you would handle all the types you care about.

Get the value

https://codeeval.dev/gist/bf99feb179bd74803a1998b966afc2b2

To minimize API surface, Int() returns int64 and works on all signed integer values (int8, int16, int32, int64).

UInt() methods returns uint64 and works on every unsigned integer values (uint8, uint16, uint32, uint64).

Trying to get integer value from value of incompatible type (like string) will panic.

To avoid panic you can first check the type with Kind().

All methods for retrieving the value:

Set the value

https://codeeval.dev/gist/5b7947a94d71566e04c1bc369dc65b33

As setInt and setStructField show, you can only change values if you start with a pointer to the value.