-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (43 loc) · 1.21 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
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"./constants"
"./handlers"
"flag"
"fmt"
log "github.com/sirupsen/logrus"
"net/http"
"os"
)
func main() {
log.SetLevel(log.DebugLevel)
// Format of command line arguments: NYTAPI NEWSAPI TODO: LOGLVL
// Cmmnd Line Flags to perform particular actions
flag.StringVar(&constants.NytKeyPtr, "nyt", "",
"nyt api key")
flag.StringVar(&constants.NewsKeyPtr, "news", "",
"NewsAPI key")
tail := flag.Args()
flag.Parse()
log.Infof("NYT Key: %v \n News Key: %v \n",
constants.NytKeyPtr, constants.NewsKeyPtr)
fmt.Printf("these are the trailing arguments: %v\n", tail)
if constants.NytKeyPtr == "" || constants.NewsKeyPtr == "" {
log.Fatal("Do not have necessary API keys")
os.Exit(1)
}
// TODO: create log file
log.SetOutput(os.Stdout)
log.Info("Starting program...")
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
mux := http.NewServeMux()
// Declare the static file directory
fs := http.FileServer(http.Dir("frontendassets"))
mux.Handle("/frontendassets/", http.StripPrefix("/frontendassets/", fs))
mux.HandleFunc("/", handlers.IndexHandler)
mux.HandleFunc("/search", handlers.SearchHandler)
log.Info("Listening on port ", port)
http.ListenAndServe(":"+port, mux)
}