I have the following structure:
/*gotime.go*/
package gotime
type Now struct {
dnow int
ynow int
mnow time.Month
}
And is there a function like:
/*gotime.go*/
func (n Now) DayNow() int {
n.dnow = time.Now().Day()
return n.dnow
}
I'm getting the following error when I want to call this package:
/*main.go*/
package main
import (
"fmt"
"./gotime"
)
blah := Now
fmt.Println(blah.DayNow())
I get errors:
# command-line-arguments
.\main.go:5: imported and not used: "_/C_/Users/ali/Desktop/test/gotime"
.\main.go:10: undefined: Now
You can look at all of the package on GitHub:
Link for this package
How can I solve this problem?
Since Now
is a struct, you need a struct Composite literal to create a value of that type.
Also since it is from another package, you need the Qualified name:
blan := gotime.Now{}
Also since you are modifying it, you should / need to use a pointer receiver:
func (n *Now) DayNow() int {
n.dnow = time.Now().Day()
return n.dnow
}