コード例 #1
0
ファイル: main.go プロジェクト: proudlily/Auth_ser
func main() {
	flag.Usage = Usage
	protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)")
	transport := flag.String("transport", "binary", "Specify transport (framed, buffered, file, memory, zlib)")

	buffered := flag.String("buffered", "off", "Use buffered transport")
	framed := flag.String("framed", "off", "Use framed transport")

	addr := flag.String("addr", "localhost:9090", "Address to listen to")
	secure := flag.Bool("secure", false, "Use tls secure transport")

	conf_path := flag.String("conf", "nil", "配置文件路径")

	flag.Parse()

	if *conf_path == "nil" {
		Usage()
		os.Exit(1)
	}

	var protocolFactory thrift.TProtocolFactory
	switch *protocol {
	case "compact":
		protocolFactory = thrift.NewTCompactProtocolFactory()
	case "simplejson":
		protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
	case "json":
		protocolFactory = thrift.NewTJSONProtocolFactory()
	case "binary":
		protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
	default:
		fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
		Usage()
		os.Exit(1)
	}

	var transportFactory thrift.TTransportFactory

	if *buffered == "on" {
		transportFactory = thrift.NewTBufferedTransportFactory(8192)
	} else {
		transportFactory = thrift.NewTTransportFactory()
	}

	if *framed == "on" {
		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	}

	//获取配置文件的路径
	complete_path(conf_path)
	//初始化控制层
	handler.Init(*conf_path)

	if err := runServer(transportFactory, *transport, protocolFactory, *addr, *secure); err != nil {
		fmt.Println("error running server:", err)
	}

}
コード例 #2
0
ファイル: main.go プロジェクト: proudlily/Auth_ser
func main() {
	//获取执行参数
	conf_path := flag.String("conf", "", "配置文件路径")
	flag.Parse()
	//获取配置文件的路径
	complete_path(conf_path)
	//初始化控制层
	handler.Init(*conf_path)

	e := echo.New()
	//调试测试
	e.Use(mw.Logger())
	e.Use(mw.Recover())
	//添加跨域cors
	e.Use(cors.Default().Handler)

	// Routes
	e.Post("/Login", UserLogin)
	e.Post("/Register", UserRegister)
	e.Run(":9091")
}