2808 explained code solutions for 75 technologies


golangHow to generate UUID and convert it to string


This uses uuid module that should be installed by go get github.com/google/uuid command:

package main

import "fmt"
import "github.com/google/uuid"

func main() {
  string_uuid = (uuid.New()).String()
}ctrl + c
github.com/google/uuid

module to work with uuid

uuid.New()

init new UUID value

.String()

converts generated UUID to string


Usage example

package main

import "fmt"
import "github.com/google/uuid"

func main() {
  string_uuid := (uuid.New()).String()
  fmt.Println( string_uuid )
}
output
2ba2d6aa-e84e-424d-82cb-96f1c951f5d2