-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
69 lines (60 loc) · 1.75 KB
/
main.go
File metadata and controls
69 lines (60 loc) · 1.75 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"log"
"net"
"net/http"
"strconv"
"time"
"clinton.dev/internal/email"
"clinton.dev/internal/utils"
"clinton.dev/internal/web"
"github.com/BurntSushi/toml"
)
type configuration struct {
PostmarkServerToken string `toml:"PostmarkServerToken"`
PostmarkAccountToken string `toml:"PostmarkAccountToken"`
WebServerIP string `toml:"WebServerIP"`
WebServerPort int `toml:"WebServerPort"`
ServeStaticFiles bool `toml:"ServeStaticFiles"`
ContactFormFromEmail string `toml:"ContactFormFromEmail"`
ContactFormToEmail string `toml:"ContactFormToEmail"`
}
func getConfiguration() (*configuration, error) {
configPath, err := utils.GetRelativeDirectory("config.toml")
if err != nil {
return nil, err
}
config := &configuration{}
_, err = toml.DecodeFile(configPath, config)
if err != nil {
return nil, err
}
return config, nil
}
func main() {
config, err := getConfiguration()
if err != nil {
log.Fatal(fmt.Sprintf("Error reading configuration file. ERROR: %v", err))
}
httpServer := &http.Server{
Addr: net.JoinHostPort(config.WebServerIP, strconv.Itoa(config.WebServerPort)),
ReadTimeout: time.Second * 15,
ReadHeaderTimeout: time.Second * 15,
WriteTimeout: time.Second * 15,
IdleTimeout: time.Minute * 60,
}
// Configure and get postmark email methods.
postmarkEmailInstance := email.New(config.PostmarkServerToken, config.PostmarkAccountToken)
// Configure and get access to webserver methods.
webServer, err := web.New(httpServer, postmarkEmailInstance, config.ServeStaticFiles,
config.ContactFormFromEmail, config.ContactFormToEmail)
if err != nil {
log.Fatal(err)
}
// Self explanatory
err = webServer.Listen()
if err != nil {
log.Fatal(err)
}
}