about summary refs log tree commit diff
path: root/server.go
blob: 974724c9f3073a1b88c87d97e8246563c7c1eeb0 (plain)
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

import (
	"flag"
	"fmt"
	"log"

	"net/http"

	"github.com/gorilla/mux"
)

var (
	// Store a list of categories
	categories []string

	// Threshold defining how old a category must be before it is considered "to
	// old" (in seconds)
	categoryAgeThreshold int

	// Define the port the server should listen on
	port int
)

func main() {
	// Parse the command line flags
	initFlags()

	// Define a new gorilla/mux router and define some endpoints
	r := mux.NewRouter()

	r.HandleFunc("/", indexHandler)
	r.HandleFunc("/v1/dumpall", dumpallHandler)
	r.HandleFunc("/v1/all", printAllHandler)
	r.HandleFunc("/v1/getTLE", getHandler)

	// Start the http server using the port provided using command line arguments
	// The Default port is 8080
	log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), r))
}

func initFlags() {
	flag.IntVar(&port, "p", 8080, "the port the server should listen on")
	flag.IntVar(&categoryAgeThreshold, "a", 3600, "max category age in seconds")
	flag.Parse()
}