fork
Configure Feed
Select the types of activity you want to include in your feed.
this repo has no description
fork
Configure Feed
Select the types of activity you want to include in your feed.
1package web
2
3import (
4 "context"
5 "net"
6 "net/http"
7 "time"
8
9 "github.com/Tulkdan/payment-gateway/internal/service"
10 "github.com/Tulkdan/payment-gateway/internal/web/handler"
11 "github.com/Tulkdan/payment-gateway/internal/web/middleware"
12 "go.uber.org/zap"
13)
14
15type Server struct {
16 port string
17 router *http.ServeMux
18 server *http.Server
19 logger *zap.Logger
20
21 paymentsService *service.PaymentService
22}
23
24func NewServer(paymentsService *service.PaymentService, port string, logger *zap.Logger) *Server {
25 return &Server{
26 port: port,
27 paymentsService: paymentsService,
28 logger: logger,
29 }
30}
31
32func (s *Server) ConfigureRouter() {
33 mux := http.NewServeMux()
34
35 paymentsHandler := handler.NewPaymentsHandler(s.paymentsService, s.logger)
36
37 mux.HandleFunc("POST /payments", middleware.WithRequestId(paymentsHandler.Create))
38 // r.HandleFunc("POST /refunds", func(http.ResponseWriter, *http.Request) {})
39 // r.HandleFunc("GET /payments/{id}", func(w http.ResponseWriter, r *http.Request) {
40 // id := r.PathValue("id")
41 // })
42
43 s.router = mux
44}
45
46func (s *Server) Start(ctx context.Context) error {
47 s.server = &http.Server{
48 Addr: ":" + s.port,
49 Handler: s.router,
50 BaseContext: func(_ net.Listener) context.Context { return ctx },
51 ReadTimeout: time.Second,
52 WriteTimeout: 10 * time.Second,
53 }
54
55 return s.server.ListenAndServe()
56}
57
58func (s *Server) Shutdown() error {
59 return s.server.Shutdown(context.Background())
60}