-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
75 lines (65 loc) · 1.8 KB
/
Copy pathmain.go
File metadata and controls
75 lines (65 loc) · 1.8 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
70
71
72
73
74
75
package main
import (
"crypto/tls"
// "go_auth/keygen"
"go_auth/user"
"log"
"net/http"
"os"
"time"
"github.com/gorilla/mux"
)
var (
certFile = os.Getenv("CERT_FILE")
keyFile = os.Getenv("KEY_FILE")
serviceAddr = os.Getenv("SERVICE_ADDR")
)
func main() {
// For loggin all requests
logger := log.New(os.Stdout, "go_auth ", log.LstdFlags|log.Lshortfile)
user.InitialMigration()
r := mux.NewRouter()
srv := newServer(r, serviceAddr)
userHandler := user.NewHandlers(logger)
userHandler.SetupRoutes(r)
// mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// // uuid := keygen.GenerateKey()
// w.Header().Set("Content-Type", "text/plain")
// w.WriteHeader(http.StatusOK)
// w.Write([]byte(uuid))
// })
err := srv.ListenAndServeTLS(certFile, keyFile)
if err != nil {
log.Fatalf("server failed to start: %v", err)
}
}
func newServer(router *mux.Router, serverAddr string) *http.Server {
tlsConfig := &tls.Config{
// Causes servers to use Go's default cipher suite preferences,
// which are tuned to avoid attacks. Does nothing on clients.
PreferServerCipherSuites: true,
// Only use curves which have assembly implementations
CurvePreferences: []tls.CurveID{
tls.CurveP256,
tls.X25519, // Go 1.8 only
},
MinVersion: tls.VersionTLS12,
CipherSuites: []uint16{
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
},
}
srv := &http.Server{
Addr: serverAddr,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
TLSConfig: tlsConfig,
Handler: router,
}
return srv
}