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
94f42a29
Commit
94f42a29
authored
Mar 17, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add options
parent
cfa601b5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
0 deletions
+99
-0
options.go
options.go
+99
-0
No files found.
options.go
0 → 100644
View file @
94f42a29
/******************************************************
# DESC : getty client/server options
# AUTHOR : Alex Stocks
# VERSION : 1.0
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# MOD : 2018-03-17 21:12
# FILE : options.go
******************************************************/
package
getty
/////////////////////////////////////////
// Server Options
/////////////////////////////////////////
type
ServerOption
func
(
*
ServerOptions
)
type
ServerOptions
struct
{
addr
string
// websocket
path
string
cert
string
privateKey
string
caCert
string
}
// @addr server listen address.
func
WithLocalAddress
(
addr
string
)
ServerOption
{
return
func
(
o
*
ServerOptions
)
{
o
.
addr
=
addr
}
}
// @path: websocket request url path
func
WithWebsocketServerPath
(
path
string
)
ServerOption
{
return
func
(
o
*
ServerOptions
)
{
o
.
path
=
path
}
}
// @cert: server certificate file
func
WithWebsocketServerCert
(
cert
string
)
ServerOption
{
return
func
(
o
*
ServerOptions
)
{
o
.
cert
=
cert
}
}
// @key: server private key(contains its public key)
func
WithWebsocketServerPrivateKey
(
key
string
)
ServerOption
{
return
func
(
o
*
ServerOptions
)
{
o
.
privateKey
=
key
}
}
// @cert is the root certificate file to verify the legitimacy of server
func
WithWebsocketServerRootCert
(
cert
string
)
ServerOption
{
return
func
(
o
*
ServerOptions
)
{
o
.
caCert
=
cert
}
}
/////////////////////////////////////////
// Client Options
/////////////////////////////////////////
type
ClientOption
func
(
*
ClientOptions
)
type
ClientOptions
struct
{
addr
string
number
int
// for wss client
// 服务端的证书文件(包含了公钥以及服务端其他一些验证信息:服务端域名、
// 服务端ip、起始有效日期、有效时长、hash算法、秘钥长度等)
cert
string
}
// @addr is server address.
func
WithServerAddress
(
addr
string
)
ClientOption
{
return
func
(
o
*
ClientOptions
)
{
o
.
addr
=
addr
}
}
// @num is connection number.
func
WithConnectionNumber
(
num
int
)
ClientOption
{
return
func
(
o
*
ClientOptions
)
{
o
.
number
=
num
}
}
// @cert is client certificate file. it can be empty.
func
WithRootCertificateFile
(
cert
string
)
ClientOption
{
return
func
(
o
*
ClientOptions
)
{
o
.
cert
=
cert
}
}
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