|
| 1 | +# Generate Module |
| 2 | + |
| 3 | +[](https://github.com/ankorstore/yokai/actions/workflows/generate-ci.yml) |
| 4 | +[](https://goreportcard.com/report/github.com/ankorstore/yokai/generate) |
| 5 | +[](https://app.codecov.io/gh/ankorstore/yokai/tree/main/generate) |
| 6 | +[](https://pkg.go.dev/github.com/ankorstore/yokai/generate) |
| 7 | + |
| 8 | +> Generation module based on [Google UUID](https://github.com/google/uuid). |
| 9 | +
|
| 10 | +<!-- TOC --> |
| 11 | + |
| 12 | +* [Installation](#installation) |
| 13 | +* [Documentation](#documentation) |
| 14 | + * [UUID](#uuid) |
| 15 | + |
| 16 | +<!-- TOC --> |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +```shell |
| 21 | +go get github.com/ankorstore/yokai/generate |
| 22 | +``` |
| 23 | + |
| 24 | +## Documentation |
| 25 | + |
| 26 | +### UUID |
| 27 | + |
| 28 | +This module provides an [UuidGenerator](uuid/generator.go) interface, allowing to generate UUIDs. |
| 29 | + |
| 30 | +The `DefaultUuidGenerator` is based on [Google UUID](https://github.com/google/uuid). |
| 31 | + |
| 32 | +```go |
| 33 | +package main |
| 34 | + |
| 35 | +import ( |
| 36 | + "fmt" |
| 37 | + |
| 38 | + "github.com/ankorstore/yokai/generate/uuid" |
| 39 | + uuidtest "github.com/ankorstore/yokai/generate/generatetest/uuid" |
| 40 | +) |
| 41 | + |
| 42 | +func main() { |
| 43 | + // default UUID generator |
| 44 | + generator := uuid.NewDefaultUuidGenerator() |
| 45 | + fmt.Printf("uuid: %s", generator.Generate()) // uuid: dcb5d8b3-4517-4957-a42c-604d11758561 |
| 46 | + |
| 47 | + // test UUID generator (with deterministic value for testing) |
| 48 | + testGenerator := uuidtest.NewTestUuidGenerator("test") |
| 49 | + fmt.Printf("uuid: %s", testGenerator.Generate()) // uuid: test |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +The module also provides a [UuidGeneratorFactory](uuid/factory.go) interface, to create |
| 54 | +the [UuidGenerator](uuid/generator.go) instances. |
| 55 | + |
| 56 | +The `DefaultUuidGeneratorFactory` generates `DefaultUuidGenerator` instances. |
| 57 | + |
| 58 | +```go |
| 59 | +package main |
| 60 | + |
| 61 | +import ( |
| 62 | + "fmt" |
| 63 | + |
| 64 | + "github.com/ankorstore/yokai/generate/uuid" |
| 65 | +) |
| 66 | + |
| 67 | +func main() { |
| 68 | + // default UUID generator factory |
| 69 | + generator := uuid.NewDefaultUuidGeneratorFactory().Create() |
| 70 | + fmt.Printf("uuid: %s", generator.Generate()) // uuid: dcb5d8b3-4517-4957-a42c-604d11758561 |
| 71 | +} |
| 72 | +``` |
0 commit comments