mirror of
https://github.com/twhite96/go-backend-api.git
synced 2025-01-31 06:59:15 +00:00
34 lines
528 B
Go
34 lines
528 B
Go
|
package server
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
"os"
|
||
|
"strconv"
|
||
|
"time"
|
||
|
|
||
|
_ "github.com/joho/godotenv/autoload"
|
||
|
)
|
||
|
|
||
|
type Server struct {
|
||
|
port int
|
||
|
}
|
||
|
|
||
|
func NewServer() *http.Server {
|
||
|
port, _ := strconv.Atoi(os.Getenv("PORT"))
|
||
|
NewServer := &Server{
|
||
|
port: port,
|
||
|
}
|
||
|
|
||
|
// Declare Server config
|
||
|
server := &http.Server{
|
||
|
Addr: fmt.Sprintf(":%d", NewServer.port),
|
||
|
Handler: NewServer.RegisterRoutes(),
|
||
|
IdleTimeout: time.Minute,
|
||
|
ReadTimeout: 10 * time.Second,
|
||
|
WriteTimeout: 30 * time.Second,
|
||
|
}
|
||
|
|
||
|
return server
|
||
|
}
|