From 9bfa4a05546b6e0237cfd64f6981839b685fc3d6 Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Sun, 29 Jul 2018 23:22:36 +0200 Subject: [PATCH] upd(all): update vendored code --- Gopkg.lock | 22 ++--- .../LICENSE => SentimensRG/sigctx/README.md} | 46 +++++++-- .../github.com/SentimensRG/sigctx/sigctx.go | 31 ++++++ .../labstack/gommon/random/random.go | 48 --------- .../github.com/titpetric/factory/database.go | 98 ++++++++++++++++--- .../googleapis/rpc/status/status.pb.go | 6 +- 6 files changed, 170 insertions(+), 81 deletions(-) rename vendor/github.com/{labstack/gommon/LICENSE => SentimensRG/sigctx/README.md} (53%) create mode 100644 vendor/github.com/SentimensRG/sigctx/sigctx.go delete mode 100644 vendor/github.com/labstack/gommon/random/random.go diff --git a/Gopkg.lock b/Gopkg.lock index 8f77b5b47..7a52e7659 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1,6 +1,12 @@ # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. +[[projects]] + branch = "master" + name = "github.com/SentimensRG/sigctx" + packages = ["."] + revision = "c19b774db63bdcae0c335d8c4bab1207713a08c6" + [[projects]] name = "github.com/davecgh/go-spew" packages = ["spew"] @@ -77,12 +83,6 @@ revision = "a79fa1e548e2c689c241d10173efd51e5d689d5b" version = "v1.2.0" -[[projects]] - name = "github.com/labstack/gommon" - packages = ["random"] - revision = "d6898124de917583f5ff5592ef931d1dfe0ddc05" - version = "0.2.6" - [[projects]] branch = "master" name = "github.com/lib/pq" @@ -117,7 +117,7 @@ ".", "resputil" ] - revision = "f3b1061ebdb281d6204f95fdc1b9cb84a48e1bd3" + revision = "3f10a81a8ec5ed5426c96e71a9029c1921d07aef" [[projects]] branch = "master" @@ -126,7 +126,7 @@ "bcrypt", "blowfish" ] - revision = "a2144134853fc9a27a7b1e3eb4f19f1a76df13c9" + revision = "c126467f60eb25f8f27e5a981f32a87e3965053f" [[projects]] branch = "master" @@ -140,7 +140,7 @@ "internal/timeseries", "trace" ] - revision = "a680a1efc54dd51c040b3b5ce4939ea3cf2ea0d1" + revision = "c4299a1a0d8524c11563db160fbf9bddbceadb21" [[projects]] name = "golang.org/x/text" @@ -173,7 +173,7 @@ branch = "master" name = "google.golang.org/genproto" packages = ["googleapis/rpc/status"] - revision = "02b4e95473316948020af0b7a4f0f22c73929b0e" + revision = "2a72893556e4d1f6c795a4c039314c9fa751eedb" [[projects]] name = "google.golang.org/grpc" @@ -210,6 +210,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "7f142f5d723e442561d3cd97848ecf4c4d484f016d0942f1516344d4acf056af" + inputs-digest = "297f1368fa993f29af05bf130133ca3e0b133c4fec4b039a6cb4ae3b94b7a63b" solver-name = "gps-cdcl" solver-version = 1 diff --git a/vendor/github.com/labstack/gommon/LICENSE b/vendor/github.com/SentimensRG/sigctx/README.md similarity index 53% rename from vendor/github.com/labstack/gommon/LICENSE rename to vendor/github.com/SentimensRG/sigctx/README.md index d2ae3edf6..763649027 100644 --- a/vendor/github.com/labstack/gommon/LICENSE +++ b/vendor/github.com/SentimensRG/sigctx/README.md @@ -1,6 +1,39 @@ -The MIT License (MIT) +# DEPRECATION WARNING -Copyright (c) 2015 labstack +`sigctx` is now part of [SentimensRG/ctx](https://github.com/SentimensRG/ctx). + +This repository will no longer receive updates. + +# sigctx +Go contexts for graceful shutdown + +## installation + +```bash +go get -u github.com/SentimensRG/sigctx +``` + +## usage + +```go +ctx := sigctx.New() // returns a regular context.Context + +// With this simple pattern, your goroutines are guaranteed to terminate correctly +ctx, cancel := context.WithCancel(ctx) +go someBlockingFunction(ctx) +defer cancel() + +<-ctx.Done() // will unblock on SIGINT and SIGTERM +``` + +## RFC + +If you find this useful, please let me know: + +## License +The MIT License + +Copyright (c) 2017 Sentimens Research Group, LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,14 +42,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/github.com/SentimensRG/sigctx/sigctx.go b/vendor/github.com/SentimensRG/sigctx/sigctx.go new file mode 100644 index 000000000..a57cb97b5 --- /dev/null +++ b/vendor/github.com/SentimensRG/sigctx/sigctx.go @@ -0,0 +1,31 @@ +package sigctx + +import ( + "context" + "os" + "os/signal" + "syscall" +) + +var ctx context.Context + +func init() { + var cancel func() + ctx, cancel = context.WithCancel(context.Background()) + + go func() { + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM) + + select { + case <-ch: + cancel() + case <-ctx.Done(): + } + }() +} + +// New signal-bound context +func New() context.Context { + return ctx +} diff --git a/vendor/github.com/labstack/gommon/random/random.go b/vendor/github.com/labstack/gommon/random/random.go deleted file mode 100644 index 482d05248..000000000 --- a/vendor/github.com/labstack/gommon/random/random.go +++ /dev/null @@ -1,48 +0,0 @@ -package random - -import ( - "math/rand" - "strings" - "time" -) - -type ( - Random struct { - } -) - -// Charsets -const ( - Uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - Lowercase = "abcdefghijklmnopqrstuvwxyz" - Alphabetic = Uppercase + Lowercase - Numeric = "0123456789" - Alphanumeric = Alphabetic + Numeric - Symbols = "`" + `~!@#$%^&*()-_+={}[]|\;:"<>,./?` - Hex = Numeric + "abcdef" -) - -var ( - global = New() -) - -func New() *Random { - rand.Seed(time.Now().UnixNano()) - return new(Random) -} - -func (r *Random) String(length uint8, charsets ...string) string { - charset := strings.Join(charsets, "") - if charset == "" { - charset = Alphanumeric - } - b := make([]byte, length) - for i := range b { - b[i] = charset[rand.Int63()%int64(len(charset))] - } - return string(b) -} - -func String(length uint8, charsets ...string) string { - return global.String(length, charsets...) -} diff --git a/vendor/github.com/titpetric/factory/database.go b/vendor/github.com/titpetric/factory/database.go index d60b2f4d4..0124384fa 100644 --- a/vendor/github.com/titpetric/factory/database.go +++ b/vendor/github.com/titpetric/factory/database.go @@ -125,7 +125,15 @@ func (r *DatabaseFactory) Get(dbName ...string) (*DB, error) { if err != nil { return nil, err } - r.instances[name] = &DB{handle, context.Background(), nil} + r.instances[name] = &DB{ + handle, + context.Background(), + nil, + &sql.TxOptions{ + ReadOnly: false, + }, + nil, + } return r.instances[name], nil } } @@ -147,24 +155,70 @@ type DB struct { ctx context.Context + Tx *sqlx.Tx + TxOpts *sql.TxOptions + Profiler DatabaseProfiler } // Quiet will return a DB handle without a profiler (throw-away) func (r *DB) Quiet() *DB { return &DB{ - DB: r.DB, + r.DB, + r.ctx, + r.Tx, + r.TxOpts, + nil, } } // With will return a DB handle with a bound context (throw-away) func (r *DB) With(ctx context.Context) *DB { return &DB{ - DB: r.DB, - ctx: ctx, + r.DB, + ctx, + r.Tx, + r.TxOpts, + r.Profiler, } } +// Begin will create a transaction in the DB with a context +func (r *DB) Begin() error { + var err error + if r.Tx != nil { + return errors.New("Transaction already started") + } + if r.ctx == nil { + r.Tx, err = r.DB.Beginx() + return errors.WithStack(err) + } + r.Tx, err = r.DB.BeginTxx(r.ctx, r.TxOpts) + return errors.WithStack(err) +} + +func (r *DB) Commit() error { + if r.Tx != nil { + if err := r.Tx.Commit(); err != nil { + return errors.WithStack(err) + } + r.Tx = nil + return nil + } + return errors.New("No transation active") +} + +func (r *DB) Rollback() error { + if r.Tx != nil { + if err := r.Tx.Rollback(); err != nil { + return errors.WithStack(err) + } + r.Tx = nil + return nil + } + return errors.New("No transaction active") +} + // SetFields will provide a string with SQL named bindings from a string slice func (r *DB) SetFields(fields []string) string { idx := 0 @@ -180,25 +234,39 @@ func (r *DB) SetFields(fields []string) string { } // NamedExec adds profiling on top of the parent DB.NameExec -func (r *DB) NamedExec(query string, arg interface{}) (sql.Result, error) { +func (r *DB) NamedExec(query string, arg interface{}) (res sql.Result, err error) { + exec := func() (sql.Result, error) { + if r.Tx != nil { + return r.Tx.NamedExecContext(r.ctx, query, arg) + } + return r.DB.NamedExecContext(r.ctx, query, arg) + } + if r.Profiler != nil { ctx := DatabaseProfilerContext{}.new(query, arg) - res, err := r.DB.NamedExecContext(r.ctx, query, arg) + res, err = exec() r.Profiler.Post(ctx) - return res, err + } else { + res, err = exec() } - return r.DB.NamedExecContext(r.ctx, query, arg) + return res, errors.Wrap(err, "exec query failed") } // Select is a helper function that will ignore sql.ErrNoRows func (r *DB) Select(dest interface{}, query string, args ...interface{}) error { var err error + exec := func() error { + if r.Tx != nil { + return r.Tx.SelectContext(r.ctx, dest, query, args...) + } + return r.DB.SelectContext(r.ctx, dest, query, args...) + } if r.Profiler != nil { ctx := DatabaseProfilerContext{}.new(query, args...) - err = r.DB.SelectContext(r.ctx, dest, query, args...) + err = exec() r.Profiler.Post(ctx) } else { - err = r.DB.SelectContext(r.ctx, dest, query, args...) + err = exec() } // clear no rows returned error if err == sql.ErrNoRows { @@ -210,12 +278,18 @@ func (r *DB) Select(dest interface{}, query string, args ...interface{}) error { // Get is a helper function that will ignore sql.ErrNoRows func (r *DB) Get(dest interface{}, query string, args ...interface{}) error { var err error + exec := func() error { + if r.Tx != nil { + return r.Tx.GetContext(r.ctx, dest, query, args...) + } + return r.DB.GetContext(r.ctx, dest, query, args...) + } if r.Profiler != nil { ctx := DatabaseProfilerContext{}.new(query, args...) - err = r.DB.GetContext(r.ctx, dest, query, args...) + err = exec() r.Profiler.Post(ctx) } else { - err = r.DB.GetContext(r.ctx, dest, query, args...) + err = exec() } // clear no rows returned error if err == sql.ErrNoRows { diff --git a/vendor/google.golang.org/genproto/googleapis/rpc/status/status.pb.go b/vendor/google.golang.org/genproto/googleapis/rpc/status/status.pb.go index 3b07a25b7..7bfe37a3d 100644 --- a/vendor/google.golang.org/genproto/googleapis/rpc/status/status.pb.go +++ b/vendor/google.golang.org/genproto/googleapis/rpc/status/status.pb.go @@ -90,7 +90,7 @@ func (m *Status) Reset() { *m = Status{} } func (m *Status) String() string { return proto.CompactTextString(m) } func (*Status) ProtoMessage() {} func (*Status) Descriptor() ([]byte, []int) { - return fileDescriptor_status_c656c685916bdf47, []int{0} + return fileDescriptor_status_c6e4de62dcdf2edf, []int{0} } func (m *Status) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Status.Unmarshal(m, b) @@ -135,9 +135,9 @@ func init() { proto.RegisterType((*Status)(nil), "google.rpc.Status") } -func init() { proto.RegisterFile("google/rpc/status.proto", fileDescriptor_status_c656c685916bdf47) } +func init() { proto.RegisterFile("google/rpc/status.proto", fileDescriptor_status_c6e4de62dcdf2edf) } -var fileDescriptor_status_c656c685916bdf47 = []byte{ +var fileDescriptor_status_c6e4de62dcdf2edf = []byte{ // 209 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4f, 0xcf, 0xcf, 0x4f, 0xcf, 0x49, 0xd5, 0x2f, 0x2a, 0x48, 0xd6, 0x2f, 0x2e, 0x49, 0x2c, 0x29, 0x2d, 0xd6, 0x2b, 0x28,