types

package
v0.34.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: BSD-2-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CookieObjectType = cty.Object(map[string]cty.Type{
	"name":        cty.String,
	"value":       cty.String,
	"quoted":      cty.Bool,
	"path":        cty.String,
	"domain":      cty.String,
	"expires":     timecty.TimeCapsuleType,
	"raw_expires": cty.String,
	"max_age":     cty.Number,
	"secure":      cty.Bool,
	"http_only":   cty.Bool,
	"same_site":   cty.String,
	"partitioned": cty.Bool,
	"raw":         cty.String,
})

CookieObjectType is the static cty object type for cookie values.

View Source
var HTTPClientResponseCapsuleType = cty.CapsuleWithOps("httpclientresponse", reflect.TypeOf(HTTPClientResponseWrapper{}), &cty.CapsuleOps{
	GoString: func(val interface{}) string {
		w := val.(*HTTPClientResponseWrapper)
		if w.R == nil {
			return "httpclientresponse(<nil>)"
		}
		return fmt.Sprintf("httpclientresponse(%d %s)", w.R.StatusCode, w.R.Status)
	},
	TypeGoString: func(_ reflect.Type) string {
		return "httpclientresponse"
	},
})

HTTPClientResponseCapsuleType is the cty capsule type for HTTPClientResponseWrapper values.

View Source
var HTTPClientResponseObjectType = cty.Object(map[string]cty.Type{
	"status":         cty.Number,
	"status_text":    cty.String,
	"ok":             cty.Bool,
	"redirected":     cty.Bool,
	"final_url":      urlcty.URLObjectType,
	"proto":          cty.String,
	"content_length": cty.Number,
	"content_type":   cty.String,
	"body":           cty.DynamicPseudoType,
	"_capsule":       HTTPClientResponseCapsuleType,
})

HTTPClientResponseObjectType is the static cty object type returned by BuildHTTPClientResponseObject.

View Source
var HTTPRequestCapsuleType = cty.CapsuleWithOps("httprequest", reflect.TypeOf(HTTPRequestWrapper{}), &cty.CapsuleOps{
	GoString: func(val interface{}) string {
		w := val.(*HTTPRequestWrapper)
		return fmt.Sprintf("httprequest(%s %s)", w.R.Method, w.R.URL.String())
	},
	TypeGoString: func(_ reflect.Type) string {
		return "httprequest"
	},
})

HTTPRequestCapsuleType is the cty capsule type for HTTPRequestWrapper values.

View Source
var HTTPRequestObjectType = cty.Object(map[string]cty.Type{
	"method":       cty.String,
	"url":          urlcty.URLObjectType,
	"proto":        cty.String,
	"proto_major":  cty.Number,
	"proto_minor":  cty.Number,
	"host":         cty.String,
	"remote_addr":  cty.String,
	"user":         cty.String,
	"password":     cty.String,
	"password_set": cty.Bool,
	"path":         cty.Map(cty.String),
	"form":         cty.Map(cty.List(cty.String)),
	"_capsule":     HTTPRequestCapsuleType,
})

HTTPRequestObjectType is the static cty object type returned by BuildHTTPRequestObject.

View Source
var HTTPResponseCapsuleType = cty.CapsuleWithOps("httpresponse", reflect.TypeOf(HTTPResponseWrapper{}), &cty.CapsuleOps{
	GoString: func(val interface{}) string {
		r := val.(*HTTPResponseWrapper)
		return fmt.Sprintf("httpresponse(%d)", r.Status)
	},
	TypeGoString: func(_ reflect.Type) string {
		return "httpresponse"
	},
})

HTTPResponseCapsuleType is the cty capsule type for HTTPResponseWrapper values.

View Source
var HTTPResponseObjectType = cty.Object(map[string]cty.Type{
	"status":   cty.Number,
	"headers":  cty.Map(cty.List(cty.String)),
	"_capsule": HTTPResponseCapsuleType,
})

HTTPResponseObjectType is the static cty object type returned by BuildHTTPResponseObject.

View Source
var MetricCapsuleType = cty.CapsuleWithOps("metric", reflect.TypeOf((*any)(nil)).Elem(), &cty.CapsuleOps{
	GoString: func(val interface{}) string {
		return fmt.Sprintf("metric(%p)", val)
	},
	TypeGoString: func(_ reflect.Type) string {
		return "metric"
	},
})
View Source
var VariableCapsuleType = cty.CapsuleWithOps("variable", reflect.TypeOf((*Variable)(nil)).Elem(), &cty.CapsuleOps{
	GoString: func(val interface{}) string {
		return fmt.Sprintf("variable(%p)", val)
	},
	TypeGoString: func(_ reflect.Type) string {
		return "Variable"
	},
})

Functions

func BuildHTTPClientResponseObject added in v0.26.0

func BuildHTTPClientResponseObject(w *HTTPClientResponseWrapper) cty.Value

BuildHTTPClientResponseObject builds a cty object value with the materialized static attributes of a response, plus a _capsule attribute holding the wrapper for interface dispatch (richcty.Gettable, richcty.Stringable, richcty.Lengthable).

func BuildHTTPRequestObject added in v0.20.0

func BuildHTTPRequestObject(r *http.Request, pathParamNames []string) cty.Value

BuildHTTPRequestObject builds a cty object value with all request fields materialized as attributes, plus a _capsule attribute holding the request capsule. pathParamNames should be pre-computed via ExtractPathParams at route registration time; pass nil when path parameters are not applicable (e.g. auth middleware).

func BuildHTTPResponseObject added in v0.20.0

func BuildHTTPResponseObject(r *HTTPResponseWrapper) cty.Value

BuildHTTPResponseObject builds a cty object value with status and headers materialized as attributes, plus a _capsule attribute holding the response capsule.

func CoerceBodyToBytes added in v0.20.0

func CoerceBodyToBytes(val cty.Value) ([]byte, string, error)

CoerceBodyToBytes converts a cty value to a byte slice and content-type string suitable for use as an HTTP response body. It is shared between the http_response() constructor and the automatic type-coercion path in writeHTTPResponse.

Coercion rules:

  • null → (nil, "", nil)
  • string → (utf-8 bytes, "text/plain; charset=utf-8", nil)
  • bytes → (raw bytes, content_type from object or "application/octet-stream", nil)
  • other → JSON-encoded via ctyjson, "application/json"

func ExtractPathParams added in v0.31.0

func ExtractPathParams(pattern string) []string

ExtractPathParams extracts path parameter names from a Go 1.22+ ServeMux route pattern (e.g. "GET /repos/{name}/commits/{sha}" → ["name", "sha"]). Call this once at route registration time and pass the result to BuildHTTPRequestObject on each request.

func GetHTTPRequestFromValue added in v0.20.0

func GetHTTPRequestFromValue(val cty.Value) (*http.Request, error)

GetHTTPRequestFromValue extracts a *http.Request from an httprequest capsule or an object with a _capsule attribute.

func LabelNamesToAttrKeys added in v0.24.0

func LabelNamesToAttrKeys(names []string) []attribute.Key

labelNamesToAttrKeys converts string label names to OTel attribute keys.

func NewHTTPClientResponseCapsule added in v0.26.0

func NewHTTPClientResponseCapsule(w *HTTPClientResponseWrapper) cty.Value

NewHTTPClientResponseCapsule wraps an HTTPClientResponseWrapper in a cty capsule value.

func NewHTTPRequestCapsule added in v0.20.0

func NewHTTPRequestCapsule(r *http.Request) cty.Value

NewHTTPRequestCapsule wraps a *http.Request in a cty capsule value.

func NewHTTPResponseCapsule added in v0.20.0

func NewHTTPResponseCapsule(r *HTTPResponseWrapper) cty.Value

NewHTTPResponseCapsule wraps an HTTPResponseWrapper in a cty capsule value.

func NewMetricCapsule added in v0.20.0

func NewMetricCapsule(m MetricValue) cty.Value

func NewVariableCapsule

func NewVariableCapsule(v *Variable) cty.Value

Types

type ComputedCounterMetric added in v0.20.0

type ComputedCounterMetric struct {
	// contains filtered or unexported fields
}

ComputedCounterMetric implements richcty.Gettable and Startable. Its value is derived by evaluating a stored hcl.Expression on a polling interval. Only positive deltas are forwarded to the OTel counter.

func NewComputedCounterMetric added in v0.20.0

func NewComputedCounterMetric(inst metric.Float64Counter, expr hcl.Expression, evalCtx *hcl.EvalContext, logger *zap.Logger, interval time.Duration) *ComputedCounterMetric

func (*ComputedCounterMetric) Get added in v0.20.0

func (*ComputedCounterMetric) Start added in v0.24.0

func (m *ComputedCounterMetric) Start(ctx context.Context)

Start launches the polling goroutine. Implements config.Startable.

type ComputedGaugeMetric added in v0.20.0

type ComputedGaugeMetric struct {
	// contains filtered or unexported fields
}

ComputedGaugeMetric implements richcty.Gettable and Startable. Its value is derived by evaluating a stored hcl.Expression on a polling interval. set() and increment() are not supported.

func NewComputedGaugeMetric added in v0.20.0

func NewComputedGaugeMetric(inst metric.Float64UpDownCounter, expr hcl.Expression, evalCtx *hcl.EvalContext, logger *zap.Logger, interval time.Duration) *ComputedGaugeMetric

func (*ComputedGaugeMetric) Get added in v0.20.0

func (m *ComputedGaugeMetric) Get(_ context.Context, args []cty.Value) (cty.Value, error)

func (*ComputedGaugeMetric) Start added in v0.24.0

func (m *ComputedGaugeMetric) Start(ctx context.Context)

Start launches the polling goroutine. Implements config.Startable.

type ComputedHistogramMetric added in v0.20.0

type ComputedHistogramMetric struct {
	// contains filtered or unexported fields
}

ComputedHistogramMetric implements richcty.Observable and Startable. At each polling interval it evaluates the stored expression and records one observation. Manual Observe() calls are also supported.

func NewComputedHistogramMetric added in v0.20.0

func NewComputedHistogramMetric(inst metric.Float64Histogram, expr hcl.Expression, evalCtx *hcl.EvalContext, logger *zap.Logger, interval time.Duration) *ComputedHistogramMetric

func (*ComputedHistogramMetric) Observe added in v0.20.0

func (m *ComputedHistogramMetric) Observe(ctx context.Context, args []cty.Value) (cty.Value, error)

Observe allows manual observations in addition to the automatic polling one.

func (*ComputedHistogramMetric) Start added in v0.24.0

func (m *ComputedHistogramMetric) Start(ctx context.Context)

Start launches the polling goroutine. Implements config.Startable.

type CounterMetric added in v0.20.0

type CounterMetric struct {
	richcty.WatchableMixin
	// contains filtered or unexported fields
}

CounterMetric implements richcty.Gettable, richcty.Settable, richcty.Incrementable, richcty.Watchable. set() uses delta semantics: only positive differences are applied to the underlying counter. If the supplied value is less than the last set value (e.g. an external reset), the call is a no-op and the counter holds its current value.

func NewCounterMetric added in v0.20.0

func NewCounterMetric(inst metric.Float64Counter, attrKeys []attribute.Key) *CounterMetric

func (*CounterMetric) Get added in v0.20.0

func (m *CounterMetric) Get(_ context.Context, args []cty.Value) (cty.Value, error)

--- richcty.Gettable ---

func (*CounterMetric) Increment added in v0.20.0

func (m *CounterMetric) Increment(ctx context.Context, args []cty.Value) (cty.Value, error)

--- richcty.Incrementable ---

func (*CounterMetric) Set added in v0.20.0

func (m *CounterMetric) Set(ctx context.Context, args []cty.Value) (cty.Value, error)

--- richcty.Settable ---

type GaugeMetric added in v0.20.0

type GaugeMetric struct {
	richcty.WatchableMixin
	// contains filtered or unexported fields
}

GaugeMetric implements richcty.Gettable, richcty.Settable, richcty.Incrementable, richcty.Watchable. Uses OTel Float64UpDownCounter with delta tracking to support absolute Set().

func NewGaugeMetric added in v0.20.0

func NewGaugeMetric(inst metric.Float64UpDownCounter, attrKeys []attribute.Key) *GaugeMetric

func (*GaugeMetric) Get added in v0.20.0

func (m *GaugeMetric) Get(_ context.Context, args []cty.Value) (cty.Value, error)

--- richcty.Gettable ---

func (*GaugeMetric) Increment added in v0.20.0

func (m *GaugeMetric) Increment(ctx context.Context, args []cty.Value) (cty.Value, error)

--- richcty.Incrementable ---

func (*GaugeMetric) Set added in v0.20.0

func (m *GaugeMetric) Set(ctx context.Context, args []cty.Value) (cty.Value, error)

--- richcty.Settable ---

type HTTPClientResponseWrapper added in v0.26.0

type HTTPClientResponseWrapper struct {
	// R is the underlying *http.Response. R.Body is the live stream unless
	// BufferedBody is set, in which case callers should read from BufferedBody
	// instead.
	R *http.Response

	// Redirected is true if at least one redirect was followed to reach the
	// final response.
	Redirected bool

	// BufferedBody, if non-nil, holds the fully-read response body. It is
	// populated when opts.as pre-decodes the body, or when a body* accessor
	// has already consumed R.Body. Once set, body* accessors read from this
	// slice instead of the live stream.
	BufferedBody []byte

	// PreDecodedBody is the cty value for the body, pre-decoded according to
	// opts.as. It is set to cty.NilVal when opts.as was not used or was
	// "none"; the materialized "body" attribute on the cty object reflects
	// this field (null when unset).
	PreDecodedBody cty.Value
}

HTTPClientResponseWrapper wraps a *http.Response received by an HTTP client call, tracking extra state that isn't part of the standard response struct.

The Body field of the embedded *http.Response may be consumed lazily by the body* get accessors. If the caller passed opts.as to the verb function, the body is fully buffered into BufferedBody at request time and the body* accessors re-serve from that buffer (and may be called more than once).

func GetHTTPClientResponseFromValue added in v0.26.0

func GetHTTPClientResponseFromValue(val cty.Value) (*HTTPClientResponseWrapper, bool)

GetHTTPClientResponseFromValue extracts an *HTTPClientResponseWrapper from an httpclientresponse capsule or an object with a _capsule attribute.

func (*HTTPClientResponseWrapper) Get added in v0.26.0

Get implements richcty.Gettable, supporting dynamic field access on httpclientresponse values.

func (*HTTPClientResponseWrapper) Length added in v0.26.0

Length implements richcty.Lengthable. Returns the buffered body length if the body has been read (e.g. via opts.as), otherwise falls back to R.ContentLength (which may be -1 if unknown).

func (*HTTPClientResponseWrapper) ToString added in v0.26.0

ToString implements richcty.Stringable, returning the response body as a string. Convenience for small responses; for large or binary responses prefer get(r, "body_bytes").

type HTTPRequestWrapper added in v0.20.0

type HTTPRequestWrapper struct {
	R *http.Request
}

HTTPRequestWrapper wraps a *http.Request as a cty capsule.

func (*HTTPRequestWrapper) Get added in v0.20.0

func (w *HTTPRequestWrapper) Get(_ context.Context, args []cty.Value) (cty.Value, error)

Get implements richcty.Gettable, supporting dynamic field access on httprequest values.

type HTTPResponseWrapper added in v0.20.0

type HTTPResponseWrapper struct {
	Status      int
	Headers     http.Header
	Body        []byte
	ContentType string
	IsError     bool
}

HTTPResponseWrapper holds the data for an HTTP response being built by an action expression.

func GetHTTPResponseFromValue added in v0.20.0

func GetHTTPResponseFromValue(val cty.Value) (*HTTPResponseWrapper, bool)

GetHTTPResponseFromValue extracts an *HTTPResponseWrapper from an httpresponse capsule or an object with a _capsule attribute.

type HistogramMetric added in v0.20.0

type HistogramMetric struct {
	// contains filtered or unexported fields
}

HistogramMetric implements richcty.Observable.

func NewHistogramMetric added in v0.20.0

func NewHistogramMetric(inst metric.Float64Histogram, attrKeys []attribute.Key) *HistogramMetric

func (*HistogramMetric) Observe added in v0.20.0

func (m *HistogramMetric) Observe(ctx context.Context, args []cty.Value) (cty.Value, error)

--- richcty.Observable ---

type MetricValue added in v0.20.0

type MetricValue interface {
	// contains filtered or unexported methods
}

MetricValue is implemented by all metric types (gauge, counter, histogram).

func GetMetricFromCapsule added in v0.20.0

func GetMetricFromCapsule(val cty.Value) (MetricValue, error)

type Variable

type Variable struct {
	richcty.WatchableMixin
	// contains filtered or unexported fields
}

Variable is a mutable, goroutine-safe value container.

func GetVariableFromCapsule

func GetVariableFromCapsule(val cty.Value) (*Variable, error)

func NewTypedVariable

func NewTypedVariable(initial cty.Value, typeName string) *Variable

NewTypedVariable creates a Variable that enforces values match the given type friendly name (e.g. "number", "string", "bool"). An empty typeName means untyped.

func NewVariable

func NewVariable(initial cty.Value) *Variable

func (*Variable) Get

func (v *Variable) Get(_ context.Context, args []cty.Value) (cty.Value, error)

Get returns the current value, or the default (args[0]) if null. Implements richcty.Gettable.

func (*Variable) Increment

func (v *Variable) Increment(ctx context.Context, args []cty.Value) (cty.Value, error)

Increment adds args[0] (delta) to the current numeric value and returns the new value. Both the current value and delta must be cty.Number. Implements richcty.Incrementable.

func (*Variable) Set

func (v *Variable) Set(ctx context.Context, args []cty.Value) (cty.Value, error)

Set updates the value (args[0]) and returns it. If called with no arguments, sets the value to null. Implements richcty.Settable. If the variable has a type constraint, non-null values must match it.

func (*Variable) SetNullable

func (v *Variable) SetNullable(b bool)

func (*Variable) SetTypeName

func (v *Variable) SetTypeName(s string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL