-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.go
45 lines (36 loc) · 1002 Bytes
/
server.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
// server.go
package l2lsp
import (
"bufio"
"encoding/json"
"os"
"github.com/HexmosTech/lama2/l2lsp/request"
outputmanager "github.com/HexmosTech/lama2/outputManager"
"github.com/rs/zerolog/log"
)
func init() {
outputmanager.ConfigureZeroLog("INFO")
}
func StartLspServer() {
log.Info().Msg("Started process")
scanner := bufio.NewScanner(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
for scanner.Scan() {
handleInput(scanner.Text(), writer)
}
}
func handleInput(input string, writer *bufio.Writer) {
log.Info().Msgf("Received input: %s", input)
var rpcRequest request.JSONRPCRequest
if err := json.Unmarshal([]byte(input), &rpcRequest); err != nil {
log.Error().Err(err).Msg("Error decoding JSON-RPC request")
return
}
rpcResponse := HandleMethod(rpcRequest)
if responseData, err := json.Marshal(rpcResponse); err != nil {
log.Error().Err(err).Msg("Error encoding JSON-RPC response")
} else {
writer.WriteString(string(responseData) + "\n")
writer.Flush()
}
}