Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mirzaakhena committed Jan 16, 2023
1 parent db1486f commit 56f799b
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 105 deletions.
6 changes: 6 additions & 0 deletions command/genapplication/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Gogen Application

Call `gogen application myapp` will

* create a folder and file application
* binding all together the controller usecase and gateway
7 changes: 7 additions & 0 deletions command/gencontroller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Gogen Controller

Call `gogen controller restapi` will

* Create a controller folder
* Collect all the fields from InportRequest and InportResponse
* create an handler and router based on gogenrc
20 changes: 20 additions & 0 deletions command/gendomain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Gogen Domain

Calling `gogen domain yourdomainname` will

* Provide all those files

```
├── Dockerfile
├── README.md
├── config.json
├── config.sample.json
├── docker-compose.yml
├── domain_yourdomainname
│ └── README.md
├── go.mod
└── gitignore
```

* Generate unique random secret key for your application in `config.json`
* Copy the basic template for controller, gateway and crud
100 changes: 0 additions & 100 deletions command/gendomain/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,103 +92,3 @@ func Run(inputs ...string) error {
return nil

}

//func insertNewDomainName(filePath, domainName string) error {
//
// f, err := os.Open(filePath)
// if err != nil {
// return err
// }
// defer func(f *os.File) {
// err := f.Close()
// if err != nil {
//
// }
// }(f)
//
// isEmptyFile := true
//
// fileContent := ""
// scanner := bufio.NewScanner(f)
// for scanner.Scan() {
//
// line := strings.TrimSpace(scanner.Text())
//
// if line == "" {
// continue
// }
//
// isEmptyFile = false
//
// x := line
// if strings.HasPrefix(line, "-") {
// x = line[1:]
// }
//
// if x == domainName {
// return fmt.Errorf("domain name already exist")
// }
//
// fileContent += line
// fileContent += "\n"
// }
// if err := scanner.Err(); err != nil {
// return err
// }
//
// if isEmptyFile {
// fileContent += fmt.Sprintf("-%s", domainName)
// } else {
// fileContent += domainName
// }
//
// fileContent += "\n"
//
// return os.WriteFile(filePath, []byte(fileContent), 0644)
//}
//
//func Rewrite(srcDir, destDir string) {
//
// // Walk through the source directory and copy each file and subdirectory to the destination directory
// err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
// if err != nil {
// fmt.Println(err)
// return err
// }
//
// // Construct the destination path by replacing the source directory with the destination directory
// destPath := filepath.Join(destDir, path[len(srcDir):])
//
// // If the current path is a directory, create it in the destination directory
// if info.IsDir() {
// os.MkdirAll(destPath, info.Mode())
// return nil
// }
//
// // If the current path is a file, copy it to the destination directory
// srcFile, err := os.Open(path)
// if err != nil {
// fmt.Println(err)
// return err
// }
// defer srcFile.Close()
//
// destFile, err := os.Create(destPath)
// if err != nil {
// fmt.Println(err)
// return err
// }
// defer destFile.Close()
//
// _, err = io.Copy(destFile, srcFile)
// if err != nil {
// fmt.Println(err)
// return err
// }
//
// return nil
// })
// if err != nil {
// return
// }
//}
6 changes: 6 additions & 0 deletions command/gengateway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Gogen Gateway

* Read the Outport and collect all must have method
* Read the existing Gateway and collect all existing method
* Create a gateway folder and file then
* Create all non-existing must have method on Gateway based on gogenrc
4 changes: 2 additions & 2 deletions command/genopenapi/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/mirzaakhena/gogen/utils"
"io/ioutil"
"os"
)

// ObjTemplate ...
Expand Down Expand Up @@ -244,7 +244,7 @@ func Run(inputs ...string) error {
return err
}

err = ioutil.WriteFile(fmt.Sprintf("domain_%s/openapi.json", domainName), file, 0644)
err = os.WriteFile(fmt.Sprintf("domain_%s/openapi.json", domainName), file, 0644)
if err != nil {
return err
}
Expand Down
55 changes: 55 additions & 0 deletions command/genrepository/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Gogen Repository

Call `gogen repository SaveOrder Order RunOrderCreate` will

* Create an entity Order (if not exist)
```
└── domain_yourdomainname
└── model
├── entity
│ └── order.go
└── vo
└── order_id.go
```

* Create repository SaveOrderRepo (if not exist)
```
└── domain_yourdomainname
└── model
└── repository
└── repository.go
```

* Inject code into Outport
```
type Outport interface {
repository.SaveOrderRepo
}
```

* Inject code into Interactor. It will replace the `//!` flag
```
func (r *runOrderCreateInteractor) Execute(ctx context.Context, req InportRequest) (*InportResponse, error) {
res := &InportResponse{}
// code your usecase definition here ...
orderObj, err := entity.NewOrder(entity.OrderCreateRequest{})
if err != nil {
return nil, err
}
err = r.outport.SaveOrder(ctx, orderObj)
if err != nil {
return nil, err
}
//!
return res, nil
}
```



42 changes: 42 additions & 0 deletions command/genservice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Gogen Service

Call `gogen service PublishOrder RunOrderCreate` will

* Create service `PublishOrderService` (if not exist)
```
└── domain_yourdomainname
└── model
└── service
└── service.go
```

* Inject code into Outport
```
type Outport interface {
service.PublishOrderService
}
```

* Inject code into Interactor. It will replace the `//!` flag
```
func (r *runOrderCreateInteractor) Execute(ctx context.Context, req InportRequest) (*InportResponse, error) {
res := &InportResponse{}
// code your usecase definition here ...
publishOrderResponse, err := r.outport.PublishOrder(ctx, service.PublishOrderServiceRequest{})
if err != nil {
return nil, err
}
_ = publishOrderResponse
//!
return res, nil
}
```



44 changes: 44 additions & 0 deletions command/genusecase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Gogen Usecase

Call `gogen usecase RunProductCreate` will

* Create file Inport, Interactor and Outport

```
└── domain_yourdomainname
└── usecase
└── runordercreate
├── README.md
├── inport.go
├── interactor.go
└── outport.go
```

* There are specialization for Inport.

if using prefix `GetAll` then InportRequest and InportResponse will have
```go
type InportRequest struct {
Page int
Size int
}

type InportResponse struct {
Count int64
Items []any
}
```
otherwise it will be empty
```go
type InportRequest struct {

}

type InportResponse struct {

}
```




Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (r *controller) authentication() gin.HandlerFunc {
}
}

func (r *ginController) authorization() gin.HandlerFunc {
func (r *controller) authorization() gin.HandlerFunc {

return func(c *gin.Context) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package {{LowerCase .UsecaseName}}

import (
"context"
"{{.PackagePath}}/shared/gogen"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package {{LowerCase .UsecaseName}}

import (
"context"
"{{.PackagePath}}/shared/gogen"
)

type Inport = gogen.Inport[InportRequest, InportResponse]
Expand Down

0 comments on commit 56f799b

Please sign in to comment.