示例#1
0
文件: example.go 项目: wtertius/gorpc
func main() {
	hm := gorpc.NewHandlersManager("github.com/sergei-svistunov/gorpc", gorpc.HandlersManagerCallbacks{})

	hm.MustRegisterHandler(test_handler1.NewHandler())

	// API
	http.Handle("/", http_json.NewAPIHandler(hm, nil, http_json.APIHandlerCallbacks{
		OnError: func(ctx context.Context, w http.ResponseWriter, req *http.Request, resp interface{}, err *gorpc.CallHandlerError) {
			log.Println(err.Error())
		},
		OnPanic: func(ctx context.Context, w http.ResponseWriter, r interface{}, trace []byte, req *http.Request) {
			log.Println(r, "\n", string(trace))
		},
	}))

	// Docs
	http.Handle("/swagger.json", http_json.NewSwaggerJSONHandler(hm, 0, http_json.SwaggerJSONCallbacks{}))
	http.Handle("/docs/", http.StripPrefix("/docs", swagger_ui.NewHTTPHandler()))

	// Client SDK
	http.Handle("/client.go", http_json_adapter.NewHandler(hm))

	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		log.Fatal(err)
	}

	//	e := client.NewExample(nil, nil, client.Callbacks{})
	//	_, err = e.TestHandler1V1(context.Background(), client.TestHandler1V1Args{})
	//	if apiErr, ok := err.(*client.ServiceError); ok {
	//		log.Println(apiErr.Code, apiErr.Error())
	//	} else {
	//		panic(err)
	//	}
}
示例#2
0
func main() {
	hm := gorpc.NewHandlersManager("github.com/sergei-svistunov/gorpc", gorpc.HandlersManagerCallbacks{}, &DummyCache{}, 0)

	if err := hm.RegisterHandler(test_handler1.NewHandler()); err != nil {
		panic(err)
	}

	http.Handle("/", http_json.NewAPIHandler(hm, http_json.APIHandlerCallbacks{}))
	http.Handle("/swagger.json", http_json.NewSwaggerJSONHandler(hm))
	http.Handle("/docs/", http.StripPrefix("/docs", swagger_ui.NewHTTPHandler()))

	http.ListenAndServe(":8080", nil)
}
示例#3
0
func main() {
	hm := gorpc.NewHandlersManager("github.com/sergei-svistunov/gorpc-tutor/server/handlers", gorpc.HandlersManagerCallbacks{})

	hm.MustRegisterHandlers(
		handlerHelloWorld.NewHandler(),
		handlerCalcSum.NewHandler(),
	)

	// Base API location
	http.Handle("/", http_json.NewAPIHandler(hm, nil, http_json.APIHandlerCallbacks{}))

	// Docs
	http.Handle("/swagger.json", http_json.NewSwaggerJSONHandler(hm, 0, http_json.SwaggerJSONCallbacks{}))
	http.Handle("/docs/", http.StripPrefix("/docs", swagger_ui.NewHTTPHandler()))

	// Client SDK
	http.Handle("/client.go", adapter.NewHandler(hm))

	if err := http.ListenAndServe(":8080", nil); err != nil {
		panic(err)
	}

}