Created
March 18, 2018 21:17
-
-
Save rafaeljesus/4a6ddd0b557a591effc2a141388e188a to your computer and use it in GitHub Desktop.
Store responsible for storing the user.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Store responsible for storing the user. | |
| func (s *StoreService) Store(user *User) error { | |
| userResourceV2 := fmt.Sprintf("%s/%s/%s", usersAPIV2, user.Email, user.Country) | |
| res, err := s.client.Get(userResourceV2) | |
| if err != nil { | |
| if err == srv.ErrCircuitBreakerOpen { | |
| // fallback to apiv1 | |
| userResourceV1 := fmt.Sprintf("%s?%s&%s", usersAPIV1, user.Email, user.Country) | |
| res, err = s.client.Get(userResourceV1) | |
| if err != nil { | |
| return fmt.Errorf("failed to fetch user: user service is unavailable: %v", err) | |
| } | |
| } else { | |
| return fmt.Errorf("failed to fetch user: %v", err) | |
| } | |
| } | |
| // code omitted | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment