Skip to content

Commit

Permalink
flags
Browse files Browse the repository at this point in the history
  • Loading branch information
tolgaOzen committed Jul 3, 2021
1 parent 0905c2f commit 5804f28
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 30 deletions.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,44 @@ You can start using this repository by cloning it.
git clone https://github.com/tolgaOzen/go-gotham
```

## FOLDER STRUCTURE
## Env
change with your database credentials

```dotenv
#DB
DB_CONNECTION=mysql
DB_USERNAME=admin
DB_DATABASE=gotham
DB_HOST=gotham-test
DB_PORT=3306
DB_PASSWORD=strong_password
```

## Flags

- prevents re-creating container methods from definitions
```
go run gotham -production
```

- run migrate methods of repositories before start
```
go run gotham -migrate
```

- run seed methods of repositories before start
```
go run gotham -seed
```

## FOLDER STRUCTURE

```
/
|- app
|- container
|- defs
|- flags
|- provider
app.go
|- config
Expand All @@ -41,8 +71,10 @@ git clone https://github.com/tolgaOzen/go-gotham
|- mails
|- middlewares
|- models
|- scopes
|- policies
|- repositories
|- transactions
|- requests
|- routers
|- rules
Expand Down
18 changes: 17 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package app

import (
`fmt`
"github.com/sarulabs/di/v2"
"gotham/app/container/dic"
`github.com/sarulabs/dingo/v4`
"log"
`os`

"gotham/app/container/dic"
`gotham/app/flags`
"gotham/app/provider"
)

var Application *App
Expand All @@ -12,6 +18,16 @@ type App struct {
Container *dic.Container
}

func init() {
if !*flags.Production {
err := dingo.GenerateContainer((*provider.Provider)(nil), "./app/container")
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}
}

/**
* New
*
Expand Down
18 changes: 18 additions & 0 deletions app/flags/base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package flags

import (
`flag`
)

var (
Production *bool
Migrate *bool
Seed *bool
)

func init() {
Production = flag.Bool("production", false, "a bool")
Migrate = flag.Bool("migrate", false, "a bool")
Seed = flag.Bool("seed", false, "a bool")
flag.Parse()
}
5 changes: 4 additions & 1 deletion database/migrations/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package migrations

import (
"gotham/app"
`gotham/app/flags`
)

func Initialize() {
_ = app.Application.Container.GetUserRepository().Migrate()
if *flags.Migrate {
_ = app.Application.Container.GetUserRepository().Migrate()
}
}
10 changes: 7 additions & 3 deletions database/seeds/base.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package seeds

import "gotham/app"
import (
`gotham/app`
`gotham/app/flags`
)

func Initialize() {
_ = app.Application.Container.GetUserRepository().Seed()
if *flags.Seed {
_ = app.Application.Container.GetUserRepository().Seed()
}
}

32 changes: 8 additions & 24 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,20 @@
package main

import (
"flag"
"fmt"
"github.com/labstack/echo/v4"
"github.com/sarulabs/dingo/v4"
"gotham/app"
provider "gotham/app/provider"
"gotham/config"
"gotham/routers"
"os"
)

func init() {
production := flag.Bool("production", false, "a bool")
flag.Parse()
if !*production {
err := dingo.GenerateContainer((*provider.Provider)(nil), "./app/container")
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}
}
`gotham/app`
`gotham/config`
`gotham/database/migrations`
`gotham/database/seeds`
`gotham/routers`
)

func main() {
config.Configurations()
app.New()
defer app.Application.Container.Delete()

//migrations.Initialize()
//seeds.Initialize()

migrations.Initialize()
seeds.Initialize()
routers.Route(echo.New())
}

0 comments on commit 5804f28

Please sign in to comment.