Skip to content

Commit

Permalink
feat: Add s2-bentobox package (#36)
Browse files Browse the repository at this point in the history
Common functionalities for implementing the Bento plugins.
  • Loading branch information
vrongmeal authored Jan 27, 2025
1 parent 81fad07 commit 9bf21a0
Show file tree
Hide file tree
Showing 5 changed files with 573 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tasks:
- |
git diff --exit-code internal/pb/*.go s2/*.sync.go && echo "Up-to-date" || {
echo "Not up-to-date"
echo "Run task:gen and update the generated code"
echo "Run `task gen` and update the generated code"
exit 1
}
Expand Down
14 changes: 7 additions & 7 deletions internal/pb/s2.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions s2-bentobox/bentobox.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package s2bentobox

import (
"context"

"github.com/s2-streamstore/s2-sdk-go/s2"
)

// Plugin name.
const PluginName = "s2"

func newBasinClient(config *Config) (*s2.BasinClient, error) {
return s2.NewBasinClient(config.Basin, config.AuthToken)
}

func newStreamClient(config *Config, stream string) (*s2.StreamClient, error) {
client, err := newBasinClient(config)
if err != nil {
return nil, err
}

// `s2.BasinClient.StreamClient` is a cheap operation.
return client.StreamClient(stream), nil
}

func waitForClosers(ctx context.Context, closers ...<-chan struct{}) error {
for _, closer := range closers {
select {
case <-ctx.Done():
return ctx.Err()
case <-closer:
}
}

return nil
}

func notifyOnce(ch chan<- struct{}) {
select {
case ch <- struct{}{}:
default:
}
}

type Logger interface {
Tracef(template string, args ...any)
Trace(message string)
Debugf(template string, args ...any)
Debug(message string)
Infof(template string, args ...any)
Info(message string)
Warnf(template string, args ...any)
Warn(message string)
Errorf(template string, args ...any)
Error(message string)
With(keyValuePairs ...any) Logger
}

type Config struct {
Basin string
AuthToken string
}
Loading

0 comments on commit 9bf21a0

Please sign in to comment.