Error in importing custom packages in Go Lang

前端 未结 3 344
有刺的猬
有刺的猬 2021-02-01 13:11

I have created a library by the name libfastget which is in the src with my program as

src
|-libfastget
|  |-libfastget.go
|
|-MainPro         


        
3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-01 13:36

    you would need to make your function exportable with an uppercase for its name:

    func Fastget(...
    

    Used as:

    n:=libfastget.Fastget(url,4,filename)
    

    The spec mentions: "Exported identifiers":

    An identifier may be exported to permit access to it from another package. An identifier is exported if both:

    • the first character of the identifier's name is a Unicode upper case letter (Unicode class "Lu"); and
    • the identifier is declared in the package block or it is a field name or method name.

    All other identifiers are not exported.

提交回复
热议问题