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 c56e41b5
authored
Aug 24, 2015
by
Iwasaki Yudai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract function for loading profile files
1 parent
acacba6f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
15 deletions
app/app.go
app/app.go
View file @
c56e41b
...
@@ -51,12 +51,32 @@ func New(options Options) (*App, error) {
...
@@ -51,12 +51,32 @@ func New(options Options) (*App, error) {
return
nil
,
errors
.
New
(
"Title format string syntax error"
)
return
nil
,
errors
.
New
(
"Title format string syntax error"
)
}
}
prefMap
,
err
:=
loadProfileFile
(
options
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
App
{
options
:
options
,
upgrader
:
&
websocket
.
Upgrader
{
ReadBufferSize
:
1024
,
WriteBufferSize
:
1024
,
Subprotocols
:
[]
string
{
"gotty"
},
},
preferences
:
prefMap
,
titleTemplate
:
titleTemplate
,
},
nil
}
func
loadProfileFile
(
options
Options
)
(
map
[
string
]
interface
{},
error
)
{
prefString
:=
[]
byte
{}
prefString
:=
[]
byte
{}
prefPath
:=
options
.
ProfileFile
prefPath
:=
options
.
ProfileFile
if
options
.
ProfileFile
==
DefaultProfileFilePath
{
if
options
.
ProfileFile
==
DefaultProfileFilePath
{
prefPath
=
os
.
Getenv
(
"HOME"
)
+
"/.gotty"
prefPath
=
os
.
Getenv
(
"HOME"
)
+
"/.gotty"
}
}
if
_
,
err
=
os
.
Stat
(
prefPath
);
os
.
IsNotExist
(
err
)
{
if
_
,
err
:
=
os
.
Stat
(
prefPath
);
os
.
IsNotExist
(
err
)
{
if
options
.
ProfileFile
!=
DefaultProfileFilePath
{
if
options
.
ProfileFile
!=
DefaultProfileFilePath
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -68,23 +88,11 @@ func New(options Options) (*App, error) {
...
@@ -68,23 +88,11 @@ func New(options Options) (*App, error) {
prefString
=
[]
byte
((
"{}"
))
prefString
=
[]
byte
((
"{}"
))
}
}
var
prefMap
map
[
string
]
interface
{}
var
prefMap
map
[
string
]
interface
{}
err
=
json
.
Unmarshal
(
prefString
,
&
prefMap
)
err
:
=
json
.
Unmarshal
(
prefString
,
&
prefMap
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
prefMap
,
nil
return
&
App
{
options
:
options
,
upgrader
:
&
websocket
.
Upgrader
{
ReadBufferSize
:
1024
,
WriteBufferSize
:
1024
,
Subprotocols
:
[]
string
{
"gotty"
},
},
preferences
:
prefMap
,
titleTemplate
:
titleTemplate
,
},
nil
}
}
func
(
app
*
App
)
Run
()
error
{
func
(
app
*
App
)
Run
()
error
{
...
...
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