Tp 55555/integrate document service client (#5)

* TP-55555 | document client and kafka integration

* TP-55555 | introduce service concept refactor code
This commit is contained in:
Varnit Goyal
2024-07-27 17:00:47 +05:30
committed by GitHub
parent f75297880d
commit f20af81520
21 changed files with 764 additions and 103 deletions

28
pkg/encoder/encoder.go Normal file
View File

@@ -0,0 +1,28 @@
package encoder
import (
"encoding/json"
"fmt"
"google.golang.org/protobuf/proto"
)
type Encoder interface {
Encode(v interface{}) ([]byte, error)
}
type JsonEncoder struct{}
type ProtoEncoder struct{}
var JsonEncoderInstance = &JsonEncoder{}
var ProtoEncoderInstance = &ProtoEncoder{}
func (j *JsonEncoder) Encode(v interface{}) ([]byte, error) {
return json.Marshal(v)
}
func (p *ProtoEncoder) Encode(v interface{}) ([]byte, error) {
if message, ok := v.(proto.Message); ok {
return proto.Marshal(message)
}
return nil, fmt.Errorf("not a proto message")
}