forked from luraproject/lura
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
49 lines (48 loc) · 1.43 KB
/
doc.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
44
45
46
47
48
49
// SPDX-License-Identifier: Apache-2.0
//Package plugin provides plugin register interfaces for building http client plugins.
//
// Usage example:
//
// package main
//
// import (
// "context"
// "errors"
// "fmt"
// "html"
// "net/http"
// )
//
// // ClientRegisterer is the symbol the plugin loader will try to load. It must implement the RegisterClient interface
// var ClientRegisterer = registerer("lura-example")
//
// type registerer string
//
// func (r registerer) RegisterClients(f func(
// name string,
// handler func(context.Context, map[string]interface{}) (http.Handler, error),
// )) {
// f(string(r), r.registerClients)
// }
//
// func (r registerer) registerClients(ctx context.Context, extra map[string]interface{}) (http.Handler, error) {
// // check the passed configuration and initialize the plugin
// name, ok := extra["name"].(string)
// if !ok {
// return nil, errors.New("wrong config")
// }
// if name != string(r) {
// return nil, fmt.Errorf("unknown register %s", name)
// }
// // return the actual handler wrapping or your custom logic so it can be used as a replacement for the default http client
// return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
// fmt.Fprintf(w, "Hello, %q", html.EscapeString(req.URL.Path))
// }), nil
// }
//
// func init() {
// fmt.Println("lura-example client plugin loaded!!!")
// }
//
// func main() {}
package plugin