Last active
July 5, 2025 15:50
-
-
Save bbasata/f70d08504e8cc827e812521aa606fbbe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "unsafe" | |
| ) | |
| func main() { | |
| fmt.Println("Sizeof(Variant{}) =", unsafe.Sizeof(Variant{}), "bytes") | |
| for item := range items { | |
| if item.StringValue() != nil { | |
| fmt.Println("Found a string value:", *item.StringValue()) | |
| } | |
| } | |
| } | |
| func items(push func(Variant) bool) { | |
| push(Int32(1)) | |
| push(String("hat")) | |
| push(String("bat")) | |
| push(Int32(3000)) | |
| } | |
| type Variant struct { | |
| stringValue *string | |
| int32Value *int32 | |
| } | |
| func String(value string) Variant { | |
| return Variant{stringValue: &value} | |
| } | |
| func Int32(value int32) Variant { | |
| return Variant{int32Value: &value} | |
| } | |
| func (t Variant) StringValue() *string { | |
| return t.stringValue | |
| } | |
| func (t Variant) Int32Value() *int32 { | |
| return t.int32Value | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment