Undefined error after using time package in Go language

Asked 1 years ago, Updated 1 years ago, 340 views

I was writing the code using the time package to read the current time in Japan in Go language, but now I get the following error message.

Commenting out a description about time does not erase the error statement.
When importing posts to the local database, I got the current time to include the posting time.

$go build

# time
/usr/local/Cellar/go/1.19.3/libexec/src/time/sleep.go:51:11:undefined:Time
/usr/local/Cellar/go/1.19.3/libexec/src/time/sleep.go:156:31:undefined:Time
/usr/local/Cellar/go/1.19.3/libexec/src/time/tick.go:12:11:undefined:Time
/usr/local/Cellar/go/1.19.3/libexec/src/time/format.go:508:9:undefined:Time
/usr/local/Cellar/go/1.19.3/libexec/src/time/format.go:539:9:undefined:Time
/usr/local/Cellar/go/1.19.3/libexec/src/time/format.go:598:9:undefined:Time
/usr/local/Cellar/go/1.19.3/libexec/src/time/format.go:614:9:undefined:Time
/usr/local/Cellar/go/1.19.3/libexec/src/time/format.go:958:35:undefined:Time
/usr/local/Cellar/go/1.19.3/libexec/src/time/format.go:967:60:undefined:Time
/usr/local/Cellar/go/1.19.3/libexec/src/time/format.go:971:69:undefined:Time
/usr/local/Cellar/go/1.19.3/libexec/src/time/sleep.go:156:31:too many errors

The above error occurs when you run go build.
Commenting out all code for time does not erase the error.

t:=time.Now().UTC()
Tokyo, err: = time.LoadLocation("Asia/Tokyo")
if err!=nil{
    fmt.Println ("Failed to get current time in Japan")
}
Date: =t.In(tokyo)

I was trying to get the current time in Japan with the above code.
I couldn't get the correct time, but I found an article saying that UTC cannot be changed in the local environment, so there is no problem.

I tried to run it as it was, but the error statement disappeared.
I tried to run the code several times to set the current time in Japan, so I think an error occurred at that time.
(The code I executed has been erased and is not left)

What is the cause of the error when I comment out the code related to time?
I would appreciate it if someone could tell me.
Thank you for your cooperation.

go

2022-12-02 06:03

1 Answers

The Go file seems to be corrupted.
Specifically, does /usr/local/Cellar/go/1.19.3/libexec/src/time/time.go not exist or overwritten?

Why don't you reinstall Go?

brew reinstall go


2022-12-02 15:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.