mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-23 04:41:19 +00:00
32 lines
667 B
Go
32 lines
667 B
Go
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_before_create_post
|
|
func api_before_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() {}
|