my CMS/Blog engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

server.go 845B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package main
  2. /*
  3. * This is freesofware under 2-clause BSD license, See LICENSE file
  4. */
  5. import (
  6. "fmt"
  7. "net/http"
  8. _ "net/http/pprof"
  9. "path/filepath"
  10. "time"
  11. "github.com/PuerkitoBio/ghost/handlers"
  12. )
  13. // Start serving the blog.
  14. func run() {
  15. var (
  16. faviconPath = filepath.Join(PublicDir, "favicon.ico")
  17. faviconCache = 2 * 24 * time.Hour
  18. )
  19. h := handlers.FaviconHandler(
  20. handlers.PanicHandler(
  21. handlers.LogHandler(
  22. handlers.GZIPHandler(
  23. http.FileServer(http.Dir(PublicDir)),
  24. nil),
  25. handlers.NewLogOptions(nil, handlers.Ldefault)),
  26. nil),
  27. faviconPath,
  28. faviconCache)
  29. // Assign the combined handler to the server.
  30. http.Handle("/", h)
  31. // Start it up.
  32. INFO("Listening on port %d", Options.Port)
  33. if err := http.ListenAndServe(fmt.Sprintf(":%d", Options.Port), nil); err != nil {
  34. FATAL(err.Error())
  35. }
  36. }