package main
import "System"
func main() {
System.boot()
}package System
import (
"github.com/codegangsta/cli"
"github.com/gorilla/mux"
)
type app struct {
Cmd *cli.App
HTTPRouter *mux.Router
Ses *mgo.Session}
// App is a singleton throughout the application
var App = new(app)
// Boot bootstraps the application
func Boot() {
App.Cmd = cli.NewApp() App.HTTPRouter = mux.NewRouter()
App.Ses = mgo.Dial("mongodb://user:pa...@server.compose.io/db_name")
}package main
import "app"
func main() {
a := app.NewApp()
}
package app
import (
"github.com/codegangsta/cli"
"github.com/gorilla/mux"
"gopkg.in/mgo.v2"
)
type components struct {
Cmd *cli.App
HTTPRouter *mux.Router
Ses *mgo.Session
}
// NewApp provides new app instance
func NewApp() *app {
c := new(components)
c.Cmd = cli.NewApp() c.HTTPRouter = mux.NewRouter()
c.Ses = mgo.Dial("mongodb://user:pa...@server.compose.io/db_name")
a := new(app)
return c, a
}That depends on the things. Not all things work the same way. You may want to factor in other aspects such as how you want to test your code and general maintainability as well.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.