42 lines
744 B
Go
42 lines
744 B
Go
package repository
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"wireguard-dashboard/client"
|
|
"wireguard-dashboard/model/entity"
|
|
"wireguard-dashboard/model/vo"
|
|
)
|
|
|
|
type server struct {
|
|
*gorm.DB
|
|
}
|
|
|
|
func Server() server {
|
|
return server{
|
|
client.DB,
|
|
}
|
|
}
|
|
|
|
// GetServer
|
|
// @description: 获取服务端信息
|
|
// @receiver r
|
|
// @return data
|
|
// @return err
|
|
func (r server) GetServer() (data *vo.Server, err error) {
|
|
err = r.Model(&entity.Server{}).First(&data).Error
|
|
return
|
|
}
|
|
|
|
// Save
|
|
// @description: 新增/更新服务端信息
|
|
// @receiver r
|
|
// @param ent
|
|
// @return err
|
|
func (r server) Save(ent *entity.Server) (err error) {
|
|
if ent.Id != "" {
|
|
return r.Model(&entity.Server{}).Updates(&ent).Error
|
|
}
|
|
|
|
return r.Model(&entity.Server{}).Create(&ent).Error
|
|
}
|