forked from ebhomengo/niki
Changed struct
This commit is contained in:
parent
6c48741646
commit
6c96b349ab
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
paymentapp "git.gocasts.ir/ebhomengo/niki/domain/payment"
|
paymentapp "git.gocasts.ir/ebhomengo/niki/paymentapp"
|
||||||
"git.gocasts.ir/ebhomengo/niki/pkg/database"
|
"git.gocasts.ir/ebhomengo/niki/pkg/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/domain/payment/service"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Handler struct {
|
|
||||||
service *service.PaymentService
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewHandler(service *service.PaymentService) *Handler {
|
|
||||||
return &Handler{
|
|
||||||
service: service,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Handler) HealthCheck(c echo.Context) error {
|
|
||||||
return c.String(200, "HealthCheck is ok")
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
httpserver "git.gocasts.ir/ebhomengo/niki/pkg/http_server"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Server struct {
|
|
||||||
httpServer httpserver.Server
|
|
||||||
handler *Handler
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewServer(httpServer httpserver.Server, handler *Handler) *Server {
|
|
||||||
return &Server{
|
|
||||||
httpServer: httpServer,
|
|
||||||
handler: handler,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) Serve() error {
|
|
||||||
s.registerRoutes()
|
|
||||||
return s.httpServer.Start()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) Stop(ctx context.Context) error {
|
|
||||||
return s.httpServer.Stop(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) registerRoutes() {
|
|
||||||
paymentGroup := s.httpServer.Router.Group("/payment")
|
|
||||||
|
|
||||||
paymentGroup.GET("/health", s.handler.HealthCheck)
|
|
||||||
}
|
|
||||||
|
|
@ -3,27 +3,23 @@ package paymentapp
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
paymenthttp "git.gocasts.ir/ebhomengo/niki/domain/payment/delivery/http"
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/pkg/database"
|
"git.gocasts.ir/ebhomengo/niki/pkg/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
server *paymenthttp.Server
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup(ctx context.Context, cfg Config, conn *database.Database) (*App, error) {
|
func Setup(ctx context.Context, cfg Config, conn *database.Database) (*App, error) {
|
||||||
|
|
||||||
//TODO Setup
|
//TODO Setup
|
||||||
|
|
||||||
return &App{
|
return &App{}, nil
|
||||||
server: nil,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Start() error {
|
func (a *App) Start() error {
|
||||||
return a.server.Serve()
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) Stop(ctx context.Context) error {
|
func (a *App) Stop(ctx context.Context) error {
|
||||||
return a.server.Stop(ctx)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +1,5 @@
|
||||||
package paymentapp
|
package paymentapp
|
||||||
|
|
||||||
type HTTPConfig struct {
|
|
||||||
Addr string `yaml:"addr" json:"addr"`
|
|
||||||
Port int
|
|
||||||
ReadTimeout int `yaml:"read_timeout" json:"read_timeout"`
|
|
||||||
WriteTimeout int `yaml:"write_timeout" json:"write_timeout"`
|
|
||||||
IdleTimeout int `yaml:"idle_timeout" json:"idle_timeout"`
|
|
||||||
AllowOrigins []string
|
|
||||||
}
|
|
||||||
type PostgresConfig struct {
|
type PostgresConfig struct {
|
||||||
Host string `yaml:"host"`
|
Host string `yaml:"host"`
|
||||||
Port int `yaml:"port"`
|
Port int `yaml:"port"`
|
||||||
|
|
@ -27,7 +19,6 @@ type LoggerConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
HTTP HTTPConfig `yaml:"http" json:"http"`
|
|
||||||
Postgres PostgresConfig `yaml:"postgres" json:"postgres"`
|
Postgres PostgresConfig `yaml:"postgres" json:"postgres"`
|
||||||
Logger LoggerConfig `yaml:"logger" json:"logger"`
|
Logger LoggerConfig `yaml:"logger" json:"logger"`
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue