good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
upper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
open
upper
Commits
c609eb44
Commit
c609eb44
authored
Nov 19, 2014
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
fix: Moving Cluster() from db package into the mongo adapter.
parent
28ce1450
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
mongo/connection.go
+52
-0
52 additions, 0 deletions
mongo/connection.go
mongo/connection_test.go
+1
-1
1 addition, 1 deletion
mongo/connection_test.go
net.go
+0
-63
0 additions, 63 deletions
net.go
with
53 additions
and
64 deletions
mongo/connection.go
+
52
−
0
View file @
c609eb44
...
...
@@ -31,6 +31,11 @@ import (
const
connectionScheme
=
`mongodb`
// cluster is an array of hosts or sockets.
type
cluster
struct
{
address
[]
db
.
Address
}
// ConnectionURL implements a MongoDB connection struct.
type
ConnectionURL
struct
{
User
string
...
...
@@ -84,6 +89,53 @@ func (c ConnectionURL) String() (s string) {
return
u
.
String
()
}
// String returns the string representation of the cluster struct.
func
(
c
cluster
)
String
()
string
{
l
:=
len
(
c
.
address
)
addresses
:=
make
([]
string
,
0
,
l
)
for
i
:=
0
;
i
<
l
;
i
++
{
addresses
=
append
(
addresses
,
c
.
address
[
i
]
.
String
())
}
return
strings
.
Join
(
addresses
,
","
)
}
// Host is undefined in a cluster struct.
func
(
c
cluster
)
Host
()
(
string
,
error
)
{
return
""
,
db
.
ErrUndefined
}
// Port is undefined in a cluster struct.
func
(
c
cluster
)
Port
()
(
uint
,
error
)
{
return
0
,
db
.
ErrUndefined
}
// Path is undefined in a cluster struct.
func
(
c
cluster
)
Path
()
(
string
,
error
)
{
return
""
,
db
.
ErrUndefined
}
// Cluster returns the array of addresses in a cluster struct.
func
(
c
cluster
)
Cluster
()
([]
db
.
Address
,
error
)
{
return
c
.
address
,
nil
}
// Cluster converts the given Address structures into a cluster structure.
func
Cluster
(
addresses
...
db
.
Address
)
cluster
{
return
cluster
{
address
:
addresses
}
}
// ParseCluster parses s into a cluster structure.
func
ParseCluster
(
s
string
)
(
c
cluster
)
{
var
hosts
[]
string
hosts
=
strings
.
Split
(
s
,
","
)
l
:=
len
(
hosts
)
for
i
:=
0
;
i
<
l
;
i
++
{
c
.
address
=
append
(
c
.
address
,
db
.
ParseAddress
(
hosts
[
i
]))
}
return
}
// ParseURL parses s into a ConnectionURL struct.
func
ParseURL
(
s
string
)
(
conn
ConnectionURL
,
err
error
)
{
var
u
*
url
.
URL
...
...
This diff is collapsed.
Click to expand it.
mongo/connection_test.go
+
1
−
1
View file @
c609eb44
...
...
@@ -68,7 +68,7 @@ func TestConnectionURL(t *testing.T) {
}
// Setting cluster.
c
.
Address
=
db
.
Cluster
(
db
.
Host
(
"localhost"
),
db
.
Host
(
"1.2.3.4"
),
db
.
HostPort
(
"example.org"
,
1234
))
c
.
Address
=
Cluster
(
db
.
Host
(
"localhost"
),
db
.
Host
(
"1.2.3.4"
),
db
.
HostPort
(
"example.org"
,
1234
))
if
c
.
String
()
!=
"mongodb://user:pass@localhost,1.2.3.4,example.org:1234/myfilename?cache=foobar&mode=ro"
{
t
.
Fatal
(
`Test failed, got:`
,
c
.
String
())
...
...
This diff is collapsed.
Click to expand it.
net.go
+
0
−
63
View file @
c609eb44
...
...
@@ -33,7 +33,6 @@ type Address interface {
Host
()
(
string
,
error
)
Port
()
(
uint
,
error
)
Path
()
(
string
,
error
)
Cluster
()
([]
Address
,
error
)
}
// socket is a UNIX address.
...
...
@@ -47,22 +46,6 @@ type host struct {
port
uint
}
// cluster is an array of hosts or sockets.
type
cluster
struct
{
address
[]
Address
}
// ParseCluster parses s into a cluster structure.
func
ParseCluster
(
s
string
)
(
c
cluster
)
{
var
hosts
[]
string
hosts
=
strings
.
Split
(
s
,
","
)
l
:=
len
(
hosts
)
for
i
:=
0
;
i
<
l
;
i
++
{
c
.
address
=
append
(
c
.
address
,
ParseAddress
(
hosts
[
i
]))
}
return
}
// ParseAddress parses s into a host or socket structures.
func
ParseAddress
(
s
string
)
Address
{
if
strings
.
HasPrefix
(
s
,
"/"
)
{
...
...
@@ -95,11 +78,6 @@ func HostPort(name string, port uint) host {
return
host
{
name
:
name
}
}
// Cluster converts the given Address structures into a cluster structure.
func
Cluster
(
addresses
...
Address
)
cluster
{
return
cluster
{
address
:
addresses
}
}
// String returns the string representation of the host struct.
func
(
h
host
)
String
()
string
{
if
h
.
port
>
0
{
...
...
@@ -129,11 +107,6 @@ func (h host) Path() (string, error) {
return
""
,
ErrUndefined
}
// Cluster returns an array with a single host struct.
func
(
h
host
)
Cluster
()
([]
Address
,
error
)
{
return
[]
Address
{
h
},
nil
}
// String() returns the string representation of the socket struct.
func
(
s
socket
)
String
()
string
{
return
s
.
path
...
...
@@ -153,39 +126,3 @@ func (s socket) Port() (uint, error) {
func
(
s
socket
)
Path
()
(
string
,
error
)
{
return
s
.
path
,
nil
}
// Cluster returns an array with a single socket struct.
func
(
s
socket
)
Cluster
()
([]
Address
,
error
)
{
return
[]
Address
{
s
},
nil
}
// String returns the string representation of the cluster struct.
func
(
c
cluster
)
String
()
string
{
l
:=
len
(
c
.
address
)
addresses
:=
make
([]
string
,
0
,
l
)
for
i
:=
0
;
i
<
l
;
i
++
{
addresses
=
append
(
addresses
,
c
.
address
[
i
]
.
String
())
}
return
strings
.
Join
(
addresses
,
","
)
}
// Host is undefined in a cluster struct.
func
(
c
cluster
)
Host
()
(
string
,
error
)
{
return
""
,
ErrUndefined
}
// Port is undefined in a cluster struct.
func
(
c
cluster
)
Port
()
(
uint
,
error
)
{
return
0
,
ErrUndefined
}
// Path is undefined in a cluster struct.
func
(
c
cluster
)
Path
()
(
string
,
error
)
{
return
""
,
ErrUndefined
}
// Cluster returns the array of addresses in a cluster struct.
func
(
c
cluster
)
Cluster
()
([]
Address
,
error
)
{
return
c
.
address
,
nil
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment