MCPcopy Create free account
hub / github.com/RezaSi/go-interview-practice / GetUser

Method GetUser

challenge-14/solution-template.go:322–339  ·  view source on GitHub ↗
(ctx context.Context, userID int64)

Source from the content-addressed store, hash-verified

320}
321
322func (c *UserServiceClient) GetUser(ctx context.Context, userID int64) (*User, error) {
323 resp, err := http.Get(fmt.Sprintf("%s/user/get?id=%d", c.baseURL, userID))
324 if err != nil {
325 return nil, err
326 }
327 defer resp.Body.Close()
328
329 if resp.StatusCode == http.StatusNotFound {
330 return nil, status.Errorf(codes.NotFound, "user not found")
331 }
332
333 var user User
334 if err := json.NewDecoder(resp.Body).Decode(&user); err != nil {
335 return nil, err
336 }
337
338 return &user, nil
339}
340
341func (c *UserServiceClient) ValidateUser(ctx context.Context, userID int64) (bool, error) {
342 resp, err := http.Get(fmt.Sprintf("%s/user/validate?id=%d", c.baseURL, userID))

Callers 1

TestUserServiceFunction · 0.95

Calls 2

CloseMethod · 0.80
GetMethod · 0.65

Tested by 1

TestUserServiceFunction · 0.76