kafka-func.go 599 B

12345678910111213141516171819202122232425262728
  1. // Author : Eric Kim
  2. // Build Date : 6 Jul 2023 Last Update 02 Aug 2018
  3. // All rights are reserved.
  4. package etc
  5. import (
  6. "bytes"
  7. "github.com/IBM/sarama"
  8. )
  9. func KafkaHeaderValue(headers []*sarama.RecordHeader, key []byte) string {
  10. for _, header := range headers {
  11. if bytes.Equal(header.Key, key) {
  12. return string(header.Value)
  13. }
  14. }
  15. return ""
  16. }
  17. func ConvertKafkaHeaders(headers []*sarama.RecordHeader) []sarama.RecordHeader {
  18. convertedHeaders := make([]sarama.RecordHeader, len(headers))
  19. for i, header := range headers {
  20. convertedHeaders[i] = *header
  21. }
  22. return convertedHeaders
  23. }