GetConfig gets the remote config and save it to the path, also return the content.
(info configf.ConfigInfo)
| 112 | |
| 113 | // GetConfig gets the remote config and save it to the path, also return the content. |
| 114 | func (c *RConf) getConfig(info configf.ConfigInfo) (config string, err error) { |
| 115 | var set string |
| 116 | if v, ok := c.comm.GetProperty("setdivision"); ok { |
| 117 | set = v |
| 118 | } |
| 119 | info.Setdivision = set |
| 120 | ret, err := c.tc.LoadConfigByInfo(&info, &config, c.comm.Client.Context()) |
| 121 | if err != nil { |
| 122 | return config, err |
| 123 | } |
| 124 | if ret != 0 { |
| 125 | return config, fmt.Errorf("ret %d", ret) |
| 126 | } |
| 127 | err = saveFile(c.path, info.Filename, config) |
| 128 | if err != nil { |
| 129 | return config, err |
| 130 | } |
| 131 | return config, nil |
| 132 | } |
| 133 | |
| 134 | func saveFile(path string, filename string, content string) error { |
| 135 | err := os.WriteFile(fmt.Sprintf("%s/%s", path, filename), []byte(content), 0644) |
no test coverage detected