type Website struct {
Name string `json:"name"`
Description string `json:"description"`
Url string `json:"url"`
}
var websites []Website
I’ve already used Typescript in JS and when I use []Website in Typescript it’s because Website is an interface just like the struct I did… So when do I have to use interfaces and when do I have to use structs ?
An interface defines a set of methods that you’re going to support for multiple different types of struct. This allows you to write methods which work for any struct which supports the interface, rather than only for a particular type of struct.
The structs implement the interface by implementing the set of methods required.