Browse Source

Mod: group/v2

Aiden 2 months ago
parent
commit
f197f05518
1 changed files with 16 additions and 9 deletions
  1. 16 9
      internal/server/server.go

+ 16 - 9
internal/server/server.go

@@ -53,14 +53,19 @@ func Register(c *gin.Context) {
 }
 
 func Group(c *gin.Context) {
-	group(c, "v.starttransfernow.com")
+	group(c, "v.starttransfernow.com", func(node *model.Node) bool {
+		return true
+	})
 }
 
 func V2Group(c *gin.Context) {
-	group(c, "v.sweeterlife.net")
+	vip := c.Query("vip")
+	group(c, "v.sweeterlife.net", func(node *model.Node) bool {
+		return (vip == "true" && node.Vip) || (vip == "false" && !node.Vip)
+	})
 }
 
-func group(c *gin.Context, host string) {
+func group(c *gin.Context, host string, predicate func(*model.Node) bool) {
 	locker.RLock()
 	defer locker.RUnlock()
 
@@ -72,13 +77,15 @@ func group(c *gin.Context, host string) {
 	countryLabelSeqs := make(map[string]int)
 	dtoNodes := make([]*dto.Node, 0)
 	for _, node := range nodes {
-		seq, ok := countryLabelSeqs[node.CountryCode]
-		if !ok {
-			countryLabelSeqs[node.CountryCode] = 0
-		} else {
-			countryLabelSeqs[node.CountryCode] = seq + 1
+		if predicate(node) {
+			seq, ok := countryLabelSeqs[node.CountryCode]
+			if !ok {
+				countryLabelSeqs[node.CountryCode] = 0
+			} else {
+				countryLabelSeqs[node.CountryCode] = seq + 1
+			}
+			dtoNodes = append(dtoNodes, convert2DtoNode(node, host))
 		}
-		dtoNodes = append(dtoNodes, convert2DtoNode(node, host))
 	}
 
 	continentMaps := make(map[string]bool)