-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
103 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
main.go |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/kiriminaja/kaj-log-activities-sdk | ||
|
||
go 1.22.3 |
This file contains 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
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package event | ||
|
||
type EventContract interface { | ||
Upsert(event string, data map[string]interface{}) (map[string]interface{}, error) | ||
List() (map[string]interface{}, error) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package event | ||
|
||
import "encoding/json" | ||
|
||
type Config struct { | ||
URL string | ||
} | ||
|
||
type Response struct { | ||
Name string `json:"name"` | ||
Message string `json:"message"` | ||
Data map[string]interface{} | ||
} | ||
|
||
func (r *Response) Cast(response []byte, val interface{}) error { | ||
return json.Unmarshal(response, &r) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package event | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/kiriminaja/kaj-log-activities-sdk/sdk/requester" | ||
) | ||
|
||
type eventCase struct { | ||
request requester.Contract | ||
endpoint string | ||
} | ||
|
||
func NewEvent(cfg Config, reqs requester.Contract) EventContract { | ||
return &eventCase{ | ||
request: reqs, | ||
endpoint: cfg.URL + "/ex/v1/event", | ||
} | ||
} | ||
|
||
func (e *eventCase) Upsert(event string, data map[string]interface{}) (map[string]interface{}, error) { | ||
payload := map[string]interface{}{ | ||
"event": event, | ||
"data": data, | ||
} | ||
body, err := json.Marshal(payload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var result map[string]interface{} | ||
response, err := e.request.POST(e.endpoint, map[string]string{}, body) | ||
if err != nil { | ||
return result, err | ||
} | ||
err = json.Unmarshal(response, &result) | ||
return result, err | ||
} | ||
|
||
func (e *eventCase) List() (map[string]interface{}, error) { | ||
var result Response | ||
data, err := e.request.GET(e.endpoint, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = result.Cast(data, &result) | ||
if err != nil { | ||
return result.Data, err | ||
} | ||
return result.Data, nil | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package packages | ||
|
||
type PackageContract interface { | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package packages | ||
|
||
type Config struct { | ||
URL string | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package packages | ||
|
||
import "github.com/kiriminaja/kaj-log-activities-sdk/sdk/requester" | ||
|
||
type packageCase struct { | ||
request requester.Contract | ||
endpoint string | ||
} | ||
|
||
func NewPackage(cfg Config, request requester.Contract) PackageContract { | ||
return &packageCase{ | ||
request: request, | ||
endpoint: cfg.URL + "/ex/v1/package/", | ||
} | ||
} |
File renamed without changes.
File renamed without changes.