mirror of
https://github.com/FiloSottile/age.git
synced 2026-03-11 08:55:41 +00:00
plugin: add Plugin example
This commit is contained in:
parent
bca79c42d2
commit
582848919a
2 changed files with 43 additions and 1 deletions
43
plugin/example_test.go
Normal file
43
plugin/example_test.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package plugin_test
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"filippo.io/age"
|
||||
"filippo.io/age/plugin"
|
||||
)
|
||||
|
||||
type Recipient struct{}
|
||||
|
||||
func (r *Recipient) Wrap(fileKey []byte) ([]*age.Stanza, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
func NewRecipient(data []byte) (*Recipient, error) {
|
||||
return &Recipient{}, nil
|
||||
}
|
||||
|
||||
type Identity struct{}
|
||||
|
||||
func (i *Identity) Unwrap(s []*age.Stanza) ([]byte, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
func NewIdentity(data []byte) (*Identity, error) {
|
||||
return &Identity{}, nil
|
||||
}
|
||||
|
||||
func ExamplePlugin_main() {
|
||||
p, err := plugin.New("example")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
p.HandleRecipient(func(data []byte) (age.Recipient, error) {
|
||||
return NewRecipient(data)
|
||||
})
|
||||
p.HandleIdentity(func(data []byte) (age.Identity, error) {
|
||||
return NewIdentity(data)
|
||||
})
|
||||
os.Exit(p.Main())
|
||||
}
|
||||
|
|
@ -12,7 +12,6 @@ import (
|
|||
"filippo.io/age/internal/format"
|
||||
)
|
||||
|
||||
// TODO: add examples.
|
||||
// TODO: add plugin test framework.
|
||||
|
||||
// Plugin is a framework for writing age plugins. It allows exposing regular
|
||||
|
|
|
|||
Loading…
Reference in a new issue