Move the constants.go template to its own file.
This commit is contained in:
		| @@ -3,6 +3,7 @@ | |||||||
|  * |  * | ||||||
|  * To regenerate, run 'go generate' in internal/lvgen. |  * To regenerate, run 'go generate' in internal/lvgen. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| package constants | package constants | ||||||
|  |  | ||||||
| // libvirt procedure identifiers and other enums | // libvirt procedure identifiers and other enums | ||||||
|   | |||||||
							
								
								
									
										28
									
								
								internal/lvgen/constants.tmpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								internal/lvgen/constants.tmpl
									
									
									
									
									
										Normal 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}} | ||||||
|  | ) | ||||||
| @@ -112,35 +112,6 @@ func Generate(proto io.Reader) error { | |||||||
| } | } | ||||||
|  |  | ||||||
| func genGo(wr io.Writer) 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 | 	// Enums and consts from the protocol definition both become go consts in | ||||||
| 	// the generated code. We'll remove "REMOTE_" and then camel-case the | 	// the generated code. We'll remove "REMOTE_" and then camel-case the | ||||||
| 	// name before making each one a go constant. | 	// name before making each one a go constant. | ||||||
| @@ -151,7 +122,10 @@ const ( | |||||||
| 		Gen.Consts[ix].Name = constNameTransform(en.Name) | 		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 { | 	if err := t.Execute(wr, Gen); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user