package repository import ( "gorm.io/gorm" "wireguard-dashboard/client" "wireguard-dashboard/http/param" "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) { return r.Model(&entity.Server{}).Create(&ent).Error } // Update // @description: 更新服务端信息 // @receiver r // @param p // @return err func (r server) Update(p param.SaveServer) (err error) { update := map[string]any{ "ip_scope": p.IpScope, "listen_port": p.ListenPort, "post_up_script": p.PostUpScript, "pre_down_script": p.PreDownScript, "post_down_script": p.PostDownScript, } return r.Model(&entity.Server{}).Where("id = ?", p.Id).Updates(&update).Error }