-
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
8 changed files
with
179 additions
and
10 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
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,37 @@ | ||
package domain | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"github.com/boreq/errors" | ||
) | ||
|
||
type EventId struct { | ||
s string | ||
} | ||
|
||
func NewEventId(s string) (EventId, error) { | ||
b, err := hex.DecodeString(s) | ||
if err != nil { | ||
return EventId{}, errors.Wrap(err, "error decoding hex") | ||
} | ||
|
||
if len(b) != sha256.Size { | ||
return EventId{}, errors.New("invalid length") | ||
} | ||
|
||
s = hex.EncodeToString(b) | ||
return EventId{s}, nil | ||
} | ||
|
||
func (id EventId) Hex() string { | ||
return id.s | ||
} | ||
|
||
func (id EventId) Bytes() []byte { | ||
b, err := hex.DecodeString(id.s) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return b | ||
} |
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,18 @@ | ||
package domain | ||
|
||
import "github.com/boreq/errors" | ||
|
||
type EventKind struct { | ||
k int | ||
} | ||
|
||
func NewEventKind(k int) (EventKind, error) { | ||
if k < 0 { | ||
return EventKind{}, errors.New("kind must be positive") | ||
} | ||
return EventKind{k}, nil | ||
} | ||
|
||
func (k EventKind) Int() int { | ||
return k.k | ||
} |
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 domain | ||
|
||
import ( | ||
"encoding/hex" | ||
"github.com/boreq/errors" | ||
) | ||
|
||
type EventSignature struct { | ||
s string | ||
} | ||
|
||
func NewEventSignature(s string) (EventSignature, error) { | ||
b, err := hex.DecodeString(s) | ||
if err != nil { | ||
return EventSignature{}, errors.Wrap(err, "error decoding hex") | ||
} | ||
|
||
if len(b) != 64 { | ||
return EventSignature{}, errors.New("invalid length") | ||
} | ||
|
||
s = hex.EncodeToString(b) | ||
return EventSignature{s}, nil | ||
} | ||
|
||
func (sig EventSignature) Hex() string { | ||
return sig.s | ||
} | ||
|
||
func (sig EventSignature) Bytes() []byte { | ||
b, err := hex.DecodeString(sig.s) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return b | ||
} |
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,15 @@ | ||
package domain | ||
|
||
import "github.com/boreq/errors" | ||
|
||
type EventTag struct { | ||
tag []string | ||
} | ||
|
||
func NewEventTag(tag []string) (EventTag, error) { | ||
if len(tag) < 2 { | ||
return EventTag{}, errors.New("tag needs at least two fields I recon") | ||
} | ||
|
||
return EventTag{tag}, nil | ||
} |