You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

db.go 803B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package system
  4. import (
  5. "code.gitea.io/gitea/models/system"
  6. "code.gitea.io/gitea/modules/json"
  7. "github.com/yuin/goldmark/util"
  8. )
  9. // DBStore can be used to store app state items in local filesystem
  10. type DBStore struct{}
  11. // Get reads the state item
  12. func (f *DBStore) Get(item StateItem) error {
  13. content, err := system.GetAppStateContent(item.Name())
  14. if err != nil {
  15. return err
  16. }
  17. if content == "" {
  18. return nil
  19. }
  20. return json.Unmarshal(util.StringToReadOnlyBytes(content), item)
  21. }
  22. // Set saves the state item
  23. func (f *DBStore) Set(item StateItem) error {
  24. b, err := json.Marshal(item)
  25. if err != nil {
  26. return err
  27. }
  28. return system.SaveAppStateContent(item.Name(), util.BytesToReadOnlyString(b))
  29. }