initDatabase init database
(dbPath string)
| 40 | |
| 41 | // initDatabase init database |
| 42 | func initDatabase(dbPath string) { |
| 43 | var err error |
| 44 | if _, err = os.Stat(dbPath); err != nil || os.IsNotExist(err) { |
| 45 | f, err := os.Create(dbPath) |
| 46 | if err != nil { |
| 47 | panic(err) |
| 48 | } |
| 49 | defer f.Close() |
| 50 | } |
| 51 | chessDB, err = gorm.Open("sqlite3", dbPath) |
| 52 | if err != nil { |
| 53 | panic(err) |
| 54 | } |
| 55 | chessDB.AutoMigrate(&elo{}, &pgn{}) |
| 56 | } |
| 57 | |
| 58 | // createELO 创建 ELO |
| 59 | func (s *chessDBService) createELO(uin int64, name string, rate int) error { |