• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang rpc.NewServer函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

func main() {
	s := rpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	s.RegisterService(new(StockService), "")
	http.Handle("/stock", s)
	http.ListenAndServe(":8080", nil)
}
开发者ID:Vishv19,项目名称:cmpe273-assignment1,代码行数:7,代码来源:rpcServer.go


示例2: main

func main() {

	//Creating stock records
	var st = (new(StockRecords))

	//TradeID Initialization
	tradeId = 0

	router := mux.NewRouter()
	server := rpc.NewServer()
	server.RegisterCodec(json.NewCodec(), "application/json")
	server.RegisterService(st, "")

	chain := alice.New(
		func(h http.Handler) http.Handler {
			return handlers.CombinedLoggingHandler(os.Stdout, h)
		},
		handlers.CompressHandler,
		func(h http.Handler) http.Handler {
			return recovery.Handler(os.Stderr, h, true)
		})

	router.Handle("/rpc", chain.Then(server))
	log.Fatal(http.ListenAndServe(":1333", server))

}
开发者ID:Noman-Khan-SJSU,项目名称:cmpe273-assignment1,代码行数:26,代码来源:Go-Server.go


示例3: Serve

//Serve adds the rpc service t to the net/http DefaultServeMux at the given path
//and allows future lookup with name.
func Serve(t interface{}, name string, path string) {
	s := rpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	s.RegisterService(t, name)
	http.Handle(path, s)
	servers[name] = path
}
开发者ID:kleopatra999,项目名称:goci,代码行数:9,代码来源:router.go


示例4: main

func main() {
	flag.Parse()

	session, err := r.Connect(r.ConnectOpts{
		Address:  *rethinkdbAddress,
		Database: *rethinkdbDatabase,
	})
	if err != nil {
		log.Fatal(err)
	}

	r.DB(*rethinkdbDatabase).TableCreate("scripts").Exec(session)
	r.DB(*rethinkdbDatabase).TableCreate("tokens").Exec(session)

	s := rpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	s.RegisterService(&service.Service{
		Session: session,
	}, "Rexd")
	http.Handle("/rpc", s)

	http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		w.Write([]byte("lavab/rexd 0.1.0\n"))
	})

	log.Printf("Binding to %s", *bindAddress)
	if err := http.ListenAndServe(*bindAddress, nil); err != nil {
		log.Fatal(err)
	}
}
开发者ID:Invacio,项目名称:rex,代码行数:30,代码来源:main.go


示例5: main

func main() {

	//initialize the stock account
	var st = (new(StockAccounts))

	//initialize a tradeId with random number
	tradeId = rand.Intn(10000) + 1

	// //register the stock account data and start server with HTTP protocol
	// rpc.Register(&st)
	// rpc.HandleHTTP()

	// //start listening
	// err := http.ListenAndServe(":1234", nil) //nil, no need for handler
	router := mux.NewRouter()
	server := rpc.NewServer()
	server.RegisterCodec(json.NewCodec(), "application/json")
	server.RegisterService(st, "")

	chain := alice.New(
		func(h http.Handler) http.Handler {
			return handlers.CombinedLoggingHandler(os.Stdout, h)
		},
		handlers.CompressHandler,
		func(h http.Handler) http.Handler {
			return recovery.Handler(os.Stderr, h, true)
		})

	router.Handle("/rpc", chain.Then(server))
	log.Fatal(http.ListenAndServe(":1234", server))

	// checkError(err)

}
开发者ID:michaelzhd,项目名称:CMPE273,代码行数:34,代码来源:stockserver_v2.go


示例6: TestService

func TestService(t *testing.T) {
	s := rpc.NewServer()
	s.RegisterCodec(NewCodec(), "application/json")
	s.RegisterService(new(Service1), "")

	var res Service1Response
	if _, err := execute(t, s, "Service1.Multiply", &Service1Request{4, 2}, &res); err != nil {
		t.Error("Expected err to be nil, but got:", err)
	}
	if res.Result != 8 {
		t.Errorf("Wrong response: %v.", res.Result)
	}
	if res.ErrorMessage != "" {
		t.Errorf("Expected error_message to be empty, but got:", res.ErrorMessage)
	}

	if code, err := execute(t, s, "Service1.ResponseError", &Service1Request{4, 2}, &res); err != nil || code != 500 {
		t.Errorf("Expected code to be 500 and error to be nil, but got", code, err)
	}
	if res.ErrorMessage == "" {
		t.Errorf("Expected error_message to be %q, but got %q", ErrResponseError, res.ErrorMessage)
	}

	if code, _ := execute(t, s, "Service1.Multiply", nil, &res); code != 400 {
		t.Errorf("Expected http response code 400, but got %v", code)
	}
}
开发者ID:richardjoo,项目名称:rpc,代码行数:27,代码来源:protorpc_test.go


示例7: Initialize

func Initialize(config *api.ApiConfig) error {

	e := localdb.Initialize(config.Log, config.LocalDB)

	if e != nil {
		return e
	}

	s := rpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	service := new(EMPService)
	service.Config = config
	s.RegisterService(service, "EMPService")

	// Register RPC Services
	http.Handle("/rpc", s)

	// Register JS Client
	http.Handle("/", http.FileServer(http.Dir(config.HttpRoot)))

	l, e := net.Listen("tcp", fmt.Sprintf(":%d", config.RPCPort))
	if e != nil {
		config.Log <- fmt.Sprintf("RPC Listen Error: %s", e)
		return e
	}

	go http.Serve(l, nil)

	go register(config)

	portStr := fmt.Sprintf(":%d", config.RPCPort)

	config.Log <- fmt.Sprintf("Started RPC Server on: %s", portStr)
	return nil
}
开发者ID:dcposch,项目名称:emp,代码行数:35,代码来源:localapi.go


示例8: New

//New returns a new Runner ready to be Announced and run tests on the
//heroku dyno grid.
func New(app, api string, tracker, hosted string) *Runner {
	n := &Runner{
		app:  app,
		api:  api,
		tcl:  client.New(tracker, http.DefaultClient, client.JsonCodec),
		base: hosted,
		rpc:  gorpc.NewServer(),
		rq:   rpc.NewRunnerQueue(),
		mc:   heroku.NewManaged(app, api, 2, 2*time.Minute),
		tm:   &runnerTaskMap{items: map[string]*runnerTask{}},
	}

	//register the run service in the rpc
	if err := n.rpc.RegisterService(n.rq, ""); err != nil {
		panic(err)
	}

	//register the pinger
	if err := n.rpc.RegisterService(pinger.Pinger{}, ""); err != nil {
		panic(err)
	}

	//register ourselves in the rpc
	if err := n.rpc.RegisterService(n, ""); err != nil {
		panic(err)
	}

	//register the codec
	n.rpc.RegisterCodec(json.NewCodec(), "application/json")

	//start processing
	go n.run()

	return n
}
开发者ID:kleopatra999,项目名称:goci,代码行数:37,代码来源:runner.go


示例9: New

//New returns a new web Builder ready to Announce to the given tracker. It
//announces that it is available at `hosted` which should be the full url of
//where this builder resides on the internet.
func New(b builder.Builder, tracker, hosted string) *Builder {
	//create our new builder
	n := &Builder{
		b:    b,
		base: hosted,
		rpc:  gorpc.NewServer(),
		tcl:  client.New(tracker, http.DefaultClient, client.JsonCodec),
		bq:   rpc.NewBuilderQueue(),
		mux:  http.NewServeMux(),
		dler: newDownloader(),
	}

	//register the build service in the rpc
	if err := n.rpc.RegisterService(n.bq, ""); err != nil {
		panic(err)
	}

	//make sure we respond to pings
	if err := n.rpc.RegisterService(pinger.Pinger{}, ""); err != nil {
		panic(err)
	}

	//register the codec
	n.rpc.RegisterCodec(json.NewCodec(), "application/json")

	//add the handlers to our mux
	n.mux.Handle("/", n.rpc)
	n.mux.Handle("/download/", http.StripPrefix("/download/", n.dler))

	//start processing tasks
	go n.run()

	return n
}
开发者ID:kleopatra999,项目名称:goci,代码行数:37,代码来源:builder.go


示例10: TestServiceBeforeAfter

func TestServiceBeforeAfter(t *testing.T) {
	s := rpc.NewServer()
	s.RegisterCodec(NewCodec(), "application/json")
	service := &Service1{}
	service.beforeAfterContext = map[string]string{}
	s.RegisterService(service, "")

	s.RegisterBeforeFunc(func(i *rpc.RequestInfo) {
		service.beforeAfterContext["before"] = "Before is true"
	})
	s.RegisterAfterFunc(func(i *rpc.RequestInfo) {
		service.beforeAfterContext["after"] = "After is true"
	})

	var res Service1Response
	if err := execute(t, s, "Service1.BeforeAfter", &Service1Request{}, &res); err != nil {
		t.Error("Expected err to be nil, but got:", err)
	}

	if res.Result != 1 {
		t.Errorf("Expected Result = 1, got %d", res.Result)
	}

	if afterValue, ok := service.beforeAfterContext["after"]; !ok || afterValue != "After is true" {
		t.Errorf("Expected after in context to be 'After is true', got %s", afterValue)
	}
}
开发者ID:alexclear,项目名称:rpc,代码行数:27,代码来源:json_test.go


示例11: main

func main() {

	//stock account Initialization
	var st = (new(StockAccounts))

	//Trade Id random generator
	tradeId = rand.Intn(99999) + 1

	//start listening
	router := mux.NewRouter()
	server := rpc.NewServer()
	server.RegisterCodec(json.NewCodec(), "application/json")
	server.RegisterService(st, "")

	chain := alice.New(
		func(h http.Handler) http.Handler {
			return handlers.CombinedLoggingHandler(os.Stdout, h)
		},
		handlers.CompressHandler,
		func(h http.Handler) http.Handler {
			return recovery.Handler(os.Stderr, h, true)
		})

	router.Handle("/rpc", chain.Then(server))
	log.Fatal(http.ListenAndServe(":8070", server))

}
开发者ID:imabdul,项目名称:cmpe273-assignment1,代码行数:27,代码来源:VirtualStockTradingServer.go


示例12: New

//New returns a new Runner ready to be Announced and run tests locally.
func New(runner, tracker, hosted string) *Runner {
	n := &Runner{
		tcl:    client.New(tracker, http.DefaultClient, client.JsonCodec),
		base:   hosted,
		runner: runner,
		rpc:    gorpc.NewServer(),
		rq:     rpc.NewRunnerQueue(),
		resp:   make(chan rpc.Output),
	}

	//register the run service in the rpc
	if err := n.rpc.RegisterService(n.rq, ""); err != nil {
		panic(err)
	}

	//register the pinger
	if err := n.rpc.RegisterService(pinger.Pinger{}, ""); err != nil {
		panic(err)
	}

	//register ourselves in the rpc
	if err := n.rpc.RegisterService(n, ""); err != nil {
		panic(err)
	}

	//register the codec
	n.rpc.RegisterCodec(json.NewCodec(), "application/json")

	//start processing
	go n.run()

	return n
}
开发者ID:kleopatra999,项目名称:goci,代码行数:34,代码来源:direct.go


示例13: TestFaults

func TestFaults(t *testing.T) {
	s := rpc.NewServer()
	s.RegisterCodec(NewCodec(), "text/xml")
	s.RegisterService(new(FaultTest), "")

	var err error

	var res1 FaultTestResponse
	err = execute(t, s, "FaultTest.Multiply", &FaultTestBadRequest{4, 2, 4}, &res1)
	if err == nil {
		t.Error("Expected err to be not nil, but got:", err)
	}
	if err.Error() != "Wrong number of arguments" {
		t.Errorf("Wrong response: %v.", err.Error())
	}

	var res2 FaultTestBadResponse
	err = execute(t, s, "FaultTest.Multiply", &FaultTestRequest{4, 2}, &res2)
	if err == nil {
		t.Error("Expected err to be not nil, but got:", err)
	}
	if !strings.HasPrefix(err.Error(), "Fields type mismatch") {
		t.Errorf("Wrong response: %v.", err.Error())
	}
}
开发者ID:kzjeef,项目名称:gorilla-xmlrpc,代码行数:25,代码来源:fault_test.go


示例14: main

func main() {
	Portfolios = make(map[float32]Portfolio)

	// HTTP request multiplexer
	// mux.Router matches incoming requests against a list of registered routes
	// and calls a handler for the route that matches the URL
	r := mux.NewRouter()

	s := rpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")

	stockDealer := new(StockDealer)
	s.RegisterService(stockDealer, "")

	// middle ware: organizing  hared functionalities
	chain := alice.New(
		func(h http.Handler) http.Handler {
			return handlers.CombinedLoggingHandler(os.Stdout, h)
		},
		handlers.CompressHandler,
		func(h http.Handler) http.Handler {
			return recovery.Handler(os.Stderr, h, true)
		})

	r.Handle("/rpc", chain.Then(s))
	fmt.Println("Server listening on 8080")
	log.Fatal(http.ListenAndServe(":8080", r))
}
开发者ID:gyoho,项目名称:cmpe273-assignment1,代码行数:28,代码来源:server.go


示例15: main

func main() {
	createHashTable()
	s := rpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	s.RegisterService(new(StockMarket), "")
	http.Handle("/rpc", s)
	http.ListenAndServe("localhost:10000", nil)
}
开发者ID:snsaraswathi,项目名称:cmpe273-assignment1,代码行数:8,代码来源:server.go


示例16: main

func main() {
	fmt.Println("preparing butler service")
	s := rpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	s.RegisterService(new(butler.Butler), "")
	http.Handle("/rpc", s)
	http.ListenAndServe(":10080", nil)
}
开发者ID:ryozaki,项目名称:gpaas,代码行数:8,代码来源:main.go


示例17: jsonRpcService

func jsonRpcService() *rpc.Server {
	s := rpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	s.RegisterService(new(KeyService), "")
	s.RegisterService(new(NameService), "")
	s.RegisterService(new(BlockService), "")
	return s
}
开发者ID:josephyzhou,项目名称:gitchain,代码行数:8,代码来源:rpc.go


示例18: main

func main() {
	fmt.Println("Starting service")
	s := rpc.NewServer()
	s.RegisterCodec(json.NewCodec(), "application/json")
	s.RegisterService(new(StringService), "")
	http.Handle("/rpc", s)
	http.ListenAndServe(":10000", nil)
}
开发者ID:jacobxk,项目名称:masteringwebservices,代码行数:8,代码来源:ch3_5_jsonrpc.go


示例19: GetServer

func GetServer() *rpc.Server {
	s := rpc.NewServer()
	s.RegisterCodec(rpcJSON.NewCodec(), "application/json")

	for _, v := range rpcCtrlList {
		s.RegisterService(v, "")
	}
	return s
}
开发者ID:sdgdsffdsfff,项目名称:svnmanager,代码行数:9,代码来源:rpc.go


示例20: main

func main() {
	server := rpc.NewServer()
	codec := json.NewCodec()
	server.RegisterCodec(codec, "application/json")
	server.RegisterCodec(codec, "application/json; charset=UTF-8") // For firefox 11 and other browsers which append the charset=UTF-8
	server.RegisterService(new(Service), "")
	http.Handle("/rpc", server)
	http.ListenAndServe("127.0.0.1:8080", nil)
}
开发者ID:chenjie1982,项目名称:CMPE273_Assignment1,代码行数:9,代码来源:server.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang rpc.Server类代码示例发布时间:2022-05-23
下一篇:
Golang pat.Router类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap