package link import ( "net/url" "time" ) type CreationModel struct { Id string `json:"id"` Name string `json:"name"` RedirectURL string `json:"redirectUrl"` Password string `json:"password"` } type ResourceModel struct { Id string `json:"id"` Name string `json:"name"` RedirectURL string `json:"redirectUrl"` Password string `json:"password"` CreationTime int64 `json:"creationTime"` } type UpdateModel struct { Name string `json:"name,omitempty"` RedirectURL string `json:"redirectUrl,omitempty"` Password string `json:"password"` } func (m *CreationModel) MapModelToEntity() (*Link, error) { u, err := url.Parse(m.RedirectURL) if err != nil { return nil, err } return &Link{ Id: m.Id, Name: m.Name, RedirectURL: *u, Password: m.Password, CreationTime: time.Now().UTC(), }, nil } func MapEntityToModel(entity *Link) ResourceModel { return ResourceModel{ Id: entity.Id, Name: entity.Name, RedirectURL: entity.RedirectURL.String(), Password: entity.Password, CreationTime: entity.CreationTime.Unix(), } }