Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump go 1.8 #1259

Merged
merged 3 commits into from Mar 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -88,7 +88,6 @@ You can access to a simple HTML frontend of Træfik.
- [Oxy](https://github.com/vulcand/oxy): an awesome proxy library made by Mailgun guys
- [Gorilla mux](https://github.com/gorilla/mux): famous request router
- [Negroni](https://github.com/codegangsta/negroni): web middlewares made simple
- [Manners](https://github.com/mailgun/manners): graceful shutdown of http.Handler servers
- [Lego](https://github.com/xenolf/lego): the best [Let's Encrypt](https://letsencrypt.org) library in go

## Test it
Expand Down
2 changes: 1 addition & 1 deletion build.Dockerfile
@@ -1,4 +1,4 @@
FROM golang:1.7
FROM golang:1.8

# Install a more recent version of mercurial to avoid mismatching results
# between glide run on a decently updated host system and the build container.
Expand Down
136 changes: 3 additions & 133 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion glide.yaml
Expand Up @@ -47,7 +47,6 @@ import:
- package: github.com/hashicorp/consul
subpackages:
- api
- package: github.com/mailgun/manners
- package: github.com/streamrail/concurrent-map
- package: github.com/stretchr/testify
subpackages:
Expand Down
62 changes: 28 additions & 34 deletions server.go
Expand Up @@ -29,13 +29,13 @@ import (
"github.com/containous/traefik/provider"
"github.com/containous/traefik/safe"
"github.com/containous/traefik/types"
"github.com/mailgun/manners"
"github.com/streamrail/concurrent-map"
"github.com/vulcand/oxy/cbreaker"
"github.com/vulcand/oxy/connlimit"
"github.com/vulcand/oxy/forward"
"github.com/vulcand/oxy/roundrobin"
"github.com/vulcand/oxy/utils"
"sync"
)

var oxyLogger = &OxyLogger{}
Expand All @@ -58,7 +58,7 @@ type Server struct {
type serverEntryPoints map[string]*serverEntryPoint

type serverEntryPoint struct {
httpServer *manners.GracefulServer
httpServer *http.Server
httpRouter *middlewares.HandlerSwitcher
}

Expand Down Expand Up @@ -114,15 +114,23 @@ func (server *Server) Wait() {

// Stop stops the server
func (server *Server) Stop() {
for serverEntryPointName, serverEntryPoint := range server.serverEntryPoints {
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(server.globalConfiguration.GraceTimeOut)*time.Second)
go func() {
log.Debugf("Waiting %d seconds before killing connections on entrypoint %s...", 30, serverEntryPointName)
serverEntryPoint.httpServer.BlockingClose()
defer log.Info("Server stopped")
var wg sync.WaitGroup
for sepn, sep := range server.serverEntryPoints {
wg.Add(1)
go func(serverEntryPointName string, serverEntryPoint *serverEntryPoint) {
defer wg.Done()
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(server.globalConfiguration.GraceTimeOut)*time.Second)
log.Debugf("Waiting %d seconds before killing connections on entrypoint %s...", server.globalConfiguration.GraceTimeOut, serverEntryPointName)
if err := serverEntryPoint.httpServer.Shutdown(ctx); err != nil {
log.Debugf("Wait is over due to: %s", err)
serverEntryPoint.httpServer.Close()
}
cancel()
}()
<-ctx.Done()
log.Debugf("Entrypoint %s closed", serverEntryPointName)
}(sepn, sep)
}
wg.Wait()
server.stopChan <- true
}

Expand Down Expand Up @@ -191,7 +199,7 @@ func (server *Server) startHTTPServers() {
if server.globalConfiguration.EntryPoints[newServerEntryPointName].Compress {
serverMiddlewares = append(serverMiddlewares, &middlewares.Compress{})
}
newsrv, err := server.prepareServer(newServerEntryPointName, newServerEntryPoint.httpRouter, server.globalConfiguration.EntryPoints[newServerEntryPointName], nil, serverMiddlewares...)
newsrv, err := server.prepareServer(newServerEntryPointName, newServerEntryPoint.httpRouter, server.globalConfiguration.EntryPoints[newServerEntryPointName], serverMiddlewares...)
if err != nil {
log.Fatal("Error preparing server: ", err)
}
Expand Down Expand Up @@ -493,21 +501,20 @@ func (server *Server) createTLSConfig(entryPointName string, tlsOption *TLS, rou
return config, nil
}

func (server *Server) startServer(srv *manners.GracefulServer, globalConfiguration GlobalConfiguration) {
func (server *Server) startServer(srv *http.Server, globalConfiguration GlobalConfiguration) {
log.Infof("Starting server on %s", srv.Addr)
var err error
if srv.TLSConfig != nil {
if err := srv.ListenAndServeTLSWithConfig(srv.TLSConfig); err != nil {
log.Fatal("Error creating server: ", err)
}
err = srv.ListenAndServeTLS("", "")
} else {
if err := srv.ListenAndServe(); err != nil {
log.Fatal("Error creating server: ", err)
}
err = srv.ListenAndServe()
}
if err != nil {
log.Error("Error creating server: ", err)
}
log.Info("Server stopped")
}

func (server *Server) prepareServer(entryPointName string, router *middlewares.HandlerSwitcher, entryPoint *EntryPoint, oldServer *manners.GracefulServer, middlewares ...negroni.Handler) (*manners.GracefulServer, error) {
func (server *Server) prepareServer(entryPointName string, router *middlewares.HandlerSwitcher, entryPoint *EntryPoint, middlewares ...negroni.Handler) (*http.Server, error) {
log.Infof("Preparing server %s %+v", entryPointName, entryPoint)
// middlewares
var negroni = negroni.New()
Expand All @@ -521,24 +528,11 @@ func (server *Server) prepareServer(entryPointName string, router *middlewares.H
return nil, err
}

if oldServer == nil {
return manners.NewWithServer(
&http.Server{
Addr: entryPoint.Address,
Handler: negroni,
TLSConfig: tlsConfig,
}), nil
}
gracefulServer, err := oldServer.HijackListener(&http.Server{
return &http.Server{
Addr: entryPoint.Address,
Handler: negroni,
TLSConfig: tlsConfig,
}, tlsConfig)
if err != nil {
log.Errorf("Error hijacking server: %s", err)
return nil, err
}
return gracefulServer, nil
}, nil
}

func (server *Server) buildEntryPoints(globalConfiguration GlobalConfiguration) map[string]*serverEntryPoint {
Expand Down
85 changes: 0 additions & 85 deletions vendor/github.com/docker/distribution/context/context.go

This file was deleted.