Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hawapi/go-sdk
HawAPI SDK for Golang
https://github.com/hawapi/go-sdk
api api-sdk hawapi hawapi-go-sdk hawapi-sdk sdk stranger-things
Last synced: about 2 months ago
JSON representation
HawAPI SDK for Golang
- Host: GitHub
- URL: https://github.com/hawapi/go-sdk
- Owner: HawAPI
- License: mit
- Created: 2024-07-02T00:10:26.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-19T21:20:12.000Z (6 months ago)
- Last Synced: 2024-07-20T11:08:28.721Z (6 months ago)
- Topics: api, api-sdk, hawapi, hawapi-go-sdk, hawapi-sdk, sdk, stranger-things
- Language: Go
- Homepage: https://pkg.go.dev/github.com/HawAPI/go-sdk
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HawAPI - go-sdk
HawAPI SDK for Golang
- [API Docs](https://hawapi.theproject.id/docs/)
- [SDK Docs](https://pkg.go.dev/github.com/HawAPI/go-sdk)## Topics
- [Installation](#installation)
- [Usage](#usage)
- [Init client](#init-client)
- [Fetch information](#fetch-information)
- [Error handling](#error-handling)## Installation
```
go get github.com/HawAPI/go-sdk/hawapi@latest
```## Usage
- [See examples](./_examples)
### Init client
```go
package mainimport (
"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,
})
}
```### Fetch information
```go
package mainimport (
"fmt""github.com/HawAPI/go-sdk/hawapi"
)func main() {
client := hawapi.NewClient()
res, err := client.ListActors()
if err != nil {
panic(err)
}
fmt.Println(res)
}
```### Error handling
- Check out the [hawapi.ErrorResponse](hawapi/error.go)
```go
package mainimport (
"fmt""github.com/HawAPI/go-sdk/hawapi"
"github.com/google/uuid"
)func main() {
client := hawapi.NewClient()
id, _ := uuid.Parse("")
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)
}
```