group.go 763 B

12345678910111213141516171819202122232425262728293031323334
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "net/http"
  5. "one-api/common"
  6. )
  7. func GetGroups(c *gin.Context) {
  8. groupNames := make([]string, 0)
  9. for groupName, _ := range common.GroupRatio {
  10. groupNames = append(groupNames, groupName)
  11. }
  12. c.JSON(http.StatusOK, gin.H{
  13. "success": true,
  14. "message": "",
  15. "data": groupNames,
  16. })
  17. }
  18. func GetUserGroups(c *gin.Context) {
  19. usableGroups := make(map[string]string)
  20. for groupName, _ := range common.GroupRatio {
  21. // UserUsableGroups contains the groups that the user can use
  22. if _, ok := common.UserUsableGroups[groupName]; ok {
  23. usableGroups[groupName] = common.UserUsableGroups[groupName]
  24. }
  25. }
  26. c.JSON(http.StatusOK, gin.H{
  27. "success": true,
  28. "message": "",
  29. "data": usableGroups,
  30. })
  31. }