Example #1
0
File: init.go Project: shaovie/go
func initSvc() (err error) {
	if err = ilog.Open(ServerConfig.LogFile); err != nil {
		return err
	}

	// Init randdom generater
	rand.Seed(time.Now().UnixNano())

	err = mc.Init(ServerConfig.MC.Host, ServerConfig.MC.Port, "mc")
	if err != nil {
		ilog.Error("mc - init fail! " + err.Error())
	}

	err = nosql.Init(ServerConfig.Nosql.Host, ServerConfig.Nosql.Port, "nosql")
	if err != nil {
		ilog.Error("nosql - init fail! " + err.Error())
	}

	err = db.Init(ServerConfig.DB.Host,
		ServerConfig.DB.Port,
		ServerConfig.DB.User,
		ServerConfig.DB.Passwd,
		ServerConfig.DB.Charset,
		ServerConfig.DB.Name)
	if err != nil {
		ilog.Error("db - init fail! " + err.Error())
	}

	return err
}
Example #2
0
func main() {

	// Set the static directory for webgo
	path := os.Getenv("GOPATH")
	if path == "" {
		fmt.Println("GOPATH NOT SET")
		return
	}
	filepath := fmt.Sprintf("%s/../frontend/src/", path)
	web.Config.StaticDir = filepath

	// Setup logging
	log := make(l4g.Logger)
	// Create a default logger that is logging messages of FINE or higher
	l4g.AddFilter("file", l4g.FINE, l4g.NewFileLogWriter("error_log.log", false))
	log.Close()

	// Setup the DB
	db.Init(path)

	// Parse command line arguments
	port := flag.Int("port", 80, "port number to start the server on")
	flag.Parse()
	url := fmt.Sprintf("0.0.0.0:%d", *port)

	// Start the server!
	serve.Routes()
	web.Run(url)
}