fork(1) download
  1. // Playground for https://stackoverflow.com/a/56699658/11458991
  2.  
  3. package main
  4.  
  5. import (
  6. "fmt"
  7. "strings"
  8. )
  9.  
  10. // RowID stores the ID of a single row in a table. An ID can be a composite of multiple columns
  11. type RowID []string
  12.  
  13. // String implements Stringer interface for RowID
  14. func (r RowID) String() string {
  15. return fmt.Sprintf("[%s]", strings.Join(r, ", "))
  16. }
  17.  
  18. func PrintChange(id fmt.Stringer) {
  19. fmt.Println(id)
  20. }
  21.  
  22. func main() {
  23. rowIDs := []RowID{
  24. {"1", "2"},
  25. {"22"},
  26. }
  27.  
  28. PrintChange(rowIDs[0])
  29.  
  30. for _, id := range rowIDs { fmt.Println(id) }
  31. }
Success #stdin #stdout 0s 3076KB
stdin
Standard input is empty
stdout
[1, 2]
[1, 2]
[22]