mercury/web/run.go
2023-09-03 00:23:48 +02:00

24 lines
457 B
Go

package web
import (
"context"
"net/http"
"strconv"
"git.sleepycat.moe/sam/mercury/web/app"
"github.com/rs/zerolog/log"
)
func Run(ctx context.Context, app *app.App, port int) {
listenAddr := ":" + strconv.Itoa(port)
ech := make(chan error)
go func() {
ech <- http.ListenAndServe(listenAddr, app.Router)
}()
log.Info().Int("port", port).Msg("Running API server")
if err := <-ech; err != nil {
log.Err(err).Msg("Running API server")
}
}