Skip to content

Instantly share code, notes, and snippets.

@MuthukumarHelios
Created February 6, 2018 18:18
Show Gist options
  • Save MuthukumarHelios/c038c7be23571bf3252c61225ea2c892 to your computer and use it in GitHub Desktop.
Save MuthukumarHelios/c038c7be23571bf3252c61225ea2c892 to your computer and use it in GitHub Desktop.
Go lang Struct with Methods
package main
import "fmt"
type Movies struct{
name string
actor string
}
var log = fmt.Println
// Normal functions
func value(m Movies) string {
log(m.name)
return m.name
}
// Struct Methods
func (m *Movies) Name_actor_by_reference() string{
return m.actor
}
func (m Movies) Name_actor_by_value() string{
return m.actor
}
func main(){
m := Movies{"Moviesname","aith"}
log(m)
value(m)
// our Struct Methods
log(m.Name_actor_by_reference())
log(m.Name_actor_by_value())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment