package models import ( "errors" ) type ResourceConfig struct { IpType int `gorm:"column:ipType" json:"ipType"` //0:本机ip,1:漂移ip ServiceIp string `gorm:"column:serviceIp" json:"serviceIp"` //外部服务ip Domain string `gorm:"column:domain" json:"domain"` //域名 FilePort int `gorm:"column:filePort" json:"filePort"` } const ( IpType_Local = 0 //本机 IpType_Drift = 1 //漂移 ) func (ResourceConfig) TableName() string { return "resource_config" } func (rc *ResourceConfig) Insert() bool { result := db.Table(rc.TableName()).Create(&rc) if result.Error !=nil { return false } if result.RowsAffected>0{ return true } return false } func (rc *ResourceConfig) Select()(err error) { result := db.Table(rc.TableName()).First(&rc) if result.Error!=nil{ return result.Error } if result.RecordNotFound() { return errors.New("not found") } return nil } func (rc *ResourceConfig) Update() bool{ result := db.Table(rc.TableName()).Update(&rc) if result.Error !=nil { return false } if result.RowsAffected>0{ return true } return false }