You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
package models
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"goftp/gormdb"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Ip struct {
|
|
|
|
|
Id string `gorm:"primaryKey;size:20"`
|
|
|
|
|
Ip string `gorm:"size:30"`
|
|
|
|
|
Updatetime string `gorm:"size:30"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
fmt.Println("Ip init()")
|
|
|
|
|
gormdb.DB.AutoMigrate(&Ip{})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TableName 会将 User 的表名重写为 `user`
|
|
|
|
|
func (Ip) TableName() string {
|
|
|
|
|
return "ip"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SaveIp(ip *Ip) {
|
|
|
|
|
result := gormdb.DB.Create(&ip)
|
|
|
|
|
if result.Error != nil {
|
|
|
|
|
fmt.Println("Failed to create Ip:", result.Error)
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Println("Ip created successfully!")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetIpById(id string) string {
|
|
|
|
|
var ip Ip
|
|
|
|
|
gormdb.DB.First(&ip, id)
|
|
|
|
|
return ip.Ip
|
|
|
|
|
|
|
|
|
|
//ipModel := new(Ip)
|
|
|
|
|
//err := orm.NewOrm().QueryTable(new(Ip)).Filter("id", id).One(ipModel)
|
|
|
|
|
//if err != nil {
|
|
|
|
|
// return ""
|
|
|
|
|
//}
|
|
|
|
|
//return ipModel.Ip
|
|
|
|
|
}
|