0

I have to run tx.exec() inside a groutine, but it always return pq: bad conenction and pq: unexpected Parse response 'D'

This is the example of my code:

func (uc OdooUseCase) SynchronizeTourPackage(tourPackageID, partnerID string, odooPackageID int64) (err error) {
    var wg sync.WaitGroup

    odooUc := OdooUseCase{UcContract: uc.UcContract}
    odooDB, err := odooUc.BuildConnection(partnerID)
    if err != nil {
        logruslogger.Log(logruslogger.WarnLevel, err.Error(), functioncaller.PrintFuncName(), "odoo-build-connection")
        return err
    }
    defer odooDB.Close()

    tourPackagePriceUseCase := TourPackagePriceUseCase{UcContract: uc.UcContract, odooDB: odooDB}
    tourPackageMealUseCase := TourPackageMealUseCase{UcContract: uc.UcContract, odooDB: odooDB}

    errs := make(chan error)

    wg.Add(1)
    go func() {
        wg.Wait()
        close(errs)
    }()

    wg.Add(1)
    go func() {
        err := tourPackagePriceUseCase.SaveFromOdoo(tourPackageID, partnerID, odooPackageID)
        if err != nil {
            logruslogger.Log(logruslogger.WarnLevel, err.Error(), functioncaller.PrintFuncName(), "save-tour-package-price", uc.ReqID)
            errs <- err
        }
        defer wg.Done()
    }()

    wg.Add(1)
    go func() {
        err := tourPackageMealUseCase.SaveFromOdoo(tourPackageID, partnerID, odooPackageID)
        if err != nil {
            logruslogger.Log(logruslogger.WarnLevel, err.Error(), functioncaller.PrintFuncName(), "save-tour-package-meal", uc.ReqID)
            errs <- err
        }
        defer wg.Done()
    }()

    err = <-errs

    return err
}

i need to run an tx.exec inside the go routine, because this function is synchronize from another database. please anyone could help me? Thanks

0 Answers0