...

Source file src/golang.org/x/text/cmd/gotext/examples/extract_http/pkg/pkg.go

Documentation: golang.org/x/text/cmd/gotext/examples/extract_http/pkg

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package pkg
     6  
     7  import (
     8  	"net/http"
     9  
    10  	"golang.org/x/text/language"
    11  	"golang.org/x/text/message"
    12  )
    13  
    14  var matcher = language.NewMatcher(message.DefaultCatalog.Languages())
    15  
    16  func Generize(w http.ResponseWriter, r *http.Request) {
    17  	lang, _ := r.Cookie("lang")
    18  	accept := r.Header.Get("Accept-Language")
    19  	tag := message.MatchLanguage(lang.String(), accept)
    20  	p := message.NewPrinter(tag)
    21  
    22  	p.Fprintf(w, "Hello %s!\n", r.Header.Get("From"))
    23  
    24  	p.Fprintf(w, "Do you like your browser (%s)?\n", r.Header.Get("User-Agent"))
    25  }
    26  

View as plain text