c255739a93
- Explicitly specify all of the valid options for etcd - Remove the default name generation (ETCD_NAME is set by its unit file now) - Seperate the etcd config from Units() - Remove support for DISCOVERY_URL - Add YAML tags for the fields
27 lines
545 B
Go
27 lines
545 B
Go
package system
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
)
|
|
|
|
// dropinContents generates the contents for a drop-in unit given the config.
|
|
// The argument must be a struct from the 'config' package.
|
|
func dropinContents(e interface{}) string {
|
|
et := reflect.TypeOf(e)
|
|
ev := reflect.ValueOf(e)
|
|
|
|
var out string
|
|
for i := 0; i < et.NumField(); i++ {
|
|
if val := ev.Field(i).String(); val != "" {
|
|
key := et.Field(i).Tag.Get("env")
|
|
out += fmt.Sprintf("Environment=\"%s=%s\"\n", key, val)
|
|
}
|
|
}
|
|
|
|
if out == "" {
|
|
return ""
|
|
}
|
|
return "[Service]\n" + out
|
|
}
|