-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
main.go
52 lines (41 loc) · 1.03 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
package main
import (
"net/http"
"github.com/kataras/iris/v12"
"golang.org/x/net/http2"
)
/*
Serve HTTP/2 without TLS and keep support for HTTP/1.1
*/
// $ go get golang.org/x/net/http2
// # Take a look at the golang.org/x/net/http2/h2c package as well,
// # you may want to use it.
// $ go run main.go
// $ brew install curl-openssl
// # Add curl-openssl to the front of your path.
// Test with the following commands:
// $ curl -v --http2 http://localhost:8080
// $ curl -v --http1.1 http://localhost:8080
func main() {
// Initialize Iris Application.
app := iris.New()
// Build the API.
app.Any("/", index)
// Finally, listen and serve on port 8080 using h2c.
app.Run(iris.Raw(func() error {
host := app.NewHost(&http.Server{
Addr: ":8080",
})
err := http2.ConfigureServer(host.Server, &http2.Server{
MaxConcurrentStreams: 250,
PermitProhibitedCipherSuites: true,
})
if err != nil {
return err
}
return host.ListenAndServe()
}))
}
func index(ctx iris.Context) {
ctx.WriteString("Hello, World!\n")
}