ETCD后台服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.9 KiB

3 years ago
  1. package models
  2. import (
  3. "encoding/json"
  4. "github.com/jinzhu/gorm"
  5. )
  6. // ServiceLst 角色表
  7. type ServiceLst struct {
  8. ServicePath string `gorm:"pk int 'service_path'" json:"service_path"`
  9. // 节点路径 需要前端拼写 规则 /services/ + 输入的IP + / + 名字 比如 /services/127.0.0.1/ETL
  10. ServiceName string `gorm:"varchar(255) 'service_name' not null" json:"service_name"` // 名字
  11. ServiceIp string `gorm:"varchar(255) 'service_ip' not null" json:"service_ip"`// ip
  12. State int `gorm:"int 'state' not null" json:"state"`// 状态 0未启动 1启动 2暂停
  13. ExePath string `gorm:"varchar(255) 'exe_path' not null" json:"exe_path"` // exe路径 C:/backend/LAPP_ETL/etl.exe
  14. Info string `gorm:"varchar(255) 'info' not null" json:"info"`// 备注
  15. }
  16. // TableName 获取表名
  17. func (ServiceLst) TableName() string {
  18. return gorm.DefaultTableNameHandler(nil, "ServiceLst")
  19. }
  20. // All 查询全部角色
  21. func (m *ServiceLst) All() (list []*ServiceLst, err error) {
  22. err = client.Table(m.TableName()).Scan(&list).Error
  23. return
  24. }
  25. // Save 保存
  26. func (m *ServiceLst) Save() (err error) {
  27. err = client.Table(m.TableName()).Save(m).Error
  28. return
  29. }
  30. // Del 删除
  31. func (m *ServiceLst) Del(ServicePath string) (err error) {
  32. err = client.Table(m.TableName()).Where("service_path = ?", ServicePath).Delete(m).Error
  33. return
  34. }
  35. // Insert 添加
  36. func (m *ServiceLst) Insert() (err error) {
  37. err = client.Create(m).Error
  38. return
  39. }
  40. // Update 修改
  41. func (m *ServiceLst) Update() (err error) {
  42. edit := make(map[string]interface{}, 0)
  43. js, _ := json.Marshal(m)
  44. json.Unmarshal(js, &edit)
  45. err = client.Model(new(ServiceLst)).Where("service_path = ?", m.ServicePath).Updates(edit).Error
  46. return
  47. }
  48. func (m *ServiceLst) FindById(ServicePath string) (one *ServiceLst, err error) {
  49. one = new(ServiceLst)
  50. err = client.Model(m).Where("service_path = ?", ServicePath).Find(one).Error
  51. return
  52. }