mirror of https://github.com/EasyDarwin/EasyDarwin
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
597 B
31 lines
597 B
package models
|
|
|
|
import (
|
|
"github.com/penggy/EasyGoLib/db"
|
|
"github.com/penggy/EasyGoLib/utils"
|
|
)
|
|
|
|
func Init() (err error) {
|
|
err = db.Init()
|
|
if err != nil {
|
|
return
|
|
}
|
|
db.SQLite.AutoMigrate(User{}, Stream{})
|
|
count := 0
|
|
sec := utils.Conf().Section("http")
|
|
defUser := sec.Key("default_username").MustString("admin")
|
|
defPass := sec.Key("default_password").MustString("admin")
|
|
db.SQLite.Model(User{}).Where("username = ?", defUser).Count(&count)
|
|
if count == 0 {
|
|
db.SQLite.Create(&User{
|
|
Username: defUser,
|
|
Password: utils.MD5(defPass),
|
|
})
|
|
}
|
|
return
|
|
}
|
|
|
|
func Close() {
|
|
db.Close()
|
|
}
|