-
Notifications
You must be signed in to change notification settings - Fork 743
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: jetstream eventbus controller implementation (#1705)
- Loading branch information
Showing
42 changed files
with
5,555 additions
and
1,182 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,21 @@ | ||
package common | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
) | ||
|
||
func MustHash(v interface{}) string { | ||
switch data := v.(type) { | ||
case []byte: | ||
hash := sha256.New() | ||
if _, err := hash.Write(data); err != nil { | ||
panic(err) | ||
} | ||
return hex.EncodeToString(hash.Sum(nil)) | ||
case string: | ||
return MustHash([]byte(data)) | ||
default: | ||
return MustHash([]byte(MustJSON(v))) | ||
} | ||
} |
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 common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMustHash(t *testing.T) { | ||
assert.Equal(t, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", MustHash([]byte("abc"))) | ||
assert.Equal(t, "d4ffe8e9ee0b48eba716706123a7187f32eae3bdcb0e7763e41e533267bd8a53", MustHash("efg")) | ||
assert.Equal(t, "a8e084ec42eff43acd61526bef35e33ddf7a8135d6aba3b140a5cae4c8c5e10b", MustHash( | ||
struct { | ||
A string | ||
B string | ||
}{A: "aAa", B: "bBb"})) | ||
} |
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,27 @@ | ||
package common | ||
|
||
import "encoding/json" | ||
|
||
func MustJSON(in interface{}) string { | ||
if data, err := json.Marshal(in); err != nil { | ||
panic(err) | ||
} else { | ||
return string(data) | ||
} | ||
} | ||
|
||
// MustUnJSON unmarshalls JSON or panics. | ||
// v - must be []byte or string | ||
// in - must be a pointer. | ||
func MustUnJSON(v interface{}, in interface{}) { | ||
switch data := v.(type) { | ||
case []byte: | ||
if err := json.Unmarshal(data, in); err != nil { | ||
panic(err) | ||
} | ||
case string: | ||
MustUnJSON([]byte(data), in) | ||
default: | ||
panic("unknown type") | ||
} | ||
} |
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 common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMustJson(t *testing.T) { | ||
assert.Equal(t, "1", MustJSON(1)) | ||
} | ||
|
||
func TestUnJSON(t *testing.T) { | ||
var in int | ||
MustUnJSON("1", &in) | ||
assert.Equal(t, 1, in) | ||
} |
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 common | ||
|
||
import ( | ||
"crypto/rand" | ||
"math/big" | ||
) | ||
|
||
// generate a random string with given length | ||
func RandomString(length int) string { | ||
seeds := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
result := make([]byte, length) | ||
for i := 0; i < length; i++ { | ||
num, _ := rand.Int(rand.Reader, big.NewInt(int64(len(seeds)))) | ||
result[i] = seeds[num.Int64()] | ||
} | ||
return string(result) | ||
} |
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,12 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRandomString(t *testing.T) { | ||
str := RandomString(20) | ||
assert.Equal(t, 20, len(str)) | ||
} |
Oops, something went wrong.