示例#1
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 := json.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...)
}
示例#2
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)
}
示例#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())
}
示例#4
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
}
示例#5
0
func Run() {
	go func() {
		s := rpc.NewServer()
		s.RegisterCodec(json.NewCodec(), "application/json")
		if err := s.RegisterService(new(AppCollectorService), ""); err != nil {
			log.Fatal(err)
		}
		http.Handle("/rpc", s)
		log.Fatal(http.ListenAndServe(":8888", nil))
	}()
}
示例#6
0
文件: rpcsvc.go 项目: daeira/plugins
func Serve(name, addr string, rcvr interface{}) {
	mux := http.NewServeMux()
	s := rpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	s.RegisterService(rcvr, name)
	mux.Handle("/", s)

	// TODO: register Plugin with host:port method
	log.Println("serving on", addr)
	graceful.Run(addr, 10*time.Second, mux)
	// TODO: deregister Plugin with host:port method
}
示例#7
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
}
示例#8
0
文件: server.go 项目: CodAdam/coco
func main() {
	s := rpc.NewServer()
	log.Printf("API Server started")
	s.RegisterCodec(json.NewCodec(), "application/json")
	provisioning := new(Provisioning)
	s.RegisterService(provisioning, "")
	log.Printf("Register Provisioning service")
	r := mux.NewRouter()
	r.Handle("/v1", s)
	log.Printf("Handle API version 1")
	log.Printf("Listen on port 7000")
	http.ListenAndServe(":7000", r)
}
示例#9
0
func main() {
	s := rpc.NewServer()
	log.Printf("Playback API started")
	s.RegisterCodec(json.NewCodec(), "application/json")
	openstack := new(openstack.OpenStack)
	s.RegisterService(openstack, "")
	log.Printf("Register OpenStack service")
	r := mux.NewRouter()
	r.Handle("/v1", s)
	log.Printf("Handle API version 1")
	log.Printf("Listen on port 7001")
	http.ListenAndServe(":7001", r)
}
示例#10
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
}
示例#11
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
}
示例#12
0
文件: routers.go 项目: m120/minio
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...)
}
示例#13
0
文件: server.go 项目: flandr/minio
// RegisterJSONCodec - register standard json codec
func (s Server) RegisterJSONCodec() {
	s.RPCServer.RegisterCodec(json.NewCodec(), "application/json")
}
示例#14
0
文件: rpc.go 项目: kahing/minio
// NewServer - provide a new instance of RPC server
func NewServer() *Server {
	s := &Server{}
	s.Server = rpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	return s
}