-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpc.go
48 lines (36 loc) · 864 Bytes
/
rpc.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
package main
import (
"fmt"
"net"
"net/http"
"net/rpc"
"gitgud.io/softashell/comfy-translator/translator"
log "github.com/sirupsen/logrus"
)
type Comfy int
func (t *Comfy) Translate(req *translator.Request, reply *translator.Response) error {
if len(req.Text) < 1 || len(req.From) < 1 || len(req.To) < 1 {
return fmt.Errorf("Empty arguments")
}
if req.From != "ja" || req.To != "en" {
return fmt.Errorf("Unsupported languages")
}
response := translator.Response{
TranslationText: translate(*req),
From: req.From,
To: req.To,
Text: req.Text,
}
*reply = response
return nil
}
func ServeComfyRPC(listenAddr string) {
comfy := new(Comfy)
rpc.Register(comfy)
rpc.HandleHTTP()
l, err := net.Listen("tcp", listenAddr)
if err != nil {
log.Fatal("listen error:", err)
}
http.Serve(l, nil)
}