Ejemplo n.º 1
0
// getControllerRPCHandler rpc handler for controller
func getControllerRPCHandler() http.Handler {
	s := jsonrpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	s.RegisterService(new(controllerRPCService), "Controller")
	// Add new RPC services here
	return registerRPC(router.NewRouter(), s)
}
Ejemplo n.º 2
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()))})
}
Ejemplo n.º 3
0
func main() {

	// parse flags
	flag.BoolVar(&seed, "s", seed, "seed db with data and exit")
	flag.StringVar(&addr, "addr", addr, "Exchange listening address")
	flag.IntVar(&port, "port", port, "Exchange listening port")
	flag.StringVar(&dbHost, "dbhost", dbHost, "Aerospike host")
	flag.IntVar(&dbPort, "dbport", dbPort, "Aerospike port")
	flag.Parse()

	listen := fmt.Sprintf("%s:%d", addr, port)

	// defined in db.gp
	connectToDatabase(dbHost, dbPort)

	if seed {
		seed_db()
		os.Exit(0)
	}

	runtime.GOMAXPROCS(runtime.NumCPU())

	///////////////////////////////////////////////////////////////////////////////////
	//
	// START SERVER
	//
	///////////////////////////////////////////////////////////////////////////////////

	// Use this for broadcasting messages to all brokers
	broadcaster := NewBroadcaster(broadcast)
	go broadcaster.Listen()

	// services
	command := new(Command)

	// export services
	rpcServer := rpc.NewServer()
	rpcServer.RegisterCodec(json.NewCodec(), "application/json")
	rpcServer.RegisterService(command, "")

	// routes
	httpRouter := http.NewServeMux()
	httpRouter.Handle("/rpc", rpcServer)
	httpRouter.HandleFunc("/ws", broadcaster.Serve)

	// server
	httpServer := &http.Server{
		Addr:           listen,
		Handler:        httpRouter,
		ReadTimeout:    1 * time.Second,
		WriteTimeout:   1 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}

	// start
	log.Printf("Starting HTTP on http://%s\n", listen)
	fmt.Fprintf(os.Stdout, "Starting HTTP on http://%s\n", listen)

	log.Panic(httpServer.ListenAndServe())
}
Ejemplo n.º 4
0
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...)
}
Ejemplo n.º 5
0
func getServerRPCHandler() http.Handler {
	s := jsonrpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	s.RegisterService(new(serverRPCService), "Server")
	mux := router.NewRouter()
	mux.Handle("/rpc", s)
	return mux
}
Ejemplo n.º 6
0
// getControllerRPCHandler rpc handler for controller
func getControllerRPCHandler() http.Handler {
	s := jsonrpc.NewServer()
	codec := json.NewCodec()
	s.RegisterCodec(codec, "application/json")
	s.RegisterCodec(codec, "application/json; charset=UTF-8")
	s.RegisterService(new(controllerRPCService), "Controller")
	mux := router.NewRouter()
	// Add new RPC services here
	mux.Handle("/rpc", s)
	mux.Handle("/{file:.*}", http.FileServer(assetFS()))
	return mux
}
Ejemplo n.º 7
0
func getServerRPCHandler(anonymous bool) http.Handler {
	var mwHandlers = []MiddlewareHandler{
		TimeValidityHandler,
	}
	if !anonymous {
		mwHandlers = append(mwHandlers, RPCSignatureHandler)
	}

	s := jsonrpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	s.RegisterService(new(serverRPCService), "Server")
	s.RegisterService(new(donutRPCService), "Donut")
	mux := router.NewRouter()
	mux.Handle("/rpc", s)

	rpcHandler := registerCustomMiddleware(mux, mwHandlers...)
	return rpcHandler
}
Ejemplo n.º 8
0
// getControllerRPCHandler rpc handler for controller
func getControllerRPCHandler(anonymous bool) http.Handler {
	var mwHandlers = []MiddlewareHandler{
		TimeValidityHandler,
	}
	if !anonymous {
		mwHandlers = append(mwHandlers, RPCSignatureHandler)
	}

	s := jsonrpc.NewServer()
	codec := json.NewCodec()
	s.RegisterCodec(codec, "application/json")
	s.RegisterCodec(codec, "application/json; charset=UTF-8")
	s.RegisterService(new(controllerRPCService), "Controller")
	mux := router.NewRouter()
	// Add new RPC services here
	mux.Handle("/rpc", s)
	mux.Handle("/{file:.*}", http.FileServer(assetFS()))

	rpcHandler := registerCustomMiddleware(mux, mwHandlers...)
	return rpcHandler
}
Ejemplo n.º 9
0
func getWebAPIHandler(web *WebAPI) http.Handler {
	var mwHandlers = []MiddlewareHandler{
		TimeValidityHandler, // Validate time.
		CorsHandler,         // CORS added only for testing purposes.
	}
	if web.AccessLog {
		mwHandlers = append(mwHandlers, AccessLogHandler)
	}

	s := jsonrpc.NewServer()
	codec := json.NewCodec()
	s.RegisterCodec(codec, "application/json")
	s.RegisterCodec(codec, "application/json; charset=UTF-8")
	s.RegisterService(web, "Web")
	mux := router.NewRouter()
	// Add new RPC services here
	mux.Handle("/rpc", s)
	// Enable this when we add assets.
	// mux.Handle("/{file:.*}", http.FileServer(assetFS()))
	return registerCustomMiddleware(mux, mwHandlers...)
}