Bläddra i källkod

add: countryName

Ben 1 år sedan
förälder
incheckning
ca2491e287
5 ändrade filer med 7 tillägg och 1 borttagningar
  1. 2 1
      cmd/slave.go
  2. 1 0
      internal/dto/request.go
  3. 1 0
      internal/dto/response.go
  4. 1 0
      internal/model/node.go
  5. 2 0
      internal/server/server.go

+ 2 - 1
cmd/slave.go

@@ -32,9 +32,10 @@ func main() {
 	}
 	countryCode := gjson.Get(string(bs), "country_code").String()
 	ip := gjson.Get(string(bs), "ip").String()
+	city := gjson.Get(string(bs), "city").String()
 	log.Printf("ipinfo: %s", string(bs))
 
-	request := dto.RegisterRequest{Ip: ip, CountryCode: countryCode, Secret: buf.String()}
+	request := dto.RegisterRequest{Ip: ip, CountryCode: countryCode, CountryName: city, Secret: buf.String()}
 	body, err := json.Marshal(request)
 	if err != nil {
 		log.Printf("err: %+v", err)

+ 1 - 0
internal/dto/request.go

@@ -3,6 +3,7 @@ package dto
 type RegisterRequest struct {
 	Ip          string `json:"ip"`
 	CountryCode string `json:"countryCode"`
+	CountryName string `json:"countryName"`
 	Secret      string `json:"secret"`
 }
 

+ 1 - 0
internal/dto/response.go

@@ -55,6 +55,7 @@ type DetailResponse struct {
 
 type Node struct {
 	CountryCode string `json:"countryCode"`
+	CountryName string `json:"countryName"`
 	Ip          string `json:"ip"`
 }
 

+ 1 - 0
internal/model/node.go

@@ -5,6 +5,7 @@ import "time"
 type Node struct {
 	Ip          string
 	CountryCode string
+	CountryName string
 	Secret      string
 
 	LastUpdateTime time.Time

+ 2 - 0
internal/server/server.go

@@ -37,6 +37,7 @@ func Register(c *gin.Context) {
 			node.Ip = request.Ip
 			node.Secret = request.Secret
 			node.CountryCode = request.CountryCode
+			node.CountryName = request.CountryName
 			node.LastUpdateTime = time.Now()
 			c.JSON(http.StatusOK, dto.RegisterResponse{
 				Response: dto.NewOkResponse(),
@@ -66,6 +67,7 @@ func List(c *gin.Context) {
 			dtoNodes = append(dtoNodes, dto.Node{
 				Ip:          node.Ip,
 				CountryCode: node.CountryCode,
+				CountryName: node.CountryName,
 			})
 		}
 	}