Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
haoqu.ma
/
gotty
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit af411114
authored
Aug 13, 2017
by
Iwasaki Yudai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show alternative URLs when address is 0.0.0.0
1 parent
2a2a0347
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
11 deletions
server/list_address.go
server/server.go
server/list_address.go
0 → 100644
View file @
af41111
package
server
import
(
"net"
)
func
listAddresses
()
(
addresses
[]
string
)
{
ifaces
,
err
:=
net
.
Interfaces
()
if
err
!=
nil
{
return
[]
string
{}
}
addresses
=
make
([]
string
,
0
,
len
(
ifaces
))
for
_
,
iface
:=
range
ifaces
{
ifAddrs
,
_
:=
iface
.
Addrs
()
for
_
,
ifAddr
:=
range
ifAddrs
{
switch
v
:=
ifAddr
.
(
type
)
{
case
*
net
.
IPNet
:
addresses
=
append
(
addresses
,
v
.
IP
.
String
())
case
*
net
.
IPAddr
:
addresses
=
append
(
addresses
,
v
.
IP
.
String
())
}
}
}
return
addresses
}
server/server.go
View file @
af41111
...
@@ -81,18 +81,28 @@ func (server *Server) Run(ctx context.Context, options ...RunOption) error {
...
@@ -81,18 +81,28 @@ func (server *Server) Run(ctx context.Context, options ...RunOption) error {
}
}
counter
:=
newCounter
(
time
.
Duration
(
server
.
options
.
Timeout
)
*
time
.
Second
)
counter
:=
newCounter
(
time
.
Duration
(
server
.
options
.
Timeout
)
*
time
.
Second
)
url
:=
server
.
setupURL
()
path
:=
"/"
if
server
.
options
.
EnableRandomUrl
{
path
=
"/"
+
randomstring
.
Generate
(
server
.
options
.
RandomUrlLength
)
+
"/"
}
url
:=
server
.
setupURL
(
server
.
options
.
Address
,
path
)
handlers
:=
server
.
setupHandlers
(
cctx
,
cancel
,
url
,
counter
)
handlers
:=
server
.
setupHandlers
(
cctx
,
cancel
,
url
,
counter
)
srv
,
err
:=
server
.
setupHTTPServer
(
handlers
,
url
)
srv
,
err
:=
server
.
setupHTTPServer
(
handlers
,
url
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"failed to setup an HTTP server"
)
return
errors
.
Wrapf
(
err
,
"failed to setup an HTTP server"
)
}
}
log
.
Printf
(
"URL: %s"
,
url
.
String
())
log
.
Printf
(
"GoTTY server is starting at: %s"
,
url
.
String
())
if
server
.
options
.
Address
==
"0.0.0.0"
{
for
_
,
address
:=
range
listAddresses
()
{
log
.
Printf
(
"Alternative URL: %s"
,
server
.
setupURL
(
address
,
path
)
.
String
())
}
}
if
server
.
options
.
PermitWrite
{
if
server
.
options
.
PermitWrite
{
log
.
Printf
(
"Permitting clients to write input to the PTY."
)
log
.
Printf
(
"Permitting clients to write input to the PTY."
)
}
}
if
server
.
options
.
Once
{
if
server
.
options
.
Once
{
log
.
Printf
(
"Once option is provided, accepting only one client"
)
log
.
Printf
(
"Once option is provided, accepting only one client"
)
}
}
...
@@ -143,18 +153,14 @@ func (server *Server) Run(ctx context.Context, options ...RunOption) error {
...
@@ -143,18 +153,14 @@ func (server *Server) Run(ctx context.Context, options ...RunOption) error {
return
err
return
err
}
}
func
(
server
*
Server
)
setupURL
()
*
url
.
URL
{
func
(
server
*
Server
)
setupURL
(
ip
string
,
path
string
)
*
url
.
URL
{
host
:=
net
.
JoinHostPort
(
server
.
options
.
Address
,
server
.
options
.
Port
)
host
:=
net
.
JoinHostPort
(
ip
,
server
.
options
.
Port
)
scheme
:=
"http"
path
:=
"/"
if
server
.
options
.
EnableRandomUrl
{
path
=
"/"
+
randomstring
.
Generate
(
server
.
options
.
RandomUrlLength
)
+
"/"
}
scheme
:=
"http"
if
server
.
options
.
EnableTLS
{
if
server
.
options
.
EnableTLS
{
scheme
=
"https"
scheme
=
"https"
}
}
return
&
url
.
URL
{
Scheme
:
scheme
,
Host
:
host
,
Path
:
path
}
return
&
url
.
URL
{
Scheme
:
scheme
,
Host
:
host
,
Path
:
path
}
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment