diff --git a/template/cmd/server/main.go b/template/cmd/server/main.go index f3f908a..7fb26ba 100644 --- a/template/cmd/server/main.go +++ b/template/cmd/server/main.go @@ -43,7 +43,7 @@ func main() { { s = service.Service{ AddService: middlewares.Compose( - postgres.NewAddStore(pgdb), + add.NewPGStore(pgdb), add.LoggingMiddleware(logger), add.ValidationMiddleware(), ).(add.Service), diff --git a/template/postgres/add.go b/template/service/add/pg.go similarity index 51% rename from template/postgres/add.go rename to template/service/add/pg.go index 33a0650..fc1c260 100644 --- a/template/postgres/add.go +++ b/template/service/add/pg.go @@ -1,26 +1,24 @@ -package postgres +package add import ( "context" "github.com/jinzhu/gorm" - - "<%= domainDir + _.folderName %>/service/add" ) -type addStore struct { +type pgStore struct { db *gorm.DB } -// NewAddStore ... -func NewAddStore(db *gorm.DB) *addStore { - return &addStore{ +// NewPGStore create new project store +func NewPGStore(db *gorm.DB) Service { + return &pgStore{ db: db, } } // Add just do a plus with 2 vars (X+Y) for the sake of demonstration, in reallity // you would want to execute a DB query/transaction here -func (s *addStore) Add(ctx context.Context, arg *add.Add) (int, error) { +func (s *pgStore) Add(ctx context.Context, arg *Add) (int, error) { return arg.X + arg.Y, nil }