Movatterモバイル変換


[0]ホーム

URL:


builtin

packagestandard library
go1.24.1Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License:BSD-3-ClauseImports:1Imported by:0

Details

Repository

cs.opensource.google/go/go

Links

Documentation

Overview

Package builtin provides documentation for Go's predeclared identifiers.The items documented here are not actually in package builtinbut their descriptions here allow godoc to present documentationfor the language's special identifiers.

Index

Constants

View Source
const (true  = 0 == 0// Untyped bool.false = 0 != 0// Untyped bool.)

true and false are the two untyped boolean values.

View Source
const iota = 0// Untyped int.

iota is a predeclared identifier representing the untyped integer ordinalnumber of the current const specification in a (usually parenthesized)const declaration. It is zero-indexed.

Variables

View Source
var nilType// Type must be a pointer, channel, func, interface, map, or slice type

nil is a predeclared identifier representing the zero value for apointer, channel, func, interface, map, or slice type.

Functions

funcappend

func append(slice []Type, elems ...Type) []Type

The append built-in function appends elements to the end of a slice. Ifit has sufficient capacity, the destination is resliced to accommodate thenew elements. If it does not, a new underlying array will be allocated.Append returns the updated slice. It is therefore necessary to store theresult of append, often in the variable holding the slice itself:

slice = append(slice, elem1, elem2)slice = append(slice, anotherSlice...)

As a special case, it is legal to append a string to a byte slice, like this:

slice = append([]byte("hello "), "world"...)

funccap

func cap(vType)int

The cap built-in function returns the capacity of v, according to its type:

  • Array: the number of elements in v (same as len(v)).
  • Pointer to array: the number of elements in *v (same as len(v)).
  • Slice: the maximum length the slice can reach when resliced;if v is nil, cap(v) is zero.
  • Channel: the channel buffer capacity, in units of elements;if v is nil, cap(v) is zero.

For some arguments, such as a simple array expression, the result can be aconstant. See the Go language specification's "Length and capacity" section fordetails.

funcclearadded ingo1.21.0

func clear[T ~[]Type | ~map[Type]Type1](t T)

The clear built-in function clears maps and slices.For maps, clear deletes all entries, resulting in an empty map.For slices, clear sets all elements up to the length of the sliceto the zero value of the respective element type. If the argumenttype is a type parameter, the type parameter's type set mustcontain only map or slice types, and clear performs the operationimplied by the type argument. If t is nil, clear is a no-op.

funcclose

func close(c chan<-Type)

The close built-in function closes a channel, which must be eitherbidirectional or send-only. It should be executed only by the sender,never the receiver, and has the effect of shutting down the channel afterthe last sent value is received. After the last value has been receivedfrom a closed channel c, any receive from c will succeed withoutblocking, returning the zero value for the channel element. The form

x, ok := <-c

will also set ok to false for a closed and empty channel.

funccomplex

func complex(r, iFloatType)ComplexType

The complex built-in function constructs a complex value from twofloating-point values. The real and imaginary parts must be of the samesize, either float32 or float64 (or assignable to them), and the returnvalue will be the corresponding complex type (complex64 for float32,complex128 for float64).

funccopy

func copy(dst, src []Type)int

The copy built-in function copies elements from a source slice into adestination slice. (As a special case, it also will copy bytes from astring to a slice of bytes.) The source and destination may overlap. Copyreturns the number of elements copied, which will be the minimum oflen(src) and len(dst).

funcdelete

func delete(m map[Type]Type1, keyType)

The delete built-in function deletes the element with the specified key(m[key]) from the map. If m is nil or there is no such element, deleteis a no-op.

funcimag

The imag built-in function returns the imaginary part of the complexnumber c. The return value will be floating point type corresponding tothe type of c.

funclen

func len(vType)int

The len built-in function returns the length of v, according to its type:

  • Array: the number of elements in v.
  • Pointer to array: the number of elements in *v (even if v is nil).
  • Slice, or map: the number of elements in v; if v is nil, len(v) is zero.
  • String: the number of bytes in v.
  • Channel: the number of elements queued (unread) in the channel buffer;if v is nil, len(v) is zero.

For some arguments, such as a string literal or a simple array expression, theresult can be a constant. See the Go language specification's "Length andcapacity" section for details.

funcmake

func make(tType, size ...IntegerType)Type

The make built-in function allocates and initializes an object of typeslice, map, or chan (only). Like new, the first argument is a type, not avalue. Unlike new, make's return type is the same as the type of itsargument, not a pointer to it. The specification of the result depends onthe type:

  • Slice: The size specifies the length. The capacity of the slice isequal to its length. A second integer argument may be provided tospecify a different capacity; it must be no smaller than thelength. For example, make([]int, 0, 10) allocates an underlying arrayof size 10 and returns a slice of length 0 and capacity 10 that isbacked by this underlying array.
  • Map: An empty map is allocated with enough space to hold thespecified number of elements. The size may be omitted, in which casea small starting size is allocated.
  • Channel: The channel's buffer is initialized with the specifiedbuffer capacity. If zero, or the size is omitted, the channel isunbuffered.

funcmaxadded ingo1.21.0

func max[Tcmp.Ordered](x T, y ...T) T

The max built-in function returns the largest value of a fixed number ofarguments ofcmp.Ordered types. There must be at least one argument.If T is a floating-point type and any of the arguments are NaNs,max will return NaN.

funcminadded ingo1.21.0

func min[Tcmp.Ordered](x T, y ...T) T

The min built-in function returns the smallest value of a fixed number ofarguments ofcmp.Ordered types. There must be at least one argument.If T is a floating-point type and any of the arguments are NaNs,min will return NaN.

funcnew

func new(Type) *Type

The new built-in function allocates memory. The first argument is a type,not a value, and the value returned is a pointer to a newlyallocated zero value of that type.

funcpanic

func panic(vany)

The panic built-in function stops normal execution of the currentgoroutine. When a function F calls panic, normal execution of F stopsimmediately. Any functions whose execution was deferred by F are run inthe usual way, and then F returns to its caller. To the caller G, theinvocation of F then behaves like a call to panic, terminating G'sexecution and running any deferred functions. This continues until allfunctions in the executing goroutine have stopped, in reverse order. Atthat point, the program is terminated with a non-zero exit code. Thistermination sequence is called panicking and can be controlled by thebuilt-in function recover.

Starting in Go 1.21, calling panic with a nil interface value or anuntyped nil causes a run-time error (a different panic).The GODEBUG setting panicnil=1 disables the run-time error.

funcprintadded ingo1.2

func print(args ...Type)

The print built-in function formats its arguments in animplementation-specific way and writes the result to standard error.Print is useful for bootstrapping and debugging; it is not guaranteedto stay in the language.

funcprintlnadded ingo1.2

func println(args ...Type)

The println built-in function formats its arguments in animplementation-specific way and writes the result to standard error.Spaces are always added between arguments and a newline is appended.Println is useful for bootstrapping and debugging; it is not guaranteedto stay in the language.

funcreal

The real built-in function returns the real part of the complex number c.The return value will be floating point type corresponding to the type of c.

funcrecover

func recover()any

The recover built-in function allows a program to manage behavior of apanicking goroutine. Executing a call to recover inside a deferredfunction (but not any function called by it) stops the panicking sequenceby restoring normal execution and retrieves the error value passed to thecall of panic. If recover is called outside the deferred function it willnot stop a panicking sequence. In this case, or when the goroutine is notpanicking, recover returns nil.

Prior to Go 1.21, recover would also return nil if panic is called witha nil argument. See [panic] for details.

Types

typeComplexType

type ComplexTypecomplex64

ComplexType is here for the purposes of documentation only. It is astand-in for either complex type: complex64 or complex128.

typeFloatType

type FloatTypefloat32

FloatType is here for the purposes of documentation only. It is a stand-infor either float type: float32 or float64.

typeIntegerType

type IntegerTypeint

IntegerType is here for the purposes of documentation only. It is a stand-infor any integer type: int, uint, int8 etc.

typeType

type Typeint

Type is here for the purposes of documentation only. It is a stand-infor any Go type, but represents the same type for any given functioninvocation.

typeType1

type Type1int

Type1 is here for the purposes of documentation only. It is a stand-infor any Go type, but represents the same type for any given functioninvocation.

typeanyadded ingo1.18

type any = interface{}

any is an alias for interface{} and is equivalent to interface{} in all ways.

typebool

type boolbool

bool is the set of boolean values, true and false.

typebyte

type byte =uint8

byte is an alias for uint8 and is equivalent to uint8 in all ways. It isused, by convention, to distinguish byte values from 8-bit unsignedinteger values.

typecomparableadded ingo1.18

type comparable interface{comparable }

comparable is an interface that is implemented by all comparable types(booleans, numbers, strings, pointers, channels, arrays of comparable types,structs whose fields are all comparable types).The comparable interface may only be used as a type parameter constraint,not as the type of a variable.

typecomplex128

type complex128complex128

complex128 is the set of all complex numbers with float64 real andimaginary parts.

typecomplex64

type complex64complex64

complex64 is the set of all complex numbers with float32 real andimaginary parts.

typeerror

type error interface {Error()string}

The error built-in interface type is the conventional interface forrepresenting an error condition, with the nil value representing no error.

typefloat32

type float32float32

float32 is the set of all IEEE 754 32-bit floating-point numbers.

typefloat64

type float64float64

float64 is the set of all IEEE 754 64-bit floating-point numbers.

typeint

type intint

int is a signed integer type that is at least 32 bits in size. It is adistinct type, however, and not an alias for, say, int32.

typeint16

type int16int16

int16 is the set of all signed 16-bit integers.Range: -32768 through 32767.

typeint32

type int32int32

int32 is the set of all signed 32-bit integers.Range: -2147483648 through 2147483647.

typeint64

type int64int64

int64 is the set of all signed 64-bit integers.Range: -9223372036854775808 through 9223372036854775807.

typeint8

type int8int8

int8 is the set of all signed 8-bit integers.Range: -128 through 127.

typerune

type rune =int32

rune is an alias for int32 and is equivalent to int32 in all ways. It isused, by convention, to distinguish character values from integer values.

typestring

type stringstring

string is the set of all strings of 8-bit bytes, conventionally but notnecessarily representing UTF-8-encoded text. A string may be empty, butnot nil. Values of string type are immutable.

typeuint

type uintuint

uint is an unsigned integer type that is at least 32 bits in size. It is adistinct type, however, and not an alias for, say, uint32.

typeuint16

type uint16uint16

uint16 is the set of all unsigned 16-bit integers.Range: 0 through 65535.

typeuint32

type uint32uint32

uint32 is the set of all unsigned 32-bit integers.Range: 0 through 4294967295.

typeuint64

type uint64uint64

uint64 is the set of all unsigned 64-bit integers.Range: 0 through 18446744073709551615.

typeuint8

type uint8uint8

uint8 is the set of all unsigned 8-bit integers.Range: 0 through 255.

typeuintptr

type uintptruintptr

uintptr is an integer type that is large enough to hold the bit pattern ofany pointer.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp