From b9205999f1f4c77c71c7766eb2e9c7c1c3d808fc Mon Sep 17 00:00:00 2001 From: Elton Minetto Date: Thu, 25 Jun 2020 14:29:02 -0300 Subject: [PATCH] feat: add mysql partial repository --- .idea/vcs.xml | 6 ++ Makefile | 1 - api/middleware/validate.go | 29 ------ cmd/main.go | 98 +++++++++--------- config/config_dev.go | 9 +- config/config_prod.go | 9 +- config/config_staging.go | 9 +- config/config_testing.go | 9 +- docker-compose.yml | 30 +++--- domain/entity/book/repository_mysql.go | 93 +++++++++++++++++ domain/entity/book/service_test.go | 3 +- domain/entity/user/fixture.go | 16 +-- domain/entity/user/repository_mysql.go | 72 +++++++++++++ go.mod | 10 ++ go.sum | 133 +++++++++++++++++++++++++ infra/init.sql | 5 + 16 files changed, 411 insertions(+), 121 deletions(-) create mode 100644 .idea/vcs.xml delete mode 100644 api/middleware/validate.go create mode 100644 domain/entity/book/repository_mysql.go create mode 100644 domain/entity/user/repository_mysql.go create mode 100644 infra/init.sql diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Makefile b/Makefile index 18e4e69..4be1026 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,6 @@ build-mocks: @~/go/bin/mockgen -source=domain/entity/user/interface.go -destination=domain/entity/user/mock/user.go -package=mock @~/go/bin/mockgen -source=domain/loan/interface.go -destination=domain/loan/mock/loan.go -package=mock - test: go test -tags testing ./... diff --git a/api/middleware/validate.go b/api/middleware/validate.go deleted file mode 100644 index 8e24703..0000000 --- a/api/middleware/validate.go +++ /dev/null @@ -1,29 +0,0 @@ -package middleware - -import ( - "context" - "encoding/json" - "github.com/eminetto/clean-architecture-go/pkg/entity" - "net/http" - "github.com/codegangsta/negroni" -) - -//Validate -func Validate(e entity.Validable) negroni.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) { - err := json.NewDecoder(r.Body).Decode(&e) - if err != nil { - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte(err.Error())) - return - } - err = e.Validate() - if err != nil { - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte(err.Error())) - return - } - ctx := context.WithValue(r.Context(), "InputParam", e) - next(w, r.WithContext(ctx)) - } -} diff --git a/cmd/main.go b/cmd/main.go index 59143ad..d4ab153 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,65 +1,57 @@ package main import ( + "database/sql" + "errors" "fmt" - "github.com/eminetto/clean-architecture-go-v2/domain/entity" - "github.com/eminetto/clean-architecture-go-v2/domain/entity/user" + "log" + "os" + + "github.com/eminetto/clean-architecture-go-v2/config" + _ "github.com/go-sql-driver/mysql" + "github.com/eminetto/clean-architecture-go-v2/domain/entity/book" + + "github.com/eminetto/clean-architecture-go-v2/pkg/metric" ) -//func handleParams() (string, error) { -// if len(os.Args) < 2 { -// return "", errors.New("Invalid query") -// } -// return os.Args[1], nil -//} +func handleParams() (string, error) { + if len(os.Args) < 2 { + return "", errors.New("Invalid query") + } + return os.Args[1], nil +} func main() { - u := &user.User{ - ID: entity.NewID(), - FirstName: "Elton", + metricService, err := metric.NewPrometheusService() + if err != nil { + log.Fatal(err.Error()) } - b := &book.Book{ - ID: entity.NewID(), - Title:"Book", + appMetric := metric.NewCLI("search") + appMetric.Started() + query, err := handleParams() + if err != nil { + log.Fatal(err.Error()) + } + + dataSourceName := fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?parseTime=true", config.DB_USER, config.DB_PASSWORD, config.DB_HOST, config.DB_DATABASE) + db, err := sql.Open("mysql", dataSourceName) + if err != nil { + log.Fatal(err.Error()) + } + defer db.Close() + repo := book.NewMySQLRepoRepository(db) + service := book.NewService(repo) + all, err := service.Search(query) + if err != nil { + log.Fatal(err) + } + for _, j := range all { + fmt.Printf("%s %s \n", j.Title, j.Author) + } + appMetric.Finished() + err = metricService.SaveCLI(appMetric) + if err != nil { + log.Fatal(err) } - fmt.Println(u) - fmt.Println(b) - //metricService, err := metric.NewPrometheusService() - //if err != nil { - // log.Fatal(err.Error()) - //} - //appMetric := metric.NewCLI("search") - //appMetric.Started() - //query, err := handleParams() - //if err != nil { - // log.Fatal(err.Error()) - //} - // - //session, err := mgo.Dial(config.MONGODB_HOST) - //if err != nil { - // log.Fatal(err.Error()) - //} - //defer session.Close() - // - //mPool := mgosession.NewPool(nil, session, config.MONGODB_CONNECTION_POOL) - //defer mPool.Close() - // - //bookmarkRepo := bookmark.NewMongoRepository(mPool, config.MONGODB_DATABASE) - //bookmarkService := bookmark.NewService(bookmarkRepo) - //all, err := bookmarkService.Search(query) - //if err != nil { - // log.Fatal(err) - //} - //if len(all) == 0 { - // log.Fatal(entity.ErrNotFound.Error()) - //} - //for _, j := range all { - // fmt.Printf("%s %s %v \n", j.Name, j.Link, j.Tags) - //} - //appMetric.Finished() - //err = metricService.SaveCLI(appMetric) - //if err != nil { - // log.Fatal(err) - //} } diff --git a/config/config_dev.go b/config/config_dev.go index ffac8a2..bf90b70 100644 --- a/config/config_dev.go +++ b/config/config_dev.go @@ -3,9 +3,10 @@ package config const ( - MONGODB_HOST = "mongodb://127.0.0.1:27017" - MONGODB_DATABASE = "bookmark" - MONGODB_CONNECTION_POOL = 5 - API_PORT = 8080 + DB_USER = "clean_architecture_go_v2" + DB_PASSWORD = "clean_architecture_go_v2" + DB_DATABASE = "clean_architecture_go_v2" + DB_HOST = "127.0.0.1" + API_PORT = 8080 PROMETHEUS_PUSHGATEWAY = "http://localhost:9091/" ) diff --git a/config/config_prod.go b/config/config_prod.go index 2afa50e..efcc062 100644 --- a/config/config_prod.go +++ b/config/config_prod.go @@ -3,9 +3,10 @@ package config const ( - MONGODB_HOST = "mongodb://127.0.0.1:27017" - MONGODB_DATABASE = "bookmark" - MONGODB_CONNECTION_POOL = 50 - API_PORT = 8080 + DB_USER = "clean_architecture_go_v2" + DB_PASSWORD = "clean_architecture_go_v2" + DB_DATABASE = "clean_architecture_go_v2" + DB_HOST = "127.0.0.1" + API_PORT = 8080 PROMETHEUS_PUSHGATEWAY = "http://localhost:9091/" ) diff --git a/config/config_staging.go b/config/config_staging.go index 65991a1..4d86a79 100644 --- a/config/config_staging.go +++ b/config/config_staging.go @@ -3,9 +3,10 @@ package config const ( - MONGODB_HOST = "mongodb://127.0.0.1:27017" - MONGODB_DATABASE = "bookmark" - MONGODB_CONNECTION_POOL = 5 - API_PORT = 8080 + DB_USER = "clean_architecture_go_v2" + DB_PASSWORD = "clean_architecture_go_v2" + DB_DATABASE = "clean_architecture_go_v2" + DB_HOST = "127.0.0.1" + API_PORT = 8080 PROMETHEUS_PUSHGATEWAY = "http://localhost:9091/" ) diff --git a/config/config_testing.go b/config/config_testing.go index 2ea19df..0ae9124 100644 --- a/config/config_testing.go +++ b/config/config_testing.go @@ -3,9 +3,10 @@ package config const ( - MONGODB_HOST = "mongodb://127.0.0.1:27017" - MONGODB_DATABASE = "bookmark" - MONGODB_CONNECTION_POOL = 5 - API_PORT = 8080 + DB_USER = "clean_architecture_go_v2" + DB_PASSWORD = "clean_architecture_go_v2" + DB_DATABASE = "clean_architecture_go_v2" + DB_HOST = "127.0.0.1" + API_PORT = 8080 PROMETHEUS_PUSHGATEWAY = "http://localhost:9091/" ) diff --git a/docker-compose.yml b/docker-compose.yml index 00513ec..6894b3b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,24 @@ version: "3" services: - mongodb: - image: mongo - ports: - - "27017:27017" - container_name: bookmark-mongodb - network_mode: "bridge" - node: - image: node:8-alpine - network_mode: "bridge" + mysql: + image: mysql:5.7 + command: --default-authentication-plugin=mysql_native_password --init-file /data/application/init.sql volumes: - - ./web:/web - - /tmp:/tmp + - ./infra/init.sql:/data/application/init.sql + environment: + MYSQL_ROOT_PASSWORD: clean_architecture_go_v2 + MYSQL_DATABASE: clean_architecture_go_v2 + MYSQL_USER: clean_architecture_go_v2 + MYSQL_PASSWORD: clean_architecture_go_v2 + ports: + - "3306:3306" + container_name: clean-architecture-go-v2-mysql + network_mode: "bridge" grafana: image: grafana/grafana ports: - "3000:3000" - container_name: bookmark-grafana + container_name: clean-architecture-go-v2-grafana network_mode: "bridge" depends_on: - prometheus @@ -29,11 +31,11 @@ services: - --config.file=/etc/prometheus/prometheus.yml volumes: - ./infra/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro - container_name: bookmark-prometheus + container_name: clean-architecture-go-v2-prometheus network_mode: "bridge" prometheus-pushgateway: image: prom/pushgateway - container_name: bookmark-pushgateway + container_name: clean-architecture-go-v2-pushgateway expose: - 9091 ports: diff --git a/domain/entity/book/repository_mysql.go b/domain/entity/book/repository_mysql.go new file mode 100644 index 0000000..80e59bd --- /dev/null +++ b/domain/entity/book/repository_mysql.go @@ -0,0 +1,93 @@ +package book + +import ( + "database/sql" + "time" + + "github.com/eminetto/clean-architecture-go-v2/domain" + + "github.com/eminetto/clean-architecture-go-v2/domain/entity" +) + +//MySQLRepo mysql repo +type MySQLRepo struct { + db *sql.DB +} + +//NewMySQLRepoRepository create new repository +func NewMySQLRepoRepository(db *sql.DB) *MySQLRepo { + return &MySQLRepo{ + db: db, + } +} + +//Create an user +func (r *MySQLRepo) Create(e *Book) (entity.ID, error) { + stmt, err := r.db.Prepare(` + insert into book (id, title, author, pages, quantity, created_at) + values(?,?,?,?,?,?)`) + if err != nil { + return e.ID, err + } + _, err = stmt.Exec( + e.ID, + e.Title, + e.Author, + e.Pages, + e.Quantity, + time.Now().Format("2006-01-02"), + ) + if err != nil { + return e.ID, err + } + err = stmt.Close() + if err != nil { + return e.ID, err + } + return e.ID, nil +} + +//Get an user +func (r *MySQLRepo) Get(id entity.ID) (*Book, error) { + return nil, nil +} + +//Update an user +func (r *MySQLRepo) Update(e *Book) error { + return nil +} + +//Search users +func (r *MySQLRepo) Search(query string) ([]*Book, error) { + stmt, err := r.db.Prepare(`select id, title, author, pages, quantity, created_at from book where title like ?`) + if err != nil { + return nil, err + } + var books []*Book + rows, err := stmt.Query("%" + query + "%") + if err != nil { + return nil, err + } + for rows.Next() { + var b Book + err = rows.Scan(&b.ID, &b.Title, &b.Author, &b.Pages, &b.Quantity, &b.CreatedAt) + if err != nil { + return nil, err + } + books = append(books, &b) + } + if len(books) == 0 { + return nil, domain.ErrNotFound + } + return books, nil +} + +//List users +func (r *MySQLRepo) List() ([]*Book, error) { + return nil, nil +} + +//Delete an user +func (r *MySQLRepo) Delete(id entity.ID) error { + return nil +} diff --git a/domain/entity/book/service_test.go b/domain/entity/book/service_test.go index e73ec36..10afb9e 100644 --- a/domain/entity/book/service_test.go +++ b/domain/entity/book/service_test.go @@ -1,9 +1,10 @@ package book import ( - "github.com/eminetto/clean-architecture-go-v2/domain" "testing" + "github.com/eminetto/clean-architecture-go-v2/domain" + "github.com/stretchr/testify/assert" ) diff --git a/domain/entity/user/fixture.go b/domain/entity/user/fixture.go index 8ddb1fb..2b776c5 100644 --- a/domain/entity/user/fixture.go +++ b/domain/entity/user/fixture.go @@ -1,16 +1,18 @@ package user import ( - "github.com/eminetto/clean-architecture-go-v2/domain/entity" "time" + + "github.com/eminetto/clean-architecture-go-v2/domain/entity" ) func NewFixtureUser() *User { - return &User{ - ID: entity.NewID(), - Email:"ozzy@metalgods.net", - FirstName:"Ozzy", - LastName: "Osbourne", + return &User{ + ID: entity.NewID(), + Email: "ozzy@metalgods.net", + Password: "123456", + FirstName: "Ozzy", + LastName: "Osbourne", CreatedAt: time.Now(), } -} \ No newline at end of file +} diff --git a/domain/entity/user/repository_mysql.go b/domain/entity/user/repository_mysql.go new file mode 100644 index 0000000..2032933 --- /dev/null +++ b/domain/entity/user/repository_mysql.go @@ -0,0 +1,72 @@ +package user + +import ( + "database/sql" + "time" + + "github.com/eminetto/clean-architecture-go-v2/domain/entity" +) + +//MySQLRepo mysql repo +type MySQLRepo struct { + db *sql.DB +} + +//NewMySQLRepoRepository create new repository +func NewMySQLRepoRepository(db *sql.DB) *MySQLRepo { + return &MySQLRepo{ + db: db, + } +} + +//Create an user +func (r *MySQLRepo) Create(e *User) (entity.ID, error) { + stmt, err := r.db.Prepare(` + insert into user (id, email, password, first_name, last_name, created_at) + values(?,?,?,?,?,?)`) + if err != nil { + return e.ID, err + } + _, err = stmt.Exec( + e.ID, + e.Email, + e.Password, + e.FirstName, + e.LastName, + time.Now().Format("2006-01-02"), + ) + if err != nil { + return e.ID, err + } + err = stmt.Close() + if err != nil { + return e.ID, err + } + return e.ID, nil +} + +//Get an user +func (r *MySQLRepo) Get(id entity.ID) (*User, error) { + return nil, nil +} + +//Update an user +func (r *MySQLRepo) Update(e *User) error { + return nil +} + +//Search users +func (r *MySQLRepo) Search(query string) ([]*User, error) { + + return nil, nil +} + +//List users +func (r *MySQLRepo) List() ([]*User, error) { + return nil, nil +} + +//Delete an user +func (r *MySQLRepo) Delete(id entity.ID) error { + return nil +} diff --git a/go.mod b/go.mod index 977b9e8..8f0dbee 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,17 @@ module github.com/eminetto/clean-architecture-go-v2 go 1.14 require ( + github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 + github.com/codegangsta/negroni v0.3.0 + github.com/eminetto/clean-architecture-go v0.0.0-20200312132632-3195811c74a3 + github.com/go-sql-driver/mysql v1.5.0 github.com/golang/mock v1.4.3 github.com/google/uuid v1.1.1 + github.com/gorilla/context v1.1.1 + github.com/gorilla/mux v1.6.2 + github.com/jimlawless/whereami v0.0.0-20160417220522-aebf70d4a772 // indirect + github.com/juju/mgosession v0.0.0-20170206150231-9ae6df2882cd + github.com/prometheus/client_golang v1.7.1 github.com/stretchr/testify v1.6.1 + gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce ) diff --git a/go.sum b/go.sum index 5f4cff9..3bcae80 100644 --- a/go.sum +++ b/go.sum @@ -1,23 +1,156 @@ +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 h1:4daAzAu0S6Vi7/lbWECcX0j45yZReDZ56BQsrVBOEEY= +github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/codegangsta/negroni v0.3.0 h1:ByBtJaE0u71x6Ebli7lm95c8oCkrmF88+s5qB2o6j8I= +github.com/codegangsta/negroni v0.3.0/go.mod h1:v0y3T5G7Y1UlFfyxFn/QLRU4a2EuNau2iZY63YTKWo0= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/eminetto/clean-architecture-go v0.0.0-20200312132632-3195811c74a3 h1:uerlmMWPsHFzK6QCTF+oM/qv87nuzRk58kQY4kEMU/w= +github.com/eminetto/clean-architecture-go v0.0.0-20200312132632-3195811c74a3/go.mod h1:33aCgzY4kvuq1zAFCfOCEet320CsQTvKPxZarxoA9Sk= +github.com/eminetto/mongo-migrate v0.1.2/go.mod h1:KoptU07Q9QTDtVWnPiHnw8/nH6LZdBzBNXoc1P17qaI= +github.com/globalsign/mgo v0.0.0-20180615134936-113d3961e731/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= +github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/mock v1.4.3 h1:GV+pQPG/EUUbkh47niozDcADz6go/dUwhVzdUQHIVRw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +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= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8= +github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk= +github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/jimlawless/whereami v0.0.0-20160417220522-aebf70d4a772 h1:AmdJkqc+PNWRgFZH/W9W5HbSt5L42ZJaG3LBqIA8D/M= +github.com/jimlawless/whereami v0.0.0-20160417220522-aebf70d4a772/go.mod h1:O5/I95fNj2n4v8dVHc/XX/rv4i9P5AAr0koHbBkPnh8= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/juju/clock v0.0.0-20180808021310-bab88fc67299/go.mod h1:nD0vlnrUjcjJhqN5WuCWZyzfd5AHZAC9/ajvbSx69xA= +github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= +github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= +github.com/juju/mgosession v0.0.0-20170206150231-9ae6df2882cd h1:3CbO++xwtTRyLg90Lw/3fIspFJ5hBUGbqZmuPWriAY4= +github.com/juju/mgosession v0.0.0-20170206150231-9ae6df2882cd/go.mod h1:Mb/0uQn/QoTNyPST6tFobkamOA8qM+EPdeg2AcDbMAE= +github.com/juju/retry v0.0.0-20180821225755-9058e192b216/go.mod h1:OohPQGsr4pnxwD5YljhQ+TZnuVRYpa5irjugL1Yuif4= +github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= +github.com/juju/utils v0.0.0-20180424094159-2000ea4ff043 h1:kjdsJcIYzmK2k4X2yVCi5Nip6sGoAuc7CLbp+qQnQUM= +github.com/juju/utils v0.0.0-20180424094159-2000ea4ff043/go.mod h1:6/KLg8Wz/y2KVGWEpkK9vMNGkOnu4k/cqs8Z1fKjTOk= +github.com/juju/version v0.0.0-20180108022336-b64dbd566305/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.5.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= +github.com/prometheus/client_golang v1.7.1 h1:NTGy1Ja9pByO+xAeH/qiWnLrKtr3hJPNjaVUwnjpdpA= +github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= +github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc= +github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= +github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8= +github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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= golang.org/x/tools v0.0.0-20190425150028-36563e24a262 h1:qsl9y/CJx34tuA7QCPNp86JNJe4spst6Ff8MjvPUdPg= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU= +gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= +gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637 h1:yiW+nvdHb9LVqSHQBXfZCieqV4fzYhNBql77zY0ykqs= +gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637/go.mod h1:BHsqpu/nsuzkT5BpiH1EMZPLyqSMM8JbIavyFACoFNk= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= diff --git a/infra/init.sql b/infra/init.sql new file mode 100644 index 0000000..ab2ec94 --- /dev/null +++ b/infra/init.sql @@ -0,0 +1,5 @@ +create database if not exists clean_architecture_go_v2; +use clean_architecture_go_v2; +create table if not exists user (id varchar(50),email varchar(255),password varchar(255),first_name varchar(100), last_name varchar(100), created_at datetime, updated_at datetime, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; +create table if not exists book (id varchar(50),title varchar(255),author varchar(255), pages integer,quantity integer, created_at datetime, updated_at datetime, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; +create table if not exists book_user (user_id varchar(50),book_id varchar(50), created_at datetime, PRIMARY KEY (`user_id`,`book_id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; \ No newline at end of file