wiki.hjertnes.website

Golang array by reference

How to append to list by reference

package main

import (
	"fmt"
	"os"
)

func test(t *[]string){
	*t = append(*t, "test")
	*t = append(*t, "test")
}


func main(){
	b := make([]string, 0)
	test(&b)
	if len(b) != 2{
		os.Exit(1)
	}
	fmt.Println(b)

}