Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
replace Json with Read
Browse files Browse the repository at this point in the history
  • Loading branch information
fayez-marble committed Jul 7, 2022
1 parent e20b63a commit 3ea9b38
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cmd/testdata/.snapshots/TestExecute-GetterAndInterfaceAndReader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package test

import (
"encoding/json"
"io"
)

type ITester interface {
Field1() string
SetField1(val string)
GetSecondField() int32
Read(p []byte) (int, error)
}

// TesterWrapper encapulates the type Tester
type TesterWrapper struct {
// The name of the original type, it gets initalized when calling Read() function, DO NOT USE IT
DataType string `json:"_data_type,omitempty"`
Tester
}

func (t TesterWrapper) Field1() string {
return t.Tester.Field1
}

func (t TesterWrapper) SetField1(val string) {
t.Tester.Field1 = val
}

func (t TesterWrapper) GetSecondField() int32
return t.Tester.Field2
}

func (t TesterWrapper) Read(p []byte) (int, error) {
t.DataType = "Tester"
data, err := json.Marshal(t)
if err != nil {
return 0, err
}
n := copy(p, data)
return n, nil
}

0 comments on commit 3ea9b38

Please sign in to comment.