-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
59 lines (59 loc) · 1.62 KB
/
doc.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
// Package tlsprotocol provides an abstraction on top of the TLS listener functionality to provide the ability to have
// individual net.Listeners for application layer protocols (ALPN) negotiated during the TLS handshake between the client
// and server.
//
// For example, lets say you have a server that you want to be able to accept generic TLS connections but split HTTP/2
// into a separate listener for handling in a different way.
//
// package main
//
// import (
// "crypto/tls"
// "fmt"
// "log"
//
// "github.com/LiamHaworth/tlsprotocol"
// )
//
// func main() {
// log.Print("Loading key pair cert.pem/key.pem")
// certs, err := tls.LoadX509KeyPair("cert.pem", "key.pem")
// if err != nil {
// log.Fatal(err)
// }
//
// log.Print("Configuring protocol listener")
// srv := &tlsprotocol.Listener{
// BindAddr: "127.0.0.1:443",
// Listeners: 1,
// TLSConfig: &tls.Config{
// Certificates: []tls.Certificate{certs},
// NextProtos: []string{"h2"},
// },
// }
//
// log.Print("Setting up listener for HTTP\\2")
// h2Listener, err := srv.Protocol("h2")
// if err != nil {
// log.Fatal(err)
// }
//
// log.Print("Starting protocol listener")
// if err := srv.Start(); err != nil {
// log.Fatal(err)
// }
//
// log.Print("Listening for connections")
// go func() {
// for {
// conn, _ := h2Listener.Accept()
// fmt.Println("Connection received via h2 (HTTP\\2)", conn)
// }
// }()
//
// for {
// conn, _ := srv.Accept()
// fmt.Println("Connection received via default", conn)
// }
// }
package tlsprotocol