Refactoring of the default values

This commit is contained in:
Eric Coissac
2025-01-24 18:09:59 +01:00
parent 3137c1f841
commit 9acb4a85a8
50 changed files with 337 additions and 166 deletions

View File

@ -1,9 +1,8 @@
package obiutils_test
import (
"testing"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiutils"
"testing"
)
func TestAbs(t *testing.T) {

View File

@ -2,6 +2,7 @@ package obiutils
import (
"path"
"path/filepath"
"strings"
)
@ -21,3 +22,16 @@ func RemoveAllExt(p string) string {
return p
}
func Basename(path string) string {
filename := filepath.Base(path)
ext := filepath.Ext(filename)
// Keep removing extensions until there are no more
for ext != "" {
filename = strings.TrimSuffix(filename, ext)
ext = filepath.Ext(filename)
}
return filename
}

40
pkg/obiutils/pipe.go Normal file
View File

@ -0,0 +1,40 @@
package obiutils
import (
"sync"
log "github.com/sirupsen/logrus"
)
var globalLocker sync.WaitGroup
var globalLockerCounter = 0
// RegisterAPipe increments the global lock counter and adds a new pipe to the global wait group.
//
// No parameters.
// No return values.
func RegisterAPipe() {
globalLocker.Add(1)
globalLockerCounter++
log.Debugln(globalLockerCounter, " Pipes are registered now")
}
// UnregisterPipe decrements the global lock counter and signals that a pipe has finished.
//
// No parameters.
// No return values.
func UnregisterPipe() {
globalLocker.Done()
globalLockerCounter--
log.Debugln(globalLockerCounter, "are still registered")
}
// WaitForLastPipe waits until all registered pipes have finished.
//
// THe function have to be called at the end of every main function.
//
// No parameters.
// No return values.
func WaitForLastPipe() {
globalLocker.Wait()
}