HawAPI SDK for Golang
go get github.com/HawAPI/go-sdk/hawapi@latest
package main
import (
"fmt"
"github.com/HawAPI/go-sdk/hawapi"
)
func main() {
// Create a new client with default options
client := hawapi.NewClient()
// Create client with custom options
client = hawapi.NewClientWithOpts(hawapi.Options{
Endpoint: "http://localhost:8080/api",
// When using 'WithOpts' or 'NewClientWithOpts' the value of
// 'UseInMemoryCache' will be set to false
UseInMemoryCache: true,
// Version
// Language
// Token
// ...
})
// You can also change the options later
client.WithOpts(hawapi.Options{
Language: "pt-BR",
// When using 'WithOpts' or 'NewClientWithOpts' the value of
// 'UseInMemoryCache' will be set to false
UseInMemoryCache: true,
})
}
package main
import (
"fmt"
"github.com/HawAPI/go-sdk/hawapi"
)
func main() {
client := hawapi.NewClient()
res, err := client.ListActors()
if err != nil {
panic(err)
}
fmt.Println(res)
}
- Check out the hawapi.ErrorResponse
package main
import (
"fmt"
"github.com/HawAPI/go-sdk/hawapi"
"github.com/google/uuid"
)
func main() {
client := hawapi.NewClient()
id, _ := uuid.Parse("<unknown uuid>")
res, err := client.FindActor(id)
if err != nil {
// If the error is coming from the API request,
// it'll be of type hawapi.ErrorResponse.
if resErr, ok := err.(hawapi.ErrorResponse); ok {
fmt.Printf("API error %d Message: %s\n", resErr.Code, resErr.Message)
} else {
fmt.Println("SDK error:", err)
}
}
fmt.Println(res)
}