Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
autoradio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ale
autoradio
Commits
f0ce712f
Commit
f0ce712f
authored
Apr 13, 2019
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the status template (and add a test)
parent
d65d469d
Pipeline
#2708
passed with stages
in 4 minutes and 39 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
14 deletions
+80
-14
node/bindata.go
node/bindata.go
+7
-7
node/node_test.go
node/node_test.go
+61
-0
node/server.go
node/server.go
+6
-1
node/templates/index.html
node/templates/index.html
+6
-6
No files found.
node/bindata.go
View file @
f0ce712f
...
...
@@ -272,21 +272,21 @@ var _templatesIndexHtml = []byte(`<!DOCTYPE html>
{{$domain := .Domain}}
{{range .Mounts}}
<li>
<a href="http://{{$domain}}{{.Mount.
Name
}}"
<a href="http://{{$domain}}{{.Mount.
Path
}}"
{{if .Mount.RelayUrl}}
data-toggle="tooltip" data-delay="300" title="relay of {{.Mount.RelayUrl}}"
{{end}}
>{{.Mount.
Name
}}</a>
<a href="http://{{$domain}}{{.Mount.
Name
}}.m3u">(m3u)</a>
>{{.Mount.
Path
}}</a>
<a href="http://{{$domain}}{{.Mount.
Path
}}.m3u">(m3u)</a>
<span class="badge">{{.Listeners}}</span>
{{if .TransMounts}}
<ul>
{{range .TransMounts}}
<li>
<a href="http://{{$domain}}{{.Mount.
Name
}}"
<a href="http://{{$domain}}{{.Mount.
Path
}}"
data-toggle="tooltip" data-delay="300" title="{{.Mount.Transcoding.String}}"
>{{.Mount.
Name
}}</a>
<a href="http://{{$domain}}{{.Mount.
Name
}}.m3u">(m3u)</a>
>{{.Mount.
Path
}}</a>
<a href="http://{{$domain}}{{.Mount.
Path
}}.m3u">(m3u)</a>
<span class="badge">{{.Listeners}}</span>
</li>
{{end}}
...
...
@@ -339,7 +339,7 @@ func templatesIndexHtml() (*asset, error) {
return
nil
,
err
}
info
:=
bindataFileInfo
{
name
:
"templates/index.html"
,
size
:
2567
,
mode
:
os
.
FileMode
(
420
),
modTime
:
time
.
Unix
(
15
43702463
,
0
)}
info
:=
bindataFileInfo
{
name
:
"templates/index.html"
,
size
:
2567
,
mode
:
os
.
FileMode
(
420
),
modTime
:
time
.
Unix
(
15
55111991
,
0
)}
a
:=
&
asset
{
bytes
:
bytes
,
info
:
info
}
return
a
,
nil
}
...
...
node/node_test.go
View file @
f0ce712f
...
...
@@ -5,11 +5,15 @@ import (
"fmt"
"log"
"net"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"
"git.autistici.org/ale/autoradio"
pb
"git.autistici.org/ale/autoradio/proto"
"github.com/golang/protobuf/proto"
"go.etcd.io/etcd/clientv3/concurrency"
"go.etcd.io/etcd/embed"
"go.etcd.io/etcd/etcdserver/api/v3client"
...
...
@@ -33,6 +37,7 @@ func TestNode(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"StartEtcd: %v"
,
err
)
}
defer
e
.
Close
()
<-
e
.
Server
.
ReadyNotify
()
cli
:=
v3client
.
New
(
e
.
Server
)
...
...
@@ -70,3 +75,59 @@ func TestNode(t *testing.T) {
n
.
Wait
()
}
}
func
TestNode_StatusPage
(
t
*
testing
.
T
)
{
cfg
:=
embed
.
NewConfig
()
cfg
.
Dir
=
"default.etcd"
defer
os
.
RemoveAll
(
cfg
.
Dir
)
e
,
err
:=
embed
.
StartEtcd
(
cfg
)
if
err
!=
nil
{
t
.
Fatalf
(
"StartEtcd: %v"
,
err
)
}
defer
e
.
Close
()
<-
e
.
Server
.
ReadyNotify
()
cli
:=
v3client
.
New
(
e
.
Server
)
session
,
_
:=
concurrency
.
NewSession
(
cli
,
concurrency
.
WithTTL
(
2
))
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
// Create a new Mount
m
:=
&
pb
.
Mount
{
Path
:
"/test.ogg"
,
SourceUsername
:
"user"
,
SourcePassword
:
"pass"
,
}
mdata
,
_
:=
proto
.
Marshal
(
m
)
_
,
err
=
cli
.
Put
(
ctx
,
autoradio
.
MountPrefix
+
"test.ogg"
,
string
(
mdata
))
if
err
!=
nil
{
t
.
Fatalf
(
"Put error: %v"
,
err
)
}
n
,
err
:=
New
(
ctx
,
session
,
&
fakeIcecast
{},
"node1"
,
[]
net
.
IP
{
net
.
ParseIP
(
"127.0.0.1"
)},
net
.
ParseIP
(
"127.0.0.1"
),
4014
,
"random"
,
0
,
0
,
)
if
err
!=
nil
{
t
.
Fatalf
(
"NewNode: %v"
,
err
)
}
httpSrv
:=
httptest
.
NewServer
(
newHTTPHandler
(
n
,
8080
,
"example.com"
))
resp
,
err
:=
http
.
Get
(
httpSrv
.
URL
)
if
err
!=
nil
{
t
.
Fatalf
(
"http.Get error: %v"
,
err
)
}
defer
resp
.
Body
.
Close
()
if
resp
.
StatusCode
!=
200
{
t
.
Fatalf
(
"HTTP response: %s"
,
resp
.
Status
)
}
}
node/server.go
View file @
f0ce712f
...
...
@@ -78,17 +78,22 @@ func (s *Server) Wait() error {
// NewServer creates a new Server. Will use publicAddrs / peerAddr to
// build all the necessary addr/port combinations.
//
// The main http handler will bind on all available interfaces. The
// DNS servers will bind only to the publicAddrs (both TCP and
// UDP). The metrics and the status services, which are internal, will
// bind on peerAddr.
func
NewServer
(
n
*
Node
,
domain
string
,
nameservers
[]
string
,
publicAddrs
[]
net
.
IP
,
peerAddr
net
.
IP
,
httpPort
,
dnsPort
,
gossipPort
,
icecastPort
,
metricsPort
int
)
*
Server
{
httpHandler
:=
newHTTPHandler
(
n
,
icecastPort
,
domain
)
dnsHandler
:=
newDNSHandler
(
n
,
domain
,
nameservers
)
servers
:=
[]
genericServer
{
newStatusServer
(
mkaddr
(
peerAddr
,
gossipPort
),
n
.
statusMgr
),
newHTTPServer
(
"main"
,
fmt
.
Sprintf
(
":%d"
,
httpPort
),
httpHandler
),
newHTTPServer
(
"metrics"
,
fmt
.
Sprintf
(
":%d"
,
metricsPort
),
newMetricsHandler
()),
}
for
_
,
ip
:=
range
publicAddrs
{
servers
=
append
(
servers
,
newHTTPServer
(
"main"
,
mkaddr
(
ip
,
httpPort
),
httpHandler
),
newDNSServer
(
"dns(udp)"
,
mkaddr
(
ip
,
dnsPort
),
"udp"
,
dnsHandler
),
newDNSServer
(
"dns(tcp)"
,
mkaddr
(
ip
,
dnsPort
),
"tcp"
,
dnsHandler
),
)
...
...
node/templates/index.html
View file @
f0ce712f
...
...
@@ -25,21 +25,21 @@
{{$domain := .Domain}}
{{range .Mounts}}
<li>
<a
href=
"http://{{$domain}}{{.Mount.
Name
}}"
<a
href=
"http://{{$domain}}{{.Mount.
Path
}}"
{{
if
.
Mount.RelayUrl
}}
data-toggle=
"tooltip"
data-delay=
"300"
title=
"relay of {{.Mount.RelayUrl}}"
{{
end
}}
>
{{.Mount.
Name
}}
</a>
<a
href=
"http://{{$domain}}{{.Mount.
Name
}}.m3u"
>
(m3u)
</a>
>
{{.Mount.
Path
}}
</a>
<a
href=
"http://{{$domain}}{{.Mount.
Path
}}.m3u"
>
(m3u)
</a>
<span
class=
"badge"
>
{{.Listeners}}
</span>
{{if .TransMounts}}
<ul>
{{range .TransMounts}}
<li>
<a
href=
"http://{{$domain}}{{.Mount.
Name
}}"
<a
href=
"http://{{$domain}}{{.Mount.
Path
}}"
data-toggle=
"tooltip"
data-delay=
"300"
title=
"{{.Mount.Transcoding.String}}"
>
{{.Mount.
Name
}}
</a>
<a
href=
"http://{{$domain}}{{.Mount.
Name
}}.m3u"
>
(m3u)
</a>
>
{{.Mount.
Path
}}
</a>
<a
href=
"http://{{$domain}}{{.Mount.
Path
}}.m3u"
>
(m3u)
</a>
<span
class=
"badge"
>
{{.Listeners}}
</span>
</li>
{{end}}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment