@kjk1/

gobook function variadic

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.39069112525532756","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgKAoJImZtdCIKKQoKLy8gOnNob3cgc3RhcnQKZnVuYyB2YXJpYWRpYyhzdHJzIC4uLnN0cmluZykgewoJLy8gc3RycyBpcyBhIHNsaWNlIG9mIHN0cmluZwoJZm9yIGksIHN0ciA6PSByYW5nZSBzdHJzIHsKCQlmbXQuUHJpbnRmKCIlZDogJXNcbiIsIGksIHN0cikKCX0KCWZtdC5QcmludCgiXG4iKQp9CgpmdW5jIG1haW4oKSB7Cgl2YXJpYWRpYygiSGVsbG8iLCAiR29vZGJ5ZSIpCgl2YXJpYWRpYygiU3RyMSIsICJTdHIyIiwgIlN0cjMiKQoKCS8vIHlvdSBjYW4gYWxzbyBnaXZlIGEgc2xpY2UgdG8gYSB2YXJpYWRpYyBmdW5jdGlvbiwgd2l0aCBgLi4uYDoKCXN0cnMgOj0gW11zdHJpbmd7ImEiLCAiYiJ9Cgl2YXJpYWRpYyhzdHJzLi4uKQp9CgovLyA6c2hvdyBlbmQ="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package main

import (
	"fmt"
)

// :show start
func variadic(strs ...string) {
	// strs is a slice of string
	for i, str := range strs {
		fmt.Printf("%d: %s\n", i, str)
	}
	fmt.Print("\n")
}

func main() {
	variadic("Hello", "Goodbye")
	variadic("Str1", "Str2", "Str3")

	// you can also give a slice to a variadic function, with `...`:
	strs := []string{"a", "b"}
	variadic(strs...)
}

// :show end