init_test_data.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import (
  3. "strings"
  4. "github.com/shopspring/decimal"
  5. "github.com/sirupsen/logrus"
  6. "github.com/spf13/viper"
  7. "gogs.daxia.dev/huanan/pkg.daxia.dev/db"
  8. "nn.daxia.dev/model"
  9. )
  10. func main() {
  11. viper.Set("gormlog", true)
  12. viper.AddConfigPath("conf")
  13. viper.AddConfigPath("configs/qznn")
  14. viper.SetConfigName("config")
  15. viper.SetConfigType("yaml")
  16. viper.AutomaticEnv()
  17. viper.SetEnvPrefix("web")
  18. viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
  19. // 从环境变量总读取
  20. err := viper.ReadInConfig()
  21. if err != nil {
  22. logrus.Fatal(err)
  23. }
  24. db.InitTest()
  25. createUser()
  26. //createDBTable()
  27. }
  28. func createUser() {
  29. var err error
  30. err = db.GetDB().Create(&model.User{
  31. Pid: 0,
  32. Name: "test1",
  33. Nickname: "test1",
  34. Mobile: "1888888888",
  35. AccountType: 0,
  36. Status: 1,
  37. Balance: decimal.NewFromInt(100),
  38. HeadImg: "",
  39. Token: "8bc766ae05120ad091e8e52c29e23c1e",
  40. City: "shenzhen",
  41. ParentTree: "group",
  42. ParentTreeStr: "",
  43. }).Error
  44. if err != nil {
  45. logrus.Fatal(err)
  46. }
  47. }