Ben hace 1 año
padre
commit
7cb8d335c5
Se han modificado 2 ficheros con 13 adiciones y 7 borrados
  1. 2 2
      internal/dto/response.go
  2. 11 5
      internal/server/server.go

+ 2 - 2
internal/dto/response.go

@@ -45,7 +45,7 @@ type RegisterResult struct {
 
 type ListResponse struct {
 	Response
-	Data []Node `json:"data"`
+	Data []*Node `json:"data"`
 }
 
 type DetailResponse struct {
@@ -68,5 +68,5 @@ type ConfigResponse struct {
 type ConfigResult struct {
 	FreeTrialDuration uint64 `json:"freeTrialDuration"`
 	Timestamp         int64  `json:"timestamp"`
-	Node              Node   `json:"node"`
+	Node              *Node  `json:"node"`
 }

+ 11 - 5
internal/server/server.go

@@ -24,12 +24,16 @@ func Config(c *gin.Context) {
 		dto.Error(c, err)
 		return
 	}
+	var node *model.Node
+	if len(healthNodes()) > 0 {
+		node = healthNodes()[0]
+	}
 	c.JSON(http.StatusOK, dto.ConfigResponse{
 		Response: dto.NewOkResponse(),
 		Data: dto.ConfigResult{
 			FreeTrialDuration: totalFreeDuration - usedDuration,
 			Timestamp:         time.Now().Unix(),
-			Node:              convert2DtoNode(healthNodes()[0]),
+			Node:              convert2DtoNode(node),
 		},
 	})
 }
@@ -102,7 +106,7 @@ func List(c *gin.Context) {
 	locker.RLock()
 	defer locker.RUnlock()
 
-	dtoNodes := make([]dto.Node, 0)
+	dtoNodes := make([]*dto.Node, 0)
 	for _, node := range healthNodes() {
 		dtoNodes = append(dtoNodes, convert2DtoNode(node))
 	}
@@ -172,7 +176,10 @@ func healthNodes() []*model.Node {
 	return healthNodes
 }
 
-func convert2DtoNode(node *model.Node) dto.Node {
+func convert2DtoNode(node *model.Node) *dto.Node {
+	if node == nil {
+		return nil
+	}
 	icon := ""
 	if node.CountryCode == "BR" {
 		icon = "http://v.starttransfernow.com/static/BR.jpg"
@@ -185,11 +192,10 @@ func convert2DtoNode(node *model.Node) dto.Node {
 	} else if node.CountryCode == "US" {
 		icon = "http://v.starttransfernow.com/static/US.jpg"
 	}
-	return dto.Node{
+	return &dto.Node{
 		Ip:          node.Ip,
 		CountryCode: node.CountryCode,
 		CountryName: node.CountryName,
 		Icon:        icon,
-		//Icon:        "https://img.zcool.cn/community/010a5a57dbc2140000018c1b0a9b5f.png",
 	}
 }