mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-08-06 13:18:30 +02:00
feat(plugins): Add API Call Example Plugin
This commit is contained in:
54
example/plugins/api-call-example/main.go
Normal file
54
example/plugins/api-call-example/main.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
plugin "aroz.org/zoraxy/api-call-example/mod/zoraxy_plugin"
|
||||
)
|
||||
|
||||
const (
|
||||
PLUGIN_ID = "org.aroz.zoraxy.api_call_example"
|
||||
UI_PATH = "/ui"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Serve the plugin intro spect
|
||||
// This will print the plugin intro spect and exit if the -introspect flag is provided
|
||||
runtimeCfg, err := plugin.ServeAndRecvSpec(&plugin.IntroSpect{
|
||||
ID: PLUGIN_ID,
|
||||
Name: "API Call Example Plugin",
|
||||
Author: "Anthony Rubick",
|
||||
AuthorContact: "",
|
||||
Description: "An example plugin for making API calls",
|
||||
Type: plugin.PluginType_Utilities,
|
||||
VersionMajor: 1,
|
||||
VersionMinor: 0,
|
||||
VersionPatch: 0,
|
||||
|
||||
UIPath: UI_PATH,
|
||||
|
||||
/* API Access Control */
|
||||
PermittedAPIEndpoints: []plugin.PermittedAPIEndpoint{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Endpoint: "/api/access/list",
|
||||
Reason: "Used to display all configured Access Rules",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error serving introspect: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Start the HTTP server
|
||||
http.HandleFunc(UI_PATH+"/", func(w http.ResponseWriter, r *http.Request) {
|
||||
RenderUI(runtimeCfg, w, r)
|
||||
})
|
||||
|
||||
serverAddr := fmt.Sprintf("127.0.0.1:%d", runtimeCfg.Port)
|
||||
fmt.Printf("Starting API Call Example Plugin on %s\n", serverAddr)
|
||||
http.ListenAndServe(serverAddr, nil)
|
||||
}
|
Reference in New Issue
Block a user