got error unsupported data type: &[] #6532
-
// There are error for all models
// 1st Error
[error] failed to parse value &models.User{ID:uuid.UUID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, CreatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), UpdatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Name:"", Email:"", Password:"", Role:"", Photo:"", ApiKey:"", Verified:false, Prompts:[]models.Prompt(nil), Folders:[]models.Folder(nil), Playgrounds:[]models.Playground(nil), PlaygroundID:uuid.UUID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}, got error unsupported data type: &[]
// 2nd Error
[error] failed to parse value &models.Folder{ID:uuid.UUID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, CreatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), UpdatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Name:"", AuthorID:uuid.UUID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, Prompts:[]models.Prompt(nil)}, got error unsupported data type: &[]
//3rd Error
[error] failed to parse value &models.Prompt{ID:uuid.UUID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, CreatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), UpdatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Title:"", Prompt:"", Tags:[]string(nil), AuthorID:uuid.UUID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, FolderID:uuid.UUID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, Description:"", Playgrounds:[]models.Playground(nil)}, got error unsupported data type: &[]
// 4th Error
[error] failed to parse value &models.Playground{ID:uuid.UUID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, CreatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), UpdatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Name:"", Template:"", Temprature:0x0, AiModel:"", TopPValue:0x0, Likes:0x0, Author:models.User{ID:uuid.UUID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, CreatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), UpdatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Name:"", Email:"", Password:"", Role:"", Photo:"", ApiKey:"", Verified:false, Prompts:[]models.Prompt(nil), Folders:[]models.Folder(nil), Playgrounds:[]models.Playground(nil), PlaygroundID:uuid.UUID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}, Forks:0x0, Likers:[]models.User(nil), PromptID:uuid.UUID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, AuthorID:uuid.UUID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}, got error unsupported data type: &[]
// user.model.go
type User struct {
ID uuid.UUID `json:"user_id" gorm:"type:uuid;default:gen_random_uuid();primary_key"`
CreatedAt time.Time `json:"created_at" gorm:"not null;default:NOW()"`
UpdatedAt time.Time `json:"-" gorm:"not null;NOW()"`
Name string `json:"name" gorm:"type:varchar(255);not null"`
Email string `json:"email" gorm:"uniqueIndex;not null"`
Password string `json:"-" gorm:"not null"` // "-" excludes the Password field from JSON
Role string `json:"user_role,omitempty" gorm:"type:varchar(255);not null"`
Photo string `json:"photo,omitempty" gorm:"type:varchar(255);default:''"`
ApiKey string `json:"-" gorm:"type:varchar(255);default:''"`
Verified bool `json:"verified" gorm:"default:false"`
Prompts []Prompt `json:"prompts" gorm:"foreignKey:UserID"`
Folders []Folder `json:"folders" gorm:"foreignKey:UserID"`
Playgrounds []Playground `json:"playgrounds" gorm:"foreignKey:UserID"`
PlaygroundID uuid.UUID `json:"folder" gorm:"type:uuid"`
}
//folder.model.go
type Folder struct {
ID uuid.UUID `json:"folder_id" gorm:"type:uuid;default:gen_random_uuid();primary_key"`
CreatedAt time.Time `json:"created_at" gorm:"not null;default:NOW()"`
UpdatedAt time.Time `json:"updated_at" gorm:"not null;NOW()"`
Name string `json:"name" gorm:"varchar(255);not null"`
AuthorID uuid.UUID `json:"author_id" gorm:"type:uuid"`
Prompts []Prompt `json:"prompts" gorm:"foreignKey:FolderID"`
}
// prompt.model.go
type Prompt struct {
ID uuid.UUID `json:"folder_id" gorm:"type:uuid;default:gen_random_uuid();primary_key"`
CreatedAt time.Time `json:"created_at" gorm:"not null;default:NOW()"`
UpdatedAt time.Time `json:"updated_at" gorm:"not null;NOW()"`
Title string `json:"prompt_title" gorm:"not null"`
Prompt string `json:"prompt" gorm:"not null"`
Tags []string `json:"tags"`
AuthorID uuid.UUID `json:"author_id" gorm:"type:uuid"`
FolderID uuid.UUID `json:"folder" gorm:"type:uuid"`
Description string `json:"description" gorm:"not null"`
Playgrounds []Playground `json:"playgrounds" gorm:"foreignKey:PromptID"`
}
// playground.model.go
type Playground struct {
ID uuid.UUID `json:"playground_id" gorm:"type:uuid;default:gen_random_uuid();primary_key"`
CreatedAt time.Time `json:"created_at" gorm:"not null;default:NOW()"`
UpdatedAt time.Time `json:"update_at" gorm:"not null;NOW()"`
Name string `json:"name" gorm:"varchar(255);not null"`
Template string `json:"prompt_template" gorm:"not null"`
Temprature uint `json:"temprature" gorm:"default:3"`
AiModel string `json:"ai_model" gorm:"default:'gpt-3.5-turbo'"`
TopPValue uint `json:"top_p_value" gorm:"default:0"`
Likes uint32 `json:"likes" gorm:"default:0"`
Author User `json:"author" gorm:"references:AuthorID"`
Forks uint32 `json:"forks_count" gorm:"default:0"`
Likers []User `json:"likers" gorm:"foreignKey:PlaygroundID"`
PromptID uuid.UUID `json:"prompt_id"`
AuthorID uuid.UUID `json:"author_id"`
} |
Beta Was this translation helpful? Give feedback.
Answered by
Codedwells
Aug 19, 2023
Replies: 1 comment
-
The error was caused by using |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Codedwells
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The error was caused by using
[]string
as a type in Prompt model Tags field. Here is a more comprehensive answerI'm still new to Go so I was not aware you cannot use that type directly in a GORM model