Analysis on the causes of Golang learning errors

Source: Internet
Author: User
Tags uppercase letter
This is a creation in Article, where the information may have evolved or changed.

7. error:reference to field ' Printf ' in object which have no fields or methods
f.printf ("%v", (Map (f,m)))
Problem point:
When you enable the import F "FMT", if you define the variable F again in the function, use F. print**, this will cause the above error.

8, Error:argument 1 have incompatible type (cannot use type Int64 as type time. Duration)
Time. Sleep (SEC*1E9)
^
Problem point:
The parameters for sleep are incorrect, and time should be used. Duration for type conversions. Even though time. The Duration type is defined using the type Duration Int64 method.
This needs to use time. Duration (sec) for the conversion to compile correctly.

9. Error:invalid break label ' L '
Break L
^
When you use the break label, you need to put the label before the for statement, or you can explode the error.
L:for.....;.. {
If.. {
Break L
}
}

10, Fatal Error:all Goroutines is asleep-deadlock!
Goroutine 1 [Select]:
Main.func_select
/home/niujie/workspace/go/src/study/go_reserved.go:364
Main.main
/home/niujie/workspace/go/src/study/go_reserved.go:398
Exit Status 2
This error occurs when the following method is called:
for{
Loop:
F.println ("I is:", i)
select{
Case <-C:
i++
If i>1{
Goto Loop
}
}
}
The correct method is as follows:
l:for{
F.println ("I is:", i)
select{
Case <-C:
i++
If i>1{
Break L
}
}
}

11../go_study.go:6:8:error:imported and not Used:sort_method
"./sort"
^
Problem point:
This is an inconsistent name when importing a custom package. That is, the package file name is inconsistent with the package name in the file.
When we import, we need to follow the package name in the file to be able to.

12. Go_study.go:5:2:cannot Find Package "Mysort" in any of:
/usr/local/go/src/pkg/mysort (from $GOROOT)
/home/niujie/workspace/go/src/mysort (from $GOPATH)
Problem point:
After the package is imported, Golang searches for the path to the package name in Goroot and Gopath. If the name is different, you will be prompted not to find the package.

13, Error:invalid reference to unexported identifier ' Mysort.bubble_sort '
Mysort.bubble_sort (n)
^
Problem point:
in the package function, if the first letter of the function name is not uppercase, then the package will not be exported. Therefore, when you define a function that needs to be exported, the
needs to capitalize the first letter of the letter.
• The name of the public function begins with an uppercase letter;
• The name of the private function starts with a lowercase caption.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.