format code
diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml
index 458aefa..459f4f8 100644
--- a/.github/workflows/github-actions.yml
+++ b/.github/workflows/github-actions.yml
@@ -69,6 +69,10 @@
chmod u+x /tmp/tools/license/license-header-checker
/tmp/tools/license/license-header-checker -v -a -r -i vendor /tmp/tools/license/license.txt . go && [[ -z `git status -s` ]]
+ - name: format
+ run: |
+ gofmt -l -w . && [[ -z `git status -s` ]]
+
- name: Install go ci lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0
diff --git a/boolean.go b/boolean.go
index ea303de..467eb8d 100644
--- a/boolean.go
+++ b/boolean.go
@@ -25,7 +25,7 @@
// ::= 'T'
// ::= 'F'
func encBool(b []byte, v bool) []byte {
- var c = BC_FALSE
+ c := BC_FALSE
if v {
c = BC_TRUE
}
diff --git a/codec.go b/codec.go
index 886e5f0..2df9e58 100644
--- a/codec.go
+++ b/codec.go
@@ -118,35 +118,35 @@
// UnpackInt16 unpacks int16 from byte array
//(0,2).unpack('n')
func UnpackInt16(b []byte) int16 {
- var arr = b[:2]
+ arr := b[:2]
return int16(binary.BigEndian.Uint16(arr))
}
// UnpackUint16 unpacks int16 from byte array
//(0,2).unpack('n')
func UnpackUint16(b []byte) uint16 {
- var arr = b[:2]
+ arr := b[:2]
return binary.BigEndian.Uint16(arr)
}
// UnpackInt32 unpacks int32 from byte array
//(0,4).unpack('N')
func UnpackInt32(b []byte) int32 {
- var arr = b[:4]
+ arr := b[:4]
return int32(binary.BigEndian.Uint32(arr))
}
// UnpackInt64 unpacks int64 from byte array
-//long (0,8).unpack('q>')
+// long (0,8).unpack('q>')
func UnpackInt64(b []byte) int64 {
- var arr = b[:8]
+ arr := b[:8]
return int64(binary.BigEndian.Uint64(arr))
}
// UnpackFloat64 unpacks float64 from byte array
-//Double (0,8).unpack('G)
+// Double (0,8).unpack('G)
func UnpackFloat64(b []byte) float64 {
- var arr = b[:8]
+ arr := b[:8]
return math.Float64frombits(binary.BigEndian.Uint64(arr))
}
@@ -159,14 +159,14 @@
return v
}
-//PackPtr pack a Ptr value
+// PackPtr pack a Ptr value
func PackPtr(v reflect.Value) reflect.Value {
vv := reflect.New(v.Type())
vv.Elem().Set(v)
return vv
}
-//UnpackPtrType unpack pointer type to original type
+// UnpackPtrType unpack pointer type to original type
func UnpackPtrType(typ reflect.Type) reflect.Type {
for typ.Kind() == reflect.Ptr {
typ = typ.Elem()
@@ -268,7 +268,7 @@
return in, nil
}
-//EnsureRawValue pack the interface with value, and make sure it's not a ref holder
+// EnsureRawValue pack the interface with value, and make sure it's not a ref holder
func EnsureRawValue(in interface{}) reflect.Value {
if v, ok := in.(reflect.Value); ok {
if v.IsValid() {
@@ -295,7 +295,7 @@
return
}
}
- //temporary process, only handle the same type of situation
+ // temporary process, only handle the same type of situation
if v.IsValid() && UnpackPtrType(dest.Type()) == UnpackPtrType(v.Type()) && dest.Kind() == reflect.Ptr && dest.CanSet() {
for dest.Type() != v.Type() {
v = PackPtr(v)
@@ -381,7 +381,7 @@
return v1.Pointer() == v2.Pointer()
}
-//SetSlice set value into slice object
+// SetSlice set value into slice object
func SetSlice(dest reflect.Value, objects interface{}) error {
if objects == nil {
return nil
@@ -422,7 +422,7 @@
return nil
}
-//ConvertSliceValueType convert to slice of destination type
+// ConvertSliceValueType convert to slice of destination type
func ConvertSliceValueType(destTyp reflect.Type, v reflect.Value) (reflect.Value, error) {
if destTyp == v.Type() {
return v, nil
diff --git a/codec_test.go b/codec_test.go
index 21c706f..a4cdd1b 100644
--- a/codec_test.go
+++ b/codec_test.go
@@ -25,7 +25,7 @@
func TestPackUint16(t *testing.T) {
// var arr []byte
// t.Logf("0X%x\n", UnpackUint16(PackUint16(uint16(0xfedc), arr)))
- var v = uint16(0xfedc)
+ v := uint16(0xfedc)
if r := UnpackUint16(PackUint16(v)); r != v {
t.Fatalf("v:0X%d, pack-unpack value:0X%x\n", v, r)
}
@@ -34,7 +34,7 @@
func TestPackInt16(t *testing.T) {
// var arr []byte
// t.Logf("0X%x\n", UnpackInt16(PackInt16(int16(0x1234), arr)))
- var v = int16(0x1234)
+ v := int16(0x1234)
if r := UnpackInt16(PackInt16(v)); r != v {
t.Fatalf("v:0X%d, pack-unpack value:0X%x\n", v, r)
}
@@ -43,7 +43,7 @@
func TestPackInt32(t *testing.T) {
// var arr []byte
// t.Logf("0X%x\n", UnpackInt32(PackInt32(int32(0x12344678), arr)))
- var v = int32(0x12344678)
+ v := int32(0x12344678)
if r := UnpackInt32(PackInt32(v)); r != v {
t.Fatalf("v:0X%d, pack-unpack value:0X%x\n", v, r)
}
@@ -52,7 +52,7 @@
func TestPackInt64(t *testing.T) {
// var arr []byte
// t.Logf("0X%x\n", UnpackInt64(PackInt64(int64(0x1234567890abcdef), arr)))
- var v = int64(0x1234567890abcdef)
+ v := int64(0x1234567890abcdef)
if r := UnpackInt64(PackInt64(v)); r != v {
t.Fatalf("v:0X%d, pack-unpack value:0X%x\n", v, r)
}
diff --git a/date.go b/date.go
index 2dae3b3..0b5329a 100644
--- a/date.go
+++ b/date.go
@@ -36,7 +36,6 @@
// ::= x4a b7 b6 b5 b4 b3 b2 b1 b0
// ::= x4b b3 b2 b1 b0 # minutes since epoch
func encDateInMs(b []byte, i interface{}) []byte {
-
value := UnpackPtrValue(reflect.ValueOf(i))
vi := value.Interface().(time.Time)
if vi == ZeroDate {
diff --git a/date_test.go b/date_test.go
index c700cf5..7e1d36a 100644
--- a/date_test.go
+++ b/date_test.go
@@ -40,7 +40,7 @@
Date3 ***time.Time
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (DateDemo) JavaClassName() string {
return "test.model.DateDemo"
}
@@ -135,7 +135,6 @@
assert.Equal(t, ZeroDate, *res.(*DateDemo).Date1)
assert.Equal(t, tz.Local().String(), (*res.(*DateDemo).Date2).String())
assert.Equal(t, tz.Local().String(), (*(*res.(*DateDemo).Date3)).String())
-
}
func TestDateNulJavaDecode(t *testing.T) {
@@ -147,7 +146,6 @@
}
func TestDateNilDecode(t *testing.T) {
-
doTestDateNull(t, "customReplyTypedFixedDateNull")
}
diff --git a/encode.go b/encode.go
index 224d35d..b6d9aed 100644
--- a/encode.go
+++ b/encode.go
@@ -40,7 +40,7 @@
// NewEncoder generate an encoder instance
func NewEncoder() *Encoder {
- var buffer = make([]byte, 64)
+ buffer := make([]byte, 64)
return &Encoder{
buffer: buffer[:0],
@@ -50,7 +50,7 @@
// Clean clean the Encoder (room) for a new object encoding.
func (e *Encoder) Clean() {
- var buffer = make([]byte, 64)
+ buffer := make([]byte, 64)
e.classInfoList = nil
e.buffer = buffer[:0]
e.refMap = make(map[unsafe.Pointer]_refElem, 7)
diff --git a/encode_test.go b/encode_test.go
index c7f444a..d8f1aaa 100644
--- a/encode_test.go
+++ b/encode_test.go
@@ -59,7 +59,6 @@
}()
out, err := cmd.Output()
-
if err != nil {
t.Logf("get java result error: %v", err)
return "", err
diff --git a/hessian.go b/hessian.go
index cd9ab70..5686a1e 100644
--- a/hessian.go
+++ b/hessian.go
@@ -104,7 +104,6 @@
// ReadHeader uses hessian codec to read dubbo header
func (h *HessianCodec) ReadHeader(header *DubboHeader) error {
-
var err error
if h.reader.Size() < HEADER_LENGTH {
@@ -166,12 +165,10 @@
}
return perrors.WithStack(err)
-
}
// ReadBody uses hessian codec to read response body
func (h *HessianCodec) ReadBody(rspObj interface{}) error {
-
if h.reader.Buffered() < h.bodyLen {
return ErrBodyNotEnough
}
diff --git a/hessian_test.go b/hessian_test.go
index 90cd4c4..9ee1469 100644
--- a/hessian_test.go
+++ b/hessian_test.go
@@ -53,7 +53,7 @@
return "com.test.casea"
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (c Case) JavaClassName() string {
return "com.test.case"
}
diff --git a/java8_time.go b/java8_time.go
index 2b80121..ed19a7f 100644
--- a/java8_time.go
+++ b/java8_time.go
@@ -35,5 +35,4 @@
RegisterPOJO(&java8_time.OffsetDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}}, Offset: java8_time.ZoneOffSet{Seconds: 7200}})
RegisterPOJO(&java8_time.OffsetTime{LocalTime: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}, ZoneOffset: java8_time.ZoneOffSet{Seconds: 7200}})
RegisterPOJO(&java8_time.ZonedDateTime{DateTime: java8_time.LocalDateTime{Date: java8_time.LocalDate{Year: 2020, Month: 6, Day: 16}, Time: java8_time.LocalTime{Hour: 6, Minute: 5, Second: 4, Nano: 3}}, Offset: java8_time.ZoneOffSet{Seconds: 7200}, ZoneId: "Z"})
-
}
diff --git a/java8_time/period.go b/java8_time/period.go
index a95df3c..f9a413d 100644
--- a/java8_time/period.go
+++ b/java8_time/period.go
@@ -16,7 +16,7 @@
*/
package java8_time
-//java8-time java.time.Period
+// java8-time java.time.Period
type Period struct {
Days int32 `hessian:"days"`
Months int32 `hessian:"months"`
diff --git a/java8_time/year.go b/java8_time/year.go
index 041e242..3f36b07 100644
--- a/java8_time/year.go
+++ b/java8_time/year.go
@@ -16,7 +16,7 @@
*/
package java8_time
-//java8-time java.time.Year
+// java8-time java.time.Year
type Year struct {
Year int32 `hessian:"year"`
}
diff --git a/java8_time/year_month.go b/java8_time/year_month.go
index 3f07a13..73f6892 100644
--- a/java8_time/year_month.go
+++ b/java8_time/year_month.go
@@ -16,7 +16,7 @@
*/
package java8_time
-//java8-time java.time.YearMonth
+// java8-time java.time.YearMonth
type YearMonth struct {
Month int32 `hessian:"month"`
Year int32 `hessian:"year"`
diff --git a/java8_time_test.go b/java8_time_test.go
index 9529c95..4851456 100644
--- a/java8_time_test.go
+++ b/java8_time_test.go
@@ -18,8 +18,9 @@
package hessian
import (
- "github.com/apache/dubbo-go-hessian2/java8_time"
"testing"
+
+ "github.com/apache/dubbo-go-hessian2/java8_time"
)
func TestJava8Time(t *testing.T) {
diff --git a/java_collection.go b/java_collection.go
index d669d12..46a5c9f 100644
--- a/java_collection.go
+++ b/java_collection.go
@@ -58,13 +58,10 @@
return getCollectionSerialize(name) != nil
}
-type JavaCollectionSerializer struct {
-}
+type JavaCollectionSerializer struct{}
func (JavaCollectionSerializer) EncObject(e *Encoder, vv POJO) error {
- var (
- err error
- )
+ var err error
v, ok := vv.(JavaCollectionObject)
if !ok {
return perrors.New("can not be converted into java collection object")
@@ -89,7 +86,7 @@
}
func (JavaCollectionSerializer) DecObject(d *Decoder, typ reflect.Type, cls *classInfo) (interface{}, error) {
- //for the java impl of hessian encode collections as list, which will not be decoded as object in go impl, this method should not be called
+ // for the java impl of hessian encode collections as list, which will not be decoded as object in go impl, this method should not be called
return nil, perrors.New("unexpected collection decode call")
}
diff --git a/java_exception/duplicate_format_flags_exception.go b/java_exception/duplicate_format_flags_exception.go
index b3358ae..c9f0759 100644
--- a/java_exception/duplicate_format_flags_exception.go
+++ b/java_exception/duplicate_format_flags_exception.go
@@ -34,7 +34,6 @@
} else {
return e.DetailMessage + " flags=" + e.Flags
}
-
}
// JavaClassName java fully qualified path
diff --git a/java_exception/exception.go b/java_exception/exception.go
index f5a00e9..b8a8866 100644
--- a/java_exception/exception.go
+++ b/java_exception/exception.go
@@ -50,7 +50,7 @@
return e.DetailMessage
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (Throwable) JavaClassName() string {
return "java.lang.Throwable"
}
@@ -80,7 +80,7 @@
return e.DetailMessage
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (Exception) JavaClassName() string {
return "java.lang.Exception"
}
@@ -101,7 +101,7 @@
LineNumber int32
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (StackTraceElement) JavaClassName() string {
return "java.lang.StackTraceElement"
}
@@ -114,7 +114,7 @@
Name string
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (Method) JavaClassName() string {
return "java.lang.reflect.Method"
}
diff --git a/java_exception/invalid_class_exception.go b/java_exception/invalid_class_exception.go
index ca97120..593b407 100644
--- a/java_exception/invalid_class_exception.go
+++ b/java_exception/invalid_class_exception.go
@@ -31,8 +31,10 @@
// NewInvalidClassException is the constructor
func NewInvalidClassException(classname string, detailMessage string) *InvalidClassException {
- return &InvalidClassException{DetailMessage: detailMessage, StackTrace: []StackTraceElement{},
- Classname: classname}
+ return &InvalidClassException{
+ DetailMessage: detailMessage, StackTrace: []StackTraceElement{},
+ Classname: classname,
+ }
}
// Error output error message
@@ -41,7 +43,6 @@
return e.DetailMessage
}
return fmt.Sprintf("%+v; %+v", e.Classname, e.DetailMessage)
-
}
// JavaClassName java fully qualified path
diff --git a/java_exception/utf_data_format_exception.go b/java_exception/utf_data_format_exception.go
index 8c6d22f..cb8c86d 100644
--- a/java_exception/utf_data_format_exception.go
+++ b/java_exception/utf_data_format_exception.go
@@ -17,7 +17,7 @@
package java_exception
-//UTFDataFormatException represents an exception of the same name in java
+// UTFDataFormatException represents an exception of the same name in java
type UTFDataFormatException struct {
SerialVersionUID int64
DetailMessage string
@@ -31,12 +31,12 @@
return &UTFDataFormatException{DetailMessage: detailMessage}
}
-//Error output error message
+// Error output error message
func (e UTFDataFormatException) Error() string {
return e.DetailMessage
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (UTFDataFormatException) JavaClassName() string {
return "java.io.UTFDataFormatException"
}
diff --git a/java_exception/write_aborted_exception.go b/java_exception/write_aborted_exception.go
index bbaa1e2..681d266 100644
--- a/java_exception/write_aborted_exception.go
+++ b/java_exception/write_aborted_exception.go
@@ -29,8 +29,10 @@
// NewWriteAbortedException is the constructor
func NewWriteAbortedException(detailMessage string, detail Throwabler) *WriteAbortedException {
- return &WriteAbortedException{DetailMessage: detailMessage, StackTrace: nil,
- Detail: detail}
+ return &WriteAbortedException{
+ DetailMessage: detailMessage, StackTrace: nil,
+ Detail: detail,
+ }
}
// Error output error message
diff --git a/java_sql_time.go b/java_sql_time.go
index 51e3abf..ab4c022 100644
--- a/java_sql_time.go
+++ b/java_sql_time.go
@@ -44,12 +44,10 @@
}
// JavaSqlTimeSerializer used to encode & decode java.sql.Time & java.sql.Date
-type JavaSqlTimeSerializer struct {
-}
+type JavaSqlTimeSerializer struct{}
// nolint
func (JavaSqlTimeSerializer) EncObject(e *Encoder, vv POJO) error {
-
var (
i int
idx int
@@ -117,7 +115,6 @@
// nolint
func (JavaSqlTimeSerializer) DecObject(d *Decoder, typ reflect.Type, cls *classInfo) (interface{}, error) {
-
if typ.Kind() != reflect.Struct {
return nil, perrors.Errorf("wrong type expect Struct but get:%s", typ.String())
}
diff --git a/java_unknown_exception.go b/java_unknown_exception.go
index 0663c4f..035fb94 100644
--- a/java_unknown_exception.go
+++ b/java_unknown_exception.go
@@ -29,7 +29,6 @@
var exceptionCheckMutex sync.Mutex
func checkAndGetException(cls *classInfo) (*structInfo, bool) {
-
if len(cls.fieldNameList) < 4 {
return nil, false
}
@@ -37,7 +36,7 @@
throwable *structInfo
ok bool
)
- var count = 0
+ count := 0
for _, item := range cls.fieldNameList {
if item == "detailMessage" || item == "suppressedExceptions" || item == "stackTrace" || item == "cause" {
count++
@@ -77,7 +76,7 @@
return fmt.Sprintf("throw %v : %v", e.name, e.DetailMessage)
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (e UnknownException) JavaClassName() string {
return e.name
}
diff --git a/java_unknown_exception_test.go b/java_unknown_exception_test.go
index 20c8e6c..8f2743e 100644
--- a/java_unknown_exception_test.go
+++ b/java_unknown_exception_test.go
@@ -20,6 +20,7 @@
import (
"testing"
)
+
import (
"github.com/stretchr/testify/assert"
)
diff --git a/list.go b/list.go
index 938d567..c3c761c 100644
--- a/list.go
+++ b/list.go
@@ -29,6 +29,7 @@
import (
perrors "github.com/pkg/errors"
)
+
import (
"github.com/apache/dubbo-go-hessian2/java_exception"
)
@@ -148,9 +149,7 @@
// ::= 'V' type int value* # fixed-length list
// ::= [x70-77] type value* # fixed-length typed list
func (e *Encoder) writeTypedList(v interface{}) error {
- var (
- err error
- )
+ var err error
value := reflect.ValueOf(v)
@@ -162,7 +161,7 @@
value = UnpackPtrValue(value)
totype := UnpackPtrType(value.Type().Elem()).String()
- var typeName = getListTypeName(totype)
+ typeName := getListTypeName(totype)
if typeName == "" {
return perrors.New("no this type name: " + totype)
}
@@ -185,9 +184,7 @@
// ::= x58 int value* # fixed-length untyped list
// ::= [x78-7f] value* # fixed-length untyped list
func (e *Encoder) writeUntypedList(v interface{}) error {
- var (
- err error
- )
+ var err error
value := reflect.ValueOf(v)
@@ -260,7 +257,7 @@
return tag == BC_LIST_FIXED_UNTYPED || tag == BC_LIST_VARIABLE_UNTYPED || listFixedUntypedLenTag(tag)
}
-//decList read list
+// decList read list
func (d *Decoder) decList(flag int32) (interface{}, error) {
var (
err error
@@ -378,7 +375,7 @@
return holder, nil
}
-//readUntypedList read untyped list
+// readUntypedList read untyped list
// Include 3 formats:
// ::= x57 value* 'Z' # variable-length untyped list
// ::= x58 int value* # fixed-length untyped list
diff --git a/list_test.go b/list_test.go
index 7fe9668..0e96ae6 100644
--- a/list_test.go
+++ b/list_test.go
@@ -68,7 +68,6 @@
res, err = d.Decode()
assert.NoError(t, err)
assert.True(t, reflect.DeepEqual(res, list_2))
-
}
func TestList(t *testing.T) {
@@ -112,14 +111,20 @@
testDecodeFramework(t, "customReplyTypedFixedList_boolean", []bool{true, false, true})
testDecodeFramework(t, "customReplyTypedVariableList_boolean", []bool{true, false, true})
- testDecodeFramework(t, "customReplyTypedFixedList_date", []time.Time{time.Unix(1560864, 0),
- time.Unix(1560864, 0), time.Unix(1560864, 0)})
- testDecodeFramework(t, "customReplyTypedVariableList_date", []time.Time{time.Unix(1560864, 0),
- time.Unix(1560864, 0), time.Unix(1560864, 0)})
+ testDecodeFramework(t, "customReplyTypedFixedList_date", []time.Time{
+ time.Unix(1560864, 0),
+ time.Unix(1560864, 0), time.Unix(1560864, 0),
+ })
+ testDecodeFramework(t, "customReplyTypedVariableList_date", []time.Time{
+ time.Unix(1560864, 0),
+ time.Unix(1560864, 0), time.Unix(1560864, 0),
+ })
testDecodeFramework(t, "customReplyTypedFixedList_arrays", [][][]int32{{{1, 2, 3}, {4, 5, 6, 7}}, {{8, 9, 10}, {11, 12, 13, 14}}})
- testDecodeFramework(t, "customReplyTypedFixedList_A0arrays", [][][]*A0{{{new(A0), new(A0), new(A0)}, {new(A0), new(A0), new(A0), nil}},
- {{new(A0)}, {new(A0)}}})
+ testDecodeFramework(t, "customReplyTypedFixedList_A0arrays", [][][]*A0{
+ {{new(A0), new(A0), new(A0)}, {new(A0), new(A0), new(A0), nil}},
+ {{new(A0)}, {new(A0)}},
+ })
testDecodeFramework(t, "customReplyTypedFixedList_Test", &TypedListTest{A: &A0{}, List: [][]*A0{{new(A0), new(A0)}, {new(A0), new(A0)}}, List1: [][]*A1{{new(A1), new(A1)}, {new(A1), new(A1)}}})
@@ -170,12 +175,16 @@
testJavaDecode(t, "customArgTypedFixedList_boolean_7", []bool{true, false, true, false, true, false, true})
testJavaDecode(t, "customArgTypedFixedList_date_0", []time.Time{})
- testJavaDecode(t, "customArgTypedFixedList_date_3", []time.Time{time.Unix(1560864, 0),
- time.Unix(1560864, 0), time.Unix(1560864, 0)})
+ testJavaDecode(t, "customArgTypedFixedList_date_3", []time.Time{
+ time.Unix(1560864, 0),
+ time.Unix(1560864, 0), time.Unix(1560864, 0),
+ })
testJavaDecode(t, "customArgTypedFixedList_arrays", [][][]int32{{{1, 2, 3}, {4, 5, 6, 7}}, {{8, 9, 10}, {11, 12, 13, 14}}})
- testJavaDecode(t, "customArgTypedFixedList_A0arrays", [][][]*A0{{{new(A0), new(A0), new(A0)}, {new(A0), new(A0), new(A0), nil}},
- {{new(A0)}, {new(A0)}}})
+ testJavaDecode(t, "customArgTypedFixedList_A0arrays", [][][]*A0{
+ {{new(A0), new(A0), new(A0)}, {new(A0), new(A0), new(A0), nil}},
+ {{new(A0)}, {new(A0)}},
+ })
testJavaDecode(t, "customArgTypedFixedList_Test", &TypedListTest{A: new(A0), List: [][]*A0{{new(A0), new(A0)}, {new(A0), new(A0)}}, List1: [][]*A1{{new(A1), new(A1)}, {new(A1), new(A1)}}})
@@ -188,7 +197,7 @@
List1 [][]*A1
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (*TypedListTest) JavaClassName() string {
return "test.TypedListTest"
}
diff --git a/map.go b/map.go
index 2b26d30..0d83d4e 100644
--- a/map.go
+++ b/map.go
@@ -158,7 +158,7 @@
entryValue interface{}
)
- //tag, _ = d.readBufByte()
+ // tag, _ = d.readBufByte()
tag, err = d.ReadByte()
// check error
if err != nil {
@@ -179,7 +179,7 @@
case BC_MAP:
d.decString(TAG_READ) // read map type , ignored
case BC_MAP_UNTYPED:
- //do nothing
+ // do nothing
default:
return perrors.Errorf("expect map header, but get %x", tag)
}
@@ -189,7 +189,7 @@
m = PackPtr(m)
d.appendRefs(m)
- //read key and value
+ // read key and value
for {
entryKey, err = d.DecodeValue()
if err != nil {
diff --git a/map_test.go b/map_test.go
index b63827d..3a84aef 100644
--- a/map_test.go
+++ b/map_test.go
@@ -81,11 +81,11 @@
testDecodeFramework(t, "replyTypedMap_0", map[interface{}]interface{}{})
testDecodeFramework(t, "replyTypedMap_1", map[interface{}]interface{}{"a": int32(0)})
testDecodeFramework(t, "replyTypedMap_2", map[interface{}]interface{}{int32(0): "a", int32(1): "b"})
- //testDecodeFramework(t, "replyTypedMap_3", []interface{}{})
+ // testDecodeFramework(t, "replyTypedMap_3", []interface{}{})
testDecodeFramework(t, "replyUntypedMap_0", map[interface{}]interface{}{})
testDecodeFramework(t, "replyUntypedMap_1", map[interface{}]interface{}{"a": int32(0)})
testDecodeFramework(t, "replyUntypedMap_2", map[interface{}]interface{}{int32(0): "a", int32(1): "b"})
- //testDecodeFramework(t, "replyTypedMap_3", []interface{}{})
+ // testDecodeFramework(t, "replyTypedMap_3", []interface{}{})
}
func TestMapEncode(t *testing.T) {
diff --git a/null_test.go b/null_test.go
index e75d900..2e0bab8 100644
--- a/null_test.go
+++ b/null_test.go
@@ -22,7 +22,7 @@
)
func TestEncNull(t *testing.T) {
- var e = NewEncoder()
+ e := NewEncoder()
e.Encode(nil)
if e.Buffer() == nil {
t.Fail()
diff --git a/object.go b/object.go
index 451cd54..0172162 100644
--- a/object.go
+++ b/object.go
@@ -646,7 +646,7 @@
return nil, perrors.Wrap(decErr, "decObject->decClassDef byte double")
}
cls, _ = clsDef.(*classInfo)
- //add to slice
+ // add to slice
d.appendClsDef(cls)
return d.DecodeValue()
diff --git a/object_test.go b/object_test.go
index 7e59157..ebc5b5d 100644
--- a/object_test.go
+++ b/object_test.go
@@ -194,8 +194,8 @@
Person: person,
CurJob: JOB{Title: "cto", Company: "facebook"},
Jobs: []JOB{
- JOB{Title: "manager", Company: "google"},
- JOB{Title: "ceo", Company: "microsoft"},
+ {Title: "manager", Company: "google"},
+ {Title: "ceo", Company: "microsoft"},
},
}
@@ -611,7 +611,7 @@
DogName string `hessian:"-"`
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (dog Dog) JavaClassName() string {
return "test.Dog"
}
@@ -622,7 +622,7 @@
Gender string
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (dog *DogAll) JavaClassName() string {
return "test.DogAll"
}
@@ -655,6 +655,7 @@
}
})
}
+
func TestIssue150_EmbedStructJavaDecode(t *testing.T) {
RegisterPOJO(&Dog{})
RegisterPOJO(&Animal{})
diff --git a/ref.go b/ref.go
index 9900a7a..09cd380 100644
--- a/ref.go
+++ b/ref.go
@@ -84,7 +84,7 @@
return holder
}
-//encRef encode ref index
+// encRef encode ref index
func encRef(b []byte, index int) []byte {
return encInt32(append(b, BC_REF), int32(index))
}
@@ -169,7 +169,7 @@
if len(d.refs) <= int(i) {
return nil, nil
- //return nil, ErrIllegalRefIndex
+ // return nil, ErrIllegalRefIndex
}
// return the exact ref object, which maybe a _refHolder
return d.refs[i], nil
diff --git a/ref_test.go b/ref_test.go
index b3cb62f..59adcbf 100644
--- a/ref_test.go
+++ b/ref_test.go
@@ -32,7 +32,7 @@
Next *circular
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (circular) JavaClassName() string {
return "circular"
}
@@ -76,7 +76,7 @@
Tags map[string]*personT
}
-//JavaClassName java fully qualified path
+// JavaClassName java fully qualified path
func (personT) JavaClassName() string {
return "person"
}
@@ -181,7 +181,7 @@
assert.Equal(t, "p5", d5.Name)
assert.Equal(t, "p6", d6.Name)
- //value equal
+ // value equal
assert.True(t, reflect.DeepEqual(d3.Relations, d4.Relations))
if d4.Marks == nil {
diff --git a/request.go b/request.go
index 032fbc8..6d0b9ee 100644
--- a/request.go
+++ b/request.go
@@ -265,7 +265,6 @@
// hessian decode request body
func unpackRequestBody(decoder *Decoder, reqObj interface{}) error {
-
if decoder == nil {
return perrors.Errorf("@decoder is nil")
}
diff --git a/response.go b/response.go
index 68f7c6b..2202c86 100644
--- a/response.go
+++ b/response.go
@@ -66,9 +66,7 @@
// https://github.com/apache/dubbo/blob/dubbo-2.7.1/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/codec/ExchangeCodec.java#L256
// hessian encode response
func packResponse(header DubboHeader, ret interface{}) ([]byte, error) {
- var (
- byteArray []byte
- )
+ var byteArray []byte
response := EnsureResponse(ret)
@@ -148,7 +146,6 @@
// byteArray{body length}
binary.BigEndian.PutUint32(byteArray[12:], uint32(pkgLen-HEADER_LENGTH))
return byteArray, nil
-
}
// hessian decode response body
@@ -361,7 +358,7 @@
if len(version) == 0 {
return 0
}
- var v = 0
+ v := 0
varr := strings.Split(version, ".")
length := len(varr)
for key, value := range varr {
diff --git a/response_test.go b/response_test.go
index 7299389..7632657 100644
--- a/response_test.go
+++ b/response_test.go
@@ -92,7 +92,7 @@
var s1r []string
doTestReflectResponse(t, s1, &s1r)
- s2 := []rr{rr{"dubbo", 666}, rr{"go", 999}}
+ s2 := []rr{{"dubbo", 666}, {"go", 999}}
var s2r []rr
doTestReflectResponse(t, s2, &s2r)
@@ -217,5 +217,4 @@
v = version2Int("2.1.3.4.5")
assert.Equal(t, 201030405, v)
-
}
diff --git a/serialize_test.go b/serialize_test.go
index f521a18..4d602c5 100644
--- a/serialize_test.go
+++ b/serialize_test.go
@@ -66,7 +66,7 @@
func TestEncodeDecodeInteger(t *testing.T) {
var bigInt bigInteger
- //bigInt := new(bigInteger)
+ // bigInt := new(bigInteger)
_ = bigInt.FromString("100256")
e := NewEncoder()
err := e.Encode(bigInt)
diff --git a/string_test.go b/string_test.go
index fe034be..dbac7c5 100644
--- a/string_test.go
+++ b/string_test.go
@@ -195,7 +195,6 @@
decodePool.Put(d)
}
-
}
func TestStringEmoji(t *testing.T) {