github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/imageunpacker/client/addDevice.go (about) 1 package client 2 3 import ( 4 "errors" 5 6 "github.com/Cloud-Foundations/Dominator/lib/srpc" 7 ) 8 9 func addDevice(client *srpc.Client, deviceId string, adder func() error) error { 10 conn, err := client.Call("ImageUnpacker.AddDevice") 11 if err != nil { 12 return err 13 } 14 defer conn.Close() 15 response, err := conn.ReadString('\n') 16 if err != nil { 17 return err 18 } 19 response = response[:len(response)-1] 20 if response != "" { 21 return errors.New(response) 22 } 23 if err := adder(); err != nil { 24 return err 25 } 26 if _, err := conn.WriteString(deviceId + "\n"); err != nil { 27 return err 28 } 29 if err := conn.Flush(); err != nil { 30 return err 31 } 32 response, err = conn.ReadString('\n') 33 if err != nil { 34 return err 35 } 36 response = response[:len(response)-1] 37 if response != "" { 38 return errors.New(response) 39 } 40 return nil 41 }