kolConfig.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 kolConfig struct {
  8. maps map[string]*kolConfigRow
  9. }
  10. type kolConfigRow struct {
  11. Userid string // telegram用户唯一标识
  12. Mark string // 类型
  13. }
  14. func (p *kolConfig) Name() string {
  15. return "kolConfig"
  16. }
  17. func (p *kolConfig) Init() {
  18. p.maps = make(map[string]*kolConfigRow)
  19. }
  20. func (p *kolConfig) OnLoad(maps interface{}, _ bool) (int, error) {
  21. list, ok := maps.([]interface{})
  22. if !ok {
  23. return 0, mhayaError.Error("maps convert to []interface{} error.")
  24. }
  25. loadMaps := make(map[string]*kolConfigRow)
  26. for index, data := range list {
  27. loadConfig := &kolConfigRow{}
  28. err := DecodeData(data, loadConfig)
  29. if err != nil {
  30. mhayaLogger.Warnf("decode error. [row = %d, %v], err = %s", index+1, loadConfig, err)
  31. continue
  32. }
  33. loadMaps[loadConfig.Userid] = loadConfig
  34. }
  35. p.maps = loadMaps
  36. return len(list), nil
  37. }
  38. func (p *kolConfig) OnAfterLoad(_ bool) {
  39. }
  40. func (p *kolConfig) Get(pk string) (*kolConfigRow, bool) {
  41. i, found := p.maps[pk]
  42. return i, found
  43. }
  44. func (p *kolConfig) Contain(pk string) bool {
  45. _, found := p.Get(pk)
  46. return found
  47. }