github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/packer/rpc/artifact.go (about) 1 package rpc 2 3 import ( 4 "github.com/mitchellh/packer/packer" 5 "net/rpc" 6 ) 7 8 // An implementation of packer.Artifact where the artifact is actually 9 // available over an RPC connection. 10 type artifact struct { 11 client *rpc.Client 12 endpoint string 13 } 14 15 // ArtifactServer wraps a packer.Artifact implementation and makes it 16 // exportable as part of a Golang RPC server. 17 type ArtifactServer struct { 18 artifact packer.Artifact 19 } 20 21 func (a *artifact) BuilderId() (result string) { 22 a.client.Call(a.endpoint+".BuilderId", new(interface{}), &result) 23 return 24 } 25 26 func (a *artifact) Files() (result []string) { 27 a.client.Call(a.endpoint+".Files", new(interface{}), &result) 28 return 29 } 30 31 func (a *artifact) Id() (result string) { 32 a.client.Call(a.endpoint+".Id", new(interface{}), &result) 33 return 34 } 35 36 func (a *artifact) String() (result string) { 37 a.client.Call(a.endpoint+".String", new(interface{}), &result) 38 return 39 } 40 41 func (a *artifact) Destroy() error { 42 var result error 43 if err := a.client.Call(a.endpoint+".Destroy", new(interface{}), &result); err != nil { 44 return err 45 } 46 47 return result 48 } 49 50 func (s *ArtifactServer) BuilderId(args *interface{}, reply *string) error { 51 *reply = s.artifact.BuilderId() 52 return nil 53 } 54 55 func (s *ArtifactServer) Files(args *interface{}, reply *[]string) error { 56 *reply = s.artifact.Files() 57 return nil 58 } 59 60 func (s *ArtifactServer) Id(args *interface{}, reply *string) error { 61 *reply = s.artifact.Id() 62 return nil 63 } 64 65 func (s *ArtifactServer) String(args *interface{}, reply *string) error { 66 *reply = s.artifact.String() 67 return nil 68 } 69 70 func (s *ArtifactServer) Destroy(args *interface{}, reply *error) error { 71 err := s.artifact.Destroy() 72 if err != nil { 73 err = NewBasicError(err) 74 } 75 76 *reply = err 77 return nil 78 }