-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kuma-cp): intOrString as decimal in the API
Signed-off-by: Jakub Dyszkiewicz <jakub.dyszkiewicz@gmail.com>
- Loading branch information
1 parent
9768528
commit f286b0e
Showing
27 changed files
with
409 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/shopspring/decimal" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
) | ||
|
||
func NewDecimalFromIntOrString(intOrString intstr.IntOrString) (decimal.Decimal, error) { | ||
switch intOrString.Type { | ||
case intstr.Int: | ||
return decimal.NewFromInt(int64(intOrString.IntVal)), nil | ||
case intstr.String: | ||
return decimal.NewFromString(intOrString.String()) | ||
default: | ||
return decimal.Zero, errors.New("invalid IntOrString") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.