2023-10-28 17:38:25 +02:00
|
|
|
package lib
|
|
|
|
|
2023-11-24 16:04:07 +01:00
|
|
|
import (
|
|
|
|
"github.com/anandvarma/namegen"
|
|
|
|
"github.com/google/uuid"
|
2023-12-30 23:24:43 +01:00
|
|
|
"github.com/lithammer/shortuuid"
|
2023-11-24 16:04:07 +01:00
|
|
|
)
|
2023-10-28 17:38:25 +02:00
|
|
|
|
|
|
|
// IdGenerator generates unique ids
|
|
|
|
type IdGenerator interface {
|
|
|
|
// GetId generates a unique ID or an error if something went wrong
|
|
|
|
GetId() (string, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type UUIDGenerator struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *UUIDGenerator) GetId() (string, error) {
|
|
|
|
id := uuid.New()
|
|
|
|
return id.String(), nil
|
|
|
|
}
|
2023-11-24 16:04:07 +01:00
|
|
|
|
2023-12-30 23:24:43 +01:00
|
|
|
type ShortIDGenerator struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *ShortIDGenerator) GetId() (string, error) {
|
|
|
|
id := shortuuid.New()
|
|
|
|
return id, nil
|
|
|
|
}
|
|
|
|
|
2023-11-24 16:04:07 +01:00
|
|
|
type IDNameGenerator struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *IDNameGenerator) GetId() (string, error) {
|
|
|
|
name_schema := namegen.New()
|
|
|
|
return name_schema.Get(), nil
|
|
|
|
}
|