-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
54 lines (46 loc) · 2.39 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"log"
"net/http"
"github.com/daluu/gorrs/protocol"
"github.com/divan/gorilla-xmlrpc/xml"
"github.com/gorilla/rpc"
)
/* add to import list of github.com/daluu/gorrs/protocol/protocol.go,
* the (exported) go remote (test) library packages
* to be served by this remote server via reflection. To do that since we
* have to explicitly reference packages to reflect on and not be able to
* just pass in package reference at runtime?
*/
/* TODO: also look into whether there's any other alternative to
* gorilla/rpc and divan/gorilla-xmlrpc/xml in case of issues with XML-RPC
* support / implementation in go. Or what can be done to extend them to do
* what we need for a go-based Robot Framework generic remote library server
*
* Full spec for said server:
* https://github.com/robotframework/RemoteInterface
*/
func main() {
RPC := rpc.NewServer()
xmlrpcCodec := xml.NewCodec()
//map XML-RPC methods to the go implemented functions
//CamelCase mapping
xmlrpcCodec.RegisterAlias("GetKeywordNames", "RobotRemoteService.GetKeywordNames")
xmlrpcCodec.RegisterAlias("GetKeywordArguments", "RobotRemoteService.GetKeywordArguments")
xmlrpcCodec.RegisterAlias("GetKeywordDocumentation", "RobotRemoteService.GetKeywordDocumentation")
xmlrpcCodec.RegisterAlias("RunKeyword", "RobotRemoteService.RunKeyword")
//pythonic mapping
xmlrpcCodec.RegisterAlias("get_keyword_names", "RobotRemoteService.GetKeywordNames")
xmlrpcCodec.RegisterAlias("get_keyword_arguments", "RobotRemoteService.GetKeywordArguments")
xmlrpcCodec.RegisterAlias("get_keyword_documentation", "RobotRemoteService.GetKeywordDocumentation")
xmlrpcCodec.RegisterAlias("run_keyword", "RobotRemoteService.RunKeyword")
//set server to handle both XML MIME types
RPC.RegisterCodec(xmlrpcCodec, "application/xml")
RPC.RegisterCodec(xmlrpcCodec, "text/xml")
RPC.RegisterService(new(protocol.RobotRemoteService), "")
http.Handle("/RPC2", RPC) //preserve option to use RPC2 endpoint
http.Handle("/", RPC) //but not make it required when using with Robot Framework
//TODO: make port and host/IP address binding be configurable via CLI flags and not fixed to localhost:8270 (the default)
log.Println("Robot remote server started on localhost:8270 under / and /RPC2 endpoints. Stop server with Ctrl+C, kill, etc. or XML-RPC method 'run_keyword' with parameter 'stop_remote_server'\n")
log.Fatal(http.ListenAndServe(":8270", nil))
}