Interfaces
// function to save a note in a json file
func (todo Todo) Save() error {
fileName := "todo.json"
json, err := json.Marshal(todo)
if err != nil {
return err
}
return os.WriteFile(fileName, json, 0644)
}Creating an interface
// certain value has a certain method guarantee
type saver interface {
Save() error
}Using an interface
Last updated