Created
January 27, 2019 17:19
-
-
Save adrianlzt/b86d45551fc55669a4a763d0705b3cad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"encoding/gob" | |
"fmt" | |
"plugin" | |
) | |
func main() { | |
fmt.Println("vim-go") | |
p, err := plugin.Open("plugin/plugin.so") | |
if err != nil { | |
panic(err) | |
} | |
coso, err := p.Lookup("Coso") | |
if err != nil { | |
panic(err) | |
} | |
c := coso.(PruebaInterface) | |
j := Persona{"pepe", 32} | |
var jGob bytes.Buffer | |
enc := gob.NewEncoder(&jGob) | |
err = enc.Encode(j) | |
if err != nil { | |
panic(err) | |
} | |
c.Prueba(jGob) | |
} | |
type Persona struct { | |
Nombre string | |
Edad int | |
} | |
type PruebaInterface interface { | |
Prueba(bytes.Buffer) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"encoding/gob" | |
"fmt" | |
) | |
type coso string | |
var Coso coso | |
type Persona struct { | |
Nombre string | |
Edad int | |
} | |
func (c coso) Prueba(data bytes.Buffer) { | |
fmt.Printf("data: %+v\n", data) | |
var persona Persona | |
dec := gob.NewDecoder(&data) | |
err := dec.Decode(&persona) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("Persona nombre:%v edad:%v\n", persona.Nombre, persona.Edad) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment