-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'e8e3c6736783957df4a8a6d17830cb2801a9c280' into minGroup…
…Size Conflicts: cmd/bosun/web/static.go
- Loading branch information
Showing
69 changed files
with
30,868 additions
and
640 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
_third_party/golang.org/x/net/context/ctxhttp/cancelreq.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2015 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build go1.5 | ||
|
||
package ctxhttp | ||
|
||
import "net/http" | ||
|
||
func canceler(client *http.Client, req *http.Request) func() { | ||
ch := make(chan struct{}) | ||
req.Cancel = ch | ||
|
||
return func() { | ||
close(ch) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
_third_party/golang.org/x/net/context/ctxhttp/cancelreq_go14.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2015 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build !go1.5 | ||
|
||
package ctxhttp | ||
|
||
import "net/http" | ||
|
||
type requestCanceler interface { | ||
CancelRequest(*http.Request) | ||
} | ||
|
||
func canceler(client *http.Client, req *http.Request) func() { | ||
rc, ok := client.Transport.(requestCanceler) | ||
if !ok { | ||
return func() {} | ||
} | ||
return func() { | ||
rc.CancelRequest(req) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2015 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Package ctxhttp provides helper functions for performing context-aware HTTP requests. | ||
package ctxhttp // import "bosun.org/_third_party/golang.org/x/net/context/ctxhttp" | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
|
||
"bosun.org/_third_party/golang.org/x/net/context" | ||
) | ||
|
||
// Do sends an HTTP request with the provided http.Client and returns an HTTP response. | ||
// If the client is nil, http.DefaultClient is used. | ||
// If the context is canceled or times out, ctx.Err() will be returned. | ||
func Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) { | ||
if client == nil { | ||
client = http.DefaultClient | ||
} | ||
|
||
// Request cancelation changed in Go 1.5, see cancelreq.go and cancelreq_go14.go. | ||
cancel := canceler(client, req) | ||
|
||
type responseAndError struct { | ||
resp *http.Response | ||
err error | ||
} | ||
result := make(chan responseAndError, 1) | ||
|
||
go func() { | ||
resp, err := client.Do(req) | ||
result <- responseAndError{resp, err} | ||
}() | ||
|
||
select { | ||
case <-ctx.Done(): | ||
cancel() | ||
return nil, ctx.Err() | ||
case r := <-result: | ||
return r.resp, r.err | ||
} | ||
} | ||
|
||
// Get issues a GET request via the Do function. | ||
func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error) { | ||
req, err := http.NewRequest("GET", url, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return Do(ctx, client, req) | ||
} | ||
|
||
// Head issues a HEAD request via the Do function. | ||
func Head(ctx context.Context, client *http.Client, url string) (*http.Response, error) { | ||
req, err := http.NewRequest("HEAD", url, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return Do(ctx, client, req) | ||
} | ||
|
||
// Post issues a POST request via the Do function. | ||
func Post(ctx context.Context, client *http.Client, url string, bodyType string, body io.Reader) (*http.Response, error) { | ||
req, err := http.NewRequest("POST", url, body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req.Header.Set("Content-Type", bodyType) | ||
return Do(ctx, client, req) | ||
} | ||
|
||
// PostForm issues a POST request via the Do function. | ||
func PostForm(ctx context.Context, client *http.Client, url string, data url.Values) (*http.Response, error) { | ||
return Post(ctx, client, url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode())) | ||
} |
72 changes: 72 additions & 0 deletions
72
_third_party/golang.org/x/net/context/ctxhttp/ctxhttp_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2015 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package ctxhttp | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
"time" | ||
|
||
"bosun.org/_third_party/golang.org/x/net/context" | ||
) | ||
|
||
const ( | ||
requestDuration = 100 * time.Millisecond | ||
requestBody = "ok" | ||
) | ||
|
||
func TestNoTimeout(t *testing.T) { | ||
ctx := context.Background() | ||
resp, err := doRequest(ctx) | ||
|
||
if resp == nil || err != nil { | ||
t.Fatalf("error received from client: %v %v", err, resp) | ||
} | ||
} | ||
func TestCancel(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
go func() { | ||
time.Sleep(requestDuration / 2) | ||
cancel() | ||
}() | ||
|
||
resp, err := doRequest(ctx) | ||
|
||
if resp != nil || err == nil { | ||
t.Fatalf("expected error, didn't get one. resp: %v", resp) | ||
} | ||
if err != ctx.Err() { | ||
t.Fatalf("expected error from context but got: %v", err) | ||
} | ||
} | ||
|
||
func TestCancelAfterRequest(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
|
||
resp, err := doRequest(ctx) | ||
|
||
// Cancel before reading the body. | ||
// Request.Body should still be readable after the context is canceled. | ||
cancel() | ||
|
||
b, err := ioutil.ReadAll(resp.Body) | ||
if err != nil || string(b) != requestBody { | ||
t.Fatalf("could not read body: %q %v", b, err) | ||
} | ||
} | ||
|
||
func doRequest(ctx context.Context) (*http.Response, error) { | ||
var okHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
time.Sleep(requestDuration) | ||
w.Write([]byte(requestBody)) | ||
}) | ||
|
||
serv := httptest.NewServer(okHandler) | ||
defer serv.Close() | ||
|
||
return Get(ctx, nil, serv.URL) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2014 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package context_test | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"bosun.org/_third_party/golang.org/x/net/context" | ||
) | ||
|
||
func ExampleWithTimeout() { | ||
// Pass a context with a timeout to tell a blocking function that it | ||
// should abandon its work after the timeout elapses. | ||
ctx, _ := context.WithTimeout(context.Background(), 100*time.Millisecond) | ||
select { | ||
case <-time.After(200 * time.Millisecond): | ||
fmt.Println("overslept") | ||
case <-ctx.Done(): | ||
fmt.Println(ctx.Err()) // prints "context deadline exceeded" | ||
} | ||
// Output: | ||
// context deadline exceeded | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This source code refers to The Go Authors for copyright purposes. | ||
# The master list of authors is in the main Go distribution, | ||
# visible at http://tip.golang.org/AUTHORS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Contributing to Go | ||
|
||
Go is an open source project. | ||
|
||
It is the work of hundreds of contributors. We appreciate your help! | ||
|
||
|
||
## Filing issues | ||
|
||
When [filing an issue](https://github.com/golang/oauth2/issues), make sure to answer these five questions: | ||
|
||
1. What version of Go are you using (`go version`)? | ||
2. What operating system and processor architecture are you using? | ||
3. What did you do? | ||
4. What did you expect to see? | ||
5. What did you see instead? | ||
|
||
General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker. | ||
The gophers there will answer or ask you to file an issue if you've tripped over a bug. | ||
|
||
## Contributing code | ||
|
||
Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html) | ||
before sending patches. | ||
|
||
**We do not accept GitHub pull requests** | ||
(we use [Gerrit](https://code.google.com/p/gerrit/) instead for code review). | ||
|
||
Unless otherwise noted, the Go source files are distributed under | ||
the BSD-style license found in the LICENSE file. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This source code was written by the Go contributors. | ||
# The master list of contributors is in the main Go distribution, | ||
# visible at http://tip.golang.org/CONTRIBUTORS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) 2009 The oauth2 Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# OAuth2 for Go | ||
|
||
[![Build Status](https://travis-ci.org/golang/oauth2.svg?branch=master)](https://travis-ci.org/golang/oauth2) | ||
|
||
oauth2 package contains a client implementation for OAuth 2.0 spec. | ||
|
||
## Installation | ||
|
||
~~~~ | ||
go get golang.org/x/oauth2 | ||
~~~~ | ||
|
||
See godoc for further documentation and examples. | ||
|
||
* [godoc.org/golang.org/x/oauth2](http://godoc.org/golang.org/x/oauth2) | ||
* [godoc.org/golang.org/x/oauth2/google](http://godoc.org/golang.org/x/oauth2/google) | ||
|
||
|
||
## App Engine | ||
|
||
In change 96e89be (March 2015) we removed the `oauth2.Context2` type in favor | ||
of the [`context.Context`](https://golang.org/x/net/context#Context) type from | ||
the `golang.org/x/net/context` package | ||
|
||
This means its no longer possible to use the "Classic App Engine" | ||
`appengine.Context` type with the `oauth2` package. (You're using | ||
Classic App Engine if you import the package `"appengine"`.) | ||
|
||
To work around this, you may use the new `"google.golang.org/appengine"` | ||
package. This package has almost the same API as the `"appengine"` package, | ||
but it can be fetched with `go get` and used on "Managed VMs" and well as | ||
Classic App Engine. | ||
|
||
See the [new `appengine` package's readme](https://github.com/golang/appengine#updating-a-go-app-engine-app) | ||
for information on updating your app. | ||
|
||
If you don't want to update your entire app to use the new App Engine packages, | ||
you may use both sets of packages in parallel, using only the new packages | ||
with the `oauth2` package. | ||
|
||
import ( | ||
"golang.org/x/net/context" | ||
"golang.org/x/oauth2" | ||
"golang.org/x/oauth2/google" | ||
newappengine "google.golang.org/appengine" | ||
newurlftech "google.golang.org/urlfetch" | ||
|
||
"appengine" | ||
) | ||
|
||
func handler(w http.ResponseWriter, r *http.Request) { | ||
var c appengine.Context = appengine.NewContext(r) | ||
c.Infof("Logging a message with the old package") | ||
|
||
var ctx context.Context = newappengine.NewContext(r) | ||
client := &http.Client{ | ||
Transport: &oauth2.Transport{ | ||
Source: google.AppEngineTokenSource(ctx, "scope"), | ||
Base: &newurlfetch.Transport{Context: ctx}, | ||
}, | ||
} | ||
client.Get("...") | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2014 The oauth2 Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build appengine appenginevm | ||
|
||
// App Engine hooks. | ||
|
||
package oauth2 | ||
|
||
import ( | ||
"net/http" | ||
|
||
"bosun.org/_third_party/golang.org/x/net/context" | ||
"bosun.org/_third_party/google.golang.org/appengine/urlfetch" | ||
) | ||
|
||
func init() { | ||
registerContextClientFunc(contextClientAppEngine) | ||
} | ||
|
||
func contextClientAppEngine(ctx context.Context) (*http.Client, error) { | ||
return urlfetch.Client(ctx), nil | ||
} |
Oops, something went wrong.