@@ -49,7 +49,7 @@ func (p *DirectoryPublisher) Publish(ctx context.Context, reader io.Reader) erro
4949 var message msg.Transform
5050
5151 err := jsonReader .ReadProtoMessage (& message )
52- if err == io .EOF {
52+ if errors . Is ( err , io .EOF ) {
5353 break
5454 }
5555
@@ -91,23 +91,23 @@ func (p *DirectoryPublisher) publishMessages(ctx context.Context, message *msg.T
9191
9292 errGroup .Go (p .doneHandler (stream .Context ()))
9393
94- opCode := message .OpCode
94+ opCode := message .GetOpCode ()
9595 if opCode == dsi3 .Opcode_OPCODE_UNKNOWN {
9696 opCode = dsi3 .Opcode_OPCODE_SET
9797 }
9898
9999 // import objects
100- for _ , object := range message .Objects {
100+ for _ , object := range message .GetObjects () {
101101 if err := validator .Object (object ); err != nil {
102- fmt .Fprintf (os .Stderr , "validation failed, object: [%s] type [%s]\n " , object .Id , object .Type )
102+ fmt .Fprintf (os .Stderr , "validation failed, object: [%s] type [%s]\n " , object .GetId () , object .GetType () )
103103 continue
104104 }
105105
106- if (opCode == dsi3 .Opcode_OPCODE_DELETE || opCode == dsi3 .Opcode_OPCODE_DELETE_WITH_RELATIONS ) && object .Type == "group" {
106+ if (opCode == dsi3 .Opcode_OPCODE_DELETE || opCode == dsi3 .Opcode_OPCODE_DELETE_WITH_RELATIONS ) && object .GetType () == "group" {
107107 continue
108108 }
109109
110- fmt .Fprintf (os .Stdout , "object: [%s] type [%s]\n " , object .Id , object .Type )
110+ fmt .Fprintf (os .Stdout , "object: [%s] type [%s]\n " , object .GetId () , object .GetType () )
111111 sErr := stream .Send (& dsi3.ImportRequest {
112112 Msg : & dsi3.ImportRequest_Object {
113113 Object : object ,
@@ -119,13 +119,14 @@ func (p *DirectoryPublisher) publishMessages(ctx context.Context, message *msg.T
119119 }
120120
121121 // import relations
122- for _ , relation := range message .Relations {
122+ for _ , relation := range message .GetRelations () {
123123 if err := validator .Relation (relation ); err != nil {
124- fmt .Fprintf (os .Stderr , "validation failed, relation: [%s] obj: [%s] subj [%s]\n " , relation .Relation , relation .ObjectId , relation .SubjectId )
124+ fmt .Fprintf (os .Stderr , "validation failed, relation: [%s] obj: [%s] subj [%s]\n " ,
125+ relation .GetRelation (), relation .GetObjectId (), relation .GetSubjectId ())
125126 continue
126127 }
127128
128- fmt .Fprintf (os .Stdout , "relation: [%s] obj: [%s] subj [%s]\n " , relation .Relation , relation .ObjectId , relation .SubjectId )
129+ fmt .Fprintf (os .Stdout , "relation: [%s] obj: [%s] subj [%s]\n " , relation .GetRelation () , relation .GetObjectId () , relation .GetSubjectId () )
129130 sErr := stream .Send (& dsi3.ImportRequest {
130131 Msg : & dsi3.ImportRequest_Relation {
131132 Relation : relation ,
@@ -154,15 +155,15 @@ func (p *DirectoryPublisher) handleStreamError(err error) {
154155 return
155156 }
156157
157- p .Log .Err (err )
158+ p .Log .Err (err ). Msg ( "stream error" )
158159 common .SetExitCode (1 )
159160}
160161
161162func (p * DirectoryPublisher ) receiver (stream dsi3.Importer_ImportClient ) func () error {
162163 return func () error {
163164 for {
164165 result , err := stream .Recv ()
165- if err == io .EOF {
166+ if errors . Is ( err , io .EOF ) {
166167 return nil
167168 }
168169
@@ -171,13 +172,13 @@ func (p *DirectoryPublisher) receiver(stream dsi3.Importer_ImportClient) func()
171172 }
172173
173174 if result != nil {
174- switch m := result .Msg .(type ) {
175+ switch m := result .GetMsg () .(type ) {
175176 case * dsi3.ImportResponse_Status :
176177 p .errs = true
177178
178179 printStatus (os .Stderr , m .Status )
179180 case * dsi3.ImportResponse_Counter :
180- switch m .Counter .Type {
181+ switch m .Counter .GetType () {
181182 case objectsCounter :
182183 p .objCounter = m .Counter
183184 case relationsCounter :
@@ -206,17 +207,17 @@ func (p *DirectoryPublisher) doneHandler(ctx context.Context) func() error {
206207func printStatus (w io.Writer , status * dsi3.ImportStatus ) {
207208 fmt .Fprintf (w , "%-9s : %s - %s (%d)\n " ,
208209 "error" ,
209- status .Msg ,
210- codes .Code (status .Code ).String (),
211- status .Code )
210+ status .GetMsg () ,
211+ codes .Code (status .GetCode () ).String (),
212+ status .GetCode () )
212213}
213214
214215func printCounter (w io.Writer , ctr * dsi3.ImportCounter ) {
215216 fmt .Fprintf (w , "%-9s : %d (set:%d delete:%d error:%d)\n " ,
216- ctr .Type ,
217- ctr .Recv ,
218- ctr .Set ,
219- ctr .Delete ,
220- ctr .Error ,
217+ ctr .GetType () ,
218+ ctr .GetRecv () ,
219+ ctr .GetSet () ,
220+ ctr .GetDelete () ,
221+ ctr .GetError () ,
221222 )
222223}
0 commit comments