zhangzengfei
2023-09-04 e8e536d1cb52d2126c8c7ce2ba1c7a76f7208678
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
}