|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "flag" |
4 | 5 | "fmt"
|
5 | 6 | "html/template"
|
6 | 7 | "net/http"
|
@@ -64,14 +65,32 @@ func add(x, y int) string {
|
64 | 65 | }
|
65 | 66 |
|
66 | 67 | func main() {
|
67 |
| - mux := http.NewServeMux() |
68 |
| - repo := NewRepository() |
| 68 | + isDevEnv := flag.Bool("dev", false, "Tells the program whether it is running in a development environment or not (defaults to false)") |
| 69 | + flag.Parse() |
69 | 70 | funcMap := template.FuncMap{
|
70 | 71 | "add": add,
|
71 | 72 | "parse": parse,
|
72 | 73 | }
|
| 74 | + var templates *template.Template |
| 75 | + if *isDevEnv { |
| 76 | + templates = template.Must(template.New("stupidfuckingbitch").Funcs(funcMap).ParseFiles( |
| 77 | + "main.html", |
| 78 | + "projects-list.html", |
| 79 | + "projects-description.html", |
| 80 | + "projects-steps-table.html", |
| 81 | + )) |
| 82 | + |
| 83 | + } else { |
| 84 | + templates = template.Must(template.New("stupidfuckingbitch").Funcs(funcMap).ParseFiles( |
| 85 | + "/usr/share/pm/html/main.html", |
| 86 | + "/usr/share/pm/html/projects-list.html", |
| 87 | + "/usr/share/pm/html/projects-description.html", |
| 88 | + "/usr/share/pm/html/projects-steps-table.html", |
| 89 | + )) |
| 90 | + } |
| 91 | + mux := http.NewServeMux() |
| 92 | + repo := NewRepository() |
73 | 93 |
|
74 |
| - templates := template.Must(template.New("stupidfuckingbitch").Funcs(funcMap).ParseFiles("main.html", "projects-list.html", "projects-description.html", "projects-steps-table.html")) |
75 | 94 | mux.HandleFunc("POST /projects/", func(w http.ResponseWriter, r *http.Request) {
|
76 | 95 | fmt.Println("Matched POST /projects")
|
77 | 96 | p := Project{
|
@@ -163,7 +182,7 @@ func main() {
|
163 | 182 | http.Redirect(w, r, "/projects/"+projectId, http.StatusSeeOther)
|
164 | 183 | })
|
165 | 184 |
|
166 |
| - port := ":8080" |
| 185 | + port := "0.0.0.0:8080" |
167 | 186 | fmt.Println("Listening on http://localhost" + port)
|
168 | 187 | http.ListenAndServe(port, mux)
|
169 | 188 | }
|
0 commit comments