In Go 1, a composite literal of array, slice, or map type can elide the type specification for the elements' initializers if they are of pointer type. All four of the initializations in this example are legal; the last one was illegal before Go 1.

type Date struct {
        month string
        day   int
    }
    // Struct values, fully qualified; always legal.
    holiday1 := []Date{
        Date{"Feb", 14},
        Date{"Nov", 11},
        Date{"Dec", 25},
    }
    // Struct values, type name elided; always legal.
    holiday2 := []Date{
        {"Feb", 14},
        {"Nov", 11},
        {"Dec", 25},
    }
    // Pointers, fully qualified, always legal.
    holiday3 := []*Date{
        &Date{"Feb", 14},
        &Date{"Nov", 11},
        &Date{"Dec", 25},
    }
    // Pointers, type name elided; legal in Go 1.
    holiday4 := []*Date{
        {"Feb", 14},
        {"Nov", 11},
        {"Dec", 25},
    }
In Go 1, a composite literal of array, slice, or map type can elide the type specification for the elements' initializers if they are of pointer type. All four of the initializations in this example are legal; the last one was illegal before Go 1.

type Date struct {
        month string
        day   int
    }
    // Struct values, fully qualified; always legal.
    holiday1 := []Date{
        Date{"Feb", 14},
        Date{"Nov", 11},
        Date{"Dec", 25},
    }
    // Struct values, type name elided; always legal.
    holiday2 := []Date{
        {"Feb", 14},
        {"Nov", 11},
        {"Dec", 25},
    }
    // Pointers, fully qualified, always legal.
    holiday3 := []*Date{
        &Date{"Feb", 14},
        &Date{"Nov", 11},
        &Date{"Dec", 25},
    }
    // Pointers, type name elided; legal in Go 1.
    holiday4 := []*Date{
        {"Feb", 14},
        {"Nov", 11},
        {"Dec", 25},
    }
By analogy with the similar property of copy, Go 1 permits a string to be appended (byte-wise) directly to a byte slice, reducing the friction between strings and byte slices. The conversion is no longer necessary:

greeting = append(greeting, "world"...)
In Go 1, code that uses goroutines can be called from init routines and global initialization expressions without introducing a deadlock.

var PackageGlobal int

func init() {
    c := make(chan int)
    go initializationFunction(c)
    PackageGlobal = <-c
}
The append predeclared variadic function makes it easy to grow a slice by adding elements to the end. A common use is to add bytes to the end of a byte slice when generating output. However, append did not provide a way to append a string to a []byte, which is another common case.

greeting := []byte{}
    greeting = append(greeting, []byte("hello ")...)
To close this gap, at least in part, Go 1 disallows close on receive-only channels. Attempting to close such a channel is a compile-time error.

var c chan int
    var csend chan<- int = c
    var crecv <-chan int = c
    close(c)     // legal
    close(csend) // legal
    close(crecv) // illegal
Go 1 introduces a new built-in type, error, which has the following definition:

type error interface {
        Error() string
    }
In Go 1, that syntax has gone; instead there is a new built-in function, delete. The call

delete(m, k)
Go 1 addressed these issues. First, structs and arrays can be compared for equality and inequality (== and !=), and therefore be used as map keys, provided they are composed from elements for which equality is also defined, using element-wise comparison.

type Day struct {
        long  string
        short string
    }
    Christmas := Day{"Christmas", "XMas"}
    Thanksgiving := Day{"Thanksgiving", "Turkey"}
    holiday := map[Day]bool{
        Christmas:    true,
        Thanksgiving: true,
    }
    fmt.Printf("Christmas is a holiday: %t\n", holiday[Christmas])
This change means that code that depends on iteration order is very likely to break early and be fixed long before it becomes a problem. Just as important, it allows the map implementation to ensure better map balancing even when programs are using range loops to select an element from a map.

m := map[string]int{"Sunday": 0, "Monday": 1}
    for name, value := range m {
        // This loop should not assume Sunday will be visited first.
        f(name, value)
    }
Libraries have been updated to use rune rather than int when appropriate. For instance, the functions unicode.ToLower and relatives now take and return a rune.

delta := 'δ' // delta has type rune.
    var DELTA rune
    DELTA = unicode.ToUpper(delta)
    epsilon := unicode.ToLower(DELTA + 1)
    if epsilon != 'δ'+1 {
        log.Fatal("inconsistent casing for Greek")
    }

Recommend

Go 1 Release Notes Changes to the language Close

Go 1 Release Notes Changes to the language Append

Go 1.6 Release Notes Core library Templates

Go 1.6 Release Notes Core library Reflect

Go 1.6 Release Notes Tools Compiler Toolchain

Go Fuzzing Corpus file format

Go Fuzzing Running fuzz tests Custom settings

Go Fuzzing Running fuzz tests Failing input

Go Fuzzing Running fuzz tests Command line output

A Quick Guide to Go's Assembler Architecture-specific details Unsupported opcodes

A Quick Guide to Go's Assembler Architecture-specific details 64-bit Intel 386 (a.k.a. amd64)

A Quick Guide to Go's Assembler Architecture-specific details 32-bit Intel 386

A Quick Guide to Go's Assembler Architecture-specific details

A Quick Guide to Go's Assembler A Quick Guide to Go's Assembler Interacting with Go types and constants

A Quick Guide to Go's Assembler A Quick Guide to Go's Assembler Directives

A Quick Guide to Go's Assembler A Quick Guide to Go's Assembler Symbols

A Quick Guide to Go's Assembler A Quick Guide to Go's Assembler

Managing Go installations Uninstalling Go Windows

Managing Go installations Installing multiple Go versions

Go 1.10 Release Notes Core library Minor changes to the library

Go 1.10 Release Notes Tools Doc

Go 1.10 Release Notes Tools Cgo

Go 1.1 Release Notes Changes to the standard library Exp and old subtrees moved to go.exp and go.text subrepositories

Go 1.1 Release Notes Changes to the standard library bufio.Scanner

Go 1.1 Release Notes Changes to the implementations and tools Build constraints

Go 1.1 Release Notes Changes to the implementations and tools Changes to the go test command

Go 1.1 Release Notes Changes to the implementations and tools Changes to the go command

Go 1.1 Release Notes Changes to the implementations and tools Unicode

Go 1.1 Release Notes Changes to the implementations and tools Size of int on 64-bit platforms

Go 1.1 Release Notes Changes to the language Method values

Go 1.1 Release Notes Changes to the language Integer division by zero

Go 1.8 Release Notes Changes to the language

Go 1.2 Release Notes Changes to the standard library The text/template and html/template packages

Go 1.2 Release Notes Changes to the standard library The fmt package

Go 1.2 Release Notes Changes to the implementations and tools The go doc command is deleted

Go 1.2 Release Notes Changes to the implementations and tools Test coverage

Go 1.2 Release Notes Changes to the implementations and tools Godoc and vet moved to the go.tools subrepository

Go 1.2 Release Notes Changes to the language Three-index slices

Go 1.2 Release Notes Changes to the language Use of nil

Go 1.5 Release Notes Core library Flag

Go 1.5 Release Notes Tools Trace command

Go 1.5 Release Notes Tools Linker

Go 1.5 Release Notes Tools Assembler

Go 1.5 Release Notes Tools Renaming

Go 1.5 Release Notes Changes to the language Map literals

Go 1.17 Release Notes Tools Vet New warnings for Is, As and Unwrap methods

Go 1.17 Release Notes Tools Vet New warning for calling signal.Notify on unbuffered channels

Go 1.17 Release Notes Tools Go command Pruned module graphs in go 1.17 modules

Debugging Go Code with GDB Tutorial Pretty Printing

Debugging Go Code with GDB Tutorial Inspecting the stack

Debugging Go Code with GDB Tutorial Setting breakpoints

Debugging Go Code with GDB Tutorial Inspecting the source

Debugging Go Code with GDB Tutorial Getting Started