Commits

Miki Tebeka  committed 48bbbf9

Last-Modified and as hex values

  • Participants
  • Parent commits d758d1b

Comments (0)

Files changed (1)

File resources/resources.go

 	"fmt"
 	"io"
 	"net/http"
+	"time"
 )
 
 type Resource interface {
 	Open() io.Reader
 	Size() int
 	Type() string
+	Time() time.Time
 }
 
 var resources map[string]Resource
 type resource struct {
 	data  []byte
 	ctype string
+	time  time.Time
 }
 
 func (rsc *resource) Open() io.Reader {
 	return rsc.ctype
 }
 
+func (rsc *resource) Time() time.Time {
+	return rsc.time
+}
+
 type handler int
 
 func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
 		return
 	}
 
-	header := w.Header()
-	header.Set("Content-Type", rsc.Type())
-	header.Set("Content-Size", fmt.Sprintf("%d", rsc.Size()))
+	w.Header().Set("Content-Type", rsc.Type())
+	w.Header().Set("Content-Size", fmt.Sprintf("%d", rsc.Size()))
+	w.Header().Set("Last-Modified", rsc.Time().UTC().Format(http.TimeFormat))
+
 	io.Copy(w, rsc.Open())
 }
 
 
 func init() {
 	resources = make(map[string]Resource)
-	resources["hello"] = &resource{[]byte("hello there"), "text/plain"}
+	resources["hello"] = &resource{
+		[]byte{
+			0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x74,
+			0x68, 0x65, 0x72, 0x65, 0xa,
+		},
+		"text/plain",
+		time.Unix(0, 0),
+	}
 }