Skip to content

Instantly share code, notes, and snippets.

@mbonell
Created January 26, 2018 18:12
Show Gist options
  • Save mbonell/1e4fe092b774b4ca20fe2074e104f567 to your computer and use it in GitHub Desktop.
Save mbonell/1e4fe092b774b4ca20fe2074e104f567 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net"
"net/http"
"net/rpc"
"github.com/techwo/rpc-server/service"
)
func main() {
s := new(service.Calculator)
err := rpc.Register(s)
if err != nil {
log.Fatal("Service registration error:", err)
}
rpc.HandleHTTP()
l, err := net.Listen("tcp", "localhost:8767")
if err != nil {
log.Fatal("Listen error:", err)
}
log.Println("Server started!")
log.Println(l.Addr())
err = http.Serve(l, nil)
if err != nil {
log.Fatal("Server error:", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment