file_config.go 936 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package config
  2. import (
  3. "eta_mini_ht_api/common/contants"
  4. "sync"
  5. )
  6. var (
  7. fileOnce sync.Once
  8. fileConfig *FileConfig
  9. )
  10. type FileOpts struct {
  11. Notice string
  12. Disclaimer string
  13. PublicKey string
  14. }
  15. type FileConfig struct {
  16. BaseConfig
  17. opts FileOpts
  18. }
  19. func (f *FileConfig) GetNotice() string {
  20. return f.opts.Notice
  21. }
  22. func (f *FileConfig) GetPublicKey() string {
  23. return f.opts.PublicKey
  24. }
  25. func (f *FileConfig) GetDisclaimer() string {
  26. return f.opts.Disclaimer
  27. }
  28. func (f *FileConfig) InitConfig() {
  29. opts := FileOpts{
  30. Notice: f.GetString("url"),
  31. Disclaimer: f.GetString("driver"),
  32. PublicKey: f.GetString("publicKey"),
  33. }
  34. f.opts = opts
  35. }
  36. func NewFileConfig() Config {
  37. if dbConfig == nil {
  38. fileOnce.Do(func() {
  39. fileConfig = &FileConfig{
  40. BaseConfig: BaseConfig{prefix: contants.FILE},
  41. opts: FileOpts{},
  42. }
  43. })
  44. }
  45. return fileConfig
  46. }
  47. func init() {
  48. Register(contants.FILE, NewFileConfig)
  49. }