Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
8dacb768
Commit
8dacb768
authored
5 years ago
by
Wolfgang Welz
Browse files
Options
Downloads
Patches
Plain Diff
Add error handling to analysis http server"
parent
fc01c115
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/analysis/webinterface/httpserver/plugin.go
+35
-10
35 additions, 10 deletions
plugins/analysis/webinterface/httpserver/plugin.go
plugins/analysis/webinterface/plugin.go
+2
-2
2 additions, 2 deletions
plugins/analysis/webinterface/plugin.go
with
37 additions
and
12 deletions
plugins/analysis/webinterface/httpserver/plugin.go
+
35
−
10
View file @
8dacb768
package
httpserver
import
(
"errors"
"net/http"
"sync"
"time"
"github.com/iotaledger/goshimmer/packages/shutdown"
"github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/
node
"
"github.com/iotaledger/hive.go/
logger
"
"golang.org/x/net/context"
"golang.org/x/net/websocket"
)
var
(
log
*
logger
.
Logger
httpServer
*
http
.
Server
router
*
http
.
ServeMux
)
func
Configure
(
plugin
*
node
.
Plugin
)
{
const
name
=
"Analysis HTTP Server"
func
Configure
()
{
log
=
logger
.
NewLogger
(
name
)
router
=
http
.
NewServeMux
()
httpServer
=
&
http
.
Server
{
Addr
:
":80"
,
Handler
:
router
}
...
...
@@ -24,12 +31,30 @@ func Configure(plugin *node.Plugin) {
router
.
HandleFunc
(
"/"
,
index
)
}
func
Run
(
plugin
*
node
.
Plugin
)
{
daemon
.
BackgroundWorker
(
"Analysis HTTP Server"
,
func
(
shutdownSignal
<-
chan
struct
{})
{
go
httpServer
.
ListenAndServe
()
<-
shutdownSignal
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
0
*
time
.
Second
)
defer
cancel
()
httpServer
.
Shutdown
(
ctx
)
},
shutdown
.
ShutdownPriorityAnalysis
)
func
Run
()
{
if
err
:=
daemon
.
BackgroundWorker
(
name
,
start
,
shutdown
.
ShutdownPriorityAnalysis
);
err
!=
nil
{
log
.
Errorf
(
"Error starting as daemon: %s"
,
err
)
}
}
func
start
(
shutdownSignal
<-
chan
struct
{})
{
var
wg
sync
.
WaitGroup
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
log
.
Infof
(
name
+
" started: address=%s"
,
httpServer
.
Addr
)
if
err
:=
httpServer
.
ListenAndServe
();
err
!=
nil
&&
!
errors
.
Is
(
err
,
http
.
ErrServerClosed
)
{
log
.
Warnf
(
"Error listening: %s"
,
err
)
}
}()
<-
shutdownSignal
log
.
Info
(
"Stopping "
+
name
+
" ..."
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
)
defer
cancel
()
if
err
:=
httpServer
.
Shutdown
(
ctx
);
err
!=
nil
{
log
.
Errorf
(
"Error closing: %s"
,
err
)
}
wg
.
Wait
()
log
.
Info
(
"Stopping "
+
name
+
" ... done"
)
}
This diff is collapsed.
Click to expand it.
plugins/analysis/webinterface/plugin.go
+
2
−
2
View file @
8dacb768
...
...
@@ -7,10 +7,10 @@ import (
)
func
Configure
(
plugin
*
node
.
Plugin
)
{
httpserver
.
Configure
(
plugin
)
httpserver
.
Configure
()
recordedevents
.
Configure
(
plugin
)
}
func
Run
(
plugin
*
node
.
Plugin
)
{
httpserver
.
Run
(
plugin
)
httpserver
.
Run
()
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment