当前位置: 首页>>代码示例>>Golang>>正文


Golang json.NewCodec函数代码示例

本文整理汇总了Golang中github.com/gorilla/rpc/v2/json.NewCodec函数的典型用法代码示例。如果您正苦于以下问题:Golang NewCodec函数的具体用法?Golang NewCodec怎么用?Golang NewCodec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewCodec函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getWebAPIHandler

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...)
}
开发者ID:pirogoeth,项目名称:minio,代码行数:26,代码来源:routers.go

示例2: getControllerRPCHandler

// 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)
}
开发者ID:solderzzc,项目名称:minio,代码行数:8,代码来源:controller-router.go

示例3: main

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())
}
开发者ID:investislife,项目名称:stock-exchange,代码行数:60,代码来源:exchange.go

示例4: getServerRPCHandler

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
}
开发者ID:StorageTW,项目名称:minio,代码行数:8,代码来源:server-router.go

示例5: Run

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))
	}()
}
开发者ID:souche-open,项目名称:smoni,代码行数:11,代码来源:rpcserver.go

示例6: Serve

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
}
开发者ID:daeira,项目名称:plugins,代码行数:12,代码来源:rpcsvc.go

示例7: getControllerRPCHandler

// 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
}
开发者ID:technosophos,项目名称:minio,代码行数:13,代码来源:controller-router.go

示例8: main

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)
}
开发者ID:CodAdam,项目名称:coco,代码行数:13,代码来源:server.go

示例9: main

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)
}
开发者ID:zhangxuekun,项目名称:fastforward,代码行数:13,代码来源:playback-api.go

示例10: getServerRPCHandler

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
}
开发者ID:harshavardhana,项目名称:minio-xl,代码行数:18,代码来源:routers.go

示例11: getControllerRPCHandler

// 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
}
开发者ID:harshavardhana,项目名称:minio-xl,代码行数:22,代码来源:routers.go

示例12: getWebAPIHandler

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...)
}
开发者ID:m120,项目名称:minio,代码行数:21,代码来源:routers.go

示例13: RegisterJSONCodec

// RegisterJSONCodec - register standard json codec
func (s Server) RegisterJSONCodec() {
	s.RPCServer.RegisterCodec(json.NewCodec(), "application/json")
}
开发者ID:flandr,项目名称:minio,代码行数:4,代码来源:server.go

示例14: NewServer

// 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
}
开发者ID:kahing,项目名称:minio,代码行数:7,代码来源:rpc.go


注:本文中的github.com/gorilla/rpc/v2/json.NewCodec函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。