Last active
March 23, 2023 11:43
-
-
Save lucaspere/3cad280796adc24d7ef5e963f428fbe4 to your computer and use it in GitHub Desktop.
Destructuring of Dynamic Structure Fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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