Skip to content

Instantly share code, notes, and snippets.

@nycdavid
Created November 10, 2017 18:07
Show Gist options
  • Save nycdavid/cbbc5d6e1d035636e5de71509bee393e to your computer and use it in GitHub Desktop.
Save nycdavid/cbbc5d6e1d035636e5de71509bee393e to your computer and use it in GitHub Desktop.
Sample code for interface post
package main
import (
"fmt"
"bytes"
"strconv"
)
type operand interface {
}
func main() {
fmt.Println("Hello!")
Addition(1, "foo", 2, "bar", 3, "baz")
}
func Addition(operands ...operand) {
var buf bytes.Buffer
for idx, operand := range operands {
switch operand.(type) {
case int:
buf.WriteString(strconv.Itoa(operand.(int)))
case string:
buf.WriteString(operand.(string))
}
if idx != len(operands) - 1 {
buf.WriteString(" + ")
}
}
fmt.Println(buf.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment