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.

45 lines
795 B
Go

5 months ago
package models
import (
5 months ago
"fmt"
"goftp/gormdb"
5 months ago
)
5 months ago
type Ip struct {
Id string `gorm:"primaryKey;size:20"`
Ip string `gorm:"size:30"`
Updatetime string `gorm:"size:30"`
}
5 months ago
func init() {
5 months ago
fmt.Println("Ip init()")
gormdb.DB.AutoMigrate(&Ip{})
5 months ago
}
5 months ago
// TableName 会将 User 的表名重写为 `user`
func (Ip) TableName() string {
return "ip"
5 months ago
}
5 months ago
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!")
5 months ago
}
5 months ago
}
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
5 months ago
}