将Go程序源导入为库

I have found code on github in Go and want to use it as library in my program. Unfortunately, whole code is in "main" package. Is there any way how I can import the code as library without changing that code?

No. Fork the repo, and fix it to work as a library, or if it's simple enough, copy the files directly into your main package.

you can import it as a separate package, something like:

import sth "path/to/your/package"

No, you can't.

Agree with @JimB - fork repo and change it like 'package main' > 'package lib' and import in your code like that:

package main

import L "somelib"

func main() {
    L.SomeFunc()
}

etc..