I am creating a simple application and after reading the go application structuring document, I am still confused.
I want this structure:
- practice
- models (packaged as models)
- routers (packaged as routers)
app.go
Inside app.goI have the following:
package main
import (
"net/http"
// I have tried the following:
"practice/models/a"
"practice/models/b"
"practice/models"
"$GOPATH/practice/models/a"
"$GOPATH/practice/models/b"
"$GOPATH/practice/models"
...
)
func main() {
http.HandleFunc("/a", AHandler)
http.HandleFunc("/b", BHandler)
http.ListenAndServe(":8080", nil)
}
Models A and B are as follows:
package models
import "net/http"
func AHandler(w http.ResponseWriter, r *http.Request) {
}
Two questions:
What is the right way to import these files in the world? Do I really have to push them to github to be able to link to them? I understand that $ GOPATH is the namespace for the entire go workspace on the local machine. My $ GOPATH lists this directory.
Do I need to define the main method inside these files? Can I just export one function and it will be a processing function?
.
docs