1
0
Fork 0
miniflux/server/server.go

36 lines
893 B
Go
Raw Normal View History

2017-11-20 00:10:04 -05:00
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package server
import (
"log"
"net/http"
"time"
2017-11-21 22:37:47 -05:00
"github.com/miniflux/miniflux2/config"
"github.com/miniflux/miniflux2/reader/feed"
"github.com/miniflux/miniflux2/storage"
2017-11-20 00:10:04 -05:00
)
2017-11-21 22:37:47 -05:00
// NewServer returns a new HTTP server.
2017-11-20 00:10:04 -05:00
func NewServer(cfg *config.Config, store *storage.Storage, feedHandler *feed.Handler) *http.Server {
server := &http.Server{
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 60 * time.Second,
Addr: cfg.Get("LISTEN_ADDR", config.DefaultListenAddr),
2017-11-21 22:37:47 -05:00
Handler: getRoutes(cfg, store, feedHandler),
2017-11-20 00:10:04 -05:00
}
go func() {
log.Printf("Listening on %s\n", server.Addr)
if err := server.ListenAndServe(); err != nil {
log.Fatal(err)
}
}()
return server
}