mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
inetrnal: rename Date to Time, make it a Text{Marshaler,Unmarshaler}
This commit is contained in:
parent
3d37e49ca0
commit
ae0541654a
@ -245,18 +245,24 @@ type GetContentType struct {
|
|||||||
Type string `xml:",chardata"`
|
Type string `xml:",chardata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Date string
|
type Time time.Time
|
||||||
|
|
||||||
func NewDate(t time.Time) Date {
|
func (t *Time) UnmarshalText(b []byte) error {
|
||||||
return Date(t.Format(time.RFC1123Z))
|
tt, err := http.ParseTime(string(b))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*t = Time(tt)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Date) Time() (time.Time, error) {
|
func (t *Time) MarshalText() ([]byte, error) {
|
||||||
return http.ParseTime(string(d))
|
s := time.Time(*t).Format(time.RFC1123Z)
|
||||||
|
return []byte(s), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://tools.ietf.org/html/rfc4918#section-15.7
|
// https://tools.ietf.org/html/rfc4918#section-15.7
|
||||||
type GetLastModified struct {
|
type GetLastModified struct {
|
||||||
XMLName xml.Name `xml:"DAV: getlastmodified"`
|
XMLName xml.Name `xml:"DAV: getlastmodified"`
|
||||||
LastModified Date `xml:",chardata"`
|
LastModified Time `xml:",chardata"`
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ var liveProps = map[xml.Name]PropfindFunc{
|
|||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
return nil, &HTTPError{Code: http.StatusNotFound}
|
return nil, &HTTPError{Code: http.StatusNotFound}
|
||||||
}
|
}
|
||||||
return &internal.GetLastModified{LastModified: internal.NewDate(fi.ModTime())}, nil
|
return &internal.GetLastModified{LastModified: internal.Time(fi.ModTime())}, nil
|
||||||
},
|
},
|
||||||
// TODO: getetag
|
// TODO: getetag
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user