github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/model/v1beta1/millicores.go (about)

     1  package v1beta1
     2  
     3  import "fmt"
     4  
     5  // A Millicore represents a thousandth of a CPU core, which is a unit of measure
     6  // used by Kubernetes. See also https://github.com/BTBurke/k8sresource.
     7  type Millicores int
     8  
     9  const (
    10  	Millicore Millicores = 1
    11  	Core      Millicores = 1000
    12  )
    13  
    14  const suffix string = "m"
    15  
    16  // String returns a string representation of this Millicore, which is either an
    17  // integer if this Millicore represents a whole number of cores or the number of
    18  // Millicores suffixed with "m".
    19  func (m Millicores) String() string {
    20  	if m%Core == 0 {
    21  		return fmt.Sprintf("%d", m/Core)
    22  	} else {
    23  		return fmt.Sprintf("%d%s", m, suffix)
    24  	}
    25  }