package model import ( "encoding/json" "time" ) type Article struct { ID int `json:"id"` Title string `json:"title"` Summary string `json:"summary"` Content string `json:"content"` CoverURL string `json:"cover_url"` ImageURLs []string `json:"image_urls"` ImageJSON string `json:"-"` // stored as JSON in DB CreatedAt time.Time `json:"created_at"` } // ScanImageJSON unmarshals image_urls from the JSON column. func (a *Article) ScanImageJSON() { if a.ImageJSON != "" { json.Unmarshal([]byte(a.ImageJSON), &a.ImageURLs) } if a.ImageURLs == nil { a.ImageURLs = []string{} } } // SetImageJSON marshals image_urls for DB storage. func (a *Article) SetImageJSON() { data, _ := json.Marshal(a.ImageURLs) a.ImageJSON = string(data) }