feat(templates): add helper functions for metadata editor form rendering
Add textToString, tagSliceToString, stringSliceToString, and formatDateForInput to convert pgtype/[]string values into HTML input value attributes for the metadata editor form fields.
This commit is contained in:
@@ -220,3 +220,25 @@ func FormatTimestamptzInTimezone(t pgtype.Timestamptz, timezone string) string {
|
|||||||
}
|
}
|
||||||
return FormatInTimezone(t.Time, timezone)
|
return FormatInTimezone(t.Time, timezone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func textToString(t pgtype.Text) string {
|
||||||
|
if t.Valid {
|
||||||
|
return t.String
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func tagSliceToString(tags []string) string {
|
||||||
|
return strings.Join(tags, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringSliceToString(s []string) string {
|
||||||
|
return strings.Join(s, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatDateForInput(d pgtype.Date) string {
|
||||||
|
if !d.Valid {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return d.Time.Format("2006-01-02")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user