Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
getty
Commits
2403c0eb
Commit
2403c0eb
authored
Oct 29, 2021
by
wei.xuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:local addr
parent
ab3fd8ec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
26 deletions
+8
-26
client.go
client.go
+0
-26
options.go
options.go
+8
-0
No files found.
client.go
View file @
2403c0eb
...
...
@@ -24,7 +24,6 @@ import (
"fmt"
"io/ioutil"
"net"
"strings"
"sync"
"sync/atomic"
"time"
...
...
@@ -111,31 +110,6 @@ func NewUDPClient(opts ...ClientOption) Client {
return
newClient
(
UDP_CLIENT
,
opts
...
)
}
// NewWSClient builds a ws client.
func
NewWSClient
(
opts
...
ClientOption
)
Client
{
c
:=
newClient
(
WS_CLIENT
,
opts
...
)
if
!
strings
.
HasPrefix
(
c
.
addr
,
"ws://"
)
{
panic
(
fmt
.
Sprintf
(
"the prefix @serverAddr:%s is not ws://"
,
c
.
addr
))
}
return
c
}
// NewWSSClient function builds a wss client.
func
NewWSSClient
(
opts
...
ClientOption
)
Client
{
c
:=
newClient
(
WSS_CLIENT
,
opts
...
)
if
c
.
cert
==
""
{
panic
(
fmt
.
Sprintf
(
"@cert:%s"
,
c
.
cert
))
}
if
!
strings
.
HasPrefix
(
c
.
addr
,
"wss://"
)
{
panic
(
fmt
.
Sprintf
(
"the prefix @serverAddr:%s is not wss://"
,
c
.
addr
))
}
return
c
}
func
(
c
*
client
)
ID
()
EndPointID
{
return
c
.
endPointID
}
...
...
options.go
View file @
2403c0eb
...
...
@@ -101,6 +101,7 @@ type ClientOption func(*ClientOptions)
type
ClientOptions
struct
{
addr
string
laddr
string
// local addr
number
int
reconnectInterval
int
// reConnect Interval
...
...
@@ -123,6 +124,13 @@ func WithServerAddress(addr string) ClientOption {
}
}
// WithLocalAddressClient @addr is server address.
func
WithLocalAddressClient
(
addr
string
)
ClientOption
{
return
func
(
o
*
ClientOptions
)
{
o
.
laddr
=
addr
}
}
// WithReconnectInterval @reconnectInterval is server address.
func
WithReconnectInterval
(
reconnectInterval
int
)
ClientOption
{
return
func
(
o
*
ClientOptions
)
{
...
...
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