Skip to content

Commit 03ef512

Browse files
committed
key: split json key to key_gojay.go
1 parent 9c5b41b commit 03ef512

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

error_gojay.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import "github.com/francoispqt/gojay"
1111
// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject
1212
func (v *Error) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
1313
switch k {
14-
case "code":
14+
case keyCode:
1515
return dec.Int64((*int64)(&v.Code))
16-
case "message":
16+
case keyMessage:
1717
return dec.String(&v.Message)
1818
}
1919
return nil
@@ -24,8 +24,8 @@ func (v *Error) NKeys() int { return 2 }
2424

2525
// MarshalJSONObject implements gojay's MarshalerJSONObject
2626
func (v *Error) MarshalJSONObject(enc *gojay.Encoder) {
27-
enc.IntKey("code", int(v.Code))
28-
enc.StringKey("message", v.Message)
27+
enc.IntKey(keyCode, int(v.Code))
28+
enc.StringKey(keyMessage, v.Message)
2929
}
3030

3131
// IsNil returns wether the structure is nil value or not

key_gojay.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2019 The go-language-server Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build gojay
6+
7+
package jsonrpc2
8+
9+
const (
10+
keyCode = "code"
11+
keyError = "error"
12+
keyID = "id"
13+
keyJSONRPC = "jsonrpc"
14+
keyMessage = "message"
15+
keyMethod = "method"
16+
keyParams = "params"
17+
keyResult = "result"
18+
)

types_gojay.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ import (
1212
"github.com/francoispqt/gojay"
1313
)
1414

15-
const (
16-
keyJSONRPC = "jsonrpc"
17-
keyID = "id"
18-
keyMethod = "method"
19-
keyParams = "params"
20-
keyError = "error"
21-
keyResult = "result"
22-
)
23-
2415
// UnmarshalJSONObject implements gojay's UnmarshalerJSONObject
2516
func (v *Request) UnmarshalJSONObject(dec *gojay.Decoder, k string) error {
2617
switch k {

0 commit comments

Comments
 (0)