Move the constants.go template to its own file.

This commit is contained in:
Geoff Hickey 2017-11-03 13:58:41 -04:00
parent 6e924657b1
commit f88cbd7a8e
3 changed files with 33 additions and 30 deletions

View File

@ -3,6 +3,7 @@
*
* To regenerate, run 'go generate' in internal/lvgen.
*/
package constants
// libvirt procedure identifiers and other enums

View File

@ -0,0 +1,28 @@
/*
* This file generated by internal/lvgen/generate.go. DO NOT EDIT BY HAND!
*
* To regenerate, run 'go generate' in internal/lvgen.
*/
package constants
// libvirt procedure identifiers and other enums
//
// These are libvirt procedure numbers which correspond to each respective
// API call between remote_internal driver and libvirtd. Each procedure is
// identified by a unique number which *may change in any future libvirt
// update*.
//
// Examples:
// REMOTE_PROC_CONNECT_OPEN = 1
// REMOTE_PROC_DOMAIN_DEFINE_XML = 11
// REMOTE_PROC_DOMAIN_MIGRATE_SET_MAX_SPEED = 207,
const (
// From enums:
{{range .Enums}}{{.Name}} = {{.Val}}
{{end}}
// From consts:
{{range .Consts}}{{.Name}} = {{.Val}}
{{end}}
)

View File

@ -112,35 +112,6 @@ func Generate(proto io.Reader) error {
}
func genGo(wr io.Writer) error {
// TODO: Move this someplace nice.
const consttempl = `/*
* This file generated by internal/lvgen/generate.go. DO NOT EDIT BY HAND!
*
* To regenerate, run 'go generate' in internal/lvgen.
*/
package constants
// libvirt procedure identifiers and other enums
//
// These are libvirt procedure numbers which correspond to each respective
// API call between remote_internal driver and libvirtd. Each procedure is
// identified by a unique number which *may change in any future libvirt
// update*.
//
// Examples:
// REMOTE_PROC_CONNECT_OPEN = 1
// REMOTE_PROC_DOMAIN_DEFINE_XML = 11
// REMOTE_PROC_DOMAIN_MIGRATE_SET_MAX_SPEED = 207,
const (
// From enums:
{{range .Enums}}{{.Name}} = {{.Val}}
{{end}}
// From consts:
{{range .Consts}}{{.Name}} = {{.Val}}
{{end}}
)
`
// Enums and consts from the protocol definition both become go consts in
// the generated code. We'll remove "REMOTE_" and then camel-case the
// name before making each one a go constant.
@ -151,7 +122,10 @@ const (
Gen.Consts[ix].Name = constNameTransform(en.Name)
}
t := template.Must(template.New("consts").Parse(consttempl))
t, err := template.ParseFiles("constants.tmpl")
if err != nil {
return err
}
if err := t.Execute(wr, Gen); err != nil {
return err
}