Skip to content

Instantly share code, notes, and snippets.

@bbasata
Last active July 5, 2025 15:50
Show Gist options
  • Select an option

  • Save bbasata/f70d08504e8cc827e812521aa606fbbe to your computer and use it in GitHub Desktop.

Select an option

Save bbasata/f70d08504e8cc827e812521aa606fbbe to your computer and use it in GitHub Desktop.
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