package models
|
|
type Operations struct {
|
Method string `gorm:"column:method;not null;default:''" json:"method"` //请求方法,POST,GET...
|
Path string `gorm:"column:path;not null;default:''" json:"path"` //请求路径,如/data/api-u/sys/login
|
Name string `gorm:"column:name;not null;default:''" json:"name"` //接口名称,如/data/api-u/sys/login
|
Exclude bool `gorm:"column:exclude;not null;default:0;" json:"exclude"` //是否排除
|
Module string `gorm:"column:module;not null;default:0;" json:"module"` //所属模块
|
ApiEnable bool `gorm:"column:api_enable;not null;default:0;" json:"api_enable"` //是否开启API
|
}
|
|
func (Operations) TableName() string {
|
return "t_operations"
|
}
|
|
func (a *Operations) FindAll(module string) (rows []Operations, err error) {
|
if err := db.Where("module = ?", module).Table(a.TableName()).Find(&rows).Error; err != nil {
|
return nil, err
|
}
|
|
return rows, nil
|
}
|
|
func (a *Operations) Insert() bool {
|
count := 0
|
result := db.Table(a.TableName()).Where("path=?", a.Path).Count(&count)
|
if count > 0 {
|
return true
|
}
|
result = db.Table(a.TableName()).Create(&a)
|
if result.Error !=nil {
|
return false
|
}
|
return result.RowsAffected>0
|
}
|