config.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package config
  2. import (
  3. "encoding/json"
  4. "os"
  5. )
  6. type Config struct {
  7. Engine struct {
  8. MainModule int
  9. }
  10. Blog struct {
  11. Pagination struct {
  12. Index int
  13. Category int
  14. }
  15. }
  16. Shop struct {
  17. Pagination struct {
  18. Index int
  19. Category int
  20. }
  21. Thumbnails struct {
  22. Thumbnail0 [3]int
  23. Thumbnail1 [3]int
  24. Thumbnail2 [3]int
  25. Thumbnail3 [3]int
  26. ThumbnailFull [3]int
  27. }
  28. Price struct {
  29. Format int
  30. Round int
  31. }
  32. Orders struct {
  33. RequiredFields struct {
  34. LastName int
  35. FirstName int
  36. MiddleName int
  37. MobilePhone int
  38. EmailAddress int
  39. Delivery int
  40. Comment int
  41. }
  42. NotifyEmail string
  43. Enabled int
  44. NewOrderEmailThemeCp string
  45. NewOrderEmailThemeUser string
  46. }
  47. }
  48. API struct {
  49. XML struct {
  50. Enabled int
  51. Name string
  52. Company string
  53. Url string
  54. }
  55. }
  56. SMTP struct {
  57. Host string
  58. Port int
  59. Login string
  60. Password string
  61. }
  62. }
  63. func ConfigNew() *Config {
  64. c := &Config{}
  65. c.configDefault()
  66. return c
  67. }
  68. func (this *Config) configDefault() {
  69. this.Engine.MainModule = 0
  70. this.Blog.Pagination.Index = 5
  71. this.Blog.Pagination.Category = 5
  72. this.Shop.Pagination.Index = 9
  73. this.Shop.Pagination.Category = 9
  74. this.Shop.Thumbnails.Thumbnail0[0] = 100
  75. this.Shop.Thumbnails.Thumbnail0[1] = 100
  76. this.Shop.Thumbnails.Thumbnail0[2] = 0
  77. this.Shop.Thumbnails.Thumbnail1[0] = 200
  78. this.Shop.Thumbnails.Thumbnail1[1] = 200
  79. this.Shop.Thumbnails.Thumbnail1[2] = 2
  80. this.Shop.Thumbnails.Thumbnail2[0] = 250
  81. this.Shop.Thumbnails.Thumbnail2[1] = 250
  82. this.Shop.Thumbnails.Thumbnail2[2] = 2
  83. this.Shop.Thumbnails.Thumbnail3[0] = 450
  84. this.Shop.Thumbnails.Thumbnail3[1] = 450
  85. this.Shop.Thumbnails.Thumbnail3[2] = 2
  86. this.Shop.Thumbnails.ThumbnailFull[0] = 1000
  87. this.Shop.Thumbnails.ThumbnailFull[1] = 800
  88. this.Shop.Thumbnails.ThumbnailFull[2] = 1
  89. this.Shop.Price.Format = 2
  90. this.Shop.Price.Round = 0
  91. this.Shop.Orders.RequiredFields.LastName = 1
  92. this.Shop.Orders.RequiredFields.FirstName = 1
  93. this.Shop.Orders.RequiredFields.MiddleName = 0
  94. this.Shop.Orders.RequiredFields.MobilePhone = 0
  95. this.Shop.Orders.RequiredFields.EmailAddress = 1
  96. this.Shop.Orders.RequiredFields.Delivery = 0
  97. this.Shop.Orders.RequiredFields.Comment = 0
  98. this.Shop.Orders.NotifyEmail = ""
  99. this.Shop.Orders.Enabled = 1
  100. this.Shop.Orders.NewOrderEmailThemeCp = "❤️ New order"
  101. this.Shop.Orders.NewOrderEmailThemeUser = "❤️ Thanks for your order"
  102. this.API.XML.Enabled = 0
  103. this.API.XML.Name = ""
  104. this.API.XML.Company = ""
  105. this.API.XML.Url = ""
  106. this.SMTP.Host = ""
  107. this.SMTP.Port = 587
  108. this.SMTP.Login = ""
  109. this.SMTP.Password = ""
  110. }
  111. func (this *Config) ConfigRead(file string) error {
  112. f, err := os.Open(file)
  113. if err != nil {
  114. return err
  115. }
  116. defer f.Close()
  117. dec := json.NewDecoder(f)
  118. return dec.Decode(this)
  119. }
  120. func (this *Config) ConfigWrite(file string) error {
  121. r, err := json.Marshal(this)
  122. if err != nil {
  123. return err
  124. }
  125. f, err := os.Create(file)
  126. if err != nil {
  127. return err
  128. }
  129. defer f.Close()
  130. _, err = f.WriteString(string(r))
  131. return err
  132. }