Answers for "golang gorm uuid"

2

using uuid golang

package main

import (
    "fmt"
    "strings"
    "github.com/google/uuid"
)

func main() {
    uuidWithHyphen := uuid.New()
    fmt.Println(uuidWithHyphen)
    uuid := strings.Replace(uuidWithHyphen.String(), "-", "", -1)
    fmt.Println(uuid)
}
Posted by: Guest on June-22-2021
0

gorm uuid

package model

import (
	"time"

	"github.com/google/uuid"
	"gorm.io/gorm"
)

type EntityUsers struct {
	ID        string `gorm:"primaryKey;"`
	Fullname  string `gorm:"type:varchar(255);unique;not null"`
	Email     string `gorm:"type:varchar(255);unique;not null"`
	Password  string `gorm:"type:varchar(255);not null"`
	Active    bool   `gorm:"type:bool;default:false"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (user *EntityUsers) BeforeCreate(db *gorm.DB) error {
	user.ID = uuid.New().String()
	return nil
}
Posted by: Guest on April-25-2021

Browse Popular Code Answers by Language