Exemple #1
0
func Start(port string, onStart func()) {

	// Logging init
	flag.Set("log_dir", utils.GetRuntimeDir(config.GetString("log_dir")))
	flag.Set("alsologtostderr", "true")
	flag.Parse()
	defer glog.Flush()

	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Charset:   "UTF-8", // Sets encoding for json and html content-types. Default is "UTF-8".
		Delims:    render.Delims{"${", "}"},
		Directory: utils.GetRuntimeDir("resources/views"),
	}))

	m.Use(martini.Static(utils.GetRuntimeDir("public")))
	controller.MappingController(m)

	http.Handle("/rpc", rpc.GetServer())
	http.Handle("/", m)

	if db.IsConnected() {
		defer db.Close()
	}

	onStart()

	for _, fn := range methods {
		go fn()
	}

	http.ListenAndServe(":"+port, nil)
}
Exemple #2
0
func Connect() {
	if err := orm.RegisterDataBase("default", "mysql", config.GetString("dataSourceName"), 30); err != nil {
		glog.Errorln(err)
		return
	}
	orm.RegisterModel(
		new(model.Group),
		new(model.WebServer),
		new(model.Config),
		new(model.Version),
	)
	log.Println("database connected")
	Db.Db, _ = orm.GetDB()
}
Exemple #3
0
func main() {
	port := "4000"
	argLen := len(os.Args)

	if argLen > 1 {
		port = os.Args[1]
	}

	log.Println("Running client on port", port)

	//设置Rpc地址
	config.Set("rpc", config.GetString("master")+"/rpc")

	bootstrap.Start(port, func() {
		//在服务器上添加自己,必须确定唯一属性
		host.Detail.Ip = "192.168.1.111"
		host.Detail.InternalIp = "192.168.1.111"
		host.Detail.Port = port
		host.Connect()
	})
}