-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClientSettings.go
More file actions
68 lines (54 loc) · 1.5 KB
/
ClientSettings.go
File metadata and controls
68 lines (54 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package jrm1
import (
"errors"
"net/http"
)
const (
ErrClientSettingsError = "error is client settings"
)
// ClientSettings are settings of an RPC client.
type ClientSettings struct {
// Target server URL schema.
schema string
// Target server host name.
host string
// Target server port number.
port uint16
// Relative URL path to which the client makes requests.
// A typical URL path is "/", however it may be different if a custom RPC
// server is used.
path string
// Custom HTTP client.
httpClient *http.Client
// Custom HTTP headers.
httpHeaders map[string]string
// If enabled, some of HTML entities will be escaped during JSON encoding.
useHtmlEscaping bool
}
// NewClientSettings is a constructor of an RPC client settings.
func NewClientSettings(schema string, host string, port uint16, path string, customHttpClient *http.Client, customHttpHeaders map[string]string, useHtmlEscaping bool) (cs *ClientSettings, err error) {
cs = &ClientSettings{
schema: schema,
host: host,
port: port,
path: path,
httpClient: customHttpClient,
httpHeaders: customHttpHeaders,
useHtmlEscaping: useHtmlEscaping,
}
err = cs.Check()
if err != nil {
return nil, err
}
return cs, nil
}
// Check validates the settings of an RPC client.
func (cs *ClientSettings) Check() (err error) {
if (len(cs.schema) == 0) ||
(len(cs.host) == 0) ||
(cs.port == 0) ||
(len(cs.path) == 0) {
return errors.New(ErrClientSettingsError)
}
return nil
}