Skip to content

Instantly share code, notes, and snippets.

@HallexCosta
Last active November 7, 2020 19:54
Show Gist options
  • Save HallexCosta/ccced1b9977d2367862e22744d873d11 to your computer and use it in GitHub Desktop.
Save HallexCosta/ccced1b9977d2367862e22744d873d11 to your computer and use it in GitHub Desktop.
Example usage method with receiver in golang
package main
import (
"fmt"
)
type User struct {
Name string
}
func (user *User) Save() bool {
fmt.Println(map[string]interface{}{
"name": user.Name,
"success": true,
})
return true
}
func main() {
user := User{
Name: "Hállex",
}
saved := user.Save()
if saved == true {
fmt.Println("Saved successfully")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment