github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/blog/content/slices/prog060.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 Extend(slice []int, element int) []int { 12 n := len(slice) 13 slice = slice[0 : n+1] 14 slice[n] = element 15 return slice 16 } 17 18 func main() { 19 var iBuffer [10]int 20 slice := iBuffer[0:0] 21 for i := 0; i < 20; i++ { 22 slice = Extend(slice, i) 23 fmt.Println(slice) 24 } 25 }