using new config package
This commit is contained in:
parent
41fe3edc93
commit
92d7a71f12
23
save.go
23
save.go
|
@ -19,7 +19,6 @@ func ConfigSave(pb proto.Message) error {
|
||||||
return ErrProtoFilename
|
return ErrProtoFilename
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal()
|
|
||||||
s := prototext.Format(pb)
|
s := prototext.Format(pb)
|
||||||
|
|
||||||
dir, name := filepath.Split(fullname)
|
dir, name := filepath.Split(fullname)
|
||||||
|
@ -35,6 +34,28 @@ func ConfigSave(pb proto.Message) error {
|
||||||
return configWrite(fullname, []byte(s))
|
return configWrite(fullname, []byte(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConfigSaveWithHeader(pb proto.Message, header string) error {
|
||||||
|
// get pb.Filename if it is there in the .proto file
|
||||||
|
fullname, ok := GetFilename(pb)
|
||||||
|
if !ok {
|
||||||
|
return ErrProtoFilename
|
||||||
|
}
|
||||||
|
|
||||||
|
s := prototext.Format(pb)
|
||||||
|
|
||||||
|
dir, name := filepath.Split(fullname)
|
||||||
|
if name == "" {
|
||||||
|
return fmt.Errorf("filename was blank")
|
||||||
|
}
|
||||||
|
err := os.MkdirAll(dir, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("ConfigSave() filename=%s %d\n", fullname, len(s))
|
||||||
|
return configWrite(fullname, []byte(header+s))
|
||||||
|
}
|
||||||
|
|
||||||
func configWrite(fullname string, data []byte) error {
|
func configWrite(fullname string, data []byte) error {
|
||||||
|
|
||||||
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
|
|
Loading…
Reference in New Issue