I need to have lookup strings which might be distinctive at compile time for the native package deal.
I’ve the next :
sort Key int
const (
txt Key = iota + 1
greeting
// cannot add txt once more right here - **compile** will fail
newKey // not but used
)
var id map[Key]string
func init() {
id = map[Key]string{txt: "txt", greeting: "greeting"}
// cannot add txt: "something" since **compile** will fail
// may add newKey: "txt" - however this requires **deliberate foolishness**
library.NewBlockType("server.log", "misc", setup).Add(
textual content.New("Log "),
stringinput.New(id[greeting]).Empty("greeting"),
// cannot cease reuse of id incorrectly, e.g. by :
// stringinput.New(id[greeting]).Empty("duplicate greeting"),
// nevertheless the generated UI is seen so this needs to be very apparent
textual content.New(" "),
stringinput.New(id[txt]).Empty("message"))
}
Right here Secret is used to restrict string lookup on the const values solely
This presents some (however not all) detection of copy/paste errors on compilation.
Any ideas/strategies please
I’m additionally if that is idiomatic code/sample or seen/used elsewhere…