-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.go
60 lines (53 loc) · 1.18 KB
/
http.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
package http
import (
"net/http"
"time"
"github.com/thoohv5/person/pkg/log"
"github.com/thoohv5/person/pkg/server"
"github.com/thoohv5/person/pkg/transport"
)
// New 注册HTTP
func New(
conf *Config,
log log.Logger,
flag bool,
handler http.Handler,
) transport.Server {
if !flag {
return nil
}
var opts = []server.Option{
server.Logger(log),
// server.TLSConfig(generateTLSConfig()),
server.Handler(handler),
}
if network := conf.Network; network != "" {
opts = append(opts, server.Network(network))
}
if addr := conf.Addr; addr != "" {
opts = append(opts, server.Address(addr))
}
if timeout := conf.Timeout; timeout > 0 {
opts = append(opts, server.Timeout(time.Duration(timeout)*time.Second))
}
srv := server.New(opts...)
return srv
}
//
// func generateTLSConfig() *tls.Config {
// pool := x509.NewCertPool()
// pool.AppendCertsFromPEM(ih.CACrt)
//
// tlsCert, err := tls.X509KeyPair(ih.ServerCrt, ih.ServerKey)
// if err != nil {
// panic(err)
// }
//
// // #nosec
// return &tls.Config{
// Certificates: []tls.Certificate{tlsCert},
// ClientCAs: pool,
// ClientAuth: tls.VerifyClientCertIfGiven,
// Rand: rand.Reader,
// }
// }