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
| package main | |
| type client struct { | |
| httpClient *http.Client | |
| address string | |
| } | |
| // Client interface | |
| type Client interface { | |
| FetchUserDetailsByID(id int) (DetailsResponse, error) |
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
| package main | |
| type service struct { | |
| client Client | |
| } | |
| // Service interface | |
| type Service interface { | |
| GetUserDetailsByUserID(id int) (DetailsResponse, error) | |
| } |
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
| package main | |
| // UserDetails Object | |
| type UserDetails struct { | |
| ID int `json:"userId"` | |
| Name string `json:"name"` | |
| Email string `json:"email"` | |
| DateOfBirth string `json:"dateOfBirth"` | |
| PhoneNumber string `json:"phoneNumber"` | |
| Gender string `json:"gender"` |
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
| package main | |
| func main() { | |
| userClient := NewClient(httpClient, "http://userservice") | |
| userSvc := NewService(userClient) | |
| user, err := GetUserDetailsByUserID(1) | |
| if err != nil { | |
| logrus.Errorf("[ERROR] failed fetching user details: %v", err) | |
| } |
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
| // GetCache to get data from cache | |
| func GetCache(key string, result interface{}) { | |
| res, err := cache.Get(key) | |
| if err != nil { | |
| log.Errorf("[ERROR] failed fetching cache: %v", err) | |
| return | |
| } | |
| err = json.Unmarshal(res, result) | |
| if err != nil { |
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
| func GetCache(key string, result interface{}) { | |
| res, err := cache.Get(key) | |
| if err != nil { | |
| log.Errorf("[ERROR] failed fetching cache: %v", err) | |
| return | |
| } | |
| err = json.Unmarshal(res, result) | |
| if err != nil { | |
| log.Errorf("[ERROR] failed parsing cache : %v", err) |
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
| // Service interface | |
| type Service interface { | |
| GetUserDetailsByUserID(id int) (DetailsResponse, error) | |
| } | |
| // service | |
| type service struct { | |
| client Client | |
| } |
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
| type service struct { | |
| client Client | |
| } | |
| // Service interface | |
| type Service interface { | |
| GetUserDetailsByUserID(id int) (DetailsResponse, error) | |
| } | |
| // NewService initialize function |
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
| package pengguna | |
| type User struct { | |
| id int | |
| name string | |
| age int | |
| gender string | |
| email string | |
| password string | |
| } |