Import Debian changes 1.0.1-1
golang-github-zenazn-goji (1.0.1-1) unstable; urgency=medium
* New upstream release
* reverse dependencies successfully built with ratt:
- golang-github-rs-zerolog
- golang-github-jackc-pgx
Thorsten Alteholz
3 years ago
0 | 0 | language: go |
1 | 1 | |
2 | matrix: | |
3 | include: | |
4 | - go: 1.2 | |
5 | install: | |
6 | - go get golang.org/x/tools/cmd/cover | |
7 | - go list -f '{{range .Imports}}{{.}} {{end}}' ./... | xargs go get -v | |
8 | - go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | xargs go get -v | |
9 | - go: 1.3 | |
10 | install: | |
11 | - go get golang.org/x/tools/cmd/cover | |
12 | - go list -f '{{range .Imports}}{{.}} {{end}}' ./... | xargs go get -v | |
13 | - go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | xargs go get -v | |
14 | - go: 1.4 | |
15 | install: | |
16 | - go get golang.org/x/tools/cmd/cover | |
17 | - go list -f '{{range .Imports}}{{.}} {{end}}' ./... | xargs go get -v | |
18 | - go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | xargs go get -v | |
19 | - go: 1.5 | |
20 | install: | |
21 | - go list -f '{{range .Imports}}{{.}} {{end}}' ./... | xargs go get -v | |
22 | - go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | xargs go get -v | |
23 | - go: 1.6 | |
24 | install: | |
25 | - go list -f '{{range .Imports}}{{.}} {{end}}' ./... | xargs go get -v | |
26 | - go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | xargs go get -v | |
27 | - go: tip | |
28 | install: | |
29 | - go list -f '{{range .Imports}}{{.}} {{end}}' ./... | xargs go get -v | |
30 | - go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | xargs go get -v | |
31 | script: | |
32 | - go test -cover ./... | |
2 | go: | |
3 | - "1.5.x" | |
4 | - "1.6.x" | |
5 | - "1.7.x" | |
6 | - "1.8.x" | |
7 | - "1.9.x" | |
8 | - "1.10.x" | |
9 | - "1.11.x" | |
10 | ||
11 | install: | |
12 | - go list -f '{{range .Imports}}{{.}} {{end}}' ./... | xargs go get -v | |
13 | - go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | xargs go get -v | |
14 | ||
15 | script: go test -cover ./... | |
16 |
0 | golang-github-zenazn-goji (1.0.1-1) unstable; urgency=medium | |
1 | ||
2 | * New upstream release | |
3 | * reverse dependencies successfully built with ratt: | |
4 | - golang-github-rs-zerolog | |
5 | - golang-github-jackc-pgx | |
6 | ||
7 | -- Thorsten Alteholz <debian@alteholz.de> Tue, 01 Dec 2020 19:54:32 +0000 | |
8 | ||
0 | 9 | golang-github-zenazn-goji (1.0+git20170812.c05078c-5) unstable; urgency=medium |
1 | 10 | |
2 | 11 | [ Michael Stapelberg ] |
0 | 0 | version=3 |
1 | 1 | opts=filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/golang-github-zenazn-goji-\$1\.tar\.gz/,\ |
2 | 2 | uversionmangle=s/(\d)[_\.\-\+]?(RC|rc|pre|dev|beta|alpha)[.]?(\d*)$/\$1~\$2\$3/ \ |
3 | https://github.com/zenazn/goji/tags .*/v?(\d\S*)\.tar\.gz | |
3 | https://github.com/zenazn/goji/tags .*/v?(\d\S*)\.tar\.gz debian uupdate |
0 | example |
8 | 8 | |
9 | 9 | import ( |
10 | 10 | "net" |
11 | "runtime" | |
12 | 11 | "sync/atomic" |
13 | 12 | |
14 | 13 | "github.com/zenazn/goji/graceful/listener" |
49 | 48 | // Unfortunately Go doesn't really give us a better way to select errors |
50 | 49 | // than this, so *shrug*. |
51 | 50 | if oe, ok := err.(*net.OpError); ok { |
52 | errOp := "accept" | |
53 | if runtime.GOOS == "windows" { | |
54 | errOp = "AcceptEx" | |
55 | } | |
56 | if oe.Op == errOp && oe.Err.Error() == errClosing { | |
57 | return nil | |
51 | switch oe.Op { | |
52 | // backward compatibility: older golang returns AcceptEx on Windows. | |
53 | // Current golang returns "accept" consistently. It's platform independent. | |
54 | // See https://github.com/golang/go/commit/b0f4ee533a875c258ac1030ee382f0ffe2de304b | |
55 | case "AcceptEx": | |
56 | fallthrough | |
57 | case "accept": | |
58 | if oe.Err.Error() == errClosing { | |
59 | return nil | |
60 | } | |
58 | 61 | } |
59 | 62 | } |
60 | 63 | return err |
11 | 11 | |
12 | 12 | var mu sync.Mutex // protects everything that follows |
13 | 13 | var listeners = make([]*listener.T, 0) |
14 | var prehooks = make([]func(), 0) | |
15 | var posthooks = make([]func(), 0) | |
14 | var prehooks = make([]func(os.Signal), 0) | |
15 | var posthooks = make([]func(os.Signal), 0) | |
16 | 16 | var closing int32 |
17 | 17 | var doubleKick, timeout time.Duration |
18 | 18 | |
39 | 39 | signal.Stop(sigchan) |
40 | 40 | } |
41 | 41 | |
42 | // PreHookWithSignal registers a function to be called before any of this | |
43 | // package's normal shutdown actions, which recieves the signal that caused the | |
44 | // shutdown (or nil for manual shutdowns). All listeners will be called in the | |
45 | // order they were added, from a single goroutine. | |
46 | func PreHookWithSignal(f func(os.Signal)) { | |
47 | mu.Lock() | |
48 | defer mu.Unlock() | |
49 | ||
50 | prehooks = append(prehooks, f) | |
51 | } | |
52 | ||
42 | 53 | // PreHook registers a function to be called before any of this package's normal |
43 | 54 | // shutdown actions. All listeners will be called in the order they were added, |
44 | 55 | // from a single goroutine. |
45 | 56 | func PreHook(f func()) { |
46 | mu.Lock() | |
47 | defer mu.Unlock() | |
48 | ||
49 | prehooks = append(prehooks, f) | |
57 | PreHookWithSignal(func(_ os.Signal) { | |
58 | f() | |
59 | }) | |
60 | } | |
61 | ||
62 | // PostHookWithSignal registers a function to be called after all of this | |
63 | // package's normal shutdown actions, which receives the signal that caused the | |
64 | // shutdown (or nil for manual shutdowns). All listeners will be called in the | |
65 | // order they were added, from a single goroutine, and are guaranteed to be | |
66 | // called after all listening connections have been closed, but before Wait() | |
67 | // returns. | |
68 | // | |
69 | // If you've Hijacked any connections that must be gracefully shut down in some | |
70 | // other way (since this library disowns all hijacked connections), it's | |
71 | // reasonable to use a PostHook to signal and wait for them. | |
72 | func PostHookWithSignal(f func(os.Signal)) { | |
73 | mu.Lock() | |
74 | defer mu.Unlock() | |
75 | ||
76 | posthooks = append(posthooks, f) | |
50 | 77 | } |
51 | 78 | |
52 | 79 | // PostHook registers a function to be called after all of this package's normal |
58 | 85 | // other way (since this library disowns all hijacked connections), it's |
59 | 86 | // reasonable to use a PostHook to signal and wait for them. |
60 | 87 | func PostHook(f func()) { |
61 | mu.Lock() | |
62 | defer mu.Unlock() | |
63 | ||
64 | posthooks = append(posthooks, f) | |
88 | PostHookWithSignal(func(_ os.Signal) { | |
89 | f() | |
90 | }) | |
65 | 91 | } |
66 | 92 | |
67 | 93 | // Shutdown manually triggers a shutdown from your application. Like Wait, |
68 | 94 | // blocks until all connections have gracefully shut down. |
69 | 95 | func Shutdown() { |
70 | shutdown(false) | |
96 | shutdown(false, nil) | |
71 | 97 | } |
72 | 98 | |
73 | 99 | // ShutdownNow triggers an immediate shutdown from your application. All |
74 | 100 | // connections (not just those that are idle) are immediately closed, even if |
75 | 101 | // they are in the middle of serving a request. |
76 | 102 | func ShutdownNow() { |
77 | shutdown(true) | |
103 | shutdown(true, nil) | |
78 | 104 | } |
79 | 105 | |
80 | 106 | // DoubleKickWindow sets the length of the window during which two back-to-back |
122 | 148 | func sigLoop() { |
123 | 149 | var last time.Time |
124 | 150 | for { |
125 | <-sigchan | |
151 | sig := <-sigchan | |
126 | 152 | now := time.Now() |
127 | 153 | mu.Lock() |
128 | 154 | force := doubleKick != 0 && now.Sub(last) < doubleKick |
129 | 155 | if t := timeout; t != 0 && !force { |
130 | 156 | go func() { |
131 | 157 | time.Sleep(t) |
132 | shutdown(true) | |
158 | shutdown(true, sig) | |
133 | 159 | }() |
134 | 160 | } |
135 | 161 | mu.Unlock() |
136 | go shutdown(force) | |
162 | go shutdown(force, sig) | |
137 | 163 | last = now |
138 | 164 | } |
139 | 165 | } |
140 | 166 | |
141 | 167 | var preOnce, closeOnce, forceOnce, postOnce, notifyOnce sync.Once |
142 | 168 | |
143 | func shutdown(force bool) { | |
169 | func shutdown(force bool, sig os.Signal) { | |
144 | 170 | preOnce.Do(func() { |
145 | 171 | mu.Lock() |
146 | 172 | defer mu.Unlock() |
147 | 173 | for _, f := range prehooks { |
148 | f() | |
174 | f(sig) | |
149 | 175 | } |
150 | 176 | }) |
151 | 177 | |
163 | 189 | mu.Lock() |
164 | 190 | defer mu.Unlock() |
165 | 191 | for _, f := range posthooks { |
166 | f() | |
192 | f(sig) | |
167 | 193 | } |
168 | 194 | }) |
169 | 195 |
63 | 63 | for _, test := range funcEqualTests { |
64 | 64 | r := funcEqual(test.a, test.b) |
65 | 65 | if r != test.result { |
66 | t.Errorf("funcEqual(%v, %v) should have been %v", | |
66 | t.Errorf("funcEqual(%p, %p) should have been %v", | |
67 | 67 | test.a, test.b, test.result) |
68 | 68 | } |
69 | 69 | } |
147 | 147 | } |
148 | 148 | |
149 | 149 | copy(m.stack[i:], m.stack[i+1:]) |
150 | m.stack = m.stack[:len(m.stack)-1 : len(m.stack)] | |
150 | m.stack = m.stack[: len(m.stack)-1 : len(m.stack)] | |
151 | 151 | |
152 | 152 | m.invalidate() |
153 | 153 | return nil |
0 | // +build !go1.8 | |
1 | ||
0 | 2 | package mutil |
1 | 3 | |
2 | 4 | import ( |
61 | 63 | b.ResponseWriter.WriteHeader(code) |
62 | 64 | } |
63 | 65 | } |
66 | ||
64 | 67 | func (b *basicWriter) Write(buf []byte) (int, error) { |
65 | 68 | b.WriteHeader(http.StatusOK) |
66 | 69 | n, err := b.ResponseWriter.Write(buf) |
74 | 77 | b.bytes += n |
75 | 78 | return n, err |
76 | 79 | } |
80 | ||
77 | 81 | func (b *basicWriter) maybeWriteHeader() { |
78 | 82 | if !b.wroteHeader { |
79 | 83 | b.WriteHeader(http.StatusOK) |
80 | 84 | } |
81 | 85 | } |
86 | ||
82 | 87 | func (b *basicWriter) Status() int { |
83 | 88 | return b.code |
84 | 89 | } |
90 | ||
85 | 91 | func (b *basicWriter) BytesWritten() int { |
86 | 92 | return b.bytes |
87 | 93 | } |
94 | ||
88 | 95 | func (b *basicWriter) Tee(w io.Writer) { |
89 | 96 | b.tee = w |
90 | 97 | } |
98 | ||
91 | 99 | func (b *basicWriter) Unwrap() http.ResponseWriter { |
92 | 100 | return b.ResponseWriter |
93 | 101 | } |
104 | 112 | cn := f.basicWriter.ResponseWriter.(http.CloseNotifier) |
105 | 113 | return cn.CloseNotify() |
106 | 114 | } |
115 | ||
107 | 116 | func (f *fancyWriter) Flush() { |
108 | 117 | fl := f.basicWriter.ResponseWriter.(http.Flusher) |
109 | 118 | fl.Flush() |
110 | 119 | } |
120 | ||
111 | 121 | func (f *fancyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { |
112 | 122 | hj := f.basicWriter.ResponseWriter.(http.Hijacker) |
113 | 123 | return hj.Hijack() |
114 | 124 | } |
125 | ||
115 | 126 | func (f *fancyWriter) ReadFrom(r io.Reader) (int64, error) { |
116 | 127 | if f.basicWriter.tee != nil { |
117 | 128 | return io.Copy(&f.basicWriter, r) |
120 | 131 | f.basicWriter.maybeWriteHeader() |
121 | 132 | return rf.ReadFrom(r) |
122 | 133 | } |
123 | ||
124 | var _ http.CloseNotifier = &fancyWriter{} | |
125 | var _ http.Flusher = &fancyWriter{} | |
126 | var _ http.Hijacker = &fancyWriter{} | |
127 | var _ io.ReaderFrom = &fancyWriter{} | |
128 | 134 | |
129 | 135 | type flushWriter struct { |
130 | 136 | basicWriter |
135 | 141 | fl.Flush() |
136 | 142 | } |
137 | 143 | |
138 | var _ http.Flusher = &flushWriter{} | |
144 | var ( | |
145 | _ http.CloseNotifier = &fancyWriter{} | |
146 | _ http.Flusher = &fancyWriter{} | |
147 | _ http.Hijacker = &fancyWriter{} | |
148 | _ io.ReaderFrom = &fancyWriter{} | |
149 | _ http.Flusher = &flushWriter{} | |
150 | ) |
0 | // +build go1.8 | |
1 | ||
2 | package mutil | |
3 | ||
4 | import ( | |
5 | "bufio" | |
6 | "io" | |
7 | "net" | |
8 | "net/http" | |
9 | ) | |
10 | ||
11 | // WriterProxy is a proxy around an http.ResponseWriter that allows you to hook | |
12 | // into various parts of the response process. | |
13 | type WriterProxy interface { | |
14 | http.ResponseWriter | |
15 | // Status returns the HTTP status of the request, or 0 if one has not | |
16 | // yet been sent. | |
17 | Status() int | |
18 | // BytesWritten returns the total number of bytes sent to the client. | |
19 | BytesWritten() int | |
20 | // Tee causes the response body to be written to the given io.Writer in | |
21 | // addition to proxying the writes through. Only one io.Writer can be | |
22 | // tee'd to at once: setting a second one will overwrite the first. | |
23 | // Writes will be sent to the proxy before being written to this | |
24 | // io.Writer. It is illegal for the tee'd writer to be modified | |
25 | // concurrently with writes. | |
26 | Tee(io.Writer) | |
27 | // Unwrap returns the original proxied target. | |
28 | Unwrap() http.ResponseWriter | |
29 | } | |
30 | ||
31 | // WrapWriter wraps an http.ResponseWriter, returning a proxy that allows you to | |
32 | // hook into various parts of the response process. | |
33 | func WrapWriter(w http.ResponseWriter) WriterProxy { | |
34 | _, fl := w.(http.Flusher) | |
35 | _, hj := w.(http.Hijacker) | |
36 | _, rf := w.(io.ReaderFrom) | |
37 | ||
38 | bw := basicWriter{ResponseWriter: w} | |
39 | if fl && hj && rf { | |
40 | return &fancyWriter{bw} | |
41 | } | |
42 | return &bw | |
43 | } | |
44 | ||
45 | // basicWriter wraps a http.ResponseWriter that implements the minimal | |
46 | // http.ResponseWriter interface. | |
47 | type basicWriter struct { | |
48 | http.ResponseWriter | |
49 | wroteHeader bool | |
50 | code int | |
51 | bytes int | |
52 | tee io.Writer | |
53 | } | |
54 | ||
55 | func (b *basicWriter) WriteHeader(code int) { | |
56 | if !b.wroteHeader { | |
57 | b.code = code | |
58 | b.wroteHeader = true | |
59 | b.ResponseWriter.WriteHeader(code) | |
60 | } | |
61 | } | |
62 | ||
63 | func (b *basicWriter) Write(buf []byte) (int, error) { | |
64 | b.WriteHeader(http.StatusOK) | |
65 | n, err := b.ResponseWriter.Write(buf) | |
66 | if b.tee != nil { | |
67 | _, err2 := b.tee.Write(buf[:n]) | |
68 | // Prefer errors generated by the proxied writer. | |
69 | if err == nil { | |
70 | err = err2 | |
71 | } | |
72 | } | |
73 | b.bytes += n | |
74 | return n, err | |
75 | } | |
76 | ||
77 | func (b *basicWriter) maybeWriteHeader() { | |
78 | if !b.wroteHeader { | |
79 | b.WriteHeader(http.StatusOK) | |
80 | } | |
81 | } | |
82 | ||
83 | func (b *basicWriter) Status() int { | |
84 | return b.code | |
85 | } | |
86 | ||
87 | func (b *basicWriter) BytesWritten() int { | |
88 | return b.bytes | |
89 | } | |
90 | ||
91 | func (b *basicWriter) Tee(w io.Writer) { | |
92 | b.tee = w | |
93 | } | |
94 | ||
95 | func (b *basicWriter) Unwrap() http.ResponseWriter { | |
96 | return b.ResponseWriter | |
97 | } | |
98 | ||
99 | // fancyWriter is a writer that additionally satisfies http.Pusher, | |
100 | // http.Flusher, http.Hijacker, and io.ReaderFrom. It exists for the common case | |
101 | // of wrapping the http.ResponseWriter that package http gives you, in order to | |
102 | // make the proxied object support the full method set of the proxied object. | |
103 | type fancyWriter struct { | |
104 | basicWriter | |
105 | } | |
106 | ||
107 | func (f *fancyWriter) Push(target string, opts *http.PushOptions) error { | |
108 | return f.basicWriter.ResponseWriter.(http.Pusher).Push(target, opts) | |
109 | } | |
110 | ||
111 | func (f *fancyWriter) Flush() { | |
112 | fl := f.basicWriter.ResponseWriter.(http.Flusher) | |
113 | fl.Flush() | |
114 | } | |
115 | ||
116 | func (f *fancyWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { | |
117 | hj := f.basicWriter.ResponseWriter.(http.Hijacker) | |
118 | return hj.Hijack() | |
119 | } | |
120 | ||
121 | func (f *fancyWriter) ReadFrom(r io.Reader) (int64, error) { | |
122 | if f.basicWriter.tee != nil { | |
123 | return io.Copy(&f.basicWriter, r) | |
124 | } | |
125 | rf := f.basicWriter.ResponseWriter.(io.ReaderFrom) | |
126 | f.basicWriter.maybeWriteHeader() | |
127 | return rf.ReadFrom(r) | |
128 | } | |
129 | ||
130 | var ( | |
131 | _ http.Pusher = &fancyWriter{} | |
132 | _ http.Flusher = &fancyWriter{} | |
133 | _ http.Hijacker = &fancyWriter{} | |
134 | _ io.ReaderFrom = &fancyWriter{} | |
135 | ) |