-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
86 lines (69 loc) · 1.89 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"flag"
"github.com/killing/seafserver/ccnet"
"github.com/killing/seafserver/log"
"github.com/killing/searpc"
"os"
"path/filepath"
"strconv"
)
type SeafRPCService int
func (svc *SeafRPCService) Echo(msg string) *searpc.Result {
return &searpc.Result{Ret: msg}
}
type StringStruct struct {
Msg string `json:"msg,omitempty"`
}
func (svc *SeafRPCService) List(msg string) *searpc.Result {
var list []StringStruct = make([]StringStruct, 3)
for i := 0; i < 3; i++ {
list[i] = StringStruct{msg + strconv.Itoa(i)}
}
return &searpc.Result{Ret: list}
}
func main() {
var ccnetConfDir, seafConfDir, logPath string
var debug bool
var logf *os.File
var err error
flag.StringVar(&ccnetConfDir, "c", "", "ccnet configuration directory path")
flag.StringVar(&seafConfDir, "d", "", "seafile configuration directory path")
flag.StringVar(&logPath, "l", "", "log file path")
flag.BoolVar(&debug, "D", false, "enable debug logs")
flag.Parse()
if ccnetConfDir == "" || seafConfDir == "" {
flag.PrintDefaults()
os.Exit(1)
}
ccnetConfDir, _ = filepath.Abs(ccnetConfDir)
seafConfDir, _ = filepath.Abs(seafConfDir)
if logPath == "" {
logPath = filepath.Join(seafConfDir, "seafile.log")
} else if logPath != "-" {
logPath, _ = filepath.Abs(logPath)
}
if logPath != "-" {
logf, err = os.OpenFile(logPath, os.O_WRONLY | os.O_APPEND | os.O_CREATE, 0666)
} else {
logf = os.Stderr
}
log.Init(logf, debug)
rpcSvr := searpc.NewServer()
svc := new(SeafRPCService)
rpcSvr.Register(svc, "seafserv-rpcserver")
client, err := ccnet.NewClient(ccnetConfDir, rpcSvr)
if err != nil {
log.Errorln("Failed to create ccnet client", err.Error())
os.Exit(1)
}
err = client.RegisterProc("seafserv-rpcserver")
if err != nil {
log.Errorln("Failed to register rpc processor:", err.Error())
os.Exit(1)
}
if err = client.Run(); err != nil {
log.Errorln(err.Error())
}
return
}