package db import ( "applet/app/db/model" "applet/app/utils/logx" "xorm.io/xorm" ) type AdminDb struct { Db *xorm.Engine `json:"db"` } func (adminDb *AdminDb) Set() { // set方法 adminDb.Db = Db } func (adminDb *AdminDb) GetAdmin(id int) (m *model.Admin, err error) { m = new(model.Admin) has, err := adminDb.Db.Where("adm_id =?", id).Get(m) if err != nil { return nil, logx.Error(err) } if has == false { return nil, nil } return m, nil } func (adminDb *AdminDb) GetAdminByUserName(userName string) (m *model.Admin, err error) { m = new(model.Admin) has, err := adminDb.Db.Where("username =?", userName).Get(m) if err != nil { return nil, logx.Error(err) } if has == false { return nil, nil } return m, nil }