Calling a method (associated to types of current package ) from other package

i have a package named as “pkg” in which there is a method PrintInfo which has a receiver of Type A struct i want to call this method in main package but in main package i can’t call it
I want to know how can i call PrintInfo method ?

package pkg

type A struct{
Name string
Age int

func (a *A)PrintInfo(){
fmt.Println("Name: “,a.Name,” Age: ",a.age)

package main
import “

var a = pkg.A{
func main(){
// how can i call method here now ?
pkg.PrintInfo() is unavailable

As PrintInfo as an *A receiver, you will need to call it using an instance of A (eg a.PrintInfo() in main instead of pkg.PrintInfo()).

1 Like

It worked !!!
Thanks man