Last active
April 29, 2022 01:57
-
-
Save mrkagelui/45e7bbfca746d8993c79a3f47e7667b5 to your computer and use it in GitHub Desktop.
optimize ram with go snippet 1
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
// dataStore retrieves data | |
type dataStore interface { | |
getData(context.Context, filter) ([]item, error) | |
} | |
// fileStorage uploads the data to file storage | |
type fileStorage interface { | |
upload(context.Context, []byte) error | |
} | |
// run is the main logic of the service | |
func (s service) run(ctx context.Context, f filter) error { | |
items, err := s.ds.getData(ctx, f) | |
if err != nil { | |
return fmt.Errorf("getting data: %v", err) | |
} | |
if err := s.up.upload(ctx, csvFrom(items)); err != nil { | |
return fmt.Errorf("uploading: %v", err) | |
} | |
return nil | |
} | |
func csvFrom(items []item) []byte { | |
// use encoding/csv package to serialize []item into []byte | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment