Skip to content

Instantly share code, notes, and snippets.

package util
import (
"fmt"
"reflect"
"strings"
)
// Use this function to ensure some struct properly inited. Tag `zero_ok`
// marks that this field can have zero value.
@man0xff
man0xff / _x-macro.go
Last active April 9, 2022 06:22
Universal way to generate some Go code from single description (like X-Macro in C).
// I was looking for some substitution for X-Macro C preprocessor trick (https://en.wikipedia.org/wiki/X_Macro).
// And this method copes with a problem in a lot more straightforward and powerful way.
// X-Macro version in C:
//
// #define SOME_STATES(_) \
// _(SOME_STATE_NEW, "NEW") \
// _(SOME_STATE_IN_PROGRESS, "IN_PROGRESS") \
// _(SOME_STATE_DONE, "DONE")
//