Xo is experimental. The source is now public on GitHub, or try Xo in your browser.
Menu · go

Docs

std/go

On this page

Index

Types

Error

struct Error {}

An error returned by a Go function: the error of a Go (T, error) result, which a binding maps to T ! go.Error. Its text is captured at the boundary, so display performs no Go call.

Source: std/go.xo:10

Error.display

fn (e: Error) display() -> Str

The Go error’s Error() text.

Source: std/go.xo:13

Error.message

fn (e: Error) message() -> Str

The Go error’s Error() text (same as display).

Source: std/go.xo:16

Error.go_type

fn (e: Error) go_type() -> Str

The Go dynamic type of the error, for example *url.Error.

Source: std/go.xo:19

Any

struct Any {}

A Go any (interface{}) value a use go binding takes or returns (decision 0412): opaque to Xo. Make one with go.any(x) (a list literal written for a ...any parameter converts its elements implicitly); read one with the as_* methods, None on another Go type. Compares as Go’s == on the interface. A value a replay rebuilt only displays, unless its function is replay rerun (core 11.3).

Source: std/go.xo:33

Any.display

fn (a: Any) display() -> Str

The value as Go’s %v.

Source: std/go.xo:36

Any.type_name

fn (a: Any) type_name() -> Str

The value’s Go type, as Go’s %T (int, *sql.Rows, <nil>).

Source: std/go.xo:39

Any.is_nil

fn (a: Any) is_nil() -> Bool

Whether the value is Go’s nil, or a nil pointer, slice or map.

Source: std/go.xo:42

Any.as_int

fn (a: Any) as_int() -> Int?

The value as an Int when it is one of Go’s integer types and fits.

Source: std/go.xo:45

Any.as_float

fn (a: Any) as_float() -> Float?

The value as a Float when it is a float64 or float32.

Source: std/go.xo:48

Any.as_bool

fn (a: Any) as_bool() -> Bool?

The value as a Bool when it is one.

Source: std/go.xo:51

Any.as_str

fn (a: Any) as_str() -> Str?

The value as a Str when its Go kind is string.

Source: std/go.xo:54

Any.as_bytes

fn (a: Any) as_bytes() -> Bytes?

The value as Bytes when it is a []byte (copied).

Source: std/go.xo:57

Any.as_list

fn (a: Any) as_list() -> List[Any]?

The elements of a Go slice or array.

Source: std/go.xo:60

Any.as_map

fn (a: Any) as_map() -> Map[Str, Any]?

The entries of a Go map with string keys.

Source: std/go.xo:63

Any.as_handle

fn (a: Any) as_handle[T]() -> T?

The use go handle of type T that holds the value, when the value’s Go type is T’s.

Source: std/go.xo:67

Out

struct Out[T] {}

A Go pointer a Go function fills through any (rows.scan, json.unmarshal): pass .any(), read .get() after the call.

Source: std/go.xo:77

Out.any

fn (o: Out[T]) any() -> Any

The pointer, as the go.Any the Go function takes.

Source: std/go.xo:84

Out.get

fn (o: Out[T]) get() -> T

The value Go wrote; a fault when Go wrote another type.

Source: std/go.xo:87

Recv

struct Recv[T] {}

A Go channel Xo receives from (decision 0421): a <-chan T or chan T a Go function, field or variable gives Xo. Sending and closing are Go’s; a nil Go channel is a closed one.

Source: std/go.xo:92

Recv.recv

fn (r: Recv[T]) recv() -> T? uses go

The next value; None once the channel is closed and empty. Waits in Go: a cancellation point (the task’s cancellation or task.with_timeout ends the wait).

Source: std/go.xo:97

Recv.try_recv

fn (r: Recv[T]) try_recv() -> T?? uses go

The next value if one is ready: None when none is, Some(None) once the channel is closed.

Source: std/go.xo:101

Recv.each

fn (r: Recv[T]) each[fx: Effects](f: fn(T) uses fx) uses go, fx

Calls f with each value until the channel is closed.

Source: std/go.xo:104

Functions

error

fn error(message: Str) -> Error

A Go error with text message (Go’s errors.New), for an Xo function a Go library calls to return (decision 0416): an Xo callback’s ! go.Error is the callback’s Go error. An Error that came from Go goes back as that Go error, so Go’s errors.Is sees it.

Source: std/go.xo:25

any

fn any[T](x: T) -> Any

An Xo value as the Go value a binding passes for it: Int as int64, Float as float64, Str as string, Bytes as []byte, Duration as time.Duration, Time as time.Time, a handle as its Go value, a List as a slice, a Map as a map, an Option as its value or nil.

Source: std/go.xo:73

out

fn out[T]() -> Out[T]

A new Go pointer to the zero value of T’s Go type (T a value type go.any takes, a handle, or go.Any).

Source: std/go.xo:81

↑ index