25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

29 satır
586B

  1. package config
  2. import (
  3. "os"
  4. "path/filepath"
  5. "strings"
  6. "gopkg.in/yaml.v3"
  7. )
  8. // Save writes the current config to an autosave file to preserve the original YAML formatting/comments.
  9. // Autosave path: <path without ext>.autosave<ext>
  10. func Save(path string, cfg Config) error {
  11. b, err := yaml.Marshal(cfg)
  12. if err != nil {
  13. return err
  14. }
  15. return os.WriteFile(autosavePath(path), b, 0o644)
  16. }
  17. func autosavePath(path string) string {
  18. ext := filepath.Ext(path)
  19. if ext == "" {
  20. return path + ".autosave"
  21. }
  22. base := strings.TrimSuffix(path, ext)
  23. return base + ".autosave" + ext
  24. }