gorouter

gorouter

  • Docs
  • Help
  • GitHub

›Examples

Quick Start

  • Installation
  • Basic example

Router

  • Routing
  • Middleware
  • Mounting Sub-Router

Examples

    Authentication

    • Basic Authentication

    Serving Files

    • Static Files
  • HTTPS
  • HTTP2
  • Multidomain
  • Panic Recovery
  • App Handler

Benchmark

  • Benchmark

HTTP2

The Go Blog - HTTP/2 Server Push

Pusher

net/http
valyala/fasthttp
package main

import (
"log"
"net/http"

"golang.org/x/net/http2"
"github.com/vardius/gorouter/v4"
)

func Pusher(w http.ResponseWriter, r *http.Request) {
if pusher, ok := w.(http.Pusher); ok {
// Push is supported.
options := &http.PushOptions{
Header: http.Header{
"Accept-Encoding": r.Header["Accept-Encoding"],
},
}
if err := pusher.Push("/script.js", options); err != nil {
log.Printf("Failed to push: %v", err)
}
}
// ...
}

func main() {
router := gorouter.New()
router.GET("/", http.HandlerFunc(Pusher))

http2.ConfigureServer(router, &http2.Server{})
log.Fatal(router.ListenAndServeTLS("router.crt", "router.key"))
}

HTTP/2 implementation for fasthttp is under construction...

← HTTPSMultidomain →
  • The Go Blog - HTTP/2 Server Push
  • Pusher
gorouter
Docs
DocumentationGoDoc
Community
Support
More
rafallorenz.comGitHubStar
Copyright © 2024 Rafał Lorenz