Skip to content

feat: implement the core logic - #1

Merged
amir78729 merged 23 commits into
mainfrom
feat/impl
Dec 22, 2025
Merged

amir78729 merged 23 commits into
mainfrom
feat/impl

Conversation

@amir78729

Copy link
Copy Markdown
Member

No description provided.

@amir78729 amir78729 self-assigned this Dec 10, 2025
Comment thread examples/basic/go.mod Outdated
Comment thread client.go Outdated
Comment thread playground/client.go Outdated
Comment thread playground/client.go Outdated
// LogLevel represents the logging level
type LogLevel string

const (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use iota to have a standard ENUM in go like proto

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm keeping the string-based approach because it's more appropriate for a public library API. String constants provide better debugging experience (you see "DEBUG" instead of 0), are JSON-serializable, and follow the pattern used by Go's standard log/slog package. iota is great for internal enums, but for public APIs that users interact with, strings are more ergonomic and stable.

Comment thread types.go Outdated
FlushInterval time.Duration
MaxBatchSize int
MaxRetries int
Adapters struct {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes instantiation a headache, have a flat or totally new struct to own Adapters.

@TheMMSH

TheMMSH commented Dec 20, 2025

Copy link
Copy Markdown

Do not use interface{} for any

Comment thread ripple_client.go Outdated
func NewClient(config ClientConfig) *Client {
// Validate required fields
if config.APIKey == "" {
panic("apiKey must be provided in config")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't panic m8

Comment thread dispatcher.go

if attempt < d.config.MaxRetries {
backoff := time.Duration(math.Pow(2, float64(attempt))) * time.Second
jitter := time.Duration(rand.Intn(1000)) * time.Millisecond

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No magic numbers (make them configurable)

Comment thread dispatcher.go Outdated
}

if attempt < d.config.MaxRetries {
backoff := time.Duration(math.Pow(2, float64(attempt))) * time.Second

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use bitwise oprators like x << 1

Comment thread dispatcher.go
d.loggerAdapter.Warn("HTTP request failed with error: %v", err)
} else {
lastErr = &HTTPError{Status: resp.Status}
d.loggerAdapter.Warn("HTTP request failed with status: %d", resp.Status)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it info?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's a negative situation, I think warning is better

Comment thread queue.go
)

// Queue represents a thread-safe FIFO queue for Event items.
type Queue struct {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect the queue to have a limit. You don't have all the RAMs in the world 😆

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The max batch size covers this.

Comment thread dispatcher.go
batchSize := min(d.config.MaxBatchSize, d.queue.Len())
batch := make([]Event, 0, batchSize)
for i := 0; i < batchSize; i++ {
if event, ok := d.queue.Dequeue(); ok {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks slow, use builtIn slice instead, you can easily batch it using x[:batchSize] for example

Comment thread dispatcher.go Outdated
if !d.timerStarted {
d.ticker = time.NewTicker(d.config.FlushInterval)
d.timerStarted = true
d.wg.Add(1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use 1.25 and wg.go() instead of add and go

Comment thread ripple_client.go Outdated
if config.FlushInterval == 0 {
config.FlushInterval = 5 * time.Second
}
if config.MaxBatchSize == 0 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!(MaxBatchSize > 0)

@amir78729
amir78729 merged commit 8167840 into main Dec 22, 2025
3 checks passed
@amir78729
amir78729 deleted the feat/impl branch January 31, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants