Created
March 6, 2022 15:25
-
-
Save xvbnm48/1583eed3490bf87f0a4777d6aa0bbf83 to your computer and use it in GitHub Desktop.
method in golang
This file contains hidden or 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" | |
| // struct | |
| type Student struct { | |
| ID string | |
| Name string | |
| Age int | |
| Email string | |
| } | |
| func main(){ | |
| // mengisi struct | |
| var s1 = Student{"1", "sakura", 20, "sakura@gmail.com"} | |
| // memanggil method | |
| s1.dataStudent() | |
| s1.getName() | |
| } | |
| // method | |
| func (s Student) dataStudent() { | |
| fmt.Println("name is ", s.Name, "with age ", s.Age, "and you email is ", s.Email) | |
| } | |
| func (s Student) getName() { | |
| fmt.Println(s.Name) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment