-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(inputs.kinesis_consumer): Cleanup code (#16267)
Co-authored-by: Dane Strandboge <136023093+DStrand1@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
274 additions
and
332 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package kinesis_consumer | ||
|
||
import ( | ||
"bytes" | ||
"compress/gzip" | ||
"compress/zlib" | ||
"fmt" | ||
"io" | ||
) | ||
|
||
type decodingFunc func([]byte) ([]byte, error) | ||
|
||
func processGzip(data []byte) ([]byte, error) { | ||
zipData, err := gzip.NewReader(bytes.NewReader(data)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer zipData.Close() | ||
return io.ReadAll(zipData) | ||
} | ||
|
||
func processZlib(data []byte) ([]byte, error) { | ||
zlibData, err := zlib.NewReader(bytes.NewReader(data)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer zlibData.Close() | ||
return io.ReadAll(zlibData) | ||
} | ||
|
||
func processNoOp(data []byte) ([]byte, error) { | ||
return data, nil | ||
} | ||
|
||
func getDecodingFunc(encoding string) (decodingFunc, error) { | ||
switch encoding { | ||
case "gzip": | ||
return processGzip, nil | ||
case "zlib": | ||
return processZlib, nil | ||
case "none", "identity", "": | ||
return processNoOp, nil | ||
} | ||
return nil, fmt.Errorf("unknown content encoding %q", encoding) | ||
} |
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.