-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
69 lines (55 loc) · 1.06 KB
/
main.go
File metadata and controls
69 lines (55 loc) · 1.06 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 (
"crypto/tls"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"time"
"gobackend/api"
"gobackend/configuration"
"gobackend/db"
)
func main() {
//Load router
router := api.InitRoutes()
//Load configuration
configuration.LoadConfiguration()
//Creating sqlite object
db.InitDB()
defer db.GetDB().Close()
port := os.Getenv("PORT")
if port == "" {
port = "8765" //localhost
}
fmt.Println(port)
srv := &http.Server{
Addr: ":" + port,
Handler: router,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
TLSConfig: tlsConfig(),
}
if err := srv.ListenAndServeTLS("", ""); err != nil {
log.Fatal(err)
}
}
func tlsConfig() *tls.Config {
crt, err := ioutil.ReadFile(configuration.Conf.Certificate)
if err != nil {
log.Fatal(err)
}
key, err := ioutil.ReadFile(configuration.Conf.ServerKey)
if err != nil {
log.Fatal(err)
}
cert, err := tls.X509KeyPair(crt, key)
if err != nil {
log.Fatal(err)
}
return &tls.Config{
Certificates: []tls.Certificate{cert},
ServerName: "localhost",
}
}