item.go 812 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package conv
  2. import (
  3. "encoding/json"
  4. "gadmin/package/gmdata"
  5. "gadmin/utility"
  6. "github.com/sirupsen/logrus"
  7. )
  8. var Item = new(cItem)
  9. type cItem struct {
  10. version string
  11. lst []*gmdata.Material
  12. }
  13. func (j *cItem) Extract(version string) {
  14. logrus.Info("cItem Extract...")
  15. j.setVersion(version).convert().save()
  16. }
  17. func (j *cItem) setVersion(version string) *cItem {
  18. j.version = version
  19. return j
  20. }
  21. func (j *cItem) convert() *cItem {
  22. b, err := GetUrlBody(j.version, "Item.json")
  23. if err != nil {
  24. logrus.Fatalf("GetUrlBody err:%+v", err)
  25. }
  26. var list []*gmdata.Material
  27. if err = json.Unmarshal(b, &list); err != nil {
  28. logrus.Fatalf("err=%v", err)
  29. }
  30. j.lst = list
  31. return j
  32. }
  33. func (j *cItem) save() {
  34. filePath := utility.LocalJsonPath(j.version, "item.json")
  35. SaveJsonPath(filePath, j.lst)
  36. }