Make go variable accept multiple types -
i develop library in go makes use of different file formats of debug package in go standard packages (http://golang.org/pkg/debug/). idea open file , print out information file. automatically recognize correct file format testing relevant file types. instance, test if file simple mach-o or fat mach-o file, trying open file both open methods:
file, err := macho.open(filename) if err != nil { fmt.println("not mach-o file.") } file, err = macho.openfat(filename) if err != nil { fmt.println("not fat mach-o file. exiting.") return }
unfortunately file variable (of course) type checked, , following error:
cannot assign *macho.fatfile file (type *macho.file) in multiple assignment
i not sure of correct way of approaching this. can point me right direction how perfom properly?
or don't declare file @ all, if you're not going it.
if _, err := macho.open(filename); err != nil { fmt.println("not mach-o file.") } if _, err = macho.openfat(filename); err != nil { fmt.println("not fat mach-o file. exiting.") return }
if wanted call function on file, declare of interface type func(s) want call, like:
var file io.closer file, err := macho.open(filename) if err != nil { fmt.println("not mach-o file.") } file, err = macho.openfat(filename) if err != nil { fmt.println("not fat mach-o file. exiting.") return } file.close()
in case it't not interesting because looks macho.file , macho.fatfile's common function close()
Comments
Post a Comment