Skip to content
Snippets Groups Projects
Commit 80feb6a9 authored by capossele's avatar capossele
Browse files

:rotating_light: fixes linter warnings.

parent 2efe84ed
No related branches found
No related tags found
No related merge requests found
......@@ -4,13 +4,12 @@ import (
"encoding/hex"
"time"
"github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/workerpool"
"github.com/iotaledger/goshimmer/packages/binary/drng/state"
"github.com/iotaledger/goshimmer/packages/shutdown"
"github.com/iotaledger/goshimmer/plugins/drng"
"github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/workerpool"
)
var drngLiveFeedWorkerCount = 1
......
......@@ -6,50 +6,60 @@ import (
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
"github.com/iotaledger/goshimmer/plugins/messagelayer"
"github.com/labstack/echo"
"github.com/pkg/errors"
)
// ExplorerMessage defines the struct of the ExplorerMessage.
type ExplorerMessage struct {
Id string `json:"id"`
Timestamp uint `json:"timestamp"`
TrunkMessageId string `json:"trunk_message_id"`
BranchMessageId string `json:"branch_message_id"`
Solid bool `json:"solid"`
// ID is the message ID.
ID string `json:"id"`
// Timestamp is the timestamp of the message.
Timestamp uint `json:"timestamp"`
// TrunkMessageId is the Trunk ID of the message.
TrunkMessageID string `json:"trunk_message_id"`
// BranchMessageId is the Branch ID of the message.
BranchMessageID string `json:"branch_message_id"`
// Solid defines the solid status of the message.
Solid bool `json:"solid"`
}
func createExplorerMessage(msg *message.Message) (*ExplorerMessage, error) {
messageId := msg.Id()
messageMetadata := messagelayer.Tangle.MessageMetadata(messageId)
messageID := msg.Id()
messageMetadata := messagelayer.Tangle.MessageMetadata(messageID)
t := &ExplorerMessage{
Id: messageId.String(),
ID: messageID.String(),
Timestamp: 0,
TrunkMessageId: msg.TrunkId().String(),
BranchMessageId: msg.BranchId().String(),
TrunkMessageID: msg.TrunkId().String(),
BranchMessageID: msg.BranchId().String(),
Solid: messageMetadata.Unwrap().IsSolid(),
}
return t, nil
}
// ExplorerAddress defines the struct of the ExplorerAddress.
type ExplorerAddress struct {
// Messagess hold the list of *ExplorerMessage.
Messages []*ExplorerMessage `json:"message"`
}
// SearchResult defines the struct of the SearchResult.
type SearchResult struct {
// Message is the *ExplorerMessage.
Message *ExplorerMessage `json:"message"`
// Address is the *ExplorerAddress.
Address *ExplorerAddress `json:"address"`
}
func setupExplorerRoutes(routeGroup *echo.Group) {
routeGroup.GET("/message/:id", func(c echo.Context) (err error) {
messageId, err := message.NewId(c.Param("id"))
messageID, err := message.NewId(c.Param("id"))
if err != nil {
return
}
t, err := findMessage(messageId)
t, err := findMessage(messageID)
if err != nil {
return
}
......@@ -78,12 +88,12 @@ func setupExplorerRoutes(routeGroup *echo.Group) {
go func() {
defer wg.Done()
messageId, err := message.NewId(search)
messageID, err := message.NewId(search)
if err != nil {
return
}
msg, err := findMessage(messageId)
msg, err := findMessage(messageID)
if err == nil {
result.Message = msg
}
......@@ -102,11 +112,11 @@ func setupExplorerRoutes(routeGroup *echo.Group) {
})
}
func findMessage(messageId message.Id) (explorerMsg *ExplorerMessage, err error) {
if !messagelayer.Tangle.Message(messageId).Consume(func(msg *message.Message) {
func findMessage(messageID message.Id) (explorerMsg *ExplorerMessage, err error) {
if !messagelayer.Tangle.Message(messageID).Consume(func(msg *message.Message) {
explorerMsg, err = createExplorerMessage(msg)
}) {
err = errors.Wrapf(ErrNotFound, "message: %s", messageId.String())
err = errors.Wrapf(ErrNotFound, "message: %s", messageID.String())
}
return
......
......@@ -3,14 +3,13 @@ package dashboard
import (
"time"
"github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/workerpool"
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/tangle"
"github.com/iotaledger/goshimmer/packages/shutdown"
"github.com/iotaledger/goshimmer/plugins/messagelayer"
"github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/workerpool"
)
var liveFeedWorkerCount = 1
......
......@@ -5,17 +5,22 @@ import (
)
const (
CFG_BIND_ADDRESS = "dashboard.bindAddress"
CFG_DEV = "dashboard.dev"
CFG_BASIC_AUTH_ENABLED = "dashboard.basic_auth.enabled"
CFG_BASIC_AUTH_USERNAME = "dashboard.basic_auth.username"
CFG_BASIC_AUTH_PASSWORD = "dashboard.basic_auth.password"
// CfgBindAddress defines the config flag of the dashboard binding address.
CfgBindAddress = "dashboard.bindAddress"
// CfgDev defines the config flag of the dashboard dev mode.
CfgDev = "dashboard.dev"
// CfgBasicAuthEnabled defines the config flag of the dashboard basic auth enabler.
CfgBasicAuthEnabled = "dashboard.basic_auth.enabled"
// CfgBasicAuthUsername defines the config flag of the dashboard basic auth username.
CfgBasicAuthUsername = "dashboard.basic_auth.username"
// CfgBasicAuthPassword defines the config flag of the dashboard basic auth password.
CfgBasicAuthPassword = "dashboard.basic_auth.password"
)
func init() {
flag.String(CFG_BIND_ADDRESS, "127.0.0.1", "the bind address of the dashboard")
flag.Bool(CFG_DEV, false, "whether the dashboard runs in dev mode")
flag.Bool(CFG_BASIC_AUTH_ENABLED, false, "whether to enable HTTP basic auth")
flag.String(CFG_BASIC_AUTH_USERNAME, "goshimmer", "HTTP basic auth username")
flag.String(CFG_BASIC_AUTH_PASSWORD, "goshimmer", "HTTP basic auth password")
flag.String(CfgBindAddress, "127.0.0.1", "the bind address of the dashboard")
flag.Bool(CfgDev, false, "whether the dashboard runs in dev mode")
flag.Bool(CfgBasicAuthEnabled, false, "whether to enable HTTP basic auth")
flag.String(CfgBasicAuthUsername, "goshimmer", "HTTP basic auth username")
flag.String(CfgBasicAuthPassword, "goshimmer", "HTTP basic auth password")
}
......@@ -9,10 +9,6 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/iotaledger/hive.go/autopeering/peer/service"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/iotaledger/goshimmer/packages/shutdown"
"github.com/iotaledger/goshimmer/plugins/autopeering"
"github.com/iotaledger/goshimmer/plugins/autopeering/local"
......@@ -21,12 +17,14 @@ import (
"github.com/iotaledger/goshimmer/plugins/gossip"
"github.com/iotaledger/goshimmer/plugins/messagelayer"
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/iotaledger/hive.go/autopeering/peer/service"
"github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/events"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
"github.com/iotaledger/hive.go/workerpool"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
// PluginName is the name of the dashboard plugin.
......@@ -40,8 +38,8 @@ var (
nodeStartAt = time.Now()
clientsMu sync.Mutex
clients = make(map[uint64]chan interface{})
nextClientID uint64 = 0
clients = make(map[uint64]chan interface{})
nextClientID uint64
wsSendWorkerCount = 1
wsSendWorkerQueueSize = 250
......@@ -90,10 +88,10 @@ func run(plugin *node.Plugin) {
e.HideBanner = true
e.Use(middleware.Recover())
if config.Node.GetBool(CFG_BASIC_AUTH_ENABLED) {
if config.Node.GetBool(CfgBasicAuthEnabled) {
e.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
if username == config.Node.GetString(CFG_BASIC_AUTH_USERNAME) &&
password == config.Node.GetString(CFG_BASIC_AUTH_PASSWORD) {
if username == config.Node.GetString(CfgBasicAuthUsername) &&
password == config.Node.GetString(CfgBasicAuthPassword) {
return true, nil
}
return false, nil
......@@ -101,7 +99,7 @@ func run(plugin *node.Plugin) {
}
setupRoutes(e)
addr := config.Node.GetString(CFG_BIND_ADDRESS)
addr := config.Node.GetString(CfgBindAddress)
log.Infof("You can now access the dashboard using: http://%s", addr)
go e.Start(addr)
......@@ -130,11 +128,17 @@ var (
)
const (
// MsgTypeNodeStatus is the type of the NodeStatus message.
MsgTypeNodeStatus byte = iota
// MsgTypeMPSMetric is the type of the message per second (MPS) metric message.
MsgTypeMPSMetric
// MsgTypeMessage is the type of the message.
MsgTypeMessage
// MsgTypeNeighborMetric is the type of the NeighborMetric message.
MsgTypeNeighborMetric
// MsgTypeDrng is the type of the dRNG message.
MsgTypeDrng
// MsgTypeTipsMetric is the type of the TipsMetric message.
MsgTypeTipsMetric
)
......@@ -144,7 +148,7 @@ type wsmsg struct {
}
type msg struct {
Id string `json:"id"`
ID string `json:"id"`
Value int64 `json:"value"`
}
......
......@@ -12,9 +12,16 @@ import (
"github.com/pkg/errors"
)
// ErrInvalidParameter defines the invalid parameter error.
var ErrInvalidParameter = errors.New("invalid parameter")
// ErrInternalError defines the internal error.
var ErrInternalError = errors.New("internal error")
// ErrNotFound defines the not found error.
var ErrNotFound = errors.New("not found")
// ErrForbidden defines the forbidden error.
var ErrForbidden = errors.New("forbidden")
// holds SPA assets
......@@ -22,7 +29,7 @@ var appBox = packr.New("Dashboard_App", "./frontend/build")
var assetsBox = packr.New("Dashboard_Assets", "./frontend/src/assets")
func indexRoute(e echo.Context) error {
if config.Node.GetBool(CFG_DEV) {
if config.Node.GetBool(CfgDev) {
res, err := http.Get("http://127.0.0.1:9090/")
if err != nil {
return err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment