Merge pull request #622 from errm/use-stdlib-context

Context is part of the stdlib in go 1.7
This commit is contained in:
Ed Robinson 2016-11-16 14:26:38 +00:00 committed by GitHub
commit 56c6174d61
10 changed files with 44 additions and 50 deletions

View file

@ -12,7 +12,7 @@ You need to run the `binary` target. This will create binaries for Linux platfor
$ make binary $ make binary
docker build -t "traefik-dev:no-more-godep-ever" -f build.Dockerfile . docker build -t "traefik-dev:no-more-godep-ever" -f build.Dockerfile .
Sending build context to Docker daemon 295.3 MB Sending build context to Docker daemon 295.3 MB
Step 0 : FROM golang:1.5 Step 0 : FROM golang:1.7
---> 8c6473912976 ---> 8c6473912976
Step 1 : RUN go get github.com/Masterminds/glide Step 1 : RUN go get github.com/Masterminds/glide
[...] [...]
@ -30,8 +30,7 @@ traefik*
###### Setting up your `go` environment ###### Setting up your `go` environment
- You need `go` v1.5+ (1.7 is acceptable) - You need `go` v1.7+
- You need to set `$ export GO15VENDOREXPERIMENT=1` environment variable if you are using go v1.5 (it is already enabled in 1.6+)
- It is recommended you clone Træfɪk into a directory like `~/go/src/github.com/containous/traefik` (This is the official golang workspace hierarchy, and will allow dependencies to resolve properly) - It is recommended you clone Træfɪk into a directory like `~/go/src/github.com/containous/traefik` (This is the official golang workspace hierarchy, and will allow dependencies to resolve properly)
- This will allow your `GOPATH` and `PATH` variable to be set to `~/go` via: - This will allow your `GOPATH` and `PATH` variable to be set to `~/go` via:
``` ```

View file

@ -1,6 +1,7 @@
package acme package acme
import ( import (
"context"
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
@ -12,7 +13,6 @@ import (
"github.com/containous/traefik/safe" "github.com/containous/traefik/safe"
"github.com/containous/traefik/types" "github.com/containous/traefik/types"
"github.com/xenolf/lego/acme" "github.com/xenolf/lego/acme"
"golang.org/x/net/context"
"io/ioutil" "io/ioutil"
fmtlog "log" fmtlog "log"
"os" "os"

View file

@ -1,6 +1,7 @@
package cluster package cluster
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/cenk/backoff" "github.com/cenk/backoff"
@ -9,7 +10,6 @@ import (
"github.com/containous/traefik/log" "github.com/containous/traefik/log"
"github.com/docker/libkv/store" "github.com/docker/libkv/store"
"github.com/satori/go.uuid" "github.com/satori/go.uuid"
"golang.org/x/net/context"
"sync" "sync"
"time" "time"
) )

View file

@ -1,12 +1,12 @@
package cluster package cluster
import ( import (
"context"
"github.com/cenk/backoff" "github.com/cenk/backoff"
"github.com/containous/traefik/log" "github.com/containous/traefik/log"
"github.com/containous/traefik/safe" "github.com/containous/traefik/safe"
"github.com/containous/traefik/types" "github.com/containous/traefik/types"
"github.com/docker/leadership" "github.com/docker/leadership"
"golang.org/x/net/context"
"time" "time"
) )

50
glide.lock generated
View file

@ -1,5 +1,5 @@
hash: 39ff28cc1d13d5915a870b14491ece1849c4eaf5a56cecd50a7676ecee6c6143 hash: 5a4ccfe1c0ee6b0c67a40ceb07a8510d61646e1551599331b626ccf1341f4048
updated: 2016-10-06T14:06:39.455848971+02:00 updated: 2016-11-15T19:22:10.412299841Z
imports: imports:
- name: github.com/abbot/go-http-auth - name: github.com/abbot/go-http-auth
version: cb4372376e1e00e9f6ab9ec142e029302c9e7140 version: cb4372376e1e00e9f6ab9ec142e029302c9e7140
@ -14,9 +14,9 @@ imports:
- name: github.com/cenk/backoff - name: github.com/cenk/backoff
version: 8edc80b07f38c27352fb186d971c628a6c32552b version: 8edc80b07f38c27352fb186d971c628a6c32552b
- name: github.com/codahale/hdrhistogram - name: github.com/codahale/hdrhistogram
version: f8ad88b59a584afeee9d334eff879b104439117b version: 9208b142303c12d8899bae836fd524ac9338b4fd
- name: github.com/codegangsta/cli - name: github.com/codegangsta/cli
version: 1efa31f08b9333f1bd4882d61f9d668a70cd902e version: bf4a526f48af7badd25d2cb02d587e1b01be3b50
- name: github.com/codegangsta/negroni - name: github.com/codegangsta/negroni
version: 3f7ce7b928e14ff890b067e5bbbc80af73690a9c version: 3f7ce7b928e14ff890b067e5bbbc80af73690a9c
- name: github.com/containous/flaeg - name: github.com/containous/flaeg
@ -26,15 +26,13 @@ imports:
- name: github.com/containous/staert - name: github.com/containous/staert
version: 92329254783dc01174f03302d51d7cf2c9ff84cf version: 92329254783dc01174f03302d51d7cf2c9ff84cf
- name: github.com/coreos/etcd - name: github.com/coreos/etcd
version: 1c9e0a0e33051fed6c05c141e6fcbfe5c7f2a899 version: c400d05d0aa73e21e431c16145e558d624098018
subpackages: subpackages:
- Godeps/_workspace/src/github.com/ugorji/go/codec
- Godeps/_workspace/src/golang.org/x/net/context
- client - client
- pkg/pathutil - pkg/pathutil
- pkg/types - pkg/types
- name: github.com/davecgh/go-spew
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
subpackages:
- spew
- name: github.com/docker/distribution - name: github.com/docker/distribution
version: 99cb7c0946d2f5a38015443e515dc916295064d7 version: 99cb7c0946d2f5a38015443e515dc916295064d7
subpackages: subpackages:
@ -157,9 +155,9 @@ imports:
- name: github.com/gambol99/go-marathon - name: github.com/gambol99/go-marathon
version: a558128c87724cd7430060ef5aedf39f83937f55 version: a558128c87724cd7430060ef5aedf39f83937f55
- name: github.com/go-check/check - name: github.com/go-check/check
version: 4f90aeace3a26ad7021961c297b22c42160c7b25 version: 11d3bc7aa68e238947792f30573146a3231fc0f1
- name: github.com/gogo/protobuf - name: github.com/gogo/protobuf
version: 99cb9b23110011cc45571c901ecae6f6f5e65cd3 version: 43ab7f0ec7b6d072e0368bd537ffefe74ed30198
subpackages: subpackages:
- proto - proto
- name: github.com/golang/glog - name: github.com/golang/glog
@ -169,7 +167,7 @@ imports:
subpackages: subpackages:
- query - query
- name: github.com/gorilla/context - name: github.com/gorilla/context
version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 version: 14f550f51af52180c2eefed15e5fd18d63c0a64a
- name: github.com/hashicorp/consul - name: github.com/hashicorp/consul
version: d8e2fb7dd594163e25a89bc52c1a4613f5c5bfb8 version: d8e2fb7dd594163e25a89bc52c1a4613f5c5bfb8
subpackages: subpackages:
@ -177,7 +175,7 @@ imports:
- name: github.com/hashicorp/go-cleanhttp - name: github.com/hashicorp/go-cleanhttp
version: ad28ea4487f05916463e2423a55166280e8254b5 version: ad28ea4487f05916463e2423a55166280e8254b5
- name: github.com/hashicorp/serf - name: github.com/hashicorp/serf
version: b03bf85930b2349eb04b97c8fac437495296e3e7 version: 598c54895cc5a7b1a24a398d635e8c0ea0959870
subpackages: subpackages:
- coordinate - coordinate
- name: github.com/jarcoal/httpmock - name: github.com/jarcoal/httpmock
@ -229,15 +227,11 @@ imports:
- name: github.com/ogier/pflag - name: github.com/ogier/pflag
version: 45c278ab3607870051a2ea9040bb85fcb8557481 version: 45c278ab3607870051a2ea9040bb85fcb8557481
- name: github.com/opencontainers/runc - name: github.com/opencontainers/runc
version: 02f8fa7863dd3f82909a73e2061897828460d52f version: ba1568de399395774ad84c2ace65937814c542ed
subpackages: subpackages:
- libcontainer/user - libcontainer/user
- name: github.com/parnurzeal/gorequest - name: github.com/parnurzeal/gorequest
version: e30af16d4e485943aab0b0885ad6bdbb8c0d3dc7 version: e30af16d4e485943aab0b0885ad6bdbb8c0d3dc7
- name: github.com/pmezard/go-difflib
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
subpackages:
- difflib
- name: github.com/ryanuber/go-glob - name: github.com/ryanuber/go-glob
version: 572520ed46dbddaed19ea3d9541bdd0494163693 version: 572520ed46dbddaed19ea3d9541bdd0494163693
- name: github.com/samuel/go-zookeeper - name: github.com/samuel/go-zookeeper
@ -253,7 +247,7 @@ imports:
- name: github.com/stretchr/objx - name: github.com/stretchr/objx
version: cbeaeb16a013161a98496fad62933b1d21786672 version: cbeaeb16a013161a98496fad62933b1d21786672
- name: github.com/stretchr/testify - name: github.com/stretchr/testify
version: 976c720a22c8eb4eb6a0b4348ad85ad12491a506 version: b8dc1cecf15bdaf1988d9e87aa7cd98d899a06d6
subpackages: subpackages:
- assert - assert
- mock - mock
@ -261,10 +255,6 @@ imports:
version: 152b5d051953fdb6e45f14b6826962aadc032324 version: 152b5d051953fdb6e45f14b6826962aadc032324
- name: github.com/tv42/zbase32 - name: github.com/tv42/zbase32
version: 03389da7e0bf9844767f82690f4d68fc097a1306 version: 03389da7e0bf9844767f82690f4d68fc097a1306
- name: github.com/ugorji/go
version: b94837a2404ab90efe9289e77a70694c355739cb
subpackages:
- codec
- name: github.com/unrolled/render - name: github.com/unrolled/render
version: 526faf80cd4b305bb8134abea8d20d5ced74faa6 version: 526faf80cd4b305bb8134abea8d20d5ced74faa6
- name: github.com/vdemeester/docker-events - name: github.com/vdemeester/docker-events
@ -288,7 +278,7 @@ imports:
- name: github.com/vulcand/route - name: github.com/vulcand/route
version: cb89d787ddbb1c5849a7ac9f79004c1fd12a4a32 version: cb89d787ddbb1c5849a7ac9f79004c1fd12a4a32
- name: github.com/vulcand/vulcand - name: github.com/vulcand/vulcand
version: bed092e10989250b48bdb6aa3b0557b207f05c80 version: 42492a3a85e294bdbdd1bcabb8c12769a81ea284
subpackages: subpackages:
- conntracker - conntracker
- plugin - plugin
@ -299,26 +289,26 @@ imports:
subpackages: subpackages:
- acme - acme
- name: golang.org/x/crypto - name: golang.org/x/crypto
version: d81fdb778bf2c40a91b24519d60cdc5767318829 version: 4ed45ec682102c643324fae5dff8dab085b6c300
subpackages: subpackages:
- bcrypt - bcrypt
- blowfish - blowfish
- ocsp - ocsp
- name: golang.org/x/net - name: golang.org/x/net
version: b400c2eff1badec7022a8c8f5bea058b6315eed7 version: 6460565bec1e8891e29ff478184c71b9e443ac36
subpackages: subpackages:
- context - context
- proxy - proxy
- publicsuffix - publicsuffix
- name: golang.org/x/sys - name: golang.org/x/sys
version: 62bee037599929a6e9146f29d10dd5208c43507d version: eb2c74142fd19a79b3f237334c7384d5167b1b46
subpackages: subpackages:
- unix - unix
- windows - windows
- name: gopkg.in/fsnotify.v1 - name: gopkg.in/fsnotify.v1
version: 944cff21b3baf3ced9a880365682152ba577d348 version: 944cff21b3baf3ced9a880365682152ba577d348
- name: gopkg.in/mgo.v2 - name: gopkg.in/mgo.v2
version: 22287bab4379e1fbf6002fb4eb769888f3fb224c version: 29cc868a5ca65f401ff318143f9408d02f4799cc
subpackages: subpackages:
- bson - bson
- name: gopkg.in/square/go-jose.v1 - name: gopkg.in/square/go-jose.v1
@ -336,11 +326,11 @@ testImports:
- name: github.com/flynn/go-shlex - name: github.com/flynn/go-shlex
version: 3f9db97f856818214da2e1057f8ad84803971cff version: 3f9db97f856818214da2e1057f8ad84803971cff
- name: github.com/gorilla/mux - name: github.com/gorilla/mux
version: 9fa818a44c2bf1396a17f9d5a3c0f6dd39d2ff8e version: e444e69cbd2e2e3e0749a2f3c717cec491552bbf
- name: github.com/libkermit/docker-check - name: github.com/libkermit/docker-check
version: cbe0ef03b3d23070eac4d00ba8828f2cc7f7e5a3 version: cbe0ef03b3d23070eac4d00ba8828f2cc7f7e5a3
- name: github.com/spf13/pflag - name: github.com/spf13/pflag
version: 08b1a584251b5b62f458943640fc8ebd4d50aaa5 version: 5644820622454e71517561946e3d94b9f9db6842
- name: github.com/vbatts/tar-split - name: github.com/vbatts/tar-split
version: bd4c5d64c3e9297f410025a3b1bd0c58f659e721 version: bd4c5d64c3e9297f410025a3b1bd0c58f659e721
subpackages: subpackages:

View file

@ -64,9 +64,6 @@ import:
version: b2fad6198110326662e9e356a97199078a4a775c version: b2fad6198110326662e9e356a97199078a4a775c
subpackages: subpackages:
- acme - acme
- package: golang.org/x/net
subpackages:
- context
- package: gopkg.in/fsnotify.v1 - package: gopkg.in/fsnotify.v1
- package: github.com/libkermit/compose - package: github.com/libkermit/compose
version: cadc5a3b83a15790174bd7fbc75ea2529785e772 version: cadc5a3b83a15790174bd7fbc75ea2529785e772

View file

@ -5,12 +5,12 @@ import (
"os/exec" "os/exec"
"time" "time"
"context"
"github.com/containous/staert" "github.com/containous/staert"
"github.com/docker/libkv" "github.com/docker/libkv"
"github.com/docker/libkv/store" "github.com/docker/libkv/store"
"github.com/docker/libkv/store/consul" "github.com/docker/libkv/store/consul"
"github.com/go-check/check" "github.com/go-check/check"
"golang.org/x/net/context"
"errors" "errors"
"github.com/containous/traefik/cluster" "github.com/containous/traefik/cluster"

View file

@ -1,6 +1,7 @@
package provider package provider
import ( import (
"context"
"errors" "errors"
"math" "math"
"net" "net"
@ -10,8 +11,6 @@ import (
"text/template" "text/template"
"time" "time"
"golang.org/x/net/context"
"github.com/BurntSushi/ty/fun" "github.com/BurntSushi/ty/fun"
"github.com/cenk/backoff" "github.com/cenk/backoff"
"github.com/containous/traefik/job" "github.com/containous/traefik/job"

View file

@ -1,8 +1,8 @@
package safe package safe
import ( import (
"context"
"github.com/containous/traefik/log" "github.com/containous/traefik/log"
"golang.org/x/net/context"
"runtime/debug" "runtime/debug"
"sync" "sync"
) )
@ -21,18 +21,20 @@ type Pool struct {
waitGroup sync.WaitGroup waitGroup sync.WaitGroup
lock sync.Mutex lock sync.Mutex
baseCtx context.Context baseCtx context.Context
baseCancel context.CancelFunc
ctx context.Context ctx context.Context
cancel context.CancelFunc cancel context.CancelFunc
} }
// NewPool creates a Pool // NewPool creates a Pool
func NewPool(parentCtx context.Context) *Pool { func NewPool(parentCtx context.Context) *Pool {
baseCtx, _ := context.WithCancel(parentCtx) baseCtx, baseCancel := context.WithCancel(parentCtx)
ctx, cancel := context.WithCancel(baseCtx) ctx, cancel := context.WithCancel(baseCtx)
return &Pool{ return &Pool{
baseCtx: baseCtx, baseCtx: baseCtx,
ctx: ctx, baseCancel: baseCancel,
cancel: cancel, ctx: ctx,
cancel: cancel,
} }
} }
@ -90,6 +92,14 @@ func (p *Pool) Stop() {
} }
} }
// Cleanup releases resources used by the pool, and should be called when the pool will no longer be used
func (p *Pool) Cleanup() {
p.Stop()
p.lock.Lock()
defer p.lock.Unlock()
p.baseCancel()
}
// Start starts all stopped routines // Start starts all stopped routines
func (p *Pool) Start() { func (p *Pool) Start() {
p.lock.Lock() p.lock.Lock()

View file

@ -4,6 +4,7 @@ Copyright
package main package main
import ( import (
"context"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"encoding/json" "encoding/json"
@ -19,8 +20,6 @@ import (
"syscall" "syscall"
"time" "time"
"golang.org/x/net/context"
"github.com/codegangsta/negroni" "github.com/codegangsta/negroni"
"github.com/containous/mux" "github.com/containous/mux"
"github.com/containous/traefik/cluster" "github.com/containous/traefik/cluster"
@ -134,7 +133,7 @@ func (server *Server) Close() {
} }
}(ctx) }(ctx)
server.stopLeadership() server.stopLeadership()
server.routinesPool.Stop() server.routinesPool.Cleanup()
close(server.configurationChan) close(server.configurationChan)
close(server.configurationValidatedChan) close(server.configurationValidatedChan)
signal.Stop(server.signals) signal.Stop(server.signals)