-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (33 loc) · 741 Bytes
/
Copy pathmain.go
File metadata and controls
42 lines (33 loc) · 741 Bytes
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 (
"log"
"net/http"
"os"
)
func main() {
port := getEnv("PORT", "8080")
dataFile := getEnv("COMPANIES_FILE", "data/companies.csv")
storage, err := NewFileCompanyStorage(dataFile)
if err != nil {
log.Fatal(err)
}
service := NewCompanyService(storage)
handler := NewHandler(service)
mux := http.NewServeMux()
handler.RegisterRoutes(mux)
RegisterSwaggerRoutes(mux)
addr := ":" + port
log.Printf("company-registry-api started on %s", addr)
log.Printf("loaded companies: %d", storage.Count())
err = http.ListenAndServe(addr, mux)
if err != nil {
log.Fatal(err)
}
}
func getEnv(key string, fallback string) string {
value := os.Getenv(key)
if value == "" {
return fallback
}
return value
}