-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (63 loc) · 1.53 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Minimal Pet Store Example
*
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* API version: 1.0.0
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package main
import (
"crypto/tls"
"flag"
"log"
"net/http"
"strconv"
"golang.org/x/net/http2"
"golang.org/x/sys/unix"
"os"
)
var (
sysConfigPath string
packageName string
)
var (
ip string
port uint
certFile string
keyFile string
keylog bool
)
func init() {
keylog = false
flag.StringVar(&ip, "ip", "localhost", "ip address of sbi server")
flag.UintVar(&port, "port", 8080, "port")
flag.StringVar(&certFile, "cert", sysConfigPath+"/"+packageName+"/https/smf.cert", "TLS certificate")
flag.StringVar(&keyFile, "key", sysConfigPath+"/"+packageName+"/https/smf.key", "TLS key")
flag.Parse()
}
func main() {
if err := unix.Prctl(unix.PR_SET_PDEATHSIG, uintptr(unix.SIGKILL), 0, 0, 0); err != nil {
log.Fatal("Prctl Fail")
return
}
var keylogFile *os.File
var err error
if keylog {
keylogFile, err = os.OpenFile("smfkey.log", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
log.Println("smfkey.log")
}
}
var server http.Server
server.Addr = ip + ":" + strconv.Itoa(int(port))
if keylog && keylogFile != nil {
server.TLSConfig = &tls.Config{
KeyLogWriter: keylogFile,
}
}
router := NewRouter()
http.Handle("/", router)
http2.ConfigureServer(&server, &http2.Server{})
log.Println(server.ListenAndServeTLS(certFile, keyFile))
}