http server

This commit is contained in:
nquidox 2025-10-25 17:41:19 +03:00
parent a995f4c75a
commit efd0924c60
2 changed files with 35 additions and 4 deletions

View file

@ -2,32 +2,49 @@ package app
import (
"context"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"imageStorage/config"
"net"
"net/http"
"time"
)
type App struct {
config *config.Config
grpcServer *grpc.Server
config *config.Config
grpcServer *grpc.Server
httpServer *gin.Engine
httpServerAddr string
}
type Deps struct {
Config *config.Config
GrpcServer *grpc.Server
HttpServer *gin.Engine
}
func NewApp(deps Deps) *App {
return &App{
config: deps.Config,
grpcServer: deps.GrpcServer,
httpServer: deps.HttpServer,
}
}
func (app *App) Start(ctx context.Context) error {
serverErr := make(chan error, 1)
addr := app.config.App.Host + ":" + app.config.App.HttpPort
server := &http.Server{
Handler: app.httpServer,
Addr: addr,
}
go func() {
log.Info("Starting server on: ", addr)
serverErr <- server.ListenAndServe()
}()
endpoint := net.JoinHostPort(app.config.App.Host, app.config.App.GrpcPort)
go func() {
listener, err := net.Listen("tcp", endpoint)