The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/kindsys/util.go

24 lines
787 B

package kindsys
// Ptr returns a pointer to a value of an arbitrary type.
//
// This function is provided to compensate for Grafana's Go code generation that
// represents optional fields using pointers.
//
// Pointers are the only technically [correct, non-ambiguous] way of
// representing an optional field in Go's type system. However, Go does not
// allow taking the address of certain primitive types inline. That is,
// this is invalid Go code:
//
// var str *string
// str = &"colorless green ideas sleep furiously"
//
// This func allows making such declarations in a single line:
//
// var str *string
// str = kindsys.Ptr("colorless green ideas sleep furiously")
//
// [correct, non-ambiguous]: https://github.com/grafana/grok/issues/1
func Ptr[T any](v T) *T {
return &v
}