Files
2026-03-02 22:36:47 +01:00

35 lines
497 B
Go

package server
import (
"fmt"
"net/http"
"os"
"strconv"
"time"
)
type Server struct {
port int
}
func NewServer() *http.Server {
port, _ := strconv.Atoi(os.Getenv("PORT"))
if port == 0 {
port = 8080
}
s := &Server{
port: port,
}
// Declare Server config
server := &http.Server{
Addr: fmt.Sprintf(":%d", s.port),
Handler: s.RegisterRoutes(),
IdleTimeout: time.Minute,
ReadTimeout: 10 * time.Second,
WriteTimeout: 30 * time.Second,
}
return server
}