Skip to content

Instantly share code, notes, and snippets.

@xvbnm48
Created March 6, 2022 15:25
Show Gist options
  • Select an option

  • Save xvbnm48/1583eed3490bf87f0a4777d6aa0bbf83 to your computer and use it in GitHub Desktop.

Select an option

Save xvbnm48/1583eed3490bf87f0a4777d6aa0bbf83 to your computer and use it in GitHub Desktop.
method in golang
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