Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-datastore
Commits
6fd76857
Commit
6fd76857
authored
Jan 30, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
elastigo: switched to use url address
parent
bccfea83
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
14 deletions
+24
-14
elastigo/datastore.go
elastigo/datastore.go
+24
-14
No files found.
elastigo/datastore.go
View file @
6fd76857
...
...
@@ -6,6 +6,8 @@ import (
ds
"github.com/jbenet/datastore.go"
"github.com/mattbaird/elastigo/api"
"github.com/mattbaird/elastigo/core"
"net/url"
"strings"
)
// Currently, elastigo does not allow connecting to multiple elasticsearch
...
...
@@ -14,16 +16,11 @@ import (
//
// Thus, we use a global static variable (GlobalInstance), and return an
// error if NewDatastore is called twice with different addresses.
var
GlobalInstance
Address
type
Address
struct
{
Host
string
Port
int
}
var
GlobalInstance
string
// Datastore uses a standard Go map for internal storage.
type
Datastore
struct
{
addr
Address
url
string
index
string
// Elastic search does not allow slashes in their object ids,
...
...
@@ -31,19 +28,32 @@ type Datastore struct {
KeyHash
func
(
ds
.
Key
)
string
}
func
NewDatastore
(
addr
Address
,
index
string
)
(
*
Datastore
,
error
)
{
if
GlobalInstance
.
Host
!=
""
&&
GlobalInstance
!=
add
r
{
func
NewDatastore
(
urlstr
string
)
(
*
Datastore
,
error
)
{
if
GlobalInstance
!=
""
&&
GlobalInstance
!=
urlst
r
{
return
nil
,
fmt
.
Errorf
(
"elastigo only allows one client. See godoc."
)
}
api
.
Domain
=
addr
.
Host
if
addr
.
Port
>
0
{
api
.
Port
=
fmt
.
Sprintf
(
"%d"
,
addr
.
Port
)
uf
:=
"http://<host>:<port>/<index>"
u
,
err
:=
url
.
Parse
(
urlstr
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error parsing url: %s (%s)"
,
urlstr
,
uf
)
}
host
:=
strings
.
Split
(
u
.
Host
,
":"
)
api
.
Domain
=
host
[
0
]
if
len
(
host
)
>
1
{
api
.
Port
=
host
[
1
]
}
index
:=
strings
.
Trim
(
u
.
Path
,
"/"
)
if
strings
.
Contains
(
index
,
"/"
)
{
e
:=
"elastigo index cannot have slashes: %s (%s -> %s)"
return
nil
,
fmt
.
Errorf
(
e
,
index
,
urlstr
,
uf
)
}
GlobalInstance
=
add
r
GlobalInstance
=
urlst
r
return
&
Datastore
{
addr
:
add
r
,
url
:
urlst
r
,
index
:
index
,
KeyHash
:
BlakeKeyHash
,
},
nil
...
...
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