forked from ebhomengo/niki
39 lines
972 B
Go
39 lines
972 B
Go
package driverapp
|
|
|
|
import (
|
|
"git.gocasts.ir/ebhomengo/niki/adapter/account"
|
|
"git.gocasts.ir/ebhomengo/niki/driverapp/delivery/http"
|
|
"git.gocasts.ir/ebhomengo/niki/driverapp/service"
|
|
"git.gocasts.ir/ebhomengo/niki/pkg/http_server"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type Application struct {
|
|
svc service.Service
|
|
accountClient account.Client
|
|
handler http.Handler
|
|
httpServer http.Server
|
|
config Config
|
|
}
|
|
|
|
func Setup(config Config, conn *grpc.ClientConn) Application {
|
|
driverValidator := service.NewValidator()
|
|
accountClient := account.New(conn)
|
|
driverSvc := service.NewService(config.DriverSvc, accountClient, driverValidator)
|
|
driverHandler := http.NewHandler(driverSvc)
|
|
|
|
httpServer := http_server.NewServer(config.HttpServer)
|
|
|
|
return Application{
|
|
svc: driverSvc,
|
|
handler: driverHandler,
|
|
httpServer: http.New(httpServer, driverHandler),
|
|
config: config,
|
|
}
|
|
|
|
}
|
|
|
|
func (app Application) Start() {
|
|
app.httpServer.Serve()
|
|
}
|