Created
December 27, 2020 08:57
-
-
Save okkez/05ffa0df08cf49014f460eb2e8543698 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module github.com/okkez/csv-aggregation-example/generator | |
go 1.14 | |
require github.com/bxcodec/faker/v3 v3.5.0 |
This file contains hidden or 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
package main | |
import( | |
"fmt" | |
"math/rand" | |
"strings" | |
"github.com/bxcodec/faker/v3" | |
) | |
const lines = 3000000 | |
var serviceNames []string | |
func randomCost() float32 { | |
return rand.Float32() * 100 | |
} | |
func init() { | |
for i := 0; i < 20; i++ { | |
serviceNames = append(serviceNames, faker.Username()) | |
} | |
} | |
func main() { | |
NumberOfServiceNames := len(serviceNames) | |
headerNames := []string{ | |
"id", | |
"name", | |
"description", | |
"cost", | |
} | |
headerLine := strings.Join(headerNames, ",") | |
fmt.Println(headerLine) | |
initialID := rand.Uint32() | |
for i := 0; i < lines; i++ { | |
line := fmt.Sprintf("%d,%s,%s,%.3f", initialID + uint32(i), serviceNames[rand.Int() % NumberOfServiceNames], faker.Sentence(), randomCost()) | |
fmt.Println(line) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment