Fudge

fudge / main.go

Commits | bovarysme Release v0.4.0 Committed on Dec 25, 2019

778 B | Download

 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
39
40
41
42
43
44
45
46
package main

//go:generate go run generate.go

import (
	"flag"
	"log"
	"net/http"
	"os"
	"time"

	"bovarys.me/fudge/config"
	"bovarys.me/fudge/handler"
)

var configPath string

func init() {
	flag.StringVar(&configPath, "config", "config.yml", "path to the config file")
	flag.Parse()
}

func main() {
	cfg, err := config.NewConfig(configPath)
	if err != nil {
		log.Fatal(err)
	}

	h, err := handler.NewHandler(cfg)
	if err != nil {
		log.Fatal(err)
	}

	logger := log.New(os.Stdout, "", log.LstdFlags)

	server := &http.Server{
		Addr:         "localhost:8080",
		Handler:      h.Router,
		ReadTimeout:  10 * time.Second,
		WriteTimeout: 10 * time.Second,
		ErrorLog:     logger,
	}

	logger.Println("Starting server on", server.Addr)
	log.Fatal(server.ListenAndServe())
}