Skip to content

Instantly share code, notes, and snippets.

@lucaspere
Last active March 23, 2023 11:43
Show Gist options
  • Save lucaspere/3cad280796adc24d7ef5e963f428fbe4 to your computer and use it in GitHub Desktop.
Save lucaspere/3cad280796adc24d7ef5e963f428fbe4 to your computer and use it in GitHub Desktop.
Destructuring of Dynamic Structure Fields
package main
import (
"bytes"
"fmt"
"log"
"strings"
)
var output bytes.Buffer
type Peason struct {
Name string
Age int
}
type Job struct {
Salary float64
Name string
}
func main() {
l := Peason{"Lucas", 26}
j := Job{1000, "Engineer"}
//Modificar a partir desta linha
// TODO: allFields deve receber apenas 1 argumento.
// De modo que se for preciso adicionar mais estruturas, não precisará de modificar o código.
allFields()
//Não modificar as linhas abaixo
if strings.ReplaceAll(output.String(), " ", "") != "Lucas261000Engineer" {
log.Fatal("Falhou")
} else {
log.Println("Boa")
}
}
func allFields(fields ...interface{}) {
fmt.Fprint(&output, fields...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment