API CALL - Creative Code Solution
Read documentation here.
apiCall := apicall.New(
WithBaseUrl("https://www.google.pt"),
)
Tip: You can create your own method for configuration, you only need to implement Option type.
response, err := apiCall.Send("GET", "/users/list", nil)
if err != nil {
panic("An error happen")
}
if !response.IsOk() {
panic("Unable to success response")
}
fmt.Println(response) // response is apicall.BaseStandard struct
response, err := apiCall.Send("POST", "/get-users", nil)
if err != nil {
panic("An error happen")
}
if !response.IsOk() {
panic("Unable to success response")
}
type User struct {
Name string
Email string
}
var users []User
err = response.GetItems(&users)
for index, user := range users {
fmt.Println(user.Name)
}