server.go 839 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package server
  5. import (
  6. "github.com/miniflux/miniflux2/config"
  7. "github.com/miniflux/miniflux2/reader/feed"
  8. "github.com/miniflux/miniflux2/storage"
  9. "log"
  10. "net/http"
  11. "time"
  12. )
  13. func NewServer(cfg *config.Config, store *storage.Storage, feedHandler *feed.Handler) *http.Server {
  14. server := &http.Server{
  15. ReadTimeout: 5 * time.Second,
  16. WriteTimeout: 10 * time.Second,
  17. IdleTimeout: 60 * time.Second,
  18. Addr: cfg.Get("LISTEN_ADDR", "127.0.0.1:8080"),
  19. Handler: getRoutes(store, feedHandler),
  20. }
  21. go func() {
  22. log.Printf("Listening on %s\n", server.Addr)
  23. if err := server.ListenAndServe(); err != nil {
  24. log.Fatal(err)
  25. }
  26. }()
  27. return server
  28. }