How to run all .go files within current directory through the command line (multi file package)

前端 未结 11 2545
滥情空心
滥情空心 2020-12-08 01:49

I\'m a newcomer to Go. I extremely like the language, but I quickly realised that I needed to start dividing my files due to an increase in program size.

go r

11条回答
  •  自闭症患者
    2020-12-08 02:37

    If i understand your question right, you need import other code as libraries.

    Little example

    ./testing/main.go:

    package main
    
    import "fmt"
    import L "testing/lib"
    
    func main() {
        fmt.Println("Hello from main()")
        L.Somefunc()
    }
    

    ./testing/lib/somelib.go:

    package lib
    
    import "fmt"
    
    func Somefunc() {
        fmt.Println("Hello from Somefunc()")
        return
    }
    

    To launch - go run main.go

提交回复
热议问题