diff --git a/Makefile b/Makefile index a0d70e0..9500758 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ mock-install: mock-gen: mockgen github.com/t4rest/t4rest-go/redis Cacher > ./redis/mock_redis/redis.go - mockgen github.com/t4rest/t4rest-go/mysql Tx > ./mysql/mock_mysql/mytx.go + mockgen github.com/t4rest/t4rest-go/mysql Tx > ./mysql/mock_tx/mytx.go fmt: go fmt ./... diff --git a/go.mod b/go.mod index 24a286f..4b1ad7a 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/go-redis/redis/v8 v8.8.2 github.com/go-sql-driver/mysql v1.6.0 - github.com/golang/mock v1.5.0 + github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.2 // indirect github.com/jmoiron/sqlx v1.3.3 github.com/julienschmidt/httprouter v1.3.0 @@ -30,9 +30,7 @@ require ( go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.16.0 golang.org/x/mod v0.4.2 // indirect - golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe // indirect golang.org/x/text v0.3.6 // indirect - golang.org/x/tools v0.1.1-0.20210302220138-2ac05c832e1a // indirect google.golang.org/api v0.44.0 // indirect gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 2402096..ff03cf2 100644 --- a/go.sum +++ b/go.sum @@ -150,6 +150,8 @@ github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.5.0 h1:jlYHihg//f7RRwuPfptm04yp4s7O6Kw8EZiVYIGcH0g= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -416,6 +418,7 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= @@ -548,6 +551,7 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 h1:b0LrWgu8+q7z4J+0Y3Umo5q1dL7NXBkKBWkaVkAq17E= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -627,9 +631,12 @@ golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe h1:WdX7u8s3yOigWAhHEaDl8r9G+4XwFQEQFtBMYyN+kXQ= golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -699,6 +706,8 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1-0.20210302220138-2ac05c832e1a h1:wcmQQeIPy0fYbQMsfxwcnzKbuBLMGaHcN0nbzHbIjdo= golang.org/x/tools v0.1.1-0.20210302220138-2ac05c832e1a/go.mod h1:9bzcO0MWcOuT0tm1iBGzDVPshzfwoVvREIui8C+MHqU= +golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/main.go b/main.go index 378ce21..c70536e 100644 --- a/main.go +++ b/main.go @@ -1,70 +1,10 @@ package main import ( - "context" - "net/http" - "time" - - "github.com/avast/retry-go" - "github.com/pkg/errors" - - "github.com/t4rest/t4rest-go/httpclient" - "github.com/t4rest/t4rest-go/logger" - "github.com/t4rest/t4rest-go/module" - ret "github.com/t4rest/t4rest-go/retry" - "github.com/t4rest/t4rest-go/trace" + "fmt" ) func main() { - log := logger.New(logger.Conf{AppID: "AppID", LogLevel: "debug"}) - defer log.Flush() - - flush, err := trace.New(trace.Conf{AppID: "AppID", CollectorEndpoint: "http://localhost:14268/api/traces"}) - if err != nil { - log.Fatal(errors.Wrap(err, "trace.New")) - } - defer flush() - - ctx := context.Background() - - httpClient := httpclient.New(httpclient.Conf{HTTPTimeout: 10 * time.Second}) - - // retry example - err500 := errors.New("Server error") - - r := ret.New(ret.Conf{Attempts: 3, DelayMs: 10 * time.Second, MaxDelayMs: 30 * time.Second}) - err = r.Do( - func() error { - - req, err := http.NewRequest(http.MethodGet, "https://google.com", nil) - if err != nil { - return err - } - req.Header.Set("Content-Type", "application/json") - resp, err := httpClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() //nolint: errcheck - - if resp.StatusCode >= http.StatusInternalServerError { - return errors.Wrap(err500, "server is down") - } - - return nil - }, - retry.OnRetry(func(i uint, err error) { - log.With("retry_attempt", i, "error", err).Info("onRetry") - }), - retry.RetryIf(func(err error) bool { - return errors.Is(err, err500) - }), - retry.Context(ctx), - ) - if err != nil { - log.With("error", err).Error("Get(google.com)") - } - - module.Run(log) + fmt.Println("golang") } diff --git a/mysql/mock_mysql/tx.go b/mysql/mock_mysql/tx.go deleted file mode 100644 index ec9cc1e..0000000 --- a/mysql/mock_mysql/tx.go +++ /dev/null @@ -1,77 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: cynet.com/go/common/mysql (interfaces: Tx) - -// Package mock_mysql is a generated GoMock package. -package mock_mysql - -import ( - "reflect" - - "github.com/golang/mock/gomock" - "github.com/jmoiron/sqlx" -) - -// MockTx is a mock of Tx interface. -type MockTx struct { - ctrl *gomock.Controller - recorder *MockTxMockRecorder -} - -// MockTxMockRecorder is the mock recorder for MockTx. -type MockTxMockRecorder struct { - mock *MockTx -} - -// NewMockTx creates a new mock instance. -func NewMockTx(ctrl *gomock.Controller) *MockTx { - mock := &MockTx{ctrl: ctrl} - mock.recorder = &MockTxMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockTx) EXPECT() *MockTxMockRecorder { - return m.recorder -} - -// Commit mocks base method. -func (m *MockTx) Commit() error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Commit") - ret0, _ := ret[0].(error) - return ret0 -} - -// Commit indicates an expected call of Commit. -func (mr *MockTxMockRecorder) Commit() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Commit", reflect.TypeOf((*MockTx)(nil).Commit)) -} - -// GetTx mocks base method. -func (m *MockTx) GetTx() *sqlx.Tx { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTx") - ret0, _ := ret[0].(*sqlx.Tx) - return ret0 -} - -// GetTx indicates an expected call of GetTx. -func (mr *MockTxMockRecorder) GetTx() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTx", reflect.TypeOf((*MockTx)(nil).GetTx)) -} - -// Rollback mocks base method. -func (m *MockTx) Rollback() error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Rollback") - ret0, _ := ret[0].(error) - return ret0 -} - -// Rollback indicates an expected call of Rollback. -func (mr *MockTxMockRecorder) Rollback() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Rollback", reflect.TypeOf((*MockTx)(nil).Rollback)) -} diff --git a/mysql/mock_mysql/mytx.go b/mysql/mock_tx/mytx.go similarity index 100% rename from mysql/mock_mysql/mytx.go rename to mysql/mock_tx/mytx.go