使用Go管理和包含多个文件的最佳方法是什么?

I am experimenting with Go and the Google AppEngine, and I would like to have multiple files imported or included within a main file.

For example, suppose I have a file with an init that has multiple web url functions, such as:

func init() {
    http.HandleFunc("/", root)
    http.HandleFunc("/1", function1)
    http.HandleFunc("/two", function2)
    http.HandleFunc("/3hree", function3)
}

I would like to have each function be in a separate file (for example, so other developers can work on them independently -- or just for ease of readability when debugging).

I don't want to make separate packages for each function, because that seems like overkill, but I think that might be the only way to do this.

Another way of asking the same question:

If you wanted a separate file with just a template, what is the best way to have this be pulled into a go file (without having to have it be in-line):

const testPage =
`<!DOCTYPE html>
<html>
<body>
    <br>this is a test
</body>
</html>`

Your application can certainly be composed of multiple files (and multiple packages). Each of those files can have their own init() functions too, so you can register handlers in each file – or keep them central in a single file.

For example:

root.go:

package app
…
func init() {
  http.HandleFunc("/root", rootHandler)
}

func rootHandler(w http.ResponseWriter, r *http.Request) {
   …
}

other.go:

package app
…
func init() {
   http.HandleFunc("/1", oneHandler)
}

… etc.

It's best if you put your template HTML in its own files alongside your Go files, rather than embedding it within strings (you could store it in the datastore too, but that's a little more work). See how the demos in the SDK do it – the mandelbrot one does this with its map.html file.

On Google App Engine this isn't possible since you do not have access to the file system module for Go. You can't access files as a file system. Trust me. I've tried. :)

The best option like you have mentioned is inline. You could in theory have some separation by having each template as a package. But it is the same concept.

Another option which is kind of a hack is to store your templates in the GAE data store. But then you're paying for data store IO operations. And even then it's a hack which is the same as inlining.