Пример #1
0
func RunSrv(args []string) {
	// netw.ShowLog = true
	// impl.ShowLog = true

	cfile := "conf/ebs.properties"
	if len(args) > 1 {
		cfile = args[1]
	}
	fmt.Println("Using config file:", cfile)
	err := conf.Cfg.InitWithFilePath(cfile)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println(dbMgr.Init("mysql", conf.DbConn()))

	p := pool.NewBytePool(8, 1024) //memory pool.
	l, cc, cms := impl.NewChanExecListener_m_j(p, conf.RC_ADDR(), netw.NewCWH(true))
	cms.AddHFunc("create-bank", CreateBank)
	cms.AddHFunc("edit-bank", EditBank)
	cms.AddHFunc("list-bank-question", ListBankQuestion)
	cms.AddHFunc("list-bank-paper", ListBankPaper)
	cms.AddHFunc("update-bank-paper", UpdateBankPaper)
	cms.AddHFunc("get-bank-paper-score", GetBankPaperScore)
	cms.AddHFunc("get-bank-item-cnt", GetBankItemCnt)
	cms.AddHFunc("get-usr-paper-record", GetUsrPaperRecord)
	cms.AddHFunc("attended-bank-info", AttendBankInfo)
	cc.Run(runtime.NumCPU() - 1) //start the chan distribution, if not start, sub handler will not receive message
	err = l.Run()                //run the listen server
	if err != nil {
		panic(err.Error())
	}
	l.Wait()
}
Пример #2
0
func init() {
	s, _ := os.Getwd()
	fmt.Println("pwd:", s)
	arr := strings.Split(s, "src")
	confPath := arr[0] + "conf/ebs.properties"
	fmt.Println("conf file path is:", confPath)
	fmt.Println(conf.Cfg.InitWithFilePath(confPath))
	DEM.G_Dn = "mysql"
	//setting database connection
	DEM.G_Dsn = conf.TestDbConn()
	//	DEM.G_Dsn = "cny:123@tcp(127.0.0.1:3306)/rcpv2_test?charset=utf8"
	fmt.Println("db init err:", dbMgr.Init("DEM", conf.TestDbConn()))
	//	fmt.Println("db init err:", dbMgr.Init("DEM", "cny:123@tcp(127.0.0.1:3306)/rcpv2_test?charset=utf8"))
	t_conn = dbMgr.DbConn()

}
Пример #3
0
func run(args []string) {
	defer StopSrv()
	cfile := "conf/ebs.properties"
	if len(args) > 1 {
		cfile = args[1]
	}
	fmt.Println("Using config file:", cfile)
	err := conf.Cfg.InitWithFilePath(cfile)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	uap_conf.Cfg = conf.Cfg

	//init js conf
	conf.JsConf()

	log.I("Config:\n%v", conf.Cfg.Show())
	//test connect
	if len(conf.DbConn()) < 1 {
		fmt.Println("DB_CONN is not exist in config")
		return
	}

	// uri := "mongodb://*****:*****@192.168.2.30:27017/fs"
	// dbName := "fs"
	//	err = trak.DbInit(conf.TRACE_DB_CONN(), conf.TRACE_DB())
	//	if err != nil {
	//		panic(fmt.Sprintf("connect mongodb err %v", err.Error()))
	//	}

	dbMgr.Init("mysql", conf.DbConn())
	uap.InitDb(dbMgr.DbConn)
	usr.CheckUcs(dbMgr.DbConn())

	if err := nets.RedirectLog(conf.LOG_ADDR(), conf.LOG_PORT(), conf.LOG_KEY(), true); err != nil {
		fmt.Println("remote log error:", err)
	}
	sinfo := `{"description": "ebs接口文档",
    "version": "1.0.0",
    "title": "ebs接口文档"
    }`
	infoParse := map[string]interface{}{}
	json.Unmarshal([]byte(sinfo), &infoParse)
	go_swagger.NewH().InitSwagger(go_swagger.Swagger{
		SwaggerVersion: "2.0",
		Info:           infoParse,
		Host:           "ebs2.dev.jxzy.com",
		BasePath:       "",
		Schemes:        []string{"http"},
	}).AddTag(go_swagger.Tag{Name: "answer", Description: "作答相关接口"})

	//
	//
	mux := http.NewServeMux()
	mux.Handle("/", NewSrvMux(mux, "", "www"))
	log.D("running server on %s", conf.ListenAddr())
	s := http.Server{Addr: conf.ListenAddr(), Handler: mux}
	err = s.ListenAndServe()
	if err != nil {
		fmt.Println(err)
	}
}