예제 #1
0
파일: server.go 프로젝트: DrHayt/gorpc
func main() {
	// s := rpcv2.NewServer()
	s := rpc
	s.RegisterCodec(json2.NewCodec(), "application/json")
	s.RegisterCodec(json2.NewCodec(), "application/json;charset=UTF-8")
	arith := new(arith.Arith)
	utility := new(utility.Utility)
	s.RegisterService(arith, "")
	s.RegisterService(utility, "")
	r := mux.NewRouter()
	r.Handle("/rpc", s)
	http.ListenAndServe(":1234", r)
}
예제 #2
0
파일: jsonrpc.go 프로젝트: donh/query
// Initialize mock JSONRPC server for NQM log
// You may use "test.mockrpc.port" to customize port of HTTP for it
func StartMockJsonRpcServer(c *C, jsonrpcServiceSetupFunc func(*rpc.Server)) {
	if testHttpServer != nil {
		return
	}

	flag.Parse()

	jsonrpcService := rpc.NewServer()
	jsonrpcService.RegisterCodec(json2.NewCodec(), "application/json")
	jsonrpcServiceSetupFunc(jsonrpcService)

	/**
	 * Set-up HTTP server for testing
	 */
	testHttpServer = httptest.NewUnstartedServer(jsonrpcService)
	listener, err := net.Listen("tcp", "127.0.0.1:"+*mockRpcPort)
	if err != nil {
		panic(err)
	}
	testHttpServer.Listener = listener
	testHttpServer.Start()
	// :~)

	rpcServiceCaller = jsonrpc.NewService(testHttpServer.URL)

	c.Logf("Test HTTP Server: \"%v\"", testHttpServer.URL)
}
예제 #3
0
// registerWebRouter - registers web router for serving minio browser.
func registerWebRouter(mux *router.Router, web *webAPIHandlers) {
	// Initialize a new json2 codec.
	codec := json2.NewCodec()

	// Minio browser router.
	webBrowserRouter := mux.NewRoute().PathPrefix(reservedBucket).Subrouter()

	// Initialize json rpc handlers.
	webRPC := jsonrpc.NewServer()
	webRPC.RegisterCodec(codec, "application/json")
	webRPC.RegisterCodec(codec, "application/json; charset=UTF-8")
	webRPC.RegisterService(web, "Web")

	// RPC handler at URI - /minio/webrpc
	webBrowserRouter.Methods("POST").Path("/webrpc").Handler(webRPC)
	webBrowserRouter.Methods("PUT").Path("/upload/{bucket}/{object:.+}").HandlerFunc(web.Upload)
	webBrowserRouter.Methods("GET").Path("/download/{bucket}/{object:.+}").Queries("token", "{token:.*}").HandlerFunc(web.Download)

	// Add compression for assets.
	compressedAssets := handlers.CompressHandler(http.StripPrefix(reservedBucket, http.FileServer(assetFS())))

	// Serve javascript files and favicon from assets.
	webBrowserRouter.Path(fmt.Sprintf("/{assets:[^/]+.js|%s}", specialAssets)).Handler(compressedAssets)

	// Serve index.html for rest of the requests.
	webBrowserRouter.Path("/{index:.*}").Handler(indexHandler{http.StripPrefix(reservedBucket, http.FileServer(assetFS()))})
}
예제 #4
0
func init() {
	s := rpc.NewServer()
	s.RegisterCodec(json2.NewCodec(), "application/json")
	s.RegisterService(new(HelloService), "")
	http.Handle("/", s)
	go http.ListenAndServe("127.0.0.1:9097", nil)
}
예제 #5
0
파일: routers.go 프로젝트: nohitall/minio
func getWebAPIHandler(web *WebAPI) http.Handler {
	var handlerFns = []HandlerFunc{
		setCacheControlHandler, // Adds Cache-Control header
		setTimeValidityHandler, // Validate time.
		setJWTAuthHandler,      // Authentication handler for verifying JWT's.
		setCorsHandler,         // CORS added only for testing purposes.
	}
	if web.AccessLog {
		handlerFns = append(handlerFns, setAccessLogHandler)
	}

	s := jsonrpc.NewServer()
	codec := json2.NewCodec()
	s.RegisterCodec(codec, "application/json")
	s.RegisterCodec(codec, "application/json; charset=UTF-8")
	s.RegisterService(web, "Web")
	mux := router.NewRouter()
	// Root router.
	root := mux.NewRoute().PathPrefix("/").Subrouter()
	root.Handle("/rpc", s)

	// Enable this when we add assets.
	root.PathPrefix("/login").Handler(http.StripPrefix("/login", http.FileServer(assetFS())))
	root.Handle("/{file:.*}", http.FileServer(assetFS()))
	return registerHandlers(mux, handlerFns...)
}
예제 #6
0
func (server *JsonDriverServer) StartServer() error {
	s := rpc.NewServer()
	s.RegisterCodec(json2.NewCodec(), "application/json-rpc")
	s.RegisterService(new(PinProtocol), "")
	s.RegisterService(new(FinProtocol), "")
	s.RegisterService(new(PingjiaProtocol), "")
	s.RegisterService(new(MsfProtocol), "")
	s.RegisterService(new(IcProtocol), "")
	s.RegisterService(new(IdcProtocol), "")
	s.RegisterService(new(DebugProtocol), "")
	s.RegisterService(new(ConfigProtocol), "")
	s.RegisterService(new(Pr2Protocol), "")
	http.Handle("/rpc", s)
	p := strconv.Itoa(server.Port)
	var err error
	//具有多个ip

	err = http.ListenAndServe("0.0.0.0:"+p, nil)
	utils.Info("json rpc server start listening ip 0.0.0.0 port %s", p)
	if err != nil {
		utils.Error("start listening ip 0.0.0.0 error:%s", err.Error())
	}

	return nil
}
예제 #7
0
func init() {
	log.Println("table8_restaurant_api.init() ... starting")
	rpc_v2 := rpc.NewServer()
	rpc_v2.RegisterCodec(json2.NewCodec(), "application/json")
	app.Register(rpc_v2)

	log.Println("table8_restaurant_api.init() ... ready")
	http.Handle("/restaurant/0.1/", rpc_v2)
}
예제 #8
0
func Serve(port string, handlers []RpcHandler) {
	r := mux.NewRouter()
	for _, handler := range handlers {
		s := rpc.NewServer()
		s.RegisterCodec(json2.NewCodec(), "application/json")
		s.RegisterService(handler.Service, "")
		r.Handle(handler.Path, s)
	}

	endless.DefaultHammerTime = -1
	endless.ListenAndServe(":"+port, r)
}
예제 #9
0
func init() {
	Server = rpc.NewServer()
	Server.RegisterCodec(json2.NewCodec(), "application/json-rpc")
	http.Handle(HTTPEndpoint, Server)
}