-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.go
More file actions
50 lines (39 loc) · 1.23 KB
/
plugin.go
File metadata and controls
50 lines (39 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/reglet-dev/reglet-plugin-sdk/application/plugin"
"github.com/reglet-dev/reglet-plugin-sdk/domain/entities"
"github.com/reglet-dev/reglet-plugin-sdk/infrastructure/wasm"
"github.com/reglet-dev/reglet/plugins/http/core"
// Import services to trigger auto-registration
_ "github.com/reglet-dev/reglet/plugins/http/services"
)
type httpPlugin struct{}
func (p *httpPlugin) Manifest(ctx context.Context) (*entities.Manifest, error) {
return core.Plugin.Manifest(), nil
}
func (p *httpPlugin) Check(ctx context.Context, configBytes []byte) (*entities.Result, error) {
// Parse config
var cfgStruct core.HTTPConfig
if err := json.Unmarshal(configBytes, &cfgStruct); err != nil {
return nil, fmt.Errorf("failed to parse config: %w", err)
}
cfg := &cfgStruct
// Determine operation - Always map to "Request"
handler, ok := core.Plugin.GetHandler("http", "request")
if !ok {
return entities.ResultErrorPtr("configuration", "Unknown operation"), nil
}
req := &plugin.Request{
Client: wasm.NewHTTPAdapter(0), // Use default HTTP adapter
Config: cfg,
Raw: configBytes,
}
return handler(ctx, req)
}
func init() {
plugin.Register(&httpPlugin{})
}
func main() {}