-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.go
68 lines (56 loc) · 1.34 KB
/
common.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package status
import (
"context"
"github.com/go-chi/chi"
"github.com/p2pNG/core"
"github.com/p2pNG/core/internal/logging"
"net/http"
)
type coreStatusConfig struct {
BuildName string
}
type coreStatusPlugin struct {
config coreStatusConfig
}
type coreStatusContext struct {
Config coreStatusConfig
}
func (p *coreStatusPlugin) Init() error {
logging.Log().Info("Core Status Plugin Init OK!")
return nil
}
func (p *coreStatusPlugin) Config() interface{} {
return &p.config
}
func (p *coreStatusPlugin) PluginInfo() *core.PluginInfo {
return &core.PluginInfo{
Name: "github.com/p2pNG/core/services/status",
Version: "0.0.0",
Prefix: "/status",
Buckets: []string{"test-bucket"},
}
}
type contextType int
const (
pluginContext contextType = iota
)
func (p *coreStatusPlugin) GetRouter() chi.Router {
r := chi.NewRouter()
r.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), pluginContext, coreStatusContext{Config: p.config})
next.ServeHTTP(w, r.WithContext(ctx))
})
})
r.Get("/info", getNodeInfo)
return r
}
func init() {
core.RegisterRouterPlugin(&coreStatusPlugin{})
}
// NodeInfo described the basic info of a node. Used for peer discovery
type NodeInfo struct {
Name string
Version string
BuildName string
}