本文整理汇总了Golang中rpc.HandleHTTP函数的典型用法代码示例。如果您正苦于以下问题:Golang HandleHTTP函数的具体用法?Golang HandleHTTP怎么用?Golang HandleHTTP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HandleHTTP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var err os.Error
// Pull in command line options or defaults if none given
flag.Parse()
f, err := os.OpenFile(*skylib.LogFileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err == nil {
defer f.Close()
log.SetOutput(f)
}
skylib.Setup(sName)
homeTmpl = template.MustParse(homeTemplate, nil)
respTmpl = template.MustParse(responseTemplate, nil)
http.HandleFunc("/", homeHandler)
http.HandleFunc("/new", submitHandler)
rpc.HandleHTTP()
portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port)
err = http.ListenAndServe(portString, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err.String())
}
}
示例2: main
func main( )
{
rpc.HandleHTTP();
l, _ := net.Listen("tcp", ":8089");
http.Serve(l, http.HandlerFunc( handleRequest ) );
}
示例3: main
func main() {
// Pull in command line options or defaults if none given
flag.Parse()
f, err := os.OpenFile(*skylib.LogFileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err == nil {
defer f.Close()
log.SetOutput(f)
}
skylib.Setup(sName)
homeTmpl = template.MustParse(homeTemplate, nil)
respTmpl = template.MustParse(responseTemplate, nil)
rpc.HandleHTTP()
portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port)
stack := new(mango.Stack)
stack.Address = portString
routes := make(map[string]mango.App)
routes["/"] = homeHandler
routes["/new"] = submitHandler
stack.Middleware(mango.Routing(routes))
stack.Run(nil)
}
示例4: main
func main() {
// Pull in command line options or defaults if none given
flag.Parse()
f, err := os.OpenFile(*skylib.LogFileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err == nil {
defer f.Close()
log.SetOutput(f)
}
skylib.Setup(sName)
r := NewGetUserDataService()
rpc.Register(r)
rpc.HandleHTTP()
portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port)
l, e := net.Listen("tcp", portString)
if e != nil {
log.Fatal("listen error:", e)
}
log.Println("Starting server")
http.Serve(l, nil)
}
示例5: Serve
// At the moment, this can start more than one Server on the same
// port, which could be a problem.
func (self *RpcService) Serve(done chan bool) {
portString := fmt.Sprintf("%s:%d", self.IPAddress, self.Port)
log.Println(portString)
l, e := net.Listen("tcp", portString)
if e != nil {
log.Fatal("listen error:", e)
}
defer l.Close()
switch self.Protocol {
default:
rpc.HandleHTTP() // Seems safe to call multiple times, but must
// that precede net.Listen()?
log.Println("Starting http server")
http.Serve(l, nil)
case "json":
log.Println("Starting jsonrpc server")
for {
conn, err := l.Accept()
if err != nil {
panic(err.String())
}
jsonrpc.ServeConn(conn)
}
}
done <- true // This may never occur.
}
示例6: main
// The Router application registers RPC listeners to accept from the initiators
// then registers RPC clients to each of the external services it may call.
func main() {
var err os.Error
// Pull in command line options or defaults if none given
flag.Parse()
f, err := os.OpenFile(*skylib.LogFileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err == nil {
defer f.Close()
log.SetOutput(f)
}
skylib.Setup("Watcher.Generic") // Change this to be more descriptive
rpc.HandleHTTP()
go monitorServices()
portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port)
l, e := net.Listen("tcp", portString)
if e != nil {
log.Fatal("listen error:", e)
}
log.Println("Starting server")
http.Serve(l, nil)
}
示例7: main
func main() {
flag.Parse()
rpc.Register(server)
rpc.HandleHTTP()
http.HandleFunc("/", Static)
http.HandleFunc("/get", Get)
http.ListenAndServe(*listenAddr, nil)
}
示例8: serveHTTP
// rpc over HTTP
func serveHTTP(addr string) {
rpc.HandleHTTP()
l, err := net.Listen("tcp", addr)
if err != nil {
log.Fatal(err)
}
http.Serve(l, nil)
}
示例9: main
func main() {
reg := NewReg()
rpc.RegisterName(registry.Name, reg)
rpc.HandleHTTP()
l, e := net.Listen("tcp", ":"+strconv.Itoa(registry.Port))
if e != nil {
log.Fatal("listen error:", e)
}
http.Serve(l, nil)
}
示例10: main
func main() {
arith := new(arith.Arith)
rpc.Register(arith)
rpc.HandleHTTP()
l, e := net.Listen("tcp", ":1234")
if e != nil {
log.Exit("listen error: ", e)
}
http.Serve(l, nil)
}
示例11: server
func server() {
ps := new(ProcessStarter)
rpc.Register(ps)
rpc.HandleHTTP()
l, e := net.Listen("tcp", ":1234")
if e != nil {
log.Exit("listen error:", e)
}
go http.Serve(l, nil)
}
示例12: RunServer
func RunServer(addr string) {
self := new(Server).Init()
rpc.Register(self)
rpc.HandleHTTP()
l, e := net.Listen("tcp", addr)
if e != nil {
log.Exit("listen error: ", e)
}
http.Serve(l, nil)
}
示例13: main
//Starts the server
func main() {
md := NewMatrixDatabase()
rpc.Register(md)
rpc.HandleHTTP()
l, e := net.Listen("tcp", ":1234")
if e != nil {
log.Fatal("listen error:", e)
}
http.Serve(l, nil)
}
示例14: main
func main() {
flag.Parse()
t := &LunchTracker{NewPoll()}
rpc.Register(t)
rpc.HandleHTTP()
l, e := net.Listen("tcp", ":"+strconv.Uitoa(*port))
if e != nil {
log.Exit("listen error:", e)
}
http.Serve(l, nil)
}
示例15: main
func main() {
sfs := new(SFS)
status := new(Status)
Init(status)
rpc.Register(sfs)
rpc.HandleHTTP()
l, e := net.Listen("tcp", ":1234")
if e != nil {
log.Fatal("listen error:", e)
}
http.Serve(l, nil)
fmt.Println("done")
}