Remove automatic uuid v4 ID generation from the models and replace it with `shared.NewId()`, which generates an Id depending on the config setting
23 lines
412 B
Go
23 lines
412 B
Go
package shared
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"github.com/nrednav/cuid2"
|
|
"github.com/rs/xid"
|
|
|
|
"git.mstar.dev/mstar/linstrom/config"
|
|
)
|
|
|
|
// Generate a new string ID
|
|
func NewId() string {
|
|
switch config.GlobalConfig.Experimental.IdGenerator {
|
|
case "uuid":
|
|
return uuid.NewString()
|
|
case "cuid":
|
|
return cuid2.Generate()
|
|
case "xid":
|
|
return xid.New().String()
|
|
default:
|
|
return xid.New().String()
|
|
}
|
|
}
|