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

36 lines
643 B
Go

3 years ago
package server
import (
"fmt"
3 years ago
"log"
3 years ago
"net/http"
"dymatrix.de/jspahl/todo/internal/config"
"github.com/gin-gonic/gin"
)
var httpServer *http.Server
var httpRouter *gin.Engine
func Setup() {
httpRouter = gin.New()
httpRouter.Use(gin.Logger())
registerRoutes(httpRouter)
}
func ListenAndServe() error {
var err error = nil
for err == nil || err == http.ErrServerClosed {
c := config.GetConfig()
httpServer = &http.Server{
Handler: httpRouter,
Addr: fmt.Sprintf("%s:%d", c.Listen.Host, c.Listen.Port),
}
3 years ago
log.Printf("Starting web server at %s", httpServer.Addr)
err = httpServer.ListenAndServe()
3 years ago
}
return err
}