Skip to content

Commit

Permalink
Start adding uuid support
Browse files Browse the repository at this point in the history
  • Loading branch information
lucapette committed Feb 24, 2022
1 parent ade74e7 commit d90456b
Show file tree
Hide file tree
Showing 13 changed files with 1,407 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/lucapette/fakedata
go 1.17

require (
github.com/gofrs/uuid v4.2.0+incompatible
github.com/kr/pretty v0.0.0-20160823170715-cfb55aafdaf3
github.com/spf13/pflag v1.0.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0=
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/kr/pretty v0.0.0-20160823170715-cfb55aafdaf3 h1:dhwb1Ev84SKKVBfLuhR4bw/29yYHzwtTyTLUWWnvYxI=
github.com/kr/pretty v0.0.0-20160823170715-cfb55aafdaf3/go.mod h1:Bvhd+E3laJ0AVkG0c9rmtZcnhV0HQ3+c3YxxqTvc/gA=
github.com/kr/text v0.0.0-20160504234017-7cafcd837844 h1:kpzneEBeC0dMewP3gr/fADv1OlblH9r1goWVwpOt3TU=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func generatorsHelp(generators fakedata.Generators) string {
buffer := &bytes.Buffer{}
pattern := fmt.Sprintf("%%-%ds%%s\n", max+2) //+2 makes the output more readable
for _, gen := range generators {
fmt.Fprintf(buffer, pattern, gen.Name, gen.Desc) // nolint: errcheck
fmt.Fprintf(buffer, pattern, gen.Name, gen.Desc)
}

return buffer.String()
Expand Down
23 changes: 23 additions & 0 deletions pkg/fakedata/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"sort"
"strconv"
"strings"
"time"

"github.com/gofrs/uuid"
"github.com/lucapette/fakedata/pkg/data"
)

Expand Down Expand Up @@ -199,6 +201,24 @@ func enum(options string) (func() string, error) {
return func() string { return withList(list)() }, nil
}

func uuidv1() string {
u1, err := uuid.NewV1()
if err != nil {
fmt.Printf("failed to generate UUID: %v\n", err)
os.Exit(1)
}
return u1.String()
}

func uuidv4() string {
u1, err := uuid.NewV4()
if err != nil {
fmt.Printf("failed to generate UUID: %v\n", err)
os.Exit(1)
}
return u1.String()
}

type generatorsMap map[string]Generator

func (gM generatorsMap) addGen(g Generator) {
Expand Down Expand Up @@ -342,5 +362,8 @@ func newFactory() (f factory) {
CustomFunc: file,
})

generators.addGen(Generator{Name: "uuidv1", Desc: "uuidv1", Func: uuidv1})
generators.addGen(Generator{Name: "uuidv4", Desc: "uuidv4", Func: uuidv4})

return factory{generators: generators}
}
15 changes: 15 additions & 0 deletions vendor/github.com/gofrs/uuid/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/gofrs/uuid/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions vendor/github.com/gofrs/uuid/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d90456b

Please sign in to comment.