forked from prest/prest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.go
43 lines (39 loc) · 1.06 KB
/
hello.go
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
// nolint
// all plugins must have their package name as `main`
// each plugin is isolated at compile time
package main
import (
"encoding/json"
)
var (
// HTTPVars route variables for the current request
HTTPVars map[string]string
// URLQuery parses RawQuery and returns the corresponding values
URLQuery map[string][]string
)
// Response return structure of the get method
type Response struct {
HTTPVars map[string]string `json:"http_vars"`
URLQuery map[string][]string `json:"url_query"`
MSG string `json:"msg"`
}
// GETHelloHandler plugin
// function is invoked via [go language plugin](https://pkg.go.dev/plugin),
// it is not possible to pass parameters, that's why there are global
// variables to receive data from http protocol
//
// BUILD:
// go build -o lib/hello.so -buildmode=plugin lib/src/hello.go
func GETHelloHandler() (ret string) {
resp := Response{
HTTPVars: HTTPVars,
URLQuery: URLQuery,
MSG: "Hello plugin caller!",
}
respJSON, err := json.Marshal(resp)
if err != nil {
return
}
ret = string(respJSON)
return
}