mirror of
https://github.com/caddyserver/caddy.git
synced 2026-08-31 07:46:42 +00:00
caddyhttp: Add time.now placeholder and update cel-go (closes #2594)
This commit is contained in:
parent
bb67e19d7b
commit
0cbf467b3f
4 changed files with 11 additions and 3 deletions
|
|
@ -21,10 +21,12 @@ import (
|
|||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
"github.com/google/cel-go/cel"
|
||||
"github.com/google/cel-go/checker/decls"
|
||||
"github.com/google/cel-go/common/types"
|
||||
|
|
@ -204,6 +206,9 @@ func (celTypeAdapter) NativeToValue(value interface{}) ref.Val {
|
|||
switch v := value.(type) {
|
||||
case celHTTPRequest:
|
||||
return v
|
||||
case time.Time:
|
||||
// TODO: eliminate direct protobuf dependency, sigh -- just wrap stdlib time.Time instead...
|
||||
return types.Timestamp{Timestamp: ×tamp.Timestamp{Seconds: v.Unix(), Nanos: int32(v.Nanosecond())}}
|
||||
case error:
|
||||
types.NewErr(v.Error())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue