Skip to content

Instantly share code, notes, and snippets.

@adrianlzt
Created January 27, 2019 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianlzt/b86d45551fc55669a4a763d0705b3cad to your computer and use it in GitHub Desktop.
Save adrianlzt/b86d45551fc55669a4a763d0705b3cad to your computer and use it in GitHub Desktop.
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)
}
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