-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (35 loc) · 1.15 KB
/
main.go
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
package main
import (
"flag"
"fmt"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"moduleLocator/internal/views"
"net/http"
"os"
)
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
hostname := flag.String("hostname", "mycooldomain.com", "The URL of this server.")
port := flag.Int("port", 80, "The server's hosting port.")
repoLocation := flag.String("repoLocation", "", "The location where you repos can be found. Requires a final '/' if the location is a directory.")
debug := flag.Bool("debug", false, "sets log level to debug.")
human := flag.Bool("human", false, "sets log style to human friendly.")
flag.Parse()
// Set the logger
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if *debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
if *human {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
views.Hostname = *hostname
views.RepoLocation = *repoLocation
log.Info().Str("hostname", *hostname).Int("port", *port).Msg("Starting Go module locator server.")
http.HandleFunc("/", views.RepoPage)
err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)
if err != nil {
log.Fatal().Err(err).Msg("")
}
}