-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
56 lines (46 loc) · 1.18 KB
/
server.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
54
55
56
package main
import (
"fmt"
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/ptheunis/go-svelte/ui"
)
const (
writeTimeout = (15 * time.Second)
readTimeout = (15 * time.Second)
idleTimeout = (60 * time.Second)
)
var hostAddr = ":8080"
// GetServer ...
func GetServer(listenPort int) (*http.Server, error) {
assets, _ := ui.Assets()
// Use the file system to serve static files
fs := http.FileServer(http.FS(assets))
r := mux.NewRouter()
r.PathPrefix("/").Handler(fs)
/*
// generate certificate pair
cert, err := tls.LoadX509KeyPair("keys/localhost.crt", "keys/localhost.key")
if err != nil {
return nil, err
}
// create the TLS Config with the CA pool and enable Client certificate validation
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
MinVersion: tls.VersionTLS13,
}
*/
// Config of session/cookie settings
// s := sessions.GetInstance()
// s.SetDomain("<realdomain>")
// s.SetExpirationDuration(1 * time.Hour)
return &http.Server{
Handler: r,
Addr: fmt.Sprintf(":%d", listenPort),
WriteTimeout: writeTimeout,
ReadTimeout: readTimeout,
IdleTimeout: idleTimeout,
//TLSConfig: tlsConfig,
}, nil
}