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.
33 lines
541 B
Go
33 lines
541 B
Go
3 years ago
|
package server
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"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),
|
||
|
}
|
||
|
}
|
||
|
return err
|
||
|
}
|