micw/server/server.go

45 lines
836 B
Go
Raw Permalink Normal View History

2024-11-13 21:10:13 +00:00
package server
import (
"context"
commonUtils "git.mic.pp.ua/anderson/nettools/common"
"github.com/jackc/pgx/v5/pgxpool"
"mic-wallet/server/config"
"mic-wallet/server/repository"
"net"
"net/http"
)
type Server struct {
Cfg *config.Processed
DB *pgxpool.Pool
HttpListener net.Listener
HttpsListener net.Listener
GrpcListener net.Listener
Mux *http.ServeMux
Repo *repository.Repository
}
func New(cfg *config.Processed) *Server {
return &Server{Cfg: cfg}
}
func (s *Server) execTasks(ctx context.Context, tasks []commonUtils.Task) error {
errChan := make(chan error)
for _, task := range tasks {
go func() {
errChan <- task(ctx)
}()
}
for {
select {
case err := <-errChan:
if err != nil {
return err
}
case <-ctx.Done():
return ctx.Err()
}
}
}