When I though what format shall I use as a program configuration file, I got to know CUE lang.
I could use comments, conditional branch and loop processing, It seems good. And look like also can call event Go lang library!? It may be too many functions for just use as a configuration file…
For now, I touched it.
Install.
$ go install cuelang.org/go/cmd/cue@latest
$ cue version
cue version v0.4.3 linux/arm64
Used such as the following file,
$ cat persons.cue
#Person: {
name: string
level: int & >=1 & <=10
role: "Administrator" | *"Developer" // Developer is the default
}
alicee: #Person
alicee: {name: "Alice", level: 6 }
bobsmith: #Person
bobsmith: {name: "Bob", level: 5 }
carryz: #Person
bobsmith: {name: "Carry", level: 5 }
Administrators: [ "alicee" ]
for person in Administrators {
"\(person)": {
role: "Administrator"
}
}
the evaluation result was:
$ cue eval persons.cue
#Person: {
name: string
level: uint & >=1 & <=10
role: "Developer"
}
alicee: {
name: "Alice"
level: 6
role: "Administrator"
}
bobsmith: {
name: "Bob"
level: 5
role: "Developer"
}
carryz: {
name: "Carry"
level: 5
role: "Developer"
}
Administrators: ["alicee"]