-
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.
Signed-off-by: Eray Ates <[email protected]>
- Loading branch information
Showing
11 changed files
with
296 additions
and
190 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/bin | ||
/.golangci.yml | ||
/coverage.* |
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,22 @@ | ||
package wkafka | ||
|
||
import "context" | ||
|
||
type ctxKey string | ||
|
||
const ( | ||
// KeyRecord is the context key for *Record. | ||
KeyRecord ctxKey = "kafka_record" | ||
) | ||
|
||
// ContextRecord returns the Record from the context in callback function. | ||
// - If the context is nil, or the Record is not set, nil is returned. | ||
func ContextRecord(ctx context.Context) *Record { | ||
if ctx == nil { | ||
return nil | ||
} | ||
|
||
record, _ := ctx.Value(KeyRecord).(*Record) | ||
|
||
return record | ||
} |
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,9 +1,40 @@ | ||
package wkafka | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/twmb/franz-go/pkg/kgo" | ||
) | ||
|
||
var ( | ||
ErrNotImplemented = fmt.Errorf("not implemented") | ||
ErrClientClosed = fmt.Errorf("client closed") | ||
ErrNilData = fmt.Errorf("nil data") | ||
// ErrSkip is use to skip message in the PreCheck hook. | ||
ErrSkip = fmt.Errorf("skip message") | ||
) | ||
|
||
func wrapErr(r *kgo.Record, err error) error { | ||
return fmt.Errorf("message error - topic: %q, partition: %d, offset: %d, key: `%s`, headers: `%s` value: `%s`: %w", | ||
r.Topic, r.Partition, r.Offset, r.Key, stringHeader(r.Headers), r.Value, err, | ||
) | ||
} | ||
|
||
func stringHeader(headers []Header) string { | ||
var str strings.Builder | ||
str.WriteString("{") | ||
for i, header := range headers { | ||
str.WriteString(fmt.Sprintf("%q: %q", header.Key, header.Value)) | ||
|
||
if i == len(headers)-1 { | ||
continue | ||
} | ||
|
||
str.WriteString(",") | ||
} | ||
|
||
str.WriteString("}") | ||
|
||
return str.String() | ||
} |
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
Oops, something went wrong.