forked from hairyhenderson/gomplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added some duration cel funcs with tests (#12)
* feat: added some duration cel funcs with tests * chore: lint fixes * feat: load other extensions * chore: bumped cel-go and added more extensions
- Loading branch information
1 parent
b1c2122
commit 19f81d0
Showing
11 changed files
with
105 additions
and
126 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,42 @@ | ||
// Code generated by gencel. DO NOT EDIT. | ||
|
||
package strings | ||
|
||
import "github.com/google/cel-go/cel" | ||
import "github.com/google/cel-go/common/types" | ||
import "github.com/google/cel-go/common/types/ref" | ||
|
||
var durationStringGen = cel.Function("duration.String", | ||
cel.Overload("duration.String_", | ||
nil, | ||
cel.StringType, | ||
cel.FunctionBinding(func(args ...ref.Val) ref.Val { | ||
|
||
var x Duration | ||
|
||
return types.DefaultTypeAdapter.NativeToValue(x.String()) | ||
|
||
}), | ||
), | ||
import ( | ||
"github.com/google/cel-go/cel" | ||
"github.com/google/cel-go/common/types" | ||
"github.com/google/cel-go/common/types/ref" | ||
) | ||
|
||
var durationNanosecondsGen = cel.Function("duration.Nanoseconds", | ||
cel.Overload("duration.Nanoseconds_", | ||
nil, | ||
cel.IntType, | ||
cel.FunctionBinding(func(args ...ref.Val) ref.Val { | ||
|
||
var x Duration | ||
|
||
return types.DefaultTypeAdapter.NativeToValue(x.Nanoseconds()) | ||
|
||
// var durationHumanize = cel.Function("HumanDuration", | ||
// cel.Overload("duration.HumanDuration", | ||
// []*cel.Type{cel.DynType}, | ||
// cel.StringType, | ||
// cel.UnaryBinding(func(value ref.Val) ref.Val { | ||
// return types.String(HumanDuration(value.Value())) | ||
// }), | ||
// ), | ||
// ) | ||
|
||
var durationAgeGen = cel.Function("Age", | ||
cel.Overload("duration.Age", | ||
[]*cel.Type{cel.StringType}, | ||
cel.DurationType, | ||
cel.UnaryBinding(func(value ref.Val) ref.Val { | ||
a := Age(value.Value().(string)) | ||
return types.Duration{Duration: a} | ||
}), | ||
), | ||
) | ||
|
||
var durationSecondsGen = cel.Function("duration.Seconds", | ||
cel.Overload("duration.Seconds_", | ||
nil, | ||
cel.DoubleType, | ||
cel.FunctionBinding(func(args ...ref.Val) ref.Val { | ||
|
||
var x Duration | ||
|
||
return types.DefaultTypeAdapter.NativeToValue(x.Seconds()) | ||
|
||
}), | ||
), | ||
) | ||
|
||
var durationHoursGen = cel.Function("duration.Hours", | ||
cel.Overload("duration.Hours_", | ||
nil, | ||
cel.DoubleType, | ||
cel.FunctionBinding(func(args ...ref.Val) ref.Val { | ||
|
||
var x Duration | ||
|
||
return types.DefaultTypeAdapter.NativeToValue(x.Hours()) | ||
|
||
}), | ||
), | ||
) | ||
|
||
var durationDaysGen = cel.Function("duration.Days", | ||
cel.Overload("duration.Days_", | ||
nil, | ||
cel.DoubleType, | ||
cel.FunctionBinding(func(args ...ref.Val) ref.Val { | ||
|
||
var x Duration | ||
|
||
return types.DefaultTypeAdapter.NativeToValue(x.Days()) | ||
|
||
}), | ||
), | ||
) | ||
|
||
var durationWeeksGen = cel.Function("duration.Weeks", | ||
cel.Overload("duration.Weeks_", | ||
nil, | ||
cel.DoubleType, | ||
cel.FunctionBinding(func(args ...ref.Val) ref.Val { | ||
|
||
var x Duration | ||
|
||
return types.DefaultTypeAdapter.NativeToValue(x.Weeks()) | ||
|
||
}), | ||
), | ||
) | ||
|
||
var durationMinutesGen = cel.Function("duration.Minutes", | ||
cel.Overload("duration.Minutes_", | ||
nil, | ||
cel.DoubleType, | ||
cel.FunctionBinding(func(args ...ref.Val) ref.Val { | ||
|
||
var x Duration | ||
|
||
return types.DefaultTypeAdapter.NativeToValue(x.Minutes()) | ||
|
||
var durationDurationGen = cel.Function("Duration", | ||
cel.Overload("duration.Duration", | ||
[]*cel.Type{cel.StringType}, | ||
cel.DurationType, | ||
cel.UnaryBinding(func(value ref.Val) ref.Val { | ||
a, err := ParseDuration(value.Value().(string)) | ||
if err != nil || a == nil { | ||
return types.Duration{} | ||
} | ||
return types.Duration{Duration: *a} | ||
}), | ||
), | ||
) |
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.