add comments, code refactor

This commit is contained in:
MaysWind
2020-12-23 00:24:45 +08:00
parent 17d1cd8719
commit 995eeae041
7 changed files with 36 additions and 9 deletions
+4
View File
@@ -5,14 +5,17 @@ import (
"github.com/mayswind/lab/pkg/settings"
)
// UuidContainer contains the current uuid generator
type UuidContainer struct {
Current UuidGenerator
}
// Initialize a uuid container singleton instance
var (
Container = &UuidContainer{}
)
// InitializeUuidGenerator initialized the current uuid generator according to the config
func InitializeUuidGenerator(config *settings.Config) error {
if config.UuidGeneratorType == settings.UUID_GENERATOR_TYPE_INTERNAL {
generator, err := NewInternalUuidGenerator(config)
@@ -24,6 +27,7 @@ func InitializeUuidGenerator(config *settings.Config) error {
return errs.ErrInvalidUuidMode
}
// GenerateUuid returns a new uuid by the current uuid generator
func (u *UuidContainer) GenerateUuid(uuidType UuidType) int64 {
return u.Current.GenerateUuid(uuidType)
}