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 83923b6f
authored
Sep 01, 2015
by
Iwasaki Yudai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check config file syntax
1 parent
62f5d4aa
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
23 additions
and
240 deletions
Godeps/Godeps.json
Godeps/_workspace/src/github.com/fatih/camelcase/.travis.yml
Godeps/_workspace/src/github.com/fatih/camelcase/LICENSE.md
Godeps/_workspace/src/github.com/fatih/camelcase/README.md
Godeps/_workspace/src/github.com/fatih/camelcase/camelcase.go
Godeps/_workspace/src/github.com/fatih/camelcase/camelcase_test.go
app/app.go
app/client_context.go
Godeps/Godeps.json
View file @
83923b6
...
...
@@ -17,10 +17,6 @@
"Rev"
:
"d5cac425555ca5cf00694df246e04f05e6a55150"
},
{
"ImportPath"
:
"github.com/fatih/camelcase"
,
"Rev"
:
"332844f2fb0193cce955f4687646abbdcc43ceeb"
},
{
"ImportPath"
:
"github.com/fatih/structs"
,
"Rev"
:
"a9f7daa9c2729e97450c2da2feda19130a367d8f"
},
...
...
Godeps/_workspace/src/github.com/fatih/camelcase/.travis.yml
deleted
100644 → 0
View file @
62f5d4a
language
:
go
go
:
1.4
Godeps/_workspace/src/github.com/fatih/camelcase/LICENSE.md
deleted
100644 → 0
View file @
62f5d4a
The MIT License (MIT)
Copyright (c) 2015 Fatih Arslan
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Godeps/_workspace/src/github.com/fatih/camelcase/README.md
deleted
100644 → 0
View file @
62f5d4a
# CamelCase [](http://godoc.org/github.com/fatih/camelcase) [](https://travis-ci.org/fatih/camelcase)
CamelCase is a Golang (Go) package to split the words of a camelcase type
string into a slice of words. It can be used to convert a camelcase word (lower
or upper case) into any type of word.
## Install
```
bash
go get github.com/fatih/camelcase
```
## Usage and examples
```
go
splitted
:=
camelcase
.
Split
(
"GolangPackage"
)
fmt
.
Println
(
splitted
[
0
],
splitted
[
1
])
// prints: "Golang", "Package"
```
Both lower camel case and upper camel case are supported. For more info please
check:
[
http://en.wikipedia.org/wiki/CamelCase
](
http://en.wikipedia.org/wiki/CamelCase
)
Below are some example cases:
```
lowercase => ["lowercase"]
Class => ["Class"]
MyClass => ["My", "Class"]
MyC => ["My", "C"]
HTML => ["HTML"]
PDFLoader => ["PDF", "Loader"]
AString => ["A", "String"]
SimpleXMLParser => ["Simple", "XML", "Parser"]
vimRPCPlugin => ["vim", "RPC", "Plugin"]
GL11Version => ["GL", "11", "Version"]
99Bottles => ["99", "Bottles"]
May5 => ["May", "5"]
BFG9000 => ["BFG", "9000"]
```
Godeps/_workspace/src/github.com/fatih/camelcase/camelcase.go
deleted
100644 → 0
View file @
62f5d4a
// Package camelcase is a micro package to split the words of a camelcase type
// string into a slice of words.
package
camelcase
import
"unicode"
// Split splits the camelcase word and returns a list of words. It also
// supports digits. Both lower camel case and upper camel case are supported.
// For more info please check: http://en.wikipedia.org/wiki/CamelCase
//
// Below are some example cases:
// lowercase => ["lowercase"]
// Class => ["Class"]
// MyClass => ["My", "Class"]
// MyC => ["My", "C"]
// HTML => ["HTML"]
// PDFLoader => ["PDF", "Loader"]
// AString => ["A", "String"]
// SimpleXMLParser => ["Simple", "XML", "Parser"]
// vimRPCPlugin => ["vim", "RPC", "Plugin"]
// GL11Version => ["GL", "11", "Version"]
// 99Bottles => ["99", "Bottles"]
// May5 => ["May", "5"]
// BFG9000 => ["BFG", "9000"]
func
Split
(
src
string
)
[]
string
{
if
src
==
""
{
return
[]
string
{}
}
splitIndex
:=
[]
int
{}
for
i
,
r
:=
range
src
{
// we don't care about first index
if
i
==
0
{
continue
}
// search till we find an upper case
if
unicode
.
IsLower
(
r
)
{
continue
}
prevRune
:=
rune
(
src
[
i
-
1
])
// for cases like: GL11Version, BFG9000
if
unicode
.
IsDigit
(
r
)
&&
!
unicode
.
IsDigit
(
prevRune
)
{
splitIndex
=
append
(
splitIndex
,
i
)
continue
}
if
!
unicode
.
IsDigit
(
r
)
&&
!
unicode
.
IsUpper
(
prevRune
)
{
// for cases like: MyC
if
i
+
1
==
len
(
src
)
{
splitIndex
=
append
(
splitIndex
,
i
)
continue
}
// for cases like: SimpleXMLParser, eclipseRCPExt
if
unicode
.
IsUpper
(
rune
(
src
[
i
+
1
]))
{
splitIndex
=
append
(
splitIndex
,
i
)
continue
}
}
// If the next char is lower case, we have found a split index
if
i
+
1
!=
len
(
src
)
&&
unicode
.
IsLower
(
rune
(
src
[
i
+
1
]))
{
splitIndex
=
append
(
splitIndex
,
i
)
}
}
// nothing to split, such as "hello", "Class", "HTML"
if
len
(
splitIndex
)
==
0
{
return
[]
string
{
src
}
}
// now split the input string into pieces
splitted
:=
make
([]
string
,
len
(
splitIndex
)
+
1
)
for
i
:=
0
;
i
<
len
(
splitIndex
)
+
1
;
i
++
{
if
i
==
0
{
// first index
splitted
[
i
]
=
src
[
:
splitIndex
[
0
]]
}
else
if
i
==
len
(
splitIndex
)
{
// last index
splitted
[
i
]
=
src
[
splitIndex
[
i
-
1
]
:
]
}
else
{
// between first and last index
splitted
[
i
]
=
src
[
splitIndex
[
i
-
1
]
:
splitIndex
[
i
]]
}
}
return
splitted
}
Godeps/_workspace/src/github.com/fatih/camelcase/camelcase_test.go
deleted
100644 → 0
View file @
62f5d4a
package
camelcase
import
(
"reflect"
"testing"
)
func
TestSplit
(
t
*
testing
.
T
)
{
var
testCases
=
[]
struct
{
input
string
output
[]
string
}{
{
input
:
""
,
output
:
[]
string
{}},
{
input
:
"lowercase"
,
output
:
[]
string
{
"lowercase"
}},
{
input
:
"Class"
,
output
:
[]
string
{
"Class"
}},
{
input
:
"MyClass"
,
output
:
[]
string
{
"My"
,
"Class"
}},
{
input
:
"MyC"
,
output
:
[]
string
{
"My"
,
"C"
}},
{
input
:
"HTML"
,
output
:
[]
string
{
"HTML"
}},
{
input
:
"PDFLoader"
,
output
:
[]
string
{
"PDF"
,
"Loader"
}},
{
input
:
"AString"
,
output
:
[]
string
{
"A"
,
"String"
}},
{
input
:
"SimpleXMLParser"
,
output
:
[]
string
{
"Simple"
,
"XML"
,
"Parser"
}},
{
input
:
"vimRPCPlugin"
,
output
:
[]
string
{
"vim"
,
"RPC"
,
"Plugin"
}},
{
input
:
"GL11Version"
,
output
:
[]
string
{
"GL"
,
"11"
,
"Version"
}},
{
input
:
"99Bottles"
,
output
:
[]
string
{
"99"
,
"Bottles"
}},
{
input
:
"May5"
,
output
:
[]
string
{
"May"
,
"5"
}},
{
input
:
"BFG9000"
,
output
:
[]
string
{
"BFG"
,
"9000"
}},
}
for
_
,
c
:=
range
testCases
{
res
:=
Split
(
c
.
input
)
if
!
reflect
.
DeepEqual
(
res
,
c
.
output
)
{
t
.
Errorf
(
"input: '%s'
\n\t
want: %v
\n\t
got : %v
\n
"
,
c
.
input
,
c
.
output
,
res
)
}
}
}
app/app.go
View file @
83923b6
...
...
@@ -18,8 +18,6 @@ import (
"github.com/braintree/manners"
"github.com/elazarl/go-bindata-assetfs"
"github.com/fatih/camelcase"
"github.com/fatih/structs"
"github.com/gorilla/websocket"
"github.com/hashicorp/hcl"
"github.com/kr/pty"
...
...
@@ -36,22 +34,22 @@ type App struct {
}
type
Options
struct
{
Address
string
Port
string
PermitWrite
bool
EnableBasicAuth
bool
Credential
string
EnableRandomUrl
bool
RandomUrlLength
int
IndexFile
string
EnableTLS
bool
TLSCrtFile
string
TLSKeyFile
string
TitleFormat
string
EnableReconnect
bool
ReconnectTime
int
Once
bool
Preferences
map
[
string
]
interface
{}
Address
string
`hcl:"address"`
Port
string
`hcl:"port"`
PermitWrite
bool
`hcl:"permit_write"`
EnableBasicAuth
bool
`hcl:"enable_basic_auth"`
Credential
string
`hcl:"credential"`
EnableRandomUrl
bool
`hcl:"enable_random_url"`
RandomUrlLength
int
`hcl:"random_url_length"`
IndexFile
string
`hcl:"index_file"`
EnableTLS
bool
`hcl:"enable_tls"`
TLSCrtFile
string
`hcl:"tls_crt_file"`
TLSKeyFile
string
`hcl:"tls_key_file"`
TitleFormat
string
`hcl:"title_format"`
EnableReconnect
bool
`hcl:"enable_reconnect"`
ReconnectTime
int
`hcl:"reconnect_time"`
Once
bool
`hcl:"once"`
Preferences
map
[
string
]
interface
{}
`hcl:"preferences"`
}
var
DefaultOptions
=
Options
{
...
...
@@ -106,34 +104,8 @@ func ApplyConfigFile(options *Options, filePath string) error {
return
err
}
config
:=
make
(
map
[
string
]
interface
{})
hcl
.
Decode
(
&
config
,
string
(
fileString
))
o
:=
structs
.
New
(
options
)
for
_
,
name
:=
range
o
.
Names
()
{
configName
:=
strings
.
ToLower
(
strings
.
Join
(
camelcase
.
Split
(
name
),
"_"
))
if
val
,
ok
:=
config
[
configName
];
ok
{
field
,
ok
:=
o
.
FieldOk
(
name
)
if
!
ok
{
return
errors
.
New
(
"No such option: "
+
name
)
}
var
err
error
if
name
==
"Preferences"
{
prefs
:=
val
.
([]
map
[
string
]
interface
{})[
0
]
htermPrefs
:=
make
(
map
[
string
]
interface
{})
for
key
,
value
:=
range
prefs
{
htermPrefs
[
strings
.
Replace
(
key
,
"_"
,
"-"
,
-
1
)]
=
value
}
err
=
field
.
Set
(
htermPrefs
)
}
else
{
err
=
field
.
Set
(
val
)
}
if
err
!=
nil
{
return
err
}
}
if
err
:=
hcl
.
Decode
(
options
,
string
(
fileString
));
err
!=
nil
{
return
err
}
return
nil
...
...
app/client_context.go
View file @
83923b6
...
...
@@ -128,7 +128,11 @@ func (context *clientContext) sendInitialize() error {
}
writer
.
Close
()
prefs
,
_
:=
json
.
Marshal
(
context
.
app
.
options
.
Preferences
)
htermPrefs
:=
make
(
map
[
string
]
interface
{})
for
key
,
value
:=
range
context
.
app
.
options
.
Preferences
{
htermPrefs
[
strings
.
Replace
(
key
,
"_"
,
"-"
,
-
1
)]
=
value
}
prefs
,
_
:=
json
.
Marshal
(
htermPrefs
)
context
.
connection
.
WriteMessage
(
websocket
.
TextMessage
,
append
([]
byte
{
SetPreferences
},
prefs
...
),
...
...
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