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