45 lines
836 B
Go
45 lines
836 B
Go
|
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()
|
||
|
}
|
||
|
}
|
||
|
}
|