Skip to content

Commit

Permalink
wip: update echo server
Browse files Browse the repository at this point in the history
  • Loading branch information
mimani68 committed Apr 3, 2023
1 parent b857630 commit a18e2dc
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ import (
"os/signal"
"syscall"

"github.com/aws/aws-sdk-go/service/account"
"github.com/cloudflare/cfssl/transport/roots/system"
"github.com/labstack/echo"
"github.com/mimani68/fintech-core/config"
"github.com/mimani68/fintech-core/data/datasource"
"github.com/mimani68/fintech-core/transport/http/echo"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"gorm.io/driver/mysql"
)

var serveCMD = &cli.Command{
Expand All @@ -26,30 +22,9 @@ var serveCMD = &cli.Command{
func serve(c *cli.Context) error {
cfg := config.NewConfig()

f, err := os.OpenFile("logs/app.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
fmt.Println(err.Error())
return err
}

logger := zap.New(f, zapcore.ErrorLevel)

mysqlRepo, err := mysql.New(cfg.Mysql, logger)
if err != nil {
fmt.Println(err.Error())
return err
}

accSrv := account.New(cfg.Account, mysqlRepo, logger)
systemSrv := system.New(cfg.Account, mysqlRepo, logger)
invitationSrv := invitation.New(cfg.Account, mysqlRepo, logger)
db := datasource.NewSqliteDataSource("sample.db")

restServer := echo.New(logger, accSrv, systemSrv, invitationSrv)
go func() {
if err := restServer.Start(cfg.App.Address); err != nil {
logger.Error(fmt.Sprintf("error happen while serving: %v", err))
}
}()
restServer := echo.NewEchoApp(db, cfg)

signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
Expand Down

0 comments on commit a18e2dc

Please sign in to comment.