-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
67 lines (58 loc) · 1.83 KB
/
main.go
File metadata and controls
67 lines (58 loc) · 1.83 KB
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
package main
import (
"context"
"flag"
"github.com/fagnercarvalho/redis-lsp/server"
"github.com/sourcegraph/jsonrpc2"
"io"
"log"
"os"
)
func main() {
var address, username, password, logFile string
var database int
var debugLogEnabled, dbCacheEnabled bool
flag.StringVar(&address, "address", "localhost:6379", "Redis instance address for caching data for autocompletion.")
flag.StringVar(&username, "username", "", "Redis instance username for caching data for autocompletion.")
flag.StringVar(&password, "password", "", "Redis instance password for caching data for autocompletion.")
flag.IntVar(&database, "database", 0, "Redis database for caching data for autocompletion.")
flag.StringVar(&logFile, "logFile", "c:/server.log", "Path for log file.")
flag.BoolVar(&debugLogEnabled, "debugLogEnabled", false, "Enables debug logging.")
flag.BoolVar(&dbCacheEnabled, "dbCacheEnabled", false, "Enables keys and users autocompletion.")
flag.Parse()
if debugLogEnabled {
f, err := os.OpenFile("c:/server.log", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0660)
if err != nil {
log.Fatal(err)
}
defer f.Close()
log.SetOutput(io.MultiWriter(os.Stderr, f))
} else {
log.SetOutput(io.Discard)
}
log.Println("starting server")
server, err := server.New(address, username, password, database, dbCacheEnabled)
if err != nil {
panic(err)
}
handler := jsonrpc2.HandlerWithError(server.Handle)
<-jsonrpc2.NewConn(
context.Background(),
jsonrpc2.NewBufferedStream(StdIo{}, jsonrpc2.VSCodeObjectCodec{}),
handler).DisconnectNotify()
log.Println("stopping server")
}
type StdIo struct{}
func (StdIo) Read(p []byte) (int, error) {
return os.Stdin.Read(p)
}
func (StdIo) Write(p []byte) (int, error) {
return os.Stdout.Write(p)
}
func (StdIo) Close() error {
err := os.Stdin.Close()
if err != nil {
return err
}
return os.Stdout.Close()
}