服务发现基础逻辑

This commit is contained in:
2024-10-12 00:38:18 +08:00
parent d1d7f56ce4
commit e6f5aaa02f
10 changed files with 216 additions and 31 deletions
+31
View File
@@ -0,0 +1,31 @@
package service
import (
"encoding/json"
"io"
"net/http"
"work_cation/models"
)
type ClientService struct {
}
var Client = &ClientService{}
func (c *ClientService) GetUser(online *models.Online) (*models.Users, error) {
var user models.Users
resp, err := http.Get(online.Url("/user"))
if err != nil {
return nil, err
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(data, &user)
if err != nil {
return nil, err
}
return &user, nil
}