mirror of
https://codeberg.org/woodpecker-plugins/go-plugin.git
synced 2024-11-24 22:35:39 +01:00
fix: make readme example compile (#17)
Resolves #16 Also formatted it. https://go.dev/play/p/sFpiRTwLGlq Reviewed-on: https://codeberg.org/woodpecker-plugins/go-plugin/pulls/17 Reviewed-by: Patrick Schratz <pat-s@noreply.codeberg.org> Co-authored-by: jolheiser <jolheiser@noreply.codeberg.org> Co-committed-by: jolheiser <jolheiser@noreply.codeberg.org>
This commit is contained in:
parent
f1c4c040ce
commit
275eb26ca7
66
README.md
66
README.md
@ -18,54 +18,56 @@ HTTP client library.
|
|||||||
## Creating plugin
|
## Creating plugin
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
package main
|
||||||
"context"
|
|
||||||
|
|
||||||
"codeberg.org/woodpecker-plugins/go-plugin"
|
import (
|
||||||
"github.com/urfave/cli/v2"
|
"context"
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
|
"codeberg.org/woodpecker-plugins/go-plugin"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
// TODO: Plugin settings
|
// TODO: Plugin settings
|
||||||
SampleFlag string
|
SampleFlag string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Plugin struct {
|
type Plugin struct {
|
||||||
*plugin.Plugin
|
*plugin.Plugin
|
||||||
Settings *Settings
|
Settings *Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) Flags() []cli.Flag {
|
func (p *Plugin) Flags() []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
// TODO: Add flags
|
// TODO: Add flags
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "sample.flag",
|
Name: "sample.flag",
|
||||||
Usage: "sample flag",
|
Usage: "sample flag",
|
||||||
EnvVars: []string{"PLUGIN_SAMPLE_FLAG"},
|
EnvVars: []string{"PLUGIN_SAMPLE_FLAG"},
|
||||||
Destination: &p.Settings.SampleFlag,
|
Destination: &p.Settings.SampleFlag,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) Execute(ctx context.Context) error {
|
func (p *Plugin) Execute(ctx context.Context) error {
|
||||||
// TODO: Implement execution
|
// TODO: Implement execution
|
||||||
log.Debug().Msg("executed")
|
log.Debug().Msg("executed")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
p := &Plugin{
|
p := &Plugin{
|
||||||
&Settings{}
|
Settings: &Settings{},
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Plugin = plugin.New(Options{
|
|
||||||
Name: "sample-plugin",
|
|
||||||
Description: "Sample plugin",
|
|
||||||
Flags: p.Flags(),
|
|
||||||
Execute: p.Execute,
|
|
||||||
})
|
|
||||||
|
|
||||||
p.Run()
|
p.Plugin = plugin.New(plugin.Options{
|
||||||
|
Name: "sample-plugin",
|
||||||
|
Description: "Sample plugin",
|
||||||
|
Flags: p.Flags(),
|
||||||
|
Execute: p.Execute,
|
||||||
|
})
|
||||||
|
|
||||||
|
p.Run()
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user