Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dwarvesf/template-go
Browse files Browse the repository at this point in the history
* 'master' of github.com:dwarvesf/template-go:
  move implement of a service from pg to service (#1)
  • Loading branch information
huygn committed Aug 15, 2018
2 parents a7c6165 + 5837594 commit 1afca9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion template/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
14 changes: 6 additions & 8 deletions template/postgres/add.go → template/service/add/pg.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 1afca9e

Please sign in to comment.