Commit ac49cdbc authored by ale's avatar ale

Update dependencies

parent 6ff61322
......@@ -98,28 +98,35 @@ func newBalancedBackend(config *BackendConfig, resolver resolver) (*balancedBack
// with a JSON-encoded request body. It will attempt to decode the
// response body as JSON.
func (b *balancedBackend) Call(ctx context.Context, shard, path string, req, resp interface{}) error {
// Serialize the request body.
data, err := json.Marshal(req)
if err != nil {
return err
}
var tg targetGenerator = b.backendTracker
if b.sharded {
if shard == "" {
return fmt.Errorf("call without shard to sharded service %s", b.baseURI.String())
}
tg = newShardedGenerator(shard, b.baseURI.Host, b.resolver)
// Create the target sequence for this call. If there are multiple
// targets, reduce the timeout on each individual call accordingly to
// accomodate eventual failover.
seq, err := b.makeSequence(shard)
if err != nil {
return err
}
innerTimeout := 1 * time.Hour
if deadline, ok := ctx.Deadline(); ok {
innerTimeout = time.Until(deadline) / time.Duration(seq.Len())
}
seq := newSequence(tg)
b.log.Printf("%016x: initialized", seq.ID())
// Call the backends in the sequence until one succeeds, with an
// exponential backoff policy controlled by the outer Context.
var httpResp *http.Response
err = backoff.Retry(func() error {
req, rerr := b.newJSONRequest(path, shard, data)
if rerr != nil {
return rerr
}
httpResp, rerr = b.do(ctx, seq, req)
innerCtx, cancel := context.WithTimeout(ctx, innerTimeout)
httpResp, rerr = b.do(innerCtx, seq, req)
cancel()
return rerr
}, backoff.WithContext(newExponentialBackOff(), ctx))
if err != nil {
......@@ -127,16 +134,34 @@ func (b *balancedBackend) Call(ctx context.Context, shard, path string, req, res
}
defer httpResp.Body.Close() // nolint
// Decode the response.
if httpResp.Header.Get("Content-Type") != "application/json" {
return errors.New("not a JSON response")
}
if resp == nil {
return nil
}
return json.NewDecoder(httpResp.Body).Decode(resp)
}
// Initialize a new target sequence.
func (b *balancedBackend) makeSequence(shard string) (*sequence, error) {
var tg targetGenerator = b.backendTracker
if b.sharded {
if shard == "" {
return nil, fmt.Errorf("call without shard to sharded service %s", b.baseURI.String())
}
tg = newShardedGenerator(shard, b.baseURI.Host, b.resolver)
}
seq := newSequence(tg)
if seq.Len() == 0 {
return nil, errNoTargets
}
b.log.Printf("%016x: initialized", seq.ID())
return seq, nil
}
// Return the URI to be used for the request. This is used both in the
// Host HTTP header and as the TLS server name used to pick a server
// certificate (if using TLS).
......@@ -213,6 +238,8 @@ func newSequence(tg targetGenerator) *sequence {
func (s *sequence) ID() uint64 { return s.id }
func (s *sequence) Len() int { return len(s.targets) }
func (s *sequence) reloadTargets() {
targets := s.tg.getTargets()
if len(targets) > 0 {
......
module github.com/google/subcommands
......@@ -26,6 +26,7 @@ import (
"os"
"path"
"sort"
"strings"
)
// A Command represents a single command.
......@@ -197,8 +198,32 @@ func explainGroup(w io.Writer, group *commandGroup) {
fmt.Fprintf(w, "Subcommands for %s:\n", group.name)
}
sort.Sort(group)
aliases := make(map[string][]string)
for _, cmd := range group.commands {
if alias, ok := cmd.(*aliaser); ok {
root := dealias(alias).Name()
if _, ok := aliases[root]; !ok {
aliases[root] = []string{}
}
aliases[root] = append(aliases[root], alias.Name())
}
}
for _, cmd := range group.commands {
fmt.Fprintf(w, "\t%-15s %s\n", cmd.Name(), cmd.Synopsis())
if _, ok := cmd.(*aliaser); ok {
continue
}
name := cmd.Name()
names := []string{name}
if a, ok := aliases[name]; ok {
names = append(names, a...)
}
fmt.Fprintf(w, "\t%-15s %s\n", strings.Join(names, ", "), cmd.Synopsis())
}
fmt.Fprintln(w)
}
......@@ -335,7 +360,7 @@ func (cdr *Commander) CommandsCommand() Command {
}
// An aliaser is a Command wrapping another Command but returning a
// different name as it's alias
// different name as its alias.
type aliaser struct {
alias string
Command
......@@ -348,6 +373,16 @@ func Alias(alias string, cmd Command) Command {
return &aliaser{alias, cmd}
}
// dealias recursivly dealiases a command until a non-aliased command
// is reached.
func dealias(cmd Command) Command {
if alias, ok := cmd.(*aliaser); ok {
return dealias(alias.Command)
}
return cmd
}
// DefaultCommander is the default commander using flag.CommandLine for flags
// and os.Args[0] for the command name.
var DefaultCommander *Commander
......
......@@ -5,26 +5,26 @@
{
"checksumSHA1": "mqNsLVty/oAcBDXv2DZeqMtGeaY=",
"path": "git.autistici.org/ai3/go-common",
"revision": "3f5c3e1bd5295686c2f1a4c87da4a1120c88beac",
"revisionTime": "2018-11-25T18:36:57Z"
"revision": "0868f2647fefb9c3855bb6242aae8aab6d0ddc6d",
"revisionTime": "2019-01-29T12:17:45Z"
},
{
"checksumSHA1": "1ChQcW9Biu/AgiKjsbJFg/+WhjQ=",
"checksumSHA1": "hKJhn/0mTkaYIHwFTy+W9TLr09M=",
"path": "git.autistici.org/ai3/go-common/clientutil",
"revision": "3f5c3e1bd5295686c2f1a4c87da4a1120c88beac",
"revisionTime": "2018-11-25T18:36:57Z"
"revision": "0868f2647fefb9c3855bb6242aae8aab6d0ddc6d",
"revisionTime": "2019-01-29T12:17:45Z"
},
{
"checksumSHA1": "TKGUNmKxj7KH3qhwiCh/6quUnwc=",
"path": "git.autistici.org/ai3/go-common/serverutil",
"revision": "3f5c3e1bd5295686c2f1a4c87da4a1120c88beac",
"revisionTime": "2018-11-25T18:36:57Z"
"revision": "0868f2647fefb9c3855bb6242aae8aab6d0ddc6d",
"revisionTime": "2019-01-29T12:17:45Z"
},
{
"checksumSHA1": "y5pRYZ/NhfEOCFslPEuUZTYXcro=",
"path": "git.autistici.org/ai3/go-common/tracing",
"revision": "3f5c3e1bd5295686c2f1a4c87da4a1120c88beac",
"revisionTime": "2018-11-25T18:36:57Z"
"revision": "0868f2647fefb9c3855bb6242aae8aab6d0ddc6d",
"revisionTime": "2019-01-29T12:17:45Z"
},
{
"checksumSHA1": "0rido7hYHQtfq3UJzVT5LClLAWc=",
......@@ -51,10 +51,10 @@
"revisionTime": "2018-11-28T19:23:52Z"
},
{
"checksumSHA1": "FMWRteujQYjCSrgenMikacQm+10=",
"checksumSHA1": "DyCF9tz8SIZoGEKtKmtsIC8GYYc=",
"path": "github.com/google/subcommands",
"revision": "5bae204cdfb2d92dcc333d56014bae6a2f6c58b1",
"revisionTime": "2018-06-18T21:44:53Z"
"revision": "d47216cd17848d55a33e6f651cbe408243ed55b8",
"revisionTime": "2019-02-11T18:27:06Z"
},
{
"checksumSHA1": "22kXObb09lweSbdIjPZGeLBjnkg=",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment