Created
February 6, 2018 18:18
-
-
Save MuthukumarHelios/c038c7be23571bf3252c61225ea2c892 to your computer and use it in GitHub Desktop.
Go lang Struct with Methods
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 "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