group.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package cluster
  2. import (
  3. "net/http"
  4. "github.com/0xJacky/Nginx-UI/model"
  5. "github.com/gin-gonic/gin"
  6. "github.com/uozi-tech/cosy"
  7. "gorm.io/gorm"
  8. )
  9. func GetGroup(c *gin.Context) {
  10. cosy.Core[model.EnvGroup](c).Get()
  11. }
  12. func GetGroupList(c *gin.Context) {
  13. cosy.Core[model.EnvGroup](c).GormScope(func(tx *gorm.DB) *gorm.DB {
  14. return tx.Order("order_id ASC")
  15. }).PagingList()
  16. }
  17. func ReloadNginx(c *gin.Context) {
  18. var json struct {
  19. NodeIDs []uint64 `json:"node_ids" binding:"required"`
  20. }
  21. if !cosy.BindAndValid(c, &json) {
  22. return
  23. }
  24. go syncReload(json.NodeIDs)
  25. c.JSON(http.StatusOK, gin.H{
  26. "message": "ok",
  27. })
  28. }
  29. func RestartNginx(c *gin.Context) {
  30. var json struct {
  31. NodeIDs []uint64 `json:"node_ids" binding:"required"`
  32. }
  33. if !cosy.BindAndValid(c, &json) {
  34. return
  35. }
  36. go syncRestart(json.NodeIDs)
  37. c.JSON(http.StatusOK, gin.H{
  38. "message": "ok",
  39. })
  40. }
  41. func AddGroup(c *gin.Context) {
  42. cosy.Core[model.EnvGroup](c).
  43. SetValidRules(gin.H{
  44. "name": "required",
  45. "sync_node_ids": "omitempty",
  46. "post_sync_action": "omitempty,oneof=" + model.PostSyncActionNone + " " + model.PostSyncActionReloadNginx,
  47. }).
  48. Create()
  49. }
  50. func ModifyGroup(c *gin.Context) {
  51. cosy.Core[model.EnvGroup](c).
  52. SetValidRules(gin.H{
  53. "name": "required",
  54. "sync_node_ids": "omitempty",
  55. "post_sync_action": "omitempty,oneof=" + model.PostSyncActionNone + " " + model.PostSyncActionReloadNginx,
  56. }).
  57. Modify()
  58. }
  59. func DeleteGroup(c *gin.Context) {
  60. cosy.Core[model.EnvGroup](c).Destroy()
  61. }
  62. func RecoverGroup(c *gin.Context) {
  63. cosy.Core[model.EnvGroup](c).Recover()
  64. }
  65. func UpdateGroupsOrder(c *gin.Context) {
  66. cosy.Core[model.EnvGroup](c).UpdateOrder()
  67. }