Skip to content

Commit bdce10f

Browse files
authored
Setup: Initial files (#1)
1 parent 2494ea1 commit bdce10f

32 files changed

+2549
-1
lines changed

.github/workflows/coverage.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: "Go Coverage"
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
10+
jobs:
11+
coverage:
12+
# Ignore drafts
13+
if: github.event.pull_request.draft == false
14+
name: Go test with coverage
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 10
20+
21+
- name: Set up Golang
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: '1.22'
25+
26+
- name: Install dependencies
27+
run: go mod tidy
28+
29+
- uses: gwatts/go-coverage-action@v2
30+
id: coverage
31+
with:
32+
coverage-threshold: 60
33+
cover-pkg: ./...

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
15+
- name: Set up Golang
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version: '1.22'
19+
20+
- name: Install dependencies
21+
run: go mod tidy
22+
23+
- name: Testing
24+
run: go test -v ./...
25+
26+
- name: Publish to pkg.go.dev
27+
run: |
28+
echo "VERSION=${{ github.ref_name }}"
29+
GOPROXY=proxy.golang.org go list -m github.com/HawAPI/go-sdk@${{ github.ref_name }}

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/dataSources.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/go-sdk.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/markdown.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,117 @@
1-
# go-sdk
1+
# HawAPI - go-sdk
2+
23
HawAPI SDK for Golang
4+
5+
- [API Docs](https://hawapi.theproject.id/docs/)
6+
- [SDK Docs](https://pkg.go.dev/github.com/HawAPI/go-sdk)
7+
8+
## Topics
9+
10+
- [Installation](#installation)
11+
- [Usage](#usage)
12+
- [Init client](#init-client)
13+
- [Fetch information](#fetch-information)
14+
- [Error handling](#error-handling)
15+
16+
## Installation
17+
18+
```
19+
go get github.com/HawAPI/go-sdk@latest
20+
```
21+
22+
## Usage
23+
24+
- [See examples](./examples)
25+
26+
### Init client
27+
28+
```go
29+
package main
30+
31+
import (
32+
"fmt"
33+
34+
"github.com/HawAPI/go-sdk"
35+
)
36+
37+
func main() {
38+
// Create a new client with default options
39+
client := hawapi.NewClient()
40+
41+
// Create client with custom options
42+
client = hawapi.NewClientWithOpts(hawapi.Options{
43+
Endpoint: "http://localhost:8080/api",
44+
// When using 'WithOpts' or 'NewClientWithOpts' the value of
45+
// 'UseInMemoryCache' will be set to false
46+
UseInMemoryCache: true,
47+
// Version
48+
// Language
49+
// Token
50+
// ...
51+
})
52+
53+
// You can also change the options later
54+
client.WithOpts(hawapi.Options{
55+
Language: "pt-BR",
56+
// When using 'WithOpts' or 'NewClientWithOpts' the value of
57+
// 'UseInMemoryCache' will be set to false
58+
UseInMemoryCache: true,
59+
})
60+
}
61+
```
62+
63+
### Fetch information
64+
65+
```go
66+
package main
67+
68+
import (
69+
"fmt"
70+
71+
"github.com/HawAPI/go-sdk"
72+
)
73+
74+
func main() {
75+
client := hawapi.NewClient()
76+
77+
res, err := client.ListActors()
78+
if err != nil {
79+
panic(err)
80+
}
81+
82+
fmt.Println(res)
83+
}
84+
```
85+
86+
### Error handling
87+
88+
- Check out the [hawapi.ErrorResponse](./pkg/hawapi/error.go)
89+
90+
```go
91+
package main
92+
93+
import (
94+
"fmt"
95+
96+
"github.com/HawAPI/go-sdk"
97+
"github.com/google/uuid"
98+
)
99+
100+
func main() {
101+
client := hawapi.NewClient()
102+
103+
id, _ := uuid.Parse("<unknown uuid>")
104+
res, err := client.FindActor(id)
105+
if err != nil {
106+
// If the error is coming from the API request,
107+
// it'll be of type hawapi.ErrorResponse.
108+
if resErr, ok := err.(hawapi.ErrorResponse); ok {
109+
fmt.Printf("API error %d Message: %s\n", resErr.Code, resErr.Message)
110+
} else {
111+
fmt.Println("SDK error:", err)
112+
}
113+
}
114+
115+
fmt.Println(res)
116+
}
117+
```

0 commit comments

Comments
 (0)