本文整理匯總了Golang中github.com/fiorix/go-web/httpxtra.Handler類的典型用法代碼示例。如果您正苦於以下問題:Golang Handler類的具體用法?Golang Handler怎麽用?Golang Handler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Handler類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runServer
func runServer(mux *http.ServeMux, c *serverConfig) {
h := httpxtra.Handler{
Handler: mux,
XHeaders: c.XHeaders,
}
if c.Log {
h.Logger = httpLogger
}
s := http.Server{
Addr: c.Addr,
Handler: h,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
}
if len(c.KeyFile) > 0 && len(c.CertFile) > 0 {
log.Printf("Starting HTTPS server on tcp/%s "+
"log=%t xheaders=%t cert=%s key=%s",
c.Addr,
c.Log,
c.XHeaders,
c.CertFile,
c.KeyFile,
)
log.Fatal(s.ListenAndServeTLS(c.CertFile, c.KeyFile))
} else {
log.Printf("Starting HTTP server on tcp/%s "+
"log=%t xheaders=%t",
c.Addr,
c.Log,
c.XHeaders,
)
log.Fatal(httpxtra.ListenAndServe(s))
}
}
示例2: main
func main() {
cf := flag.String("config", "freegeoip.conf", "set config file")
flag.Parse()
if buf, err := ioutil.ReadFile(*cf); err != nil {
log.Fatal(err)
} else {
conf = &Settings{}
if err := xml.Unmarshal(buf, conf); err != nil {
log.Fatal(err)
}
}
runtime.GOMAXPROCS(runtime.NumCPU())
log.Printf("FreeGeoIP server starting. debug=%t", conf.Debug)
http.Handle("/", http.FileServer(http.Dir(conf.DocumentRoot)))
h := GeoipHandler()
http.HandleFunc("/csv/", h)
http.HandleFunc("/xml/", h)
http.HandleFunc("/json/", h)
wg := new(sync.WaitGroup)
for _, l := range conf.Listen {
if l.Addr == "" {
continue
}
wg.Add(1)
h := httpxtra.Handler{XHeaders: l.XHeaders}
if l.Log {
h.Logger = logger
}
s := http.Server{
Addr: l.Addr,
Handler: h,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
}
if l.KeyFile == "" {
log.Printf("Listening HTTP on %s "+
"log=%t xheaders=%t",
l.Addr, l.Log, l.XHeaders)
go func() {
log.Fatal(httpxtra.ListenAndServe(s))
}()
} else {
log.Printf("Listening HTTPS on %s "+
"log=%t xheaders=%t cert=%s key=%s",
l.Addr, l.Log, l.XHeaders,
l.CertFile, l.KeyFile)
go func() {
log.Fatal(s.ListenAndServeTLS(
l.CertFile,
l.KeyFile,
))
}()
}
}
wg.Wait()
}
示例3: main
func main() {
cf := flag.String("config", "freegeoip.conf", "set config file")
prof := flag.Bool("profile", false, "run cpu and mem profiling")
flag.Parse()
if buf, err := ioutil.ReadFile(*cf); err != nil {
log.Fatal(err)
} else {
conf = &ConfigFile{}
if err := xml.Unmarshal(buf, conf); err != nil {
log.Fatal(err)
}
}
if *prof {
profile()
}
runtime.GOMAXPROCS(runtime.NumCPU())
log.Printf("FreeGeoIP server starting. debug=%t", conf.Debug)
if conf.Debug && len(conf.DebugSrv) > 0 {
go func() {
// server for expvar's /debug/vars only
log.Printf("Starting DEBUG HTTP server on %s", conf.DebugSrv)
log.Fatal(http.ListenAndServe(conf.DebugSrv, nil))
}()
}
mux := http.NewServeMux()
mux.Handle("/", http.FileServer(http.Dir(conf.DocumentRoot)))
h := LookupHandler()
mux.HandleFunc("/csv/", h)
mux.HandleFunc("/xml/", h)
mux.HandleFunc("/json/", h)
wg := new(sync.WaitGroup)
for _, l := range conf.Listen {
if l.Addr == "" {
continue
}
wg.Add(1)
h := httpxtra.Handler{Handler: mux, XHeaders: l.XHeaders}
if l.Log {
h.Logger = logger
}
s := http.Server{
Addr: l.Addr,
Handler: h,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
}
if l.KeyFile == "" && l.CertFile == "" {
log.Printf("Starting HTTP server on %s "+
"log=%t xheaders=%t",
l.Addr, l.Log, l.XHeaders)
go func() {
log.Fatal(httpxtra.ListenAndServe(s))
}()
} else {
log.Printf("Starting HTTPS server on %s "+
"log=%t xheaders=%t cert=%s key=%s",
l.Addr, l.Log, l.XHeaders,
l.CertFile, l.KeyFile)
go func() {
log.Fatal(s.ListenAndServeTLS(
l.CertFile,
l.KeyFile,
))
}()
}
}
wg.Wait()
}