32 lines
757 B
Go
32 lines
757 B
Go
package v1
|
|
|
|
import (
|
|
"encoding/json"
|
|
"path"
|
|
"strconv"
|
|
)
|
|
|
|
type TravelWay struct {
|
|
ID int `json:"id" gorm:"autoIncrement;primaryKey"`
|
|
Plan int `json:"plan"`
|
|
Image string `json:"image" gorm:"type:char(8)"`
|
|
Lat float32 `json:"lat"`
|
|
Lon float32 `json:"lon"`
|
|
Address string `json:"address" gorm:"type:varchar(64)"`
|
|
CreatedAt int64 `json:"createdAt"`
|
|
}
|
|
|
|
func (w *TravelWay) ImagePath(dir string) string {
|
|
return path.Join(dir, strconv.Itoa(w.Plan), strconv.Itoa(w.ID) + w.Image)
|
|
}
|
|
|
|
func (w *TravelWay) ImageSrc() string {
|
|
if w.Image == "" {
|
|
return ""
|
|
}
|
|
return "/" + path.Join("img", strconv.Itoa(w.Plan), strconv.Itoa(w.ID) + w.Image)
|
|
}
|
|
|
|
func (w *TravelWay)Bytes()([]byte, error){
|
|
return json.Marshal(w)
|
|
} |