Structures / Methods

type swap struct {}

func (s *swap) strings(s1, s2 *string) {
    *s1, *s2 = *s2, *s1
}

var s1 = "A"
var s2 = "B"
swap := swap{}
swap.strings(&s1, &s2)
//s1 is "B", s2 is "A"

fmt.Println("s1 =", s1)
fmt.Println("s2 =", s2)