()
| 166 | } |
| 167 | |
| 168 | func (opt *Plugin) Save() error { |
| 169 | if opt.saveTimer == nil { |
| 170 | var lock sync.Mutex |
| 171 | opt.saveTimer = time.AfterFunc(time.Second, func() { |
| 172 | lock.Lock() |
| 173 | defer lock.Unlock() |
| 174 | if opt.RawConfig.Modify == nil { |
| 175 | os.Remove(opt.settingPath()) |
| 176 | return |
| 177 | } |
| 178 | file, err := os.OpenFile(opt.settingPath(), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666) |
| 179 | if err == nil { |
| 180 | defer file.Close() |
| 181 | err = yaml.NewEncoder(file).Encode(opt.RawConfig.Modify) |
| 182 | } |
| 183 | if err == nil { |
| 184 | opt.Info("config saved") |
| 185 | } |
| 186 | }) |
| 187 | } else { |
| 188 | opt.saveTimer.Reset(time.Second) |
| 189 | } |
| 190 | return nil |
| 191 | } |
| 192 | |
| 193 | func (opt *Plugin) AssignPubConfig(puber *Publisher) { |
| 194 | if puber.Config == nil { |
no test coverage detected