PlatformConfig.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // this file is auto create by program, don't edit manually
  2. package data
  3. import (
  4. mhayaError "github.com/mhaya/error"
  5. mhayaLogger "github.com/mhaya/logger"
  6. )
  7. type platformConfig struct {
  8. maps map[int]*PlatformConfigRow
  9. }
  10. type PlatformConfigRow struct {
  11. ID int // 平台ID
  12. Name string // 名称
  13. Enable int //是否开启
  14. }
  15. func (p *platformConfig) Name() string {
  16. return "PlatformConfig"
  17. }
  18. func (p *platformConfig) Init() {
  19. p.maps = make(map[int]*PlatformConfigRow)
  20. }
  21. func (p *platformConfig) OnLoad(maps interface{}, _ bool) (int, error) {
  22. list, ok := maps.([]interface{})
  23. if !ok {
  24. return 0, mhayaError.Error("maps convert to []interface{} error.")
  25. }
  26. loadMaps := make(map[int]*PlatformConfigRow)
  27. for index, data := range list {
  28. loadConfig := &PlatformConfigRow{}
  29. err := DecodeData(data, loadConfig)
  30. if err != nil {
  31. mhayaLogger.Warnf("decode error. [row = %d, %v], err = %s", index+1, loadConfig, err)
  32. continue
  33. }
  34. loadMaps[loadConfig.ID] = loadConfig
  35. }
  36. p.maps = loadMaps
  37. return len(list), nil
  38. }
  39. func (p *platformConfig) OnAfterLoad(_ bool) {
  40. }
  41. func (p *platformConfig) GatMap() map[int]*PlatformConfigRow {
  42. var ret = make(map[int]*PlatformConfigRow)
  43. for _, v := range p.maps {
  44. if v.Enable == 1 {
  45. ret[v.ID] = v
  46. }
  47. }
  48. return ret
  49. }
  50. func (p *platformConfig) Get(pk int) (*PlatformConfigRow, bool) {
  51. i, found := p.maps[pk]
  52. return i, found
  53. }
  54. func (p *platformConfig) Contain(pk int) bool {
  55. _, found := p.Get(pk)
  56. return found
  57. }