This repository has been archived by the owner on May 7, 2023. It is now read-only.
-
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
10 changed files
with
135 additions
and
77 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 |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
*.so | ||
archai | ||
|
||
*.coverprofile | ||
|
||
# Folders | ||
_obj | ||
_test | ||
|
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
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
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
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
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
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
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
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,36 @@ | ||
package simplejson | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
type Json interface{} | ||
type Object map[string]Json | ||
type String string | ||
type Array []Json | ||
type ObjectArray []Object | ||
|
||
func Read(buf []byte) (Object, error) { | ||
var js Object | ||
|
||
err := json.Unmarshal(buf, &js) | ||
return js, errors.Wrap(err, "Input is not JSON") | ||
} | ||
|
||
func Write(js Object) ([]byte, error) { | ||
out, err := json.Marshal(js) | ||
return out, errors.Wrap(err, "Marshalling as JSON failed") | ||
} | ||
|
||
func Validate(buf []byte) ([]byte, error) { | ||
var ( | ||
err error | ||
) | ||
js, err := Read(buf) | ||
if err != nil { | ||
return buf, err | ||
} | ||
return Write(js) | ||
} |
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 |
---|---|---|
@@ -1,8 +1,25 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/scoiatael/archai/simplejson" | ||
) | ||
|
||
type Event struct { | ||
ID string | ||
Stream string | ||
Blob []byte | ||
Meta map[string]string | ||
} | ||
|
||
func EventToJson(e Event) ([]byte, error) { | ||
object := make(simplejson.Object) | ||
object["id"] = e.ID | ||
object["stream"] = e.Stream | ||
payload, err := simplejson.Read(e.Blob) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
object["payload"] = payload | ||
return simplejson.Write(object) | ||
|
||
} |