forked from st3v/go-plugins
/
disable_rpc.go
45 lines (36 loc) · 867 Bytes
/
disable_rpc.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
// Package disable_rpc disables the /rpc endpoint
package disable_rpc
import (
"net/http"
"github.com/micro/cli"
"github.com/micro/micro/plugin"
)
type disable_rpc struct{}
func (i *disable_rpc) Flags() []cli.Flag {
return nil
}
func (r *disable_rpc) Commands() []cli.Command {
return nil
}
func (r *disable_rpc) Handler() plugin.Handler {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/rpc" {
http.Error(w, "forbidden", 403)
return
}
// serve request
h.ServeHTTP(w, r)
})
}
}
func (r *disable_rpc) Init(ctx *cli.Context) error {
return nil
}
func (r *disable_rpc) String() string {
return "disable_rpc"
}
// NewPlugin creates a new plugin expecting the service specified via flag
func NewPlugin() plugin.Plugin {
return &disable_rpc{}
}