I am using https://github.com/google/uuid in my project and I want my User Struct to have an id with as a UUID but It will not let me assign it as the data type. When I try to it gives me the error syntax error: unexpected :, expecting type
. Here is my code for reference:
package postgres
import (
"time"
"github.com/google/uuid"
)
type DbUser struct {
ID: uuid.UUID,
Username: string,
Password: string,
Email: string,
DateOfBirth: time,
dateCreated: time,
}
Can anyone help me clarify the syntax for passing a struct element or variable as a UUID?
Your struct definition is wrong, you're using the syntax for a composite literal. It should be:
type DbUser struct {
ID uuid.UUID
Username string
Password string
Email string
DateOfBirth time.Time
dateCreated time.Time
}
Also note that time
is not a type, it's a package name.
You may want to take the Tour of Go to learn the basic syntax.