mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
36 lines
582 B
Go
36 lines
582 B
Go
package utils
|
|
|
|
import (
|
|
"errors"
|
|
"path/filepath"
|
|
"runtime"
|
|
)
|
|
|
|
const (
|
|
defaultTLSDir = "tls"
|
|
)
|
|
|
|
// Util vars
|
|
var (
|
|
ErrGoMaxProcsFailure = errors.New("failed to set GOMAXPROCS")
|
|
)
|
|
|
|
// AdjustGoMaxProcs sets the runtime GOMAXPROCS val
|
|
func AdjustGoMaxProcs(maxProcs int) error {
|
|
n := runtime.NumCPU()
|
|
if maxProcs < 0 || maxProcs > n {
|
|
maxProcs = n
|
|
}
|
|
|
|
if i := runtime.GOMAXPROCS(maxProcs); i != maxProcs {
|
|
return ErrGoMaxProcsFailure
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// GetTLSDir returns the default TLS dir
|
|
func GetTLSDir(dir string) string {
|
|
return filepath.Join(dir, defaultTLSDir)
|
|
}
|