all repos

mugit @ 012e7df

🐮 git server that your cow will love

mugit/main.go(view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main

import (
	"log"
	"log/slog"
	"net"
	"net/http"
	"os"
	"strconv"

	"olexsmir.xyz/mugit/internal/config"
	"olexsmir.xyz/mugit/internal/handlers"
)

func main() {
	if err := run(); err != nil {
		log.Fatalf("main: %s", err)
		os.Exit(1)
	}
}

func run() error {
	cfg, err := config.Load("/home/olex/code/mugit/config.yml")
	if err != nil {
		slog.Error("config error", "err", err)
		return err
	}

	mux := handlers.InitRoutes(cfg)

	port := strconv.Itoa(cfg.Server.Port)
	slog.Info("starting server", "host", cfg.Server.Host, "port", port)
	if err = http.ListenAndServe(net.JoinHostPort(cfg.Server.Host, port), mux); err != nil {
		slog.Error("server error", "err", err)
	}

	return nil
}