44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
|
package server_web
|
||
|
|
||
|
import (
|
||
|
"cake_crm/internal/models/storage"
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"github.com/go-pkgz/routegroup"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
type server struct {
|
||
|
storage storage.IStorage
|
||
|
port int
|
||
|
}
|
||
|
|
||
|
func NewServer(
|
||
|
storage storage.IStorage,
|
||
|
port int,
|
||
|
) IServer {
|
||
|
return &server{
|
||
|
storage: storage,
|
||
|
port: port,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (s *server) Run(ctx context.Context) error {
|
||
|
router := routegroup.New(http.NewServeMux())
|
||
|
router.HandleFunc("GET /products", s.getAllProductsHandler)
|
||
|
router.HandleFunc("GET /products/:id", s.getProductById)
|
||
|
router.HandleFunc("GET /category/:id/breadcrumbs", s.getBreadcrumbsByCategoryId)
|
||
|
return http.ListenAndServe(fmt.Sprintf(":%d", s.port), router)
|
||
|
}
|
||
|
|
||
|
func (s *server) Stop(ctx context.Context) error {
|
||
|
//TODO implement me
|
||
|
panic("implement me")
|
||
|
}
|
||
|
|
||
|
func (s *server) getAllProductsHandler(w http.ResponseWriter, r *http.Request) {}
|
||
|
|
||
|
func (s *server) getProductById(w http.ResponseWriter, r *http.Request) {}
|
||
|
|
||
|
func (s *server) getBreadcrumbsByCategoryId(w http.ResponseWriter, r *http.Request) {}
|