// +build THIS_IS_BROKEN package main import ( "bytes" "fmt" "net/http" "net/url" "text/template" "time" ) type xmler interface { XML(b *bytes.Buffer) } // See: http://www.webdav.org/specs/rfc4918.html // 14.7 href XML Element type href url.URL func (h *href) XML(b *bytes.Buffer) { b.WriteString("" + template.HTMLEscapeString((*url.URL)(h).String()) + "") } // 14.16 multistatus XML Element type multistatus []*response func (m multistatus) XML(b *bytes.Buffer) { b.WriteString("") for _, r := range m { r.XML(b) } b.WriteString("") } // 14.24 response XML Element type response struct { href *href body xmler // hrefsstatus OR propstats } func (r *response) XML(b *bytes.Buffer) { b.WriteString("") r.href.XML(b) r.body.XML(b) b.WriteString("") } // part of 14.24 response XML element type hrefsstatus struct { hrefs []*href status status } func (hs *hrefsstatus) XML(b *bytes.Buffer) { for _, h := range hs.hrefs { h.XML(b) } hs.status.XML(b) } // part of 14.24 response element type propstats []propstat func (p propstats) XML(b *bytes.Buffer) { b.WriteString("") for _, prop := range p { prop.XML(b) } b.WriteString("") } // 14.22 propstat XML Element type propstat struct { props []xmler status status } func (p *propstat) XML(b *bytes.Buffer) { b.WriteString("") for _, prop := range p.props { prop.XML(b) } b.WriteString("") p.status.XML(b) } // 14.28 status XML element type status int func (s status) XML(b *bytes.Buffer) { b.WriteString(fmt.Sprintf("HTTP/1.1 %d %s", s, template.HTMLEscapeString(http.StatusText(int(s))))) } // 15.1 creationdate Property type creationdate uint64 // seconds from unix epoch func (c creationdate) XML(b *bytes.Buffer) { b.WriteString("") b.WriteString(epochToXMLTime(int64(c))) b.WriteString("") } // 15.4 getcontentlength Property type getcontentlength uint64 func (l getcontentlength) XML(b *bytes.Buffer) { b.WriteString("") b.WriteString(fmt.Sprint(l)) b.WriteString("") } // 15.7 getlastmodified Property type getlastmodified uint64 // seconds from unix epoch func (g getlastmodified) XML(b *bytes.Buffer) { b.WriteString("") b.WriteString(epochToXMLTime(int64(g))) b.WriteString("") } // 15.9 resourcetype Property type resourcetype bool // true if collection (directory), false otherwise func (r resourcetype) XML(b *bytes.Buffer) { b.WriteString("") if r { b.WriteString("") } b.WriteString("") } // helpers func epochToXMLTime(sec int64) string { return template.HTMLEscapeString(time.Unix(sec, 0).UTC().Format(time.RFC3339)) }