mirror of https://github.com/LemmyNet/lemmy
Proof of concept for Plugin system (fixes #3562)
parent
7540b02723
commit
a65ccaf665
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,5 @@
|
||||
module example_plugin
|
||||
|
||||
go 1.22.0
|
||||
|
||||
require github.com/extism/go-pdk v1.0.2 // indirect
|
@ -0,0 +1,2 @@
|
||||
github.com/extism/go-pdk v1.0.2 h1:UB7oTW3tw2zoMlsUdBEDAAbhQg9OudzgNeyCwQYZ730=
|
||||
github.com/extism/go-pdk v1.0.2/go.mod h1:Gz+LIU/YCKnKXhgge8yo5Yu1F/lbv7KtKFkiCSzW/P4=
|
@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/extism/go-pdk"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type CreatePost struct {
|
||||
Name string `json:"name"`
|
||||
Body string `json:"body"`
|
||||
// skipping other fields for now
|
||||
}
|
||||
|
||||
//export api_create_post
|
||||
func api_create_post() int32 {
|
||||
params := CreatePost{}
|
||||
// use json input helper, which automatically unmarshals the plugin input into your struct
|
||||
err := pdk.InputJSON(¶ms)
|
||||
if err != nil {
|
||||
pdk.SetError(err)
|
||||
return 1
|
||||
}
|
||||
if params.Body == "plugin should block this" {
|
||||
pdk.SetError(errors.New("blocked by plugin"))
|
||||
return 1
|
||||
}
|
||||
greeting := `Created post "` + params.Name + `"!`
|
||||
pdk.OutputString(greeting)
|
||||
return 0
|
||||
}
|
||||
|
||||
func main() {}
|
Loading…
Reference in New Issue