github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/blog/content/slices/prog150.go (about)

     1  // +build OMIT
     2  
     3  // Copyright 2013 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package main
     8  
     9  import (
    10  	"fmt"
    11  )
    12  
    13  func main() {
    14  	// START OMIT
    15  	// Create a couple of starter slices.
    16  	slice := []int{1, 2, 3}
    17  	slice2 := []int{55, 66, 77}
    18  	fmt.Println("Start slice: ", slice)
    19  	fmt.Println("Start slice2:", slice2)
    20  
    21  	// Add an item to a slice.
    22  	slice = append(slice, 4)
    23  	fmt.Println("Add one item:", slice)
    24  
    25  	// Add one slice to another.
    26  	slice = append(slice, slice2...)
    27  	fmt.Println("Add one slice:", slice)
    28  
    29  	// Make a copy of a slice (of int).
    30  	slice3 := append([]int(nil), slice...)
    31  	fmt.Println("Copy a slice:", slice3)
    32  
    33  	// Copy a slice to the end of itself.
    34  	fmt.Println("Before append to self:", slice)
    35  	slice = append(slice, slice...)
    36  	fmt.Println("After append to self:", slice)
    37  	// END OMIT
    38  }