This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
orion/cmd/server/rpc/server.go

39 lines
865 B
Go
Raw Normal View History

package rpc
import (
"fmt"
"net/http"
"github.com/gorilla/rpc"
"github.com/gorilla/rpc/json"
)
// OrionService is the JSON-RPC API
type OrionService struct{}
// HelloArgs is the arguments expected by the Hello method
type HelloArgs struct {
Who string
}
// HelloResponse is the response returned from the Hello method
type HelloResponse struct {
Message string
}
// Hello is a demo RPC method fro the OrionService
func (o *OrionService) Hello(r *http.Request, args *HelloArgs, reply *HelloResponse) error {
reply.Message = fmt.Sprintf("hello %s", args.Who)
return nil
}
// NewServer returns a new configured JSON-RPC server
func NewServer() *rpc.Server {
server := rpc.NewServer()
server.RegisterCodec(json.NewCodec(), "application/json")
if err := server.RegisterService(new(OrionService), "Orion"); err != nil {
panic(err)
}
return server
}