gui_embedded.go 688 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //+build !guidev
  2. package main
  3. import (
  4. "fmt"
  5. "log"
  6. "mime"
  7. "net/http"
  8. "path/filepath"
  9. "time"
  10. "github.com/calmh/syncthing/auto"
  11. )
  12. func embeddedStatic() interface{} {
  13. var modt = time.Now().UTC().Format(http.TimeFormat)
  14. return func(res http.ResponseWriter, req *http.Request, log *log.Logger) {
  15. file := req.URL.Path
  16. if file[0] == '/' {
  17. file = file[1:]
  18. }
  19. bs, ok := auto.Assets[file]
  20. if !ok {
  21. return
  22. }
  23. mtype := mime.TypeByExtension(filepath.Ext(req.URL.Path))
  24. if len(mtype) != 0 {
  25. res.Header().Set("Content-Type", mtype)
  26. }
  27. res.Header().Set("Content-Size", fmt.Sprintf("%d", len(bs)))
  28. res.Header().Set("Last-Modified", modt)
  29. res.Write(bs)
  30. }
  31. }