id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
152,100 | denverdino/aliyungo | cdn/auth/sign_url.go | Sign | func (s URLSigner) Sign(uri string, expires time.Time) (string, error) {
r, err := url.Parse(uri)
if err != nil {
return "", fmt.Errorf("unable to parse url: %s", uri)
}
switch s.authType {
case "a":
return aTypeSign(r, s.privKey, expires), nil
case "b":
return bTypeSign(r, s.privKey, expires), nil
case "c":
return cTypeSign(r, s.privKey, expires), nil
default:
return "", fmt.Errorf("invalid authentication type")
}
} | go | func (s URLSigner) Sign(uri string, expires time.Time) (string, error) {
r, err := url.Parse(uri)
if err != nil {
return "", fmt.Errorf("unable to parse url: %s", uri)
}
switch s.authType {
case "a":
return aTypeSign(r, s.privKey, expires), nil
case "b":
return bTypeSign(r, s.privKey, expires), nil
case "c":
return cTypeSign(r, s.privKey, expires), nil
default:
return "", fmt.Errorf("invalid authentication type")
}
} | [
"func",
"(",
"s",
"URLSigner",
")",
"Sign",
"(",
"uri",
"string",
",",
"expires",
"time",
".",
"Time",
")",
"(",
"string",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"uri",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"uri",
")",
"\n",
"}",
"\n\n",
"switch",
"s",
".",
"authType",
"{",
"case",
"\"",
"\"",
":",
"return",
"aTypeSign",
"(",
"r",
",",
"s",
".",
"privKey",
",",
"expires",
")",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"bTypeSign",
"(",
"r",
",",
"s",
".",
"privKey",
",",
"expires",
")",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"cTypeSign",
"(",
"r",
",",
"s",
".",
"privKey",
",",
"expires",
")",
",",
"nil",
"\n",
"default",
":",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // Sign returns a signed aliyuncdn url based on authentication type | [
"Sign",
"returns",
"a",
"signed",
"aliyuncdn",
"url",
"based",
"on",
"authentication",
"type"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/cdn/auth/sign_url.go#L27-L43 |
152,101 | denverdino/aliyungo | oss/multi.go | Complete | func (m *Multi) Complete(parts []Part) error {
params := make(url.Values)
params.Set("uploadId", m.UploadId)
c := completeUpload{}
for _, p := range parts {
c.Parts = append(c.Parts, completePart{p.N, p.ETag})
}
sort.Sort(c.Parts)
data, err := xml.Marshal(&c)
if err != nil {
return err
}
for attempt := attempts.Start(); attempt.Next(); {
req := &request{
method: "POST",
bucket: m.Bucket.Name,
path: m.Key,
params: params,
payload: bytes.NewReader(data),
}
err := m.Bucket.Client.query(req, nil)
if shouldRetry(err) && attempt.HasNext() {
continue
}
return err
}
panic("unreachable")
} | go | func (m *Multi) Complete(parts []Part) error {
params := make(url.Values)
params.Set("uploadId", m.UploadId)
c := completeUpload{}
for _, p := range parts {
c.Parts = append(c.Parts, completePart{p.N, p.ETag})
}
sort.Sort(c.Parts)
data, err := xml.Marshal(&c)
if err != nil {
return err
}
for attempt := attempts.Start(); attempt.Next(); {
req := &request{
method: "POST",
bucket: m.Bucket.Name,
path: m.Key,
params: params,
payload: bytes.NewReader(data),
}
err := m.Bucket.Client.query(req, nil)
if shouldRetry(err) && attempt.HasNext() {
continue
}
return err
}
panic("unreachable")
} | [
"func",
"(",
"m",
"*",
"Multi",
")",
"Complete",
"(",
"parts",
"[",
"]",
"Part",
")",
"error",
"{",
"params",
":=",
"make",
"(",
"url",
".",
"Values",
")",
"\n",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"m",
".",
"UploadId",
")",
"\n\n",
"c",
":=",
"completeUpload",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"parts",
"{",
"c",
".",
"Parts",
"=",
"append",
"(",
"c",
".",
"Parts",
",",
"completePart",
"{",
"p",
".",
"N",
",",
"p",
".",
"ETag",
"}",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"c",
".",
"Parts",
")",
"\n",
"data",
",",
"err",
":=",
"xml",
".",
"Marshal",
"(",
"&",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"attempt",
":=",
"attempts",
".",
"Start",
"(",
")",
";",
"attempt",
".",
"Next",
"(",
")",
";",
"{",
"req",
":=",
"&",
"request",
"{",
"method",
":",
"\"",
"\"",
",",
"bucket",
":",
"m",
".",
"Bucket",
".",
"Name",
",",
"path",
":",
"m",
".",
"Key",
",",
"params",
":",
"params",
",",
"payload",
":",
"bytes",
".",
"NewReader",
"(",
"data",
")",
",",
"}",
"\n",
"err",
":=",
"m",
".",
"Bucket",
".",
"Client",
".",
"query",
"(",
"req",
",",
"nil",
")",
"\n",
"if",
"shouldRetry",
"(",
"err",
")",
"&&",
"attempt",
".",
"HasNext",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // Complete assembles the given previously uploaded parts into the
// final object. This operation may take several minutes.
// | [
"Complete",
"assembles",
"the",
"given",
"previously",
"uploaded",
"parts",
"into",
"the",
"final",
"object",
".",
"This",
"operation",
"may",
"take",
"several",
"minutes",
"."
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/oss/multi.go#L425-L453 |
152,102 | denverdino/aliyungo | common/client.go | Init | func (client *Client) Init(endpoint, version, accessKeyId, accessKeySecret string) {
client.AccessKeyId = accessKeyId
ak := accessKeySecret
if !strings.HasSuffix(ak, "&") {
ak += "&"
}
client.AccessKeySecret = ak
client.debug = false
handshakeTimeout, err := strconv.Atoi(os.Getenv("TLSHandshakeTimeout"))
if err != nil {
handshakeTimeout = 0
}
if handshakeTimeout == 0 {
client.httpClient = &http.Client{}
} else {
t := &http.Transport{
TLSHandshakeTimeout: time.Duration(handshakeTimeout) * time.Second}
client.httpClient = &http.Client{Transport: t}
}
client.endpoint = endpoint
client.version = version
} | go | func (client *Client) Init(endpoint, version, accessKeyId, accessKeySecret string) {
client.AccessKeyId = accessKeyId
ak := accessKeySecret
if !strings.HasSuffix(ak, "&") {
ak += "&"
}
client.AccessKeySecret = ak
client.debug = false
handshakeTimeout, err := strconv.Atoi(os.Getenv("TLSHandshakeTimeout"))
if err != nil {
handshakeTimeout = 0
}
if handshakeTimeout == 0 {
client.httpClient = &http.Client{}
} else {
t := &http.Transport{
TLSHandshakeTimeout: time.Duration(handshakeTimeout) * time.Second}
client.httpClient = &http.Client{Transport: t}
}
client.endpoint = endpoint
client.version = version
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"Init",
"(",
"endpoint",
",",
"version",
",",
"accessKeyId",
",",
"accessKeySecret",
"string",
")",
"{",
"client",
".",
"AccessKeyId",
"=",
"accessKeyId",
"\n",
"ak",
":=",
"accessKeySecret",
"\n",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"ak",
",",
"\"",
"\"",
")",
"{",
"ak",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"client",
".",
"AccessKeySecret",
"=",
"ak",
"\n",
"client",
".",
"debug",
"=",
"false",
"\n",
"handshakeTimeout",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"handshakeTimeout",
"=",
"0",
"\n",
"}",
"\n",
"if",
"handshakeTimeout",
"==",
"0",
"{",
"client",
".",
"httpClient",
"=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n",
"}",
"else",
"{",
"t",
":=",
"&",
"http",
".",
"Transport",
"{",
"TLSHandshakeTimeout",
":",
"time",
".",
"Duration",
"(",
"handshakeTimeout",
")",
"*",
"time",
".",
"Second",
"}",
"\n",
"client",
".",
"httpClient",
"=",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"t",
"}",
"\n",
"}",
"\n",
"client",
".",
"endpoint",
"=",
"endpoint",
"\n",
"client",
".",
"version",
"=",
"version",
"\n",
"}"
] | // Initialize properties of a client instance | [
"Initialize",
"properties",
"of",
"a",
"client",
"instance"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/client.go#L44-L65 |
152,103 | denverdino/aliyungo | common/client.go | NewInit | func (client *Client) NewInit(endpoint, version, accessKeyId, accessKeySecret, serviceCode string, regionID Region) {
client.Init(endpoint, version, accessKeyId, accessKeySecret)
client.serviceCode = serviceCode
client.regionID = regionID
} | go | func (client *Client) NewInit(endpoint, version, accessKeyId, accessKeySecret, serviceCode string, regionID Region) {
client.Init(endpoint, version, accessKeyId, accessKeySecret)
client.serviceCode = serviceCode
client.regionID = regionID
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"NewInit",
"(",
"endpoint",
",",
"version",
",",
"accessKeyId",
",",
"accessKeySecret",
",",
"serviceCode",
"string",
",",
"regionID",
"Region",
")",
"{",
"client",
".",
"Init",
"(",
"endpoint",
",",
"version",
",",
"accessKeyId",
",",
"accessKeySecret",
")",
"\n",
"client",
".",
"serviceCode",
"=",
"serviceCode",
"\n",
"client",
".",
"regionID",
"=",
"regionID",
"\n",
"}"
] | // Initialize properties of a client instance including regionID | [
"Initialize",
"properties",
"of",
"a",
"client",
"instance",
"including",
"regionID"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/client.go#L68-L72 |
152,104 | denverdino/aliyungo | common/client.go | InitClient | func (client *Client) InitClient() *Client {
client.debug = false
handshakeTimeout, err := strconv.Atoi(os.Getenv("TLSHandshakeTimeout"))
if err != nil {
handshakeTimeout = 0
}
if handshakeTimeout == 0 {
client.httpClient = &http.Client{}
} else {
t := &http.Transport{
TLSHandshakeTimeout: time.Duration(handshakeTimeout) * time.Second}
client.httpClient = &http.Client{Transport: t}
}
return client
} | go | func (client *Client) InitClient() *Client {
client.debug = false
handshakeTimeout, err := strconv.Atoi(os.Getenv("TLSHandshakeTimeout"))
if err != nil {
handshakeTimeout = 0
}
if handshakeTimeout == 0 {
client.httpClient = &http.Client{}
} else {
t := &http.Transport{
TLSHandshakeTimeout: time.Duration(handshakeTimeout) * time.Second}
client.httpClient = &http.Client{Transport: t}
}
return client
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"InitClient",
"(",
")",
"*",
"Client",
"{",
"client",
".",
"debug",
"=",
"false",
"\n",
"handshakeTimeout",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"handshakeTimeout",
"=",
"0",
"\n",
"}",
"\n",
"if",
"handshakeTimeout",
"==",
"0",
"{",
"client",
".",
"httpClient",
"=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n",
"}",
"else",
"{",
"t",
":=",
"&",
"http",
".",
"Transport",
"{",
"TLSHandshakeTimeout",
":",
"time",
".",
"Duration",
"(",
"handshakeTimeout",
")",
"*",
"time",
".",
"Second",
"}",
"\n",
"client",
".",
"httpClient",
"=",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"t",
"}",
"\n",
"}",
"\n",
"return",
"client",
"\n",
"}"
] | // Intialize client object when all properties are ready | [
"Intialize",
"client",
"object",
"when",
"all",
"properties",
"are",
"ready"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/client.go#L75-L89 |
152,105 | denverdino/aliyungo | common/client.go | setEndpointByLocation | func (client *Client) setEndpointByLocation(region Region, serviceCode, accessKeyId, accessKeySecret, securityToken string) {
locationClient := NewLocationClient(accessKeyId, accessKeySecret, securityToken)
locationClient.SetDebug(true)
ep := locationClient.DescribeOpenAPIEndpoint(region, serviceCode)
if ep == "" {
ep = loadEndpointFromFile(region, serviceCode)
}
if ep != "" {
client.endpoint = ep
}
} | go | func (client *Client) setEndpointByLocation(region Region, serviceCode, accessKeyId, accessKeySecret, securityToken string) {
locationClient := NewLocationClient(accessKeyId, accessKeySecret, securityToken)
locationClient.SetDebug(true)
ep := locationClient.DescribeOpenAPIEndpoint(region, serviceCode)
if ep == "" {
ep = loadEndpointFromFile(region, serviceCode)
}
if ep != "" {
client.endpoint = ep
}
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"setEndpointByLocation",
"(",
"region",
"Region",
",",
"serviceCode",
",",
"accessKeyId",
",",
"accessKeySecret",
",",
"securityToken",
"string",
")",
"{",
"locationClient",
":=",
"NewLocationClient",
"(",
"accessKeyId",
",",
"accessKeySecret",
",",
"securityToken",
")",
"\n",
"locationClient",
".",
"SetDebug",
"(",
"true",
")",
"\n",
"ep",
":=",
"locationClient",
".",
"DescribeOpenAPIEndpoint",
"(",
"region",
",",
"serviceCode",
")",
"\n",
"if",
"ep",
"==",
"\"",
"\"",
"{",
"ep",
"=",
"loadEndpointFromFile",
"(",
"region",
",",
"serviceCode",
")",
"\n",
"}",
"\n\n",
"if",
"ep",
"!=",
"\"",
"\"",
"{",
"client",
".",
"endpoint",
"=",
"ep",
"\n",
"}",
"\n",
"}"
] | //NewClient using location service | [
"NewClient",
"using",
"location",
"service"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/client.go#L104-L115 |
152,106 | denverdino/aliyungo | common/client.go | ensureProperties | func (client *Client) ensureProperties() error {
var msg string
if client.endpoint == "" {
msg = fmt.Sprintf("endpoint cannot be empty!")
} else if client.version == "" {
msg = fmt.Sprintf("version cannot be empty!")
} else if client.AccessKeyId == "" {
msg = fmt.Sprintf("AccessKeyId cannot be empty!")
} else if client.AccessKeySecret == "" {
msg = fmt.Sprintf("AccessKeySecret cannot be empty!")
}
if msg != "" {
return errors.New(msg)
}
return nil
} | go | func (client *Client) ensureProperties() error {
var msg string
if client.endpoint == "" {
msg = fmt.Sprintf("endpoint cannot be empty!")
} else if client.version == "" {
msg = fmt.Sprintf("version cannot be empty!")
} else if client.AccessKeyId == "" {
msg = fmt.Sprintf("AccessKeyId cannot be empty!")
} else if client.AccessKeySecret == "" {
msg = fmt.Sprintf("AccessKeySecret cannot be empty!")
}
if msg != "" {
return errors.New(msg)
}
return nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"ensureProperties",
"(",
")",
"error",
"{",
"var",
"msg",
"string",
"\n\n",
"if",
"client",
".",
"endpoint",
"==",
"\"",
"\"",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"client",
".",
"version",
"==",
"\"",
"\"",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"client",
".",
"AccessKeyId",
"==",
"\"",
"\"",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"client",
".",
"AccessKeySecret",
"==",
"\"",
"\"",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"msg",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"msg",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Ensure all necessary properties are valid | [
"Ensure",
"all",
"necessary",
"properties",
"are",
"valid"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/client.go#L118-L136 |
152,107 | denverdino/aliyungo | common/client.go | WithVersion | func (client *Client) WithVersion(version string) *Client {
client.SetVersion(version)
return client
} | go | func (client *Client) WithVersion(version string) *Client {
client.SetVersion(version)
return client
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"WithVersion",
"(",
"version",
"string",
")",
"*",
"Client",
"{",
"client",
".",
"SetVersion",
"(",
"version",
")",
"\n",
"return",
"client",
"\n",
"}"
] | // WithVersion sets custom version | [
"WithVersion",
"sets",
"custom",
"version"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/client.go#L149-L152 |
152,108 | denverdino/aliyungo | common/client.go | WithRegionID | func (client *Client) WithRegionID(regionID Region) *Client {
client.SetRegionID(regionID)
return client
} | go | func (client *Client) WithRegionID(regionID Region) *Client {
client.SetRegionID(regionID)
return client
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"WithRegionID",
"(",
"regionID",
"Region",
")",
"*",
"Client",
"{",
"client",
".",
"SetRegionID",
"(",
"regionID",
")",
"\n",
"return",
"client",
"\n",
"}"
] | // WithRegionID sets Region ID | [
"WithRegionID",
"sets",
"Region",
"ID"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/client.go#L155-L158 |
152,109 | denverdino/aliyungo | common/client.go | WithServiceCode | func (client *Client) WithServiceCode(serviceCode string) *Client {
client.SetServiceCode(serviceCode)
return client
} | go | func (client *Client) WithServiceCode(serviceCode string) *Client {
client.SetServiceCode(serviceCode)
return client
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"WithServiceCode",
"(",
"serviceCode",
"string",
")",
"*",
"Client",
"{",
"client",
".",
"SetServiceCode",
"(",
"serviceCode",
")",
"\n",
"return",
"client",
"\n",
"}"
] | //WithServiceCode sets serviceCode | [
"WithServiceCode",
"sets",
"serviceCode"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/client.go#L161-L164 |
152,110 | denverdino/aliyungo | common/client.go | WithAccessKeyId | func (client *Client) WithAccessKeyId(id string) *Client {
client.SetAccessKeyId(id)
return client
} | go | func (client *Client) WithAccessKeyId(id string) *Client {
client.SetAccessKeyId(id)
return client
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"WithAccessKeyId",
"(",
"id",
"string",
")",
"*",
"Client",
"{",
"client",
".",
"SetAccessKeyId",
"(",
"id",
")",
"\n",
"return",
"client",
"\n",
"}"
] | // WithAccessKeyId sets new AccessKeyId | [
"WithAccessKeyId",
"sets",
"new",
"AccessKeyId"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/client.go#L167-L170 |
152,111 | denverdino/aliyungo | common/client.go | WithAccessKeySecret | func (client *Client) WithAccessKeySecret(secret string) *Client {
client.SetAccessKeySecret(secret)
return client
} | go | func (client *Client) WithAccessKeySecret(secret string) *Client {
client.SetAccessKeySecret(secret)
return client
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"WithAccessKeySecret",
"(",
"secret",
"string",
")",
"*",
"Client",
"{",
"client",
".",
"SetAccessKeySecret",
"(",
"secret",
")",
"\n",
"return",
"client",
"\n",
"}"
] | // WithAccessKeySecret sets new AccessKeySecret | [
"WithAccessKeySecret",
"sets",
"new",
"AccessKeySecret"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/client.go#L173-L176 |
152,112 | denverdino/aliyungo | common/client.go | WithSecurityToken | func (client *Client) WithSecurityToken(securityToken string) *Client {
client.SetSecurityToken(securityToken)
return client
} | go | func (client *Client) WithSecurityToken(securityToken string) *Client {
client.SetSecurityToken(securityToken)
return client
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"WithSecurityToken",
"(",
"securityToken",
"string",
")",
"*",
"Client",
"{",
"client",
".",
"SetSecurityToken",
"(",
"securityToken",
")",
"\n",
"return",
"client",
"\n",
"}"
] | // WithSecurityToken sets securityToken | [
"WithSecurityToken",
"sets",
"securityToken"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/client.go#L179-L182 |
152,113 | denverdino/aliyungo | common/client.go | Invoke | func (client *Client) Invoke(action string, args interface{}, response interface{}) error {
if err := client.ensureProperties(); err != nil {
return err
}
//init endpoint
if err := client.initEndpoint(); err != nil {
return err
}
request := Request{}
request.init(client.version, action, client.AccessKeyId, client.securityToken, client.regionID)
query := util.ConvertToQueryValues(request)
util.SetQueryValues(args, &query)
// Sign request
signature := util.CreateSignatureForRequest(ECSRequestMethod, &query, client.AccessKeySecret)
// Generate the request URL
requestURL := client.endpoint + "?" + query.Encode() + "&Signature=" + url.QueryEscape(signature)
httpReq, err := http.NewRequest(ECSRequestMethod, requestURL, nil)
if err != nil {
return GetClientError(err)
}
// TODO move to util and add build val flag
httpReq.Header.Set("X-SDK-Client", `AliyunGO/`+Version+client.businessInfo)
httpReq.Header.Set("User-Agent", httpReq.UserAgent()+" "+client.userAgent)
t0 := time.Now()
httpResp, err := client.httpClient.Do(httpReq)
t1 := time.Now()
if err != nil {
return GetClientError(err)
}
statusCode := httpResp.StatusCode
if client.debug {
log.Printf("Invoke %s %s %d (%v)", ECSRequestMethod, requestURL, statusCode, t1.Sub(t0))
}
defer httpResp.Body.Close()
body, err := ioutil.ReadAll(httpResp.Body)
if err != nil {
return GetClientError(err)
}
if client.debug {
var prettyJSON bytes.Buffer
err = json.Indent(&prettyJSON, body, "", " ")
log.Println(string(prettyJSON.Bytes()))
}
if statusCode >= 400 && statusCode <= 599 {
errorResponse := ErrorResponse{}
err = json.Unmarshal(body, &errorResponse)
ecsError := &Error{
ErrorResponse: errorResponse,
StatusCode: statusCode,
}
return ecsError
}
err = json.Unmarshal(body, response)
//log.Printf("%++v", response)
if err != nil {
return GetClientError(err)
}
return nil
} | go | func (client *Client) Invoke(action string, args interface{}, response interface{}) error {
if err := client.ensureProperties(); err != nil {
return err
}
//init endpoint
if err := client.initEndpoint(); err != nil {
return err
}
request := Request{}
request.init(client.version, action, client.AccessKeyId, client.securityToken, client.regionID)
query := util.ConvertToQueryValues(request)
util.SetQueryValues(args, &query)
// Sign request
signature := util.CreateSignatureForRequest(ECSRequestMethod, &query, client.AccessKeySecret)
// Generate the request URL
requestURL := client.endpoint + "?" + query.Encode() + "&Signature=" + url.QueryEscape(signature)
httpReq, err := http.NewRequest(ECSRequestMethod, requestURL, nil)
if err != nil {
return GetClientError(err)
}
// TODO move to util and add build val flag
httpReq.Header.Set("X-SDK-Client", `AliyunGO/`+Version+client.businessInfo)
httpReq.Header.Set("User-Agent", httpReq.UserAgent()+" "+client.userAgent)
t0 := time.Now()
httpResp, err := client.httpClient.Do(httpReq)
t1 := time.Now()
if err != nil {
return GetClientError(err)
}
statusCode := httpResp.StatusCode
if client.debug {
log.Printf("Invoke %s %s %d (%v)", ECSRequestMethod, requestURL, statusCode, t1.Sub(t0))
}
defer httpResp.Body.Close()
body, err := ioutil.ReadAll(httpResp.Body)
if err != nil {
return GetClientError(err)
}
if client.debug {
var prettyJSON bytes.Buffer
err = json.Indent(&prettyJSON, body, "", " ")
log.Println(string(prettyJSON.Bytes()))
}
if statusCode >= 400 && statusCode <= 599 {
errorResponse := ErrorResponse{}
err = json.Unmarshal(body, &errorResponse)
ecsError := &Error{
ErrorResponse: errorResponse,
StatusCode: statusCode,
}
return ecsError
}
err = json.Unmarshal(body, response)
//log.Printf("%++v", response)
if err != nil {
return GetClientError(err)
}
return nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"Invoke",
"(",
"action",
"string",
",",
"args",
"interface",
"{",
"}",
",",
"response",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"err",
":=",
"client",
".",
"ensureProperties",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"//init endpoint",
"if",
"err",
":=",
"client",
".",
"initEndpoint",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"request",
":=",
"Request",
"{",
"}",
"\n",
"request",
".",
"init",
"(",
"client",
".",
"version",
",",
"action",
",",
"client",
".",
"AccessKeyId",
",",
"client",
".",
"securityToken",
",",
"client",
".",
"regionID",
")",
"\n\n",
"query",
":=",
"util",
".",
"ConvertToQueryValues",
"(",
"request",
")",
"\n",
"util",
".",
"SetQueryValues",
"(",
"args",
",",
"&",
"query",
")",
"\n\n",
"// Sign request",
"signature",
":=",
"util",
".",
"CreateSignatureForRequest",
"(",
"ECSRequestMethod",
",",
"&",
"query",
",",
"client",
".",
"AccessKeySecret",
")",
"\n\n",
"// Generate the request URL",
"requestURL",
":=",
"client",
".",
"endpoint",
"+",
"\"",
"\"",
"+",
"query",
".",
"Encode",
"(",
")",
"+",
"\"",
"\"",
"+",
"url",
".",
"QueryEscape",
"(",
"signature",
")",
"\n\n",
"httpReq",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"ECSRequestMethod",
",",
"requestURL",
",",
"nil",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"GetClientError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// TODO move to util and add build val flag",
"httpReq",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"`AliyunGO/`",
"+",
"Version",
"+",
"client",
".",
"businessInfo",
")",
"\n\n",
"httpReq",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"httpReq",
".",
"UserAgent",
"(",
")",
"+",
"\"",
"\"",
"+",
"client",
".",
"userAgent",
")",
"\n\n",
"t0",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"httpResp",
",",
"err",
":=",
"client",
".",
"httpClient",
".",
"Do",
"(",
"httpReq",
")",
"\n",
"t1",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"GetClientError",
"(",
"err",
")",
"\n",
"}",
"\n",
"statusCode",
":=",
"httpResp",
".",
"StatusCode",
"\n\n",
"if",
"client",
".",
"debug",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"ECSRequestMethod",
",",
"requestURL",
",",
"statusCode",
",",
"t1",
".",
"Sub",
"(",
"t0",
")",
")",
"\n",
"}",
"\n\n",
"defer",
"httpResp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"httpResp",
".",
"Body",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"GetClientError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"client",
".",
"debug",
"{",
"var",
"prettyJSON",
"bytes",
".",
"Buffer",
"\n",
"err",
"=",
"json",
".",
"Indent",
"(",
"&",
"prettyJSON",
",",
"body",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"log",
".",
"Println",
"(",
"string",
"(",
"prettyJSON",
".",
"Bytes",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"if",
"statusCode",
">=",
"400",
"&&",
"statusCode",
"<=",
"599",
"{",
"errorResponse",
":=",
"ErrorResponse",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"&",
"errorResponse",
")",
"\n",
"ecsError",
":=",
"&",
"Error",
"{",
"ErrorResponse",
":",
"errorResponse",
",",
"StatusCode",
":",
"statusCode",
",",
"}",
"\n",
"return",
"ecsError",
"\n",
"}",
"\n\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"response",
")",
"\n",
"//log.Printf(\"%++v\", response)",
"if",
"err",
"!=",
"nil",
"{",
"return",
"GetClientError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Invoke sends the raw HTTP request for ECS services | [
"Invoke",
"sends",
"the",
"raw",
"HTTP",
"request",
"for",
"ECS",
"services"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/client.go#L278-L353 |
152,114 | denverdino/aliyungo | ecs/route_tables.go | WaitForAllRouteEntriesAvailable | func (client *Client) WaitForAllRouteEntriesAvailable(vrouterId string, routeTableId string, timeout int) error {
if timeout <= 0 {
timeout = DefaultTimeout
}
args := DescribeRouteTablesArgs{
VRouterId: vrouterId,
RouteTableId: routeTableId,
}
for {
routeTables, _, err := client.DescribeRouteTables(&args)
if err != nil {
return err
}
if len(routeTables) == 0 {
return common.GetClientErrorFromString("Not found")
}
success := true
loop:
for _, routeTable := range routeTables {
for _, routeEntry := range routeTable.RouteEntrys.RouteEntry {
if routeEntry.Status != RouteEntryStatusAvailable {
success = false
break loop
}
}
}
if success {
break
}
timeout = timeout - DefaultWaitForInterval
if timeout <= 0 {
return common.GetClientErrorFromString("Timeout")
}
time.Sleep(DefaultWaitForInterval * time.Second)
}
return nil
} | go | func (client *Client) WaitForAllRouteEntriesAvailable(vrouterId string, routeTableId string, timeout int) error {
if timeout <= 0 {
timeout = DefaultTimeout
}
args := DescribeRouteTablesArgs{
VRouterId: vrouterId,
RouteTableId: routeTableId,
}
for {
routeTables, _, err := client.DescribeRouteTables(&args)
if err != nil {
return err
}
if len(routeTables) == 0 {
return common.GetClientErrorFromString("Not found")
}
success := true
loop:
for _, routeTable := range routeTables {
for _, routeEntry := range routeTable.RouteEntrys.RouteEntry {
if routeEntry.Status != RouteEntryStatusAvailable {
success = false
break loop
}
}
}
if success {
break
}
timeout = timeout - DefaultWaitForInterval
if timeout <= 0 {
return common.GetClientErrorFromString("Timeout")
}
time.Sleep(DefaultWaitForInterval * time.Second)
}
return nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"WaitForAllRouteEntriesAvailable",
"(",
"vrouterId",
"string",
",",
"routeTableId",
"string",
",",
"timeout",
"int",
")",
"error",
"{",
"if",
"timeout",
"<=",
"0",
"{",
"timeout",
"=",
"DefaultTimeout",
"\n",
"}",
"\n",
"args",
":=",
"DescribeRouteTablesArgs",
"{",
"VRouterId",
":",
"vrouterId",
",",
"RouteTableId",
":",
"routeTableId",
",",
"}",
"\n",
"for",
"{",
"routeTables",
",",
"_",
",",
"err",
":=",
"client",
".",
"DescribeRouteTables",
"(",
"&",
"args",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"routeTables",
")",
"==",
"0",
"{",
"return",
"common",
".",
"GetClientErrorFromString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"success",
":=",
"true",
"\n\n",
"loop",
":",
"for",
"_",
",",
"routeTable",
":=",
"range",
"routeTables",
"{",
"for",
"_",
",",
"routeEntry",
":=",
"range",
"routeTable",
".",
"RouteEntrys",
".",
"RouteEntry",
"{",
"if",
"routeEntry",
".",
"Status",
"!=",
"RouteEntryStatusAvailable",
"{",
"success",
"=",
"false",
"\n",
"break",
"loop",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"success",
"{",
"break",
"\n",
"}",
"\n",
"timeout",
"=",
"timeout",
"-",
"DefaultWaitForInterval",
"\n",
"if",
"timeout",
"<=",
"0",
"{",
"return",
"common",
".",
"GetClientErrorFromString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"DefaultWaitForInterval",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // WaitForAllRouteEntriesAvailable waits for all route entries to Available status | [
"WaitForAllRouteEntriesAvailable",
"waits",
"for",
"all",
"route",
"entries",
"to",
"Available",
"status"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/ecs/route_tables.go#L147-L186 |
152,115 | denverdino/aliyungo | cs/client.go | NewClient | func NewClient(accessKeyId, accessKeySecret string) *Client {
return &Client{
AccessKeyId: accessKeyId,
AccessKeySecret: accessKeySecret,
endpoint: CSDefaultEndpoint,
Version: CSAPIVersion,
httpClient: &http.Client{},
}
} | go | func NewClient(accessKeyId, accessKeySecret string) *Client {
return &Client{
AccessKeyId: accessKeyId,
AccessKeySecret: accessKeySecret,
endpoint: CSDefaultEndpoint,
Version: CSAPIVersion,
httpClient: &http.Client{},
}
} | [
"func",
"NewClient",
"(",
"accessKeyId",
",",
"accessKeySecret",
"string",
")",
"*",
"Client",
"{",
"return",
"&",
"Client",
"{",
"AccessKeyId",
":",
"accessKeyId",
",",
"AccessKeySecret",
":",
"accessKeySecret",
",",
"endpoint",
":",
"CSDefaultEndpoint",
",",
"Version",
":",
"CSAPIVersion",
",",
"httpClient",
":",
"&",
"http",
".",
"Client",
"{",
"}",
",",
"}",
"\n",
"}"
] | // NewClient creates a new instance of CRM client | [
"NewClient",
"creates",
"a",
"new",
"instance",
"of",
"CRM",
"client"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/cs/client.go#L48-L56 |
152,116 | denverdino/aliyungo | nas/client.go | NewClient | func NewClient(accessKeyId, accessKeySecret string) *Client {
client := &Client{}
client.Init(END_POINT, VERSION, accessKeyId, accessKeySecret)
return client
} | go | func NewClient(accessKeyId, accessKeySecret string) *Client {
client := &Client{}
client.Init(END_POINT, VERSION, accessKeyId, accessKeySecret)
return client
} | [
"func",
"NewClient",
"(",
"accessKeyId",
",",
"accessKeySecret",
"string",
")",
"*",
"Client",
"{",
"client",
":=",
"&",
"Client",
"{",
"}",
"\n",
"client",
".",
"Init",
"(",
"END_POINT",
",",
"VERSION",
",",
"accessKeyId",
",",
"accessKeySecret",
")",
"\n",
"return",
"client",
"\n",
"}"
] | // NewClient creates a new instance of NAS client | [
"NewClient",
"creates",
"a",
"new",
"instance",
"of",
"NAS",
"client"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/nas/client.go#L20-L24 |
152,117 | denverdino/aliyungo | util/util.go | EncodeWithoutEscape | func EncodeWithoutEscape(v url.Values) string {
if v == nil {
return ""
}
var buf bytes.Buffer
keys := make([]string, 0, len(v))
for k := range v {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
vs := v[k]
prefix := k
for _, v := range vs {
if buf.Len() > 0 {
buf.WriteByte('&')
}
buf.WriteString(prefix)
if v != "" {
buf.WriteString("=")
buf.WriteString(v)
}
}
}
return buf.String()
} | go | func EncodeWithoutEscape(v url.Values) string {
if v == nil {
return ""
}
var buf bytes.Buffer
keys := make([]string, 0, len(v))
for k := range v {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
vs := v[k]
prefix := k
for _, v := range vs {
if buf.Len() > 0 {
buf.WriteByte('&')
}
buf.WriteString(prefix)
if v != "" {
buf.WriteString("=")
buf.WriteString(v)
}
}
}
return buf.String()
} | [
"func",
"EncodeWithoutEscape",
"(",
"v",
"url",
".",
"Values",
")",
"string",
"{",
"if",
"v",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"v",
")",
")",
"\n",
"for",
"k",
":=",
"range",
"v",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"keys",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"keys",
"{",
"vs",
":=",
"v",
"[",
"k",
"]",
"\n",
"prefix",
":=",
"k",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"vs",
"{",
"if",
"buf",
".",
"Len",
"(",
")",
">",
"0",
"{",
"buf",
".",
"WriteByte",
"(",
"'&'",
")",
"\n",
"}",
"\n",
"buf",
".",
"WriteString",
"(",
"prefix",
")",
"\n",
"if",
"v",
"!=",
"\"",
"\"",
"{",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"buf",
".",
"WriteString",
"(",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] | // Like Encode, but key and value are not escaped | [
"Like",
"Encode",
"but",
"key",
"and",
"value",
"are",
"not",
"escaped"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/util/util.go#L70-L95 |
152,118 | denverdino/aliyungo | ecs/instances.go | WaitForInstanceAsyn | func (client *Client) WaitForInstanceAsyn(instanceId string, status InstanceStatus, timeout int) error {
if timeout <= 0 {
timeout = InstanceDefaultTimeout
}
for {
instance, err := client.DescribeInstanceAttribute(instanceId)
if err != nil {
e, _ := err.(*common.Error)
if e.Code != "InvalidInstanceId.NotFound" && e.Code != "Forbidden.InstanceNotFound" {
return err
}
} else if instance != nil && instance.Status == status {
//TODO
break
}
timeout = timeout - DefaultWaitForInterval
if timeout <= 0 {
return common.GetClientErrorFromString("Timeout")
}
time.Sleep(DefaultWaitForInterval * time.Second)
}
return nil
} | go | func (client *Client) WaitForInstanceAsyn(instanceId string, status InstanceStatus, timeout int) error {
if timeout <= 0 {
timeout = InstanceDefaultTimeout
}
for {
instance, err := client.DescribeInstanceAttribute(instanceId)
if err != nil {
e, _ := err.(*common.Error)
if e.Code != "InvalidInstanceId.NotFound" && e.Code != "Forbidden.InstanceNotFound" {
return err
}
} else if instance != nil && instance.Status == status {
//TODO
break
}
timeout = timeout - DefaultWaitForInterval
if timeout <= 0 {
return common.GetClientErrorFromString("Timeout")
}
time.Sleep(DefaultWaitForInterval * time.Second)
}
return nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"WaitForInstanceAsyn",
"(",
"instanceId",
"string",
",",
"status",
"InstanceStatus",
",",
"timeout",
"int",
")",
"error",
"{",
"if",
"timeout",
"<=",
"0",
"{",
"timeout",
"=",
"InstanceDefaultTimeout",
"\n",
"}",
"\n",
"for",
"{",
"instance",
",",
"err",
":=",
"client",
".",
"DescribeInstanceAttribute",
"(",
"instanceId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"e",
",",
"_",
":=",
"err",
".",
"(",
"*",
"common",
".",
"Error",
")",
"\n",
"if",
"e",
".",
"Code",
"!=",
"\"",
"\"",
"&&",
"e",
".",
"Code",
"!=",
"\"",
"\"",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"if",
"instance",
"!=",
"nil",
"&&",
"instance",
".",
"Status",
"==",
"status",
"{",
"//TODO",
"break",
"\n",
"}",
"\n",
"timeout",
"=",
"timeout",
"-",
"DefaultWaitForInterval",
"\n",
"if",
"timeout",
"<=",
"0",
"{",
"return",
"common",
".",
"GetClientErrorFromString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"DefaultWaitForInterval",
"*",
"time",
".",
"Second",
")",
"\n\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // WaitForInstance waits for instance to given status
// when instance.NotFound wait until timeout | [
"WaitForInstance",
"waits",
"for",
"instance",
"to",
"given",
"status",
"when",
"instance",
".",
"NotFound",
"wait",
"until",
"timeout"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/ecs/instances.go#L343-L366 |
152,119 | denverdino/aliyungo | util/iso6801.go | GetISO8601TimeStamp | func GetISO8601TimeStamp(ts time.Time) string {
t := ts.UTC()
return fmt.Sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
} | go | func GetISO8601TimeStamp(ts time.Time) string {
t := ts.UTC()
return fmt.Sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
} | [
"func",
"GetISO8601TimeStamp",
"(",
"ts",
"time",
".",
"Time",
")",
"string",
"{",
"t",
":=",
"ts",
".",
"UTC",
"(",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Year",
"(",
")",
",",
"t",
".",
"Month",
"(",
")",
",",
"t",
".",
"Day",
"(",
")",
",",
"t",
".",
"Hour",
"(",
")",
",",
"t",
".",
"Minute",
"(",
")",
",",
"t",
".",
"Second",
"(",
")",
")",
"\n",
"}"
] | // GetISO8601TimeStamp gets timestamp string in ISO8601 format | [
"GetISO8601TimeStamp",
"gets",
"timestamp",
"string",
"in",
"ISO8601",
"format"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/util/iso6801.go#L10-L13 |
152,120 | denverdino/aliyungo | util/iso6801.go | MarshalJSON | func (it ISO6801Time) MarshalJSON() ([]byte, error) {
return []byte(time.Time(it).Format(jsonFormatISO8601)), nil
} | go | func (it ISO6801Time) MarshalJSON() ([]byte, error) {
return []byte(time.Time(it).Format(jsonFormatISO8601)), nil
} | [
"func",
"(",
"it",
"ISO6801Time",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"[",
"]",
"byte",
"(",
"time",
".",
"Time",
"(",
"it",
")",
".",
"Format",
"(",
"jsonFormatISO8601",
")",
")",
",",
"nil",
"\n",
"}"
] | // MarshalJSON serializes the ISO6801Time into JSON string | [
"MarshalJSON",
"serializes",
"the",
"ISO6801Time",
"into",
"JSON",
"string"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/util/iso6801.go#L46-L48 |
152,121 | denverdino/aliyungo | util/iso6801.go | UnmarshalJSON | func (it *ISO6801Time) UnmarshalJSON(data []byte) error {
str := string(data)
if str == "\"\"" || len(data) == 0 {
return nil
}
var t time.Time
var err error
if str[0] == '"' {
t, err = time.ParseInLocation(jsonFormatISO8601, str, time.UTC)
if err != nil {
t, err = time.ParseInLocation(jsonFormatISO8601withoutSeconds, str, time.UTC)
}
} else {
var i int64
i, err = strconv.ParseInt(str, 10, 64)
if err == nil {
t = time.Unix(i/1000, i%1000)
}
}
if err == nil {
*it = ISO6801Time(t)
}
return err
} | go | func (it *ISO6801Time) UnmarshalJSON(data []byte) error {
str := string(data)
if str == "\"\"" || len(data) == 0 {
return nil
}
var t time.Time
var err error
if str[0] == '"' {
t, err = time.ParseInLocation(jsonFormatISO8601, str, time.UTC)
if err != nil {
t, err = time.ParseInLocation(jsonFormatISO8601withoutSeconds, str, time.UTC)
}
} else {
var i int64
i, err = strconv.ParseInt(str, 10, 64)
if err == nil {
t = time.Unix(i/1000, i%1000)
}
}
if err == nil {
*it = ISO6801Time(t)
}
return err
} | [
"func",
"(",
"it",
"*",
"ISO6801Time",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"str",
":=",
"string",
"(",
"data",
")",
"\n\n",
"if",
"str",
"==",
"\"",
"\\\"",
"\\\"",
"\"",
"||",
"len",
"(",
"data",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"t",
"time",
".",
"Time",
"\n",
"var",
"err",
"error",
"\n",
"if",
"str",
"[",
"0",
"]",
"==",
"'\"'",
"{",
"t",
",",
"err",
"=",
"time",
".",
"ParseInLocation",
"(",
"jsonFormatISO8601",
",",
"str",
",",
"time",
".",
"UTC",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"t",
",",
"err",
"=",
"time",
".",
"ParseInLocation",
"(",
"jsonFormatISO8601withoutSeconds",
",",
"str",
",",
"time",
".",
"UTC",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"var",
"i",
"int64",
"\n",
"i",
",",
"err",
"=",
"strconv",
".",
"ParseInt",
"(",
"str",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"t",
"=",
"time",
".",
"Unix",
"(",
"i",
"/",
"1000",
",",
"i",
"%",
"1000",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"*",
"it",
"=",
"ISO6801Time",
"(",
"t",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // UnmarshalJSON deserializes the ISO6801Time from JSON string | [
"UnmarshalJSON",
"deserializes",
"the",
"ISO6801Time",
"from",
"JSON",
"string"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/util/iso6801.go#L51-L75 |
152,122 | denverdino/aliyungo | ecs/disks.go | WaitForDisk | func (client *Client) WaitForDisk(regionId common.Region, diskId string, status DiskStatus, timeout int) error {
if timeout <= 0 {
timeout = DefaultTimeout
}
args := DescribeDisksArgs{
RegionId: regionId,
DiskIds: []string{diskId},
}
for {
disks, _, err := client.DescribeDisks(&args)
if err != nil {
return err
}
if disks == nil || len(disks) == 0 {
return common.GetClientErrorFromString("Not found")
}
if disks[0].Status == status {
break
}
timeout = timeout - DefaultWaitForInterval
if timeout <= 0 {
return common.GetClientErrorFromString("Timeout")
}
time.Sleep(DefaultWaitForInterval * time.Second)
}
return nil
} | go | func (client *Client) WaitForDisk(regionId common.Region, diskId string, status DiskStatus, timeout int) error {
if timeout <= 0 {
timeout = DefaultTimeout
}
args := DescribeDisksArgs{
RegionId: regionId,
DiskIds: []string{diskId},
}
for {
disks, _, err := client.DescribeDisks(&args)
if err != nil {
return err
}
if disks == nil || len(disks) == 0 {
return common.GetClientErrorFromString("Not found")
}
if disks[0].Status == status {
break
}
timeout = timeout - DefaultWaitForInterval
if timeout <= 0 {
return common.GetClientErrorFromString("Timeout")
}
time.Sleep(DefaultWaitForInterval * time.Second)
}
return nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"WaitForDisk",
"(",
"regionId",
"common",
".",
"Region",
",",
"diskId",
"string",
",",
"status",
"DiskStatus",
",",
"timeout",
"int",
")",
"error",
"{",
"if",
"timeout",
"<=",
"0",
"{",
"timeout",
"=",
"DefaultTimeout",
"\n",
"}",
"\n",
"args",
":=",
"DescribeDisksArgs",
"{",
"RegionId",
":",
"regionId",
",",
"DiskIds",
":",
"[",
"]",
"string",
"{",
"diskId",
"}",
",",
"}",
"\n\n",
"for",
"{",
"disks",
",",
"_",
",",
"err",
":=",
"client",
".",
"DescribeDisks",
"(",
"&",
"args",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"disks",
"==",
"nil",
"||",
"len",
"(",
"disks",
")",
"==",
"0",
"{",
"return",
"common",
".",
"GetClientErrorFromString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"disks",
"[",
"0",
"]",
".",
"Status",
"==",
"status",
"{",
"break",
"\n",
"}",
"\n",
"timeout",
"=",
"timeout",
"-",
"DefaultWaitForInterval",
"\n",
"if",
"timeout",
"<=",
"0",
"{",
"return",
"common",
".",
"GetClientErrorFromString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"DefaultWaitForInterval",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // WaitForDisk waits for disk to given status | [
"WaitForDisk",
"waits",
"for",
"disk",
"to",
"given",
"status"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/ecs/disks.go#L336-L363 |
152,123 | denverdino/aliyungo | cms/bytesbuffer/bytesbuffer.go | WriteByteString | func (this *BytesBuffer) WriteByteString(byteStr string) error {
var tmp []byte = make([]byte, 2)
re := regexp.MustCompile("[^a-fA-F0-9]")
clean_str := re.ReplaceAllString(byteStr, "")
src := bytes.NewBufferString(clean_str)
cnt := src.Len() / 2
for i := 0; i < cnt; i++ {
num := 0
_, err := src.Read(tmp)
if err != nil {
return err
}
fmt.Sscanf(string(tmp), "%X", &num)
this.Buffer.WriteByte(byte(num))
}
return nil
} | go | func (this *BytesBuffer) WriteByteString(byteStr string) error {
var tmp []byte = make([]byte, 2)
re := regexp.MustCompile("[^a-fA-F0-9]")
clean_str := re.ReplaceAllString(byteStr, "")
src := bytes.NewBufferString(clean_str)
cnt := src.Len() / 2
for i := 0; i < cnt; i++ {
num := 0
_, err := src.Read(tmp)
if err != nil {
return err
}
fmt.Sscanf(string(tmp), "%X", &num)
this.Buffer.WriteByte(byte(num))
}
return nil
} | [
"func",
"(",
"this",
"*",
"BytesBuffer",
")",
"WriteByteString",
"(",
"byteStr",
"string",
")",
"error",
"{",
"var",
"tmp",
"[",
"]",
"byte",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"2",
")",
"\n\n",
"re",
":=",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
"\n",
"clean_str",
":=",
"re",
".",
"ReplaceAllString",
"(",
"byteStr",
",",
"\"",
"\"",
")",
"\n\n",
"src",
":=",
"bytes",
".",
"NewBufferString",
"(",
"clean_str",
")",
"\n\n",
"cnt",
":=",
"src",
".",
"Len",
"(",
")",
"/",
"2",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"cnt",
";",
"i",
"++",
"{",
"num",
":=",
"0",
"\n",
"_",
",",
"err",
":=",
"src",
".",
"Read",
"(",
"tmp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"fmt",
".",
"Sscanf",
"(",
"string",
"(",
"tmp",
")",
",",
"\"",
"\"",
",",
"&",
"num",
")",
"\n",
"this",
".",
"Buffer",
".",
"WriteByte",
"(",
"byte",
"(",
"num",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // \x31\x32\x33\x34 -> 1234
// %31%32%33%34 -> 1234
// 31323334 -> 1234 | [
"\\",
"x31",
"\\",
"x32",
"\\",
"x33",
"\\",
"x34",
"-",
">",
"1234",
"%31%32%33%34",
"-",
">",
"1234",
"31323334",
"-",
">",
"1234"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/cms/bytesbuffer/bytesbuffer.go#L61-L81 |
152,124 | denverdino/aliyungo | cms/bytesbuffer/bytesbuffer.go | WriteToByteString | func (this *BytesBuffer) WriteToByteString(w io.Writer, prefix string) (n int64, err error) {
slen := this.Buffer.Len()
dst := bytes.NewBufferString("")
for i := 0; i < slen; i++ {
c, _ := this.Buffer.ReadByte()
dst.WriteString(fmt.Sprintf("%s%02X", prefix, c))
}
return dst.WriteTo(w)
} | go | func (this *BytesBuffer) WriteToByteString(w io.Writer, prefix string) (n int64, err error) {
slen := this.Buffer.Len()
dst := bytes.NewBufferString("")
for i := 0; i < slen; i++ {
c, _ := this.Buffer.ReadByte()
dst.WriteString(fmt.Sprintf("%s%02X", prefix, c))
}
return dst.WriteTo(w)
} | [
"func",
"(",
"this",
"*",
"BytesBuffer",
")",
"WriteToByteString",
"(",
"w",
"io",
".",
"Writer",
",",
"prefix",
"string",
")",
"(",
"n",
"int64",
",",
"err",
"error",
")",
"{",
"slen",
":=",
"this",
".",
"Buffer",
".",
"Len",
"(",
")",
"\n",
"dst",
":=",
"bytes",
".",
"NewBufferString",
"(",
"\"",
"\"",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"slen",
";",
"i",
"++",
"{",
"c",
",",
"_",
":=",
"this",
".",
"Buffer",
".",
"ReadByte",
"(",
")",
"\n",
"dst",
".",
"WriteString",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"prefix",
",",
"c",
")",
")",
"\n",
"}",
"\n\n",
"return",
"dst",
".",
"WriteTo",
"(",
"w",
")",
"\n",
"}"
] | // Buffer will be empty after Write | [
"Buffer",
"will",
"be",
"empty",
"after",
"Write"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/cms/bytesbuffer/bytesbuffer.go#L99-L109 |
152,125 | denverdino/aliyungo | common/regions.go | IsValidRegion | func IsValidRegion(r string) bool {
for _, v := range ValidRegions {
if r == string(v) {
return true
}
}
return false
} | go | func IsValidRegion(r string) bool {
for _, v := range ValidRegions {
if r == string(v) {
return true
}
}
return false
} | [
"func",
"IsValidRegion",
"(",
"r",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"ValidRegions",
"{",
"if",
"r",
"==",
"string",
"(",
"v",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsValidRegion checks if r is an Ali supported region. | [
"IsValidRegion",
"checks",
"if",
"r",
"is",
"an",
"Ali",
"supported",
"region",
"."
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/common/regions.go#L48-L55 |
152,126 | denverdino/aliyungo | oss/client.go | NewOSSClientForAssumeRole | func NewOSSClientForAssumeRole(region Region, internal bool, accessKeyId string, accessKeySecret string, securityToken string, secure bool) *Client {
return &Client{
AccessKeyId: accessKeyId,
AccessKeySecret: accessKeySecret,
SecurityToken: securityToken,
Region: region,
Internal: internal,
debug: false,
Secure: secure,
}
} | go | func NewOSSClientForAssumeRole(region Region, internal bool, accessKeyId string, accessKeySecret string, securityToken string, secure bool) *Client {
return &Client{
AccessKeyId: accessKeyId,
AccessKeySecret: accessKeySecret,
SecurityToken: securityToken,
Region: region,
Internal: internal,
debug: false,
Secure: secure,
}
} | [
"func",
"NewOSSClientForAssumeRole",
"(",
"region",
"Region",
",",
"internal",
"bool",
",",
"accessKeyId",
"string",
",",
"accessKeySecret",
"string",
",",
"securityToken",
"string",
",",
"secure",
"bool",
")",
"*",
"Client",
"{",
"return",
"&",
"Client",
"{",
"AccessKeyId",
":",
"accessKeyId",
",",
"AccessKeySecret",
":",
"accessKeySecret",
",",
"SecurityToken",
":",
"securityToken",
",",
"Region",
":",
"region",
",",
"Internal",
":",
"internal",
",",
"debug",
":",
"false",
",",
"Secure",
":",
"secure",
",",
"}",
"\n",
"}"
] | // NewOSSClient creates a new OSS. | [
"NewOSSClient",
"creates",
"a",
"new",
"OSS",
"."
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/oss/client.go#L96-L106 |
152,127 | denverdino/aliyungo | oss/client.go | GetWithParams | func (b *Bucket) GetWithParams(path string, params url.Values) (data []byte, err error) {
resp, err := b.GetResponseWithParamsAndHeaders(path, params, nil)
if err != nil {
return nil, err
}
data, err = ioutil.ReadAll(resp.Body)
resp.Body.Close()
return data, err
} | go | func (b *Bucket) GetWithParams(path string, params url.Values) (data []byte, err error) {
resp, err := b.GetResponseWithParamsAndHeaders(path, params, nil)
if err != nil {
return nil, err
}
data, err = ioutil.ReadAll(resp.Body)
resp.Body.Close()
return data, err
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"GetWithParams",
"(",
"path",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"b",
".",
"GetResponseWithParamsAndHeaders",
"(",
"path",
",",
"params",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"data",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"return",
"data",
",",
"err",
"\n",
"}"
] | // Get retrieves an object from an bucket. | [
"Get",
"retrieves",
"an",
"object",
"from",
"an",
"bucket",
"."
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/oss/client.go#L319-L327 |
152,128 | denverdino/aliyungo | oss/client.go | Exists | func (b *Bucket) Exists(path string) (exists bool, err error) {
for attempt := attempts.Start(); attempt.Next(); {
req := &request{
method: "HEAD",
bucket: b.Name,
path: path,
}
err = b.Client.prepare(req)
if err != nil {
return
}
resp, err := b.Client.run(req, nil)
if shouldRetry(err) && attempt.HasNext() {
continue
}
if err != nil {
// We can treat a 403 or 404 as non existence
if e, ok := err.(*Error); ok && (e.StatusCode == 403 || e.StatusCode == 404) {
return false, nil
}
return false, err
}
if resp.StatusCode/100 == 2 {
exists = true
}
if resp.Body != nil {
resp.Body.Close()
}
return exists, err
}
return false, fmt.Errorf("OSS Currently Unreachable")
} | go | func (b *Bucket) Exists(path string) (exists bool, err error) {
for attempt := attempts.Start(); attempt.Next(); {
req := &request{
method: "HEAD",
bucket: b.Name,
path: path,
}
err = b.Client.prepare(req)
if err != nil {
return
}
resp, err := b.Client.run(req, nil)
if shouldRetry(err) && attempt.HasNext() {
continue
}
if err != nil {
// We can treat a 403 or 404 as non existence
if e, ok := err.(*Error); ok && (e.StatusCode == 403 || e.StatusCode == 404) {
return false, nil
}
return false, err
}
if resp.StatusCode/100 == 2 {
exists = true
}
if resp.Body != nil {
resp.Body.Close()
}
return exists, err
}
return false, fmt.Errorf("OSS Currently Unreachable")
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"Exists",
"(",
"path",
"string",
")",
"(",
"exists",
"bool",
",",
"err",
"error",
")",
"{",
"for",
"attempt",
":=",
"attempts",
".",
"Start",
"(",
")",
";",
"attempt",
".",
"Next",
"(",
")",
";",
"{",
"req",
":=",
"&",
"request",
"{",
"method",
":",
"\"",
"\"",
",",
"bucket",
":",
"b",
".",
"Name",
",",
"path",
":",
"path",
",",
"}",
"\n",
"err",
"=",
"b",
".",
"Client",
".",
"prepare",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"b",
".",
"Client",
".",
"run",
"(",
"req",
",",
"nil",
")",
"\n\n",
"if",
"shouldRetry",
"(",
"err",
")",
"&&",
"attempt",
".",
"HasNext",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"// We can treat a 403 or 404 as non existence",
"if",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"Error",
")",
";",
"ok",
"&&",
"(",
"e",
".",
"StatusCode",
"==",
"403",
"||",
"e",
".",
"StatusCode",
"==",
"404",
")",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"/",
"100",
"==",
"2",
"{",
"exists",
"=",
"true",
"\n",
"}",
"\n",
"if",
"resp",
".",
"Body",
"!=",
"nil",
"{",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"return",
"exists",
",",
"err",
"\n",
"}",
"\n",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // Exists checks whether or not an object exists on an bucket using a HEAD request. | [
"Exists",
"checks",
"whether",
"or",
"not",
"an",
"object",
"exists",
"on",
"an",
"bucket",
"using",
"a",
"HEAD",
"request",
"."
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/oss/client.go#L355-L390 |
152,129 | denverdino/aliyungo | oss/client.go | SignedURLWithArgs | func (b *Bucket) SignedURLWithArgs(path string, expires time.Time, params url.Values, headers http.Header) string {
return b.SignedURLWithMethod("GET", path, expires, params, headers)
} | go | func (b *Bucket) SignedURLWithArgs(path string, expires time.Time, params url.Values, headers http.Header) string {
return b.SignedURLWithMethod("GET", path, expires, params, headers)
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"SignedURLWithArgs",
"(",
"path",
"string",
",",
"expires",
"time",
".",
"Time",
",",
"params",
"url",
".",
"Values",
",",
"headers",
"http",
".",
"Header",
")",
"string",
"{",
"return",
"b",
".",
"SignedURLWithMethod",
"(",
"\"",
"\"",
",",
"path",
",",
"expires",
",",
"params",
",",
"headers",
")",
"\n",
"}"
] | // SignedURLWithArgs returns a signed URL that allows anyone holding the URL
// to retrieve the object at path. The signature is valid until expires. | [
"SignedURLWithArgs",
"returns",
"a",
"signed",
"URL",
"that",
"allows",
"anyone",
"holding",
"the",
"URL",
"to",
"retrieve",
"the",
"object",
"at",
"path",
".",
"The",
"signature",
"is",
"valid",
"until",
"expires",
"."
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/oss/client.go#L850-L852 |
152,130 | denverdino/aliyungo | oss/client.go | SignedURLWithMethod | func (b *Bucket) SignedURLWithMethod(method, path string, expires time.Time, params url.Values, headers http.Header) string {
var uv = url.Values{}
if params != nil {
uv = params
}
uv.Set("Expires", strconv.FormatInt(expires.Unix(), 10))
uv.Set("OSSAccessKeyId", b.AccessKeyId)
req := &request{
method: method,
bucket: b.Name,
path: path,
params: uv,
headers: headers,
}
err := b.Client.prepare(req)
if err != nil {
panic(err)
}
u, err := req.url()
if err != nil {
panic(err)
}
return u.String()
} | go | func (b *Bucket) SignedURLWithMethod(method, path string, expires time.Time, params url.Values, headers http.Header) string {
var uv = url.Values{}
if params != nil {
uv = params
}
uv.Set("Expires", strconv.FormatInt(expires.Unix(), 10))
uv.Set("OSSAccessKeyId", b.AccessKeyId)
req := &request{
method: method,
bucket: b.Name,
path: path,
params: uv,
headers: headers,
}
err := b.Client.prepare(req)
if err != nil {
panic(err)
}
u, err := req.url()
if err != nil {
panic(err)
}
return u.String()
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"SignedURLWithMethod",
"(",
"method",
",",
"path",
"string",
",",
"expires",
"time",
".",
"Time",
",",
"params",
"url",
".",
"Values",
",",
"headers",
"http",
".",
"Header",
")",
"string",
"{",
"var",
"uv",
"=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"if",
"params",
"!=",
"nil",
"{",
"uv",
"=",
"params",
"\n",
"}",
"\n\n",
"uv",
".",
"Set",
"(",
"\"",
"\"",
",",
"strconv",
".",
"FormatInt",
"(",
"expires",
".",
"Unix",
"(",
")",
",",
"10",
")",
")",
"\n",
"uv",
".",
"Set",
"(",
"\"",
"\"",
",",
"b",
".",
"AccessKeyId",
")",
"\n\n",
"req",
":=",
"&",
"request",
"{",
"method",
":",
"method",
",",
"bucket",
":",
"b",
".",
"Name",
",",
"path",
":",
"path",
",",
"params",
":",
"uv",
",",
"headers",
":",
"headers",
",",
"}",
"\n",
"err",
":=",
"b",
".",
"Client",
".",
"prepare",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"u",
",",
"err",
":=",
"req",
".",
"url",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"u",
".",
"String",
"(",
")",
"\n",
"}"
] | // SignedURLWithMethod returns a signed URL that allows anyone holding the URL
// to either retrieve the object at path or make a HEAD request against it. The signature is valid until expires. | [
"SignedURLWithMethod",
"returns",
"a",
"signed",
"URL",
"that",
"allows",
"anyone",
"holding",
"the",
"URL",
"to",
"either",
"retrieve",
"the",
"object",
"at",
"path",
"or",
"make",
"a",
"HEAD",
"request",
"against",
"it",
".",
"The",
"signature",
"is",
"valid",
"until",
"expires",
"."
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/oss/client.go#L867-L894 |
152,131 | denverdino/aliyungo | oss/client.go | PostFormArgsEx | func (b *Bucket) PostFormArgsEx(path string, expires time.Time, redirect string, conds []string) (action string, fields map[string]string) {
conditions := []string{}
fields = map[string]string{
"AWSAccessKeyId": b.AccessKeyId,
"key": path,
}
if conds != nil {
conditions = append(conditions, conds...)
}
conditions = append(conditions, fmt.Sprintf("{\"key\": \"%s\"}", path))
conditions = append(conditions, fmt.Sprintf("{\"bucket\": \"%s\"}", b.Name))
if redirect != "" {
conditions = append(conditions, fmt.Sprintf("{\"success_action_redirect\": \"%s\"}", redirect))
fields["success_action_redirect"] = redirect
}
vExpiration := expires.Format("2006-01-02T15:04:05Z")
vConditions := strings.Join(conditions, ",")
policy := fmt.Sprintf("{\"expiration\": \"%s\", \"conditions\": [%s]}", vExpiration, vConditions)
policy64 := base64.StdEncoding.EncodeToString([]byte(policy))
fields["policy"] = policy64
signer := hmac.New(sha1.New, []byte(b.AccessKeySecret))
signer.Write([]byte(policy64))
fields["signature"] = base64.StdEncoding.EncodeToString(signer.Sum(nil))
action = fmt.Sprintf("%s/%s/", b.Client.Region, b.Name)
return
} | go | func (b *Bucket) PostFormArgsEx(path string, expires time.Time, redirect string, conds []string) (action string, fields map[string]string) {
conditions := []string{}
fields = map[string]string{
"AWSAccessKeyId": b.AccessKeyId,
"key": path,
}
if conds != nil {
conditions = append(conditions, conds...)
}
conditions = append(conditions, fmt.Sprintf("{\"key\": \"%s\"}", path))
conditions = append(conditions, fmt.Sprintf("{\"bucket\": \"%s\"}", b.Name))
if redirect != "" {
conditions = append(conditions, fmt.Sprintf("{\"success_action_redirect\": \"%s\"}", redirect))
fields["success_action_redirect"] = redirect
}
vExpiration := expires.Format("2006-01-02T15:04:05Z")
vConditions := strings.Join(conditions, ",")
policy := fmt.Sprintf("{\"expiration\": \"%s\", \"conditions\": [%s]}", vExpiration, vConditions)
policy64 := base64.StdEncoding.EncodeToString([]byte(policy))
fields["policy"] = policy64
signer := hmac.New(sha1.New, []byte(b.AccessKeySecret))
signer.Write([]byte(policy64))
fields["signature"] = base64.StdEncoding.EncodeToString(signer.Sum(nil))
action = fmt.Sprintf("%s/%s/", b.Client.Region, b.Name)
return
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"PostFormArgsEx",
"(",
"path",
"string",
",",
"expires",
"time",
".",
"Time",
",",
"redirect",
"string",
",",
"conds",
"[",
"]",
"string",
")",
"(",
"action",
"string",
",",
"fields",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"conditions",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"fields",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"b",
".",
"AccessKeyId",
",",
"\"",
"\"",
":",
"path",
",",
"}",
"\n\n",
"if",
"conds",
"!=",
"nil",
"{",
"conditions",
"=",
"append",
"(",
"conditions",
",",
"conds",
"...",
")",
"\n",
"}",
"\n\n",
"conditions",
"=",
"append",
"(",
"conditions",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\"",
",",
"path",
")",
")",
"\n",
"conditions",
"=",
"append",
"(",
"conditions",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\"",
",",
"b",
".",
"Name",
")",
")",
"\n",
"if",
"redirect",
"!=",
"\"",
"\"",
"{",
"conditions",
"=",
"append",
"(",
"conditions",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\"",
",",
"redirect",
")",
")",
"\n",
"fields",
"[",
"\"",
"\"",
"]",
"=",
"redirect",
"\n",
"}",
"\n\n",
"vExpiration",
":=",
"expires",
".",
"Format",
"(",
"\"",
"\"",
")",
"\n",
"vConditions",
":=",
"strings",
".",
"Join",
"(",
"conditions",
",",
"\"",
"\"",
")",
"\n",
"policy",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\"",
",",
"vExpiration",
",",
"vConditions",
")",
"\n",
"policy64",
":=",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"[",
"]",
"byte",
"(",
"policy",
")",
")",
"\n",
"fields",
"[",
"\"",
"\"",
"]",
"=",
"policy64",
"\n\n",
"signer",
":=",
"hmac",
".",
"New",
"(",
"sha1",
".",
"New",
",",
"[",
"]",
"byte",
"(",
"b",
".",
"AccessKeySecret",
")",
")",
"\n",
"signer",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"policy64",
")",
")",
"\n",
"fields",
"[",
"\"",
"\"",
"]",
"=",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"signer",
".",
"Sum",
"(",
"nil",
")",
")",
"\n\n",
"action",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"Client",
".",
"Region",
",",
"b",
".",
"Name",
")",
"\n",
"return",
"\n",
"}"
] | // PostFormArgsEx returns the action and input fields needed to allow anonymous
// uploads to a bucket within the expiration limit
// Additional conditions can be specified with conds | [
"PostFormArgsEx",
"returns",
"the",
"action",
"and",
"input",
"fields",
"needed",
"to",
"allow",
"anonymous",
"uploads",
"to",
"a",
"bucket",
"within",
"the",
"expiration",
"limit",
"Additional",
"conditions",
"can",
"be",
"specified",
"with",
"conds"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/oss/client.go#L936-L966 |
152,132 | denverdino/aliyungo | oss/client.go | PostFormArgs | func (b *Bucket) PostFormArgs(path string, expires time.Time, redirect string) (action string, fields map[string]string) {
return b.PostFormArgsEx(path, expires, redirect, nil)
} | go | func (b *Bucket) PostFormArgs(path string, expires time.Time, redirect string) (action string, fields map[string]string) {
return b.PostFormArgsEx(path, expires, redirect, nil)
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"PostFormArgs",
"(",
"path",
"string",
",",
"expires",
"time",
".",
"Time",
",",
"redirect",
"string",
")",
"(",
"action",
"string",
",",
"fields",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"return",
"b",
".",
"PostFormArgsEx",
"(",
"path",
",",
"expires",
",",
"redirect",
",",
"nil",
")",
"\n",
"}"
] | // PostFormArgs returns the action and input fields needed to allow anonymous
// uploads to a bucket within the expiration limit | [
"PostFormArgs",
"returns",
"the",
"action",
"and",
"input",
"fields",
"needed",
"to",
"allow",
"anonymous",
"uploads",
"to",
"a",
"bucket",
"within",
"the",
"expiration",
"limit"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/oss/client.go#L970-L972 |
152,133 | denverdino/aliyungo | oss/client.go | prepare | func (client *Client) prepare(req *request) error {
// Copy so they can be mutated without affecting on retries.
headers := copyHeader(req.headers)
// security-token should be in either Params or Header, cannot be in both
if len(req.params.Get("security-token")) == 0 && len(client.SecurityToken) != 0 {
headers.Set("x-oss-security-token", client.SecurityToken)
}
params := make(url.Values)
for k, v := range req.params {
params[k] = v
}
req.params = params
req.headers = headers
if !req.prepared {
req.prepared = true
if req.method == "" {
req.method = "GET"
}
if !strings.HasPrefix(req.path, "/") {
req.path = "/" + req.path
}
err := client.setBaseURL(req)
if err != nil {
return err
}
}
req.headers.Set("Date", util.GetGMTime())
client.signRequest(req)
return nil
} | go | func (client *Client) prepare(req *request) error {
// Copy so they can be mutated without affecting on retries.
headers := copyHeader(req.headers)
// security-token should be in either Params or Header, cannot be in both
if len(req.params.Get("security-token")) == 0 && len(client.SecurityToken) != 0 {
headers.Set("x-oss-security-token", client.SecurityToken)
}
params := make(url.Values)
for k, v := range req.params {
params[k] = v
}
req.params = params
req.headers = headers
if !req.prepared {
req.prepared = true
if req.method == "" {
req.method = "GET"
}
if !strings.HasPrefix(req.path, "/") {
req.path = "/" + req.path
}
err := client.setBaseURL(req)
if err != nil {
return err
}
}
req.headers.Set("Date", util.GetGMTime())
client.signRequest(req)
return nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"prepare",
"(",
"req",
"*",
"request",
")",
"error",
"{",
"// Copy so they can be mutated without affecting on retries.",
"headers",
":=",
"copyHeader",
"(",
"req",
".",
"headers",
")",
"\n",
"// security-token should be in either Params or Header, cannot be in both",
"if",
"len",
"(",
"req",
".",
"params",
".",
"Get",
"(",
"\"",
"\"",
")",
")",
"==",
"0",
"&&",
"len",
"(",
"client",
".",
"SecurityToken",
")",
"!=",
"0",
"{",
"headers",
".",
"Set",
"(",
"\"",
"\"",
",",
"client",
".",
"SecurityToken",
")",
"\n",
"}",
"\n\n",
"params",
":=",
"make",
"(",
"url",
".",
"Values",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"req",
".",
"params",
"{",
"params",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"req",
".",
"params",
"=",
"params",
"\n",
"req",
".",
"headers",
"=",
"headers",
"\n\n",
"if",
"!",
"req",
".",
"prepared",
"{",
"req",
".",
"prepared",
"=",
"true",
"\n",
"if",
"req",
".",
"method",
"==",
"\"",
"\"",
"{",
"req",
".",
"method",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"req",
".",
"path",
",",
"\"",
"\"",
")",
"{",
"req",
".",
"path",
"=",
"\"",
"\"",
"+",
"req",
".",
"path",
"\n",
"}",
"\n\n",
"err",
":=",
"client",
".",
"setBaseURL",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"req",
".",
"headers",
".",
"Set",
"(",
"\"",
"\"",
",",
"util",
".",
"GetGMTime",
"(",
")",
")",
"\n",
"client",
".",
"signRequest",
"(",
"req",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // prepare sets up req to be delivered to OSS. | [
"prepare",
"sets",
"up",
"req",
"to",
"be",
"delivered",
"to",
"OSS",
"."
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/oss/client.go#L1050-L1087 |
152,134 | denverdino/aliyungo | oss/client.go | CopyLargeFileInParallel | func (b *Bucket) CopyLargeFileInParallel(sourcePath string, destPath string, contentType string, perm ACL, options Options, maxConcurrency int) error {
if maxConcurrency < 1 {
maxConcurrency = 1
}
currentLength, err := b.GetContentLength(sourcePath)
log.Printf("Parallel Copy large file[size: %d] from %s to %s\n", currentLength, sourcePath, destPath)
if err != nil {
return err
}
if currentLength < maxCopytSize {
_, err := b.PutCopy(destPath, perm,
CopyOptions{},
b.Path(sourcePath))
return err
}
multi, err := b.InitMulti(destPath, contentType, perm, options)
if err != nil {
return err
}
numParts := (currentLength + defaultChunkSize - 1) / defaultChunkSize
completedParts := make([]Part, numParts)
errChan := make(chan error, numParts)
limiter := make(chan struct{}, maxConcurrency)
var start int64 = 0
var to int64 = 0
var partNumber = 0
sourcePathForCopy := b.Path(sourcePath)
for start = 0; start < currentLength; start = to {
to = start + defaultChunkSize
if to > currentLength {
to = currentLength
}
partNumber++
rangeStr := fmt.Sprintf("bytes=%d-%d", start, to-1)
limiter <- struct{}{}
go func(partNumber int, rangeStr string) {
_, part, err := multi.PutPartCopyWithContentLength(partNumber,
CopyOptions{CopySourceOptions: rangeStr},
sourcePathForCopy, currentLength)
if err == nil {
completedParts[partNumber-1] = part
} else {
log.Printf("Unable in PutPartCopy of part %d for %s: %v\n", partNumber, sourcePathForCopy, err)
}
errChan <- err
<-limiter
}(partNumber, rangeStr)
}
fullyCompleted := true
for range completedParts {
err := <-errChan
if err != nil {
fullyCompleted = false
}
}
if fullyCompleted {
err = multi.Complete(completedParts)
} else {
err = multi.Abort()
}
return err
} | go | func (b *Bucket) CopyLargeFileInParallel(sourcePath string, destPath string, contentType string, perm ACL, options Options, maxConcurrency int) error {
if maxConcurrency < 1 {
maxConcurrency = 1
}
currentLength, err := b.GetContentLength(sourcePath)
log.Printf("Parallel Copy large file[size: %d] from %s to %s\n", currentLength, sourcePath, destPath)
if err != nil {
return err
}
if currentLength < maxCopytSize {
_, err := b.PutCopy(destPath, perm,
CopyOptions{},
b.Path(sourcePath))
return err
}
multi, err := b.InitMulti(destPath, contentType, perm, options)
if err != nil {
return err
}
numParts := (currentLength + defaultChunkSize - 1) / defaultChunkSize
completedParts := make([]Part, numParts)
errChan := make(chan error, numParts)
limiter := make(chan struct{}, maxConcurrency)
var start int64 = 0
var to int64 = 0
var partNumber = 0
sourcePathForCopy := b.Path(sourcePath)
for start = 0; start < currentLength; start = to {
to = start + defaultChunkSize
if to > currentLength {
to = currentLength
}
partNumber++
rangeStr := fmt.Sprintf("bytes=%d-%d", start, to-1)
limiter <- struct{}{}
go func(partNumber int, rangeStr string) {
_, part, err := multi.PutPartCopyWithContentLength(partNumber,
CopyOptions{CopySourceOptions: rangeStr},
sourcePathForCopy, currentLength)
if err == nil {
completedParts[partNumber-1] = part
} else {
log.Printf("Unable in PutPartCopy of part %d for %s: %v\n", partNumber, sourcePathForCopy, err)
}
errChan <- err
<-limiter
}(partNumber, rangeStr)
}
fullyCompleted := true
for range completedParts {
err := <-errChan
if err != nil {
fullyCompleted = false
}
}
if fullyCompleted {
err = multi.Complete(completedParts)
} else {
err = multi.Abort()
}
return err
} | [
"func",
"(",
"b",
"*",
"Bucket",
")",
"CopyLargeFileInParallel",
"(",
"sourcePath",
"string",
",",
"destPath",
"string",
",",
"contentType",
"string",
",",
"perm",
"ACL",
",",
"options",
"Options",
",",
"maxConcurrency",
"int",
")",
"error",
"{",
"if",
"maxConcurrency",
"<",
"1",
"{",
"maxConcurrency",
"=",
"1",
"\n",
"}",
"\n\n",
"currentLength",
",",
"err",
":=",
"b",
".",
"GetContentLength",
"(",
"sourcePath",
")",
"\n\n",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"currentLength",
",",
"sourcePath",
",",
"destPath",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"currentLength",
"<",
"maxCopytSize",
"{",
"_",
",",
"err",
":=",
"b",
".",
"PutCopy",
"(",
"destPath",
",",
"perm",
",",
"CopyOptions",
"{",
"}",
",",
"b",
".",
"Path",
"(",
"sourcePath",
")",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"multi",
",",
"err",
":=",
"b",
".",
"InitMulti",
"(",
"destPath",
",",
"contentType",
",",
"perm",
",",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"numParts",
":=",
"(",
"currentLength",
"+",
"defaultChunkSize",
"-",
"1",
")",
"/",
"defaultChunkSize",
"\n",
"completedParts",
":=",
"make",
"(",
"[",
"]",
"Part",
",",
"numParts",
")",
"\n\n",
"errChan",
":=",
"make",
"(",
"chan",
"error",
",",
"numParts",
")",
"\n",
"limiter",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
",",
"maxConcurrency",
")",
"\n\n",
"var",
"start",
"int64",
"=",
"0",
"\n",
"var",
"to",
"int64",
"=",
"0",
"\n",
"var",
"partNumber",
"=",
"0",
"\n",
"sourcePathForCopy",
":=",
"b",
".",
"Path",
"(",
"sourcePath",
")",
"\n\n",
"for",
"start",
"=",
"0",
";",
"start",
"<",
"currentLength",
";",
"start",
"=",
"to",
"{",
"to",
"=",
"start",
"+",
"defaultChunkSize",
"\n",
"if",
"to",
">",
"currentLength",
"{",
"to",
"=",
"currentLength",
"\n",
"}",
"\n",
"partNumber",
"++",
"\n\n",
"rangeStr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"start",
",",
"to",
"-",
"1",
")",
"\n",
"limiter",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n",
"go",
"func",
"(",
"partNumber",
"int",
",",
"rangeStr",
"string",
")",
"{",
"_",
",",
"part",
",",
"err",
":=",
"multi",
".",
"PutPartCopyWithContentLength",
"(",
"partNumber",
",",
"CopyOptions",
"{",
"CopySourceOptions",
":",
"rangeStr",
"}",
",",
"sourcePathForCopy",
",",
"currentLength",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"completedParts",
"[",
"partNumber",
"-",
"1",
"]",
"=",
"part",
"\n",
"}",
"else",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"partNumber",
",",
"sourcePathForCopy",
",",
"err",
")",
"\n",
"}",
"\n",
"errChan",
"<-",
"err",
"\n",
"<-",
"limiter",
"\n",
"}",
"(",
"partNumber",
",",
"rangeStr",
")",
"\n",
"}",
"\n\n",
"fullyCompleted",
":=",
"true",
"\n",
"for",
"range",
"completedParts",
"{",
"err",
":=",
"<-",
"errChan",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fullyCompleted",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"fullyCompleted",
"{",
"err",
"=",
"multi",
".",
"Complete",
"(",
"completedParts",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"multi",
".",
"Abort",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Copy large file in the same bucket | [
"Copy",
"large",
"file",
"in",
"the",
"same",
"bucket"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/oss/client.go#L1346-L1421 |
152,135 | denverdino/aliyungo | util/signature.go | CreateSignature | func CreateSignature(stringToSignature, accessKeySecret string) string {
// Crypto by HMAC-SHA1
hmacSha1 := hmac.New(sha1.New, []byte(accessKeySecret))
hmacSha1.Write([]byte(stringToSignature))
sign := hmacSha1.Sum(nil)
// Encode to Base64
base64Sign := base64.StdEncoding.EncodeToString(sign)
return base64Sign
} | go | func CreateSignature(stringToSignature, accessKeySecret string) string {
// Crypto by HMAC-SHA1
hmacSha1 := hmac.New(sha1.New, []byte(accessKeySecret))
hmacSha1.Write([]byte(stringToSignature))
sign := hmacSha1.Sum(nil)
// Encode to Base64
base64Sign := base64.StdEncoding.EncodeToString(sign)
return base64Sign
} | [
"func",
"CreateSignature",
"(",
"stringToSignature",
",",
"accessKeySecret",
"string",
")",
"string",
"{",
"// Crypto by HMAC-SHA1",
"hmacSha1",
":=",
"hmac",
".",
"New",
"(",
"sha1",
".",
"New",
",",
"[",
"]",
"byte",
"(",
"accessKeySecret",
")",
")",
"\n",
"hmacSha1",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"stringToSignature",
")",
")",
"\n",
"sign",
":=",
"hmacSha1",
".",
"Sum",
"(",
"nil",
")",
"\n\n",
"// Encode to Base64",
"base64Sign",
":=",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"sign",
")",
"\n\n",
"return",
"base64Sign",
"\n",
"}"
] | //CreateSignature creates signature for string following Aliyun rules | [
"CreateSignature",
"creates",
"signature",
"for",
"string",
"following",
"Aliyun",
"rules"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/util/signature.go#L12-L22 |
152,136 | denverdino/aliyungo | util/signature.go | CreateSignatureForRequest | func CreateSignatureForRequest(method string, values *url.Values, accessKeySecret string) string {
canonicalizedQueryString := percentReplace(values.Encode())
stringToSign := method + "&%2F&" + url.QueryEscape(canonicalizedQueryString)
return CreateSignature(stringToSign, accessKeySecret)
} | go | func CreateSignatureForRequest(method string, values *url.Values, accessKeySecret string) string {
canonicalizedQueryString := percentReplace(values.Encode())
stringToSign := method + "&%2F&" + url.QueryEscape(canonicalizedQueryString)
return CreateSignature(stringToSign, accessKeySecret)
} | [
"func",
"CreateSignatureForRequest",
"(",
"method",
"string",
",",
"values",
"*",
"url",
".",
"Values",
",",
"accessKeySecret",
"string",
")",
"string",
"{",
"canonicalizedQueryString",
":=",
"percentReplace",
"(",
"values",
".",
"Encode",
"(",
")",
")",
"\n\n",
"stringToSign",
":=",
"method",
"+",
"\"",
"\"",
"+",
"url",
".",
"QueryEscape",
"(",
"canonicalizedQueryString",
")",
"\n",
"return",
"CreateSignature",
"(",
"stringToSign",
",",
"accessKeySecret",
")",
"\n",
"}"
] | // CreateSignatureForRequest creates signature for query string values | [
"CreateSignatureForRequest",
"creates",
"signature",
"for",
"query",
"string",
"values"
] | 611ead8a6fedf409d6512b6e4f44f3f1cbc65755 | https://github.com/denverdino/aliyungo/blob/611ead8a6fedf409d6512b6e4f44f3f1cbc65755/util/signature.go#L33-L39 |
152,137 | alecthomas/jsonschema | reflect.go | ReflectFromType | func ReflectFromType(t reflect.Type) *Schema {
r := &Reflector{}
return r.ReflectFromType(t)
} | go | func ReflectFromType(t reflect.Type) *Schema {
r := &Reflector{}
return r.ReflectFromType(t)
} | [
"func",
"ReflectFromType",
"(",
"t",
"reflect",
".",
"Type",
")",
"*",
"Schema",
"{",
"r",
":=",
"&",
"Reflector",
"{",
"}",
"\n",
"return",
"r",
".",
"ReflectFromType",
"(",
"t",
")",
"\n",
"}"
] | // ReflectFromType generates root schema using the default Reflector | [
"ReflectFromType",
"generates",
"root",
"schema",
"using",
"the",
"default",
"Reflector"
] | eff3f6c90428ddd2d988c9b686d92488c6430b77 | https://github.com/alecthomas/jsonschema/blob/eff3f6c90428ddd2d988c9b686d92488c6430b77/reflect.go#L81-L84 |
152,138 | alecthomas/jsonschema | reflect.go | Reflect | func (r *Reflector) Reflect(v interface{}) *Schema {
return r.ReflectFromType(reflect.TypeOf(v))
} | go | func (r *Reflector) Reflect(v interface{}) *Schema {
return r.ReflectFromType(reflect.TypeOf(v))
} | [
"func",
"(",
"r",
"*",
"Reflector",
")",
"Reflect",
"(",
"v",
"interface",
"{",
"}",
")",
"*",
"Schema",
"{",
"return",
"r",
".",
"ReflectFromType",
"(",
"reflect",
".",
"TypeOf",
"(",
"v",
")",
")",
"\n",
"}"
] | // Reflect reflects to Schema from a value. | [
"Reflect",
"reflects",
"to",
"Schema",
"from",
"a",
"value",
"."
] | eff3f6c90428ddd2d988c9b686d92488c6430b77 | https://github.com/alecthomas/jsonschema/blob/eff3f6c90428ddd2d988c9b686d92488c6430b77/reflect.go#L106-L108 |
152,139 | alecthomas/jsonschema | reflect.go | ReflectFromType | func (r *Reflector) ReflectFromType(t reflect.Type) *Schema {
definitions := Definitions{}
if r.ExpandedStruct {
st := &Type{
Version: Version,
Type: "object",
Properties: map[string]*Type{},
AdditionalProperties: []byte("false"),
}
if r.AllowAdditionalProperties {
st.AdditionalProperties = []byte("true")
}
r.reflectStructFields(st, definitions, t)
r.reflectStruct(definitions, t)
delete(definitions, t.Name())
return &Schema{Type: st, Definitions: definitions}
}
s := &Schema{
Type: r.reflectTypeToSchema(definitions, t),
Definitions: definitions,
}
return s
} | go | func (r *Reflector) ReflectFromType(t reflect.Type) *Schema {
definitions := Definitions{}
if r.ExpandedStruct {
st := &Type{
Version: Version,
Type: "object",
Properties: map[string]*Type{},
AdditionalProperties: []byte("false"),
}
if r.AllowAdditionalProperties {
st.AdditionalProperties = []byte("true")
}
r.reflectStructFields(st, definitions, t)
r.reflectStruct(definitions, t)
delete(definitions, t.Name())
return &Schema{Type: st, Definitions: definitions}
}
s := &Schema{
Type: r.reflectTypeToSchema(definitions, t),
Definitions: definitions,
}
return s
} | [
"func",
"(",
"r",
"*",
"Reflector",
")",
"ReflectFromType",
"(",
"t",
"reflect",
".",
"Type",
")",
"*",
"Schema",
"{",
"definitions",
":=",
"Definitions",
"{",
"}",
"\n",
"if",
"r",
".",
"ExpandedStruct",
"{",
"st",
":=",
"&",
"Type",
"{",
"Version",
":",
"Version",
",",
"Type",
":",
"\"",
"\"",
",",
"Properties",
":",
"map",
"[",
"string",
"]",
"*",
"Type",
"{",
"}",
",",
"AdditionalProperties",
":",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
",",
"}",
"\n",
"if",
"r",
".",
"AllowAdditionalProperties",
"{",
"st",
".",
"AdditionalProperties",
"=",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"r",
".",
"reflectStructFields",
"(",
"st",
",",
"definitions",
",",
"t",
")",
"\n",
"r",
".",
"reflectStruct",
"(",
"definitions",
",",
"t",
")",
"\n",
"delete",
"(",
"definitions",
",",
"t",
".",
"Name",
"(",
")",
")",
"\n",
"return",
"&",
"Schema",
"{",
"Type",
":",
"st",
",",
"Definitions",
":",
"definitions",
"}",
"\n",
"}",
"\n\n",
"s",
":=",
"&",
"Schema",
"{",
"Type",
":",
"r",
".",
"reflectTypeToSchema",
"(",
"definitions",
",",
"t",
")",
",",
"Definitions",
":",
"definitions",
",",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // ReflectFromType generates root schema | [
"ReflectFromType",
"generates",
"root",
"schema"
] | eff3f6c90428ddd2d988c9b686d92488c6430b77 | https://github.com/alecthomas/jsonschema/blob/eff3f6c90428ddd2d988c9b686d92488c6430b77/reflect.go#L111-L134 |
152,140 | alecthomas/jsonschema | reflect.go | reflectStruct | func (r *Reflector) reflectStruct(definitions Definitions, t reflect.Type) *Type {
st := &Type{
Type: "object",
Properties: map[string]*Type{},
AdditionalProperties: []byte("false"),
}
if r.AllowAdditionalProperties {
st.AdditionalProperties = []byte("true")
}
definitions[t.Name()] = st
r.reflectStructFields(st, definitions, t)
return &Type{
Version: Version,
Ref: "#/definitions/" + t.Name(),
}
} | go | func (r *Reflector) reflectStruct(definitions Definitions, t reflect.Type) *Type {
st := &Type{
Type: "object",
Properties: map[string]*Type{},
AdditionalProperties: []byte("false"),
}
if r.AllowAdditionalProperties {
st.AdditionalProperties = []byte("true")
}
definitions[t.Name()] = st
r.reflectStructFields(st, definitions, t)
return &Type{
Version: Version,
Ref: "#/definitions/" + t.Name(),
}
} | [
"func",
"(",
"r",
"*",
"Reflector",
")",
"reflectStruct",
"(",
"definitions",
"Definitions",
",",
"t",
"reflect",
".",
"Type",
")",
"*",
"Type",
"{",
"st",
":=",
"&",
"Type",
"{",
"Type",
":",
"\"",
"\"",
",",
"Properties",
":",
"map",
"[",
"string",
"]",
"*",
"Type",
"{",
"}",
",",
"AdditionalProperties",
":",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
",",
"}",
"\n",
"if",
"r",
".",
"AllowAdditionalProperties",
"{",
"st",
".",
"AdditionalProperties",
"=",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"definitions",
"[",
"t",
".",
"Name",
"(",
")",
"]",
"=",
"st",
"\n",
"r",
".",
"reflectStructFields",
"(",
"st",
",",
"definitions",
",",
"t",
")",
"\n\n",
"return",
"&",
"Type",
"{",
"Version",
":",
"Version",
",",
"Ref",
":",
"\"",
"\"",
"+",
"t",
".",
"Name",
"(",
")",
",",
"}",
"\n",
"}"
] | // Refects a struct to a JSON Schema type. | [
"Refects",
"a",
"struct",
"to",
"a",
"JSON",
"Schema",
"type",
"."
] | eff3f6c90428ddd2d988c9b686d92488c6430b77 | https://github.com/alecthomas/jsonschema/blob/eff3f6c90428ddd2d988c9b686d92488c6430b77/reflect.go#L248-L264 |
152,141 | alecthomas/jsonschema | reflect.go | genericKeywords | func (t *Type) genericKeywords(tags []string) {
for _, tag := range tags {
nameValue := strings.Split(tag, "=")
if len(nameValue) == 2 {
name, val := nameValue[0], nameValue[1]
switch name {
case "title":
t.Title = val
case "description":
t.Description = val
}
}
}
} | go | func (t *Type) genericKeywords(tags []string) {
for _, tag := range tags {
nameValue := strings.Split(tag, "=")
if len(nameValue) == 2 {
name, val := nameValue[0], nameValue[1]
switch name {
case "title":
t.Title = val
case "description":
t.Description = val
}
}
}
} | [
"func",
"(",
"t",
"*",
"Type",
")",
"genericKeywords",
"(",
"tags",
"[",
"]",
"string",
")",
"{",
"for",
"_",
",",
"tag",
":=",
"range",
"tags",
"{",
"nameValue",
":=",
"strings",
".",
"Split",
"(",
"tag",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"nameValue",
")",
"==",
"2",
"{",
"name",
",",
"val",
":=",
"nameValue",
"[",
"0",
"]",
",",
"nameValue",
"[",
"1",
"]",
"\n",
"switch",
"name",
"{",
"case",
"\"",
"\"",
":",
"t",
".",
"Title",
"=",
"val",
"\n",
"case",
"\"",
"\"",
":",
"t",
".",
"Description",
"=",
"val",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // read struct tags for generic keyworks | [
"read",
"struct",
"tags",
"for",
"generic",
"keyworks"
] | eff3f6c90428ddd2d988c9b686d92488c6430b77 | https://github.com/alecthomas/jsonschema/blob/eff3f6c90428ddd2d988c9b686d92488c6430b77/reflect.go#L312-L325 |
152,142 | alecthomas/jsonschema | reflect.go | stringKeywords | func (t *Type) stringKeywords(tags []string) {
for _, tag := range tags {
nameValue := strings.Split(tag, "=")
if len(nameValue) == 2 {
name, val := nameValue[0], nameValue[1]
switch name {
case "minLength":
i, _ := strconv.Atoi(val)
t.MinLength = i
case "maxLength":
i, _ := strconv.Atoi(val)
t.MaxLength = i
case "pattern":
t.Pattern = val
case "format":
switch val {
case "date-time", "email", "hostname", "ipv4", "ipv6", "uri":
t.Format = val
break
}
case "default":
t.Default = val
case "example":
t.Examples = append(t.Examples, val)
}
}
}
} | go | func (t *Type) stringKeywords(tags []string) {
for _, tag := range tags {
nameValue := strings.Split(tag, "=")
if len(nameValue) == 2 {
name, val := nameValue[0], nameValue[1]
switch name {
case "minLength":
i, _ := strconv.Atoi(val)
t.MinLength = i
case "maxLength":
i, _ := strconv.Atoi(val)
t.MaxLength = i
case "pattern":
t.Pattern = val
case "format":
switch val {
case "date-time", "email", "hostname", "ipv4", "ipv6", "uri":
t.Format = val
break
}
case "default":
t.Default = val
case "example":
t.Examples = append(t.Examples, val)
}
}
}
} | [
"func",
"(",
"t",
"*",
"Type",
")",
"stringKeywords",
"(",
"tags",
"[",
"]",
"string",
")",
"{",
"for",
"_",
",",
"tag",
":=",
"range",
"tags",
"{",
"nameValue",
":=",
"strings",
".",
"Split",
"(",
"tag",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"nameValue",
")",
"==",
"2",
"{",
"name",
",",
"val",
":=",
"nameValue",
"[",
"0",
"]",
",",
"nameValue",
"[",
"1",
"]",
"\n",
"switch",
"name",
"{",
"case",
"\"",
"\"",
":",
"i",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"val",
")",
"\n",
"t",
".",
"MinLength",
"=",
"i",
"\n",
"case",
"\"",
"\"",
":",
"i",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"val",
")",
"\n",
"t",
".",
"MaxLength",
"=",
"i",
"\n",
"case",
"\"",
"\"",
":",
"t",
".",
"Pattern",
"=",
"val",
"\n",
"case",
"\"",
"\"",
":",
"switch",
"val",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"t",
".",
"Format",
"=",
"val",
"\n",
"break",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"t",
".",
"Default",
"=",
"val",
"\n",
"case",
"\"",
"\"",
":",
"t",
".",
"Examples",
"=",
"append",
"(",
"t",
".",
"Examples",
",",
"val",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // read struct tags for string type keyworks | [
"read",
"struct",
"tags",
"for",
"string",
"type",
"keyworks"
] | eff3f6c90428ddd2d988c9b686d92488c6430b77 | https://github.com/alecthomas/jsonschema/blob/eff3f6c90428ddd2d988c9b686d92488c6430b77/reflect.go#L328-L355 |
152,143 | alecthomas/jsonschema | reflect.go | numbericKeywords | func (t *Type) numbericKeywords(tags []string) {
for _, tag := range tags {
nameValue := strings.Split(tag, "=")
if len(nameValue) == 2 {
name, val := nameValue[0], nameValue[1]
switch name {
case "multipleOf":
i, _ := strconv.Atoi(val)
t.MultipleOf = i
case "minimum":
i, _ := strconv.Atoi(val)
t.Minimum = i
case "maximum":
i, _ := strconv.Atoi(val)
t.Maximum = i
case "exclusiveMaximum":
b, _ := strconv.ParseBool(val)
t.ExclusiveMaximum = b
case "exclusiveMinimum":
b, _ := strconv.ParseBool(val)
t.ExclusiveMinimum = b
case "default":
i, _ := strconv.Atoi(val)
t.Default = i
case "example":
if i, err := strconv.Atoi(val); err == nil {
t.Examples = append(t.Examples, i)
}
}
}
}
} | go | func (t *Type) numbericKeywords(tags []string) {
for _, tag := range tags {
nameValue := strings.Split(tag, "=")
if len(nameValue) == 2 {
name, val := nameValue[0], nameValue[1]
switch name {
case "multipleOf":
i, _ := strconv.Atoi(val)
t.MultipleOf = i
case "minimum":
i, _ := strconv.Atoi(val)
t.Minimum = i
case "maximum":
i, _ := strconv.Atoi(val)
t.Maximum = i
case "exclusiveMaximum":
b, _ := strconv.ParseBool(val)
t.ExclusiveMaximum = b
case "exclusiveMinimum":
b, _ := strconv.ParseBool(val)
t.ExclusiveMinimum = b
case "default":
i, _ := strconv.Atoi(val)
t.Default = i
case "example":
if i, err := strconv.Atoi(val); err == nil {
t.Examples = append(t.Examples, i)
}
}
}
}
} | [
"func",
"(",
"t",
"*",
"Type",
")",
"numbericKeywords",
"(",
"tags",
"[",
"]",
"string",
")",
"{",
"for",
"_",
",",
"tag",
":=",
"range",
"tags",
"{",
"nameValue",
":=",
"strings",
".",
"Split",
"(",
"tag",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"nameValue",
")",
"==",
"2",
"{",
"name",
",",
"val",
":=",
"nameValue",
"[",
"0",
"]",
",",
"nameValue",
"[",
"1",
"]",
"\n",
"switch",
"name",
"{",
"case",
"\"",
"\"",
":",
"i",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"val",
")",
"\n",
"t",
".",
"MultipleOf",
"=",
"i",
"\n",
"case",
"\"",
"\"",
":",
"i",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"val",
")",
"\n",
"t",
".",
"Minimum",
"=",
"i",
"\n",
"case",
"\"",
"\"",
":",
"i",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"val",
")",
"\n",
"t",
".",
"Maximum",
"=",
"i",
"\n",
"case",
"\"",
"\"",
":",
"b",
",",
"_",
":=",
"strconv",
".",
"ParseBool",
"(",
"val",
")",
"\n",
"t",
".",
"ExclusiveMaximum",
"=",
"b",
"\n",
"case",
"\"",
"\"",
":",
"b",
",",
"_",
":=",
"strconv",
".",
"ParseBool",
"(",
"val",
")",
"\n",
"t",
".",
"ExclusiveMinimum",
"=",
"b",
"\n",
"case",
"\"",
"\"",
":",
"i",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"val",
")",
"\n",
"t",
".",
"Default",
"=",
"i",
"\n",
"case",
"\"",
"\"",
":",
"if",
"i",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"val",
")",
";",
"err",
"==",
"nil",
"{",
"t",
".",
"Examples",
"=",
"append",
"(",
"t",
".",
"Examples",
",",
"i",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // read struct tags for numberic type keyworks | [
"read",
"struct",
"tags",
"for",
"numberic",
"type",
"keyworks"
] | eff3f6c90428ddd2d988c9b686d92488c6430b77 | https://github.com/alecthomas/jsonschema/blob/eff3f6c90428ddd2d988c9b686d92488c6430b77/reflect.go#L358-L389 |
152,144 | bitfinexcom/bitfinex-api-go | utils/nonce.go | GetNonce | func (u *EpochNonceGenerator) GetNonce() string {
return strconv.FormatUint(atomic.AddUint64(&u.nonce, 1), 10)
} | go | func (u *EpochNonceGenerator) GetNonce() string {
return strconv.FormatUint(atomic.AddUint64(&u.nonce, 1), 10)
} | [
"func",
"(",
"u",
"*",
"EpochNonceGenerator",
")",
"GetNonce",
"(",
")",
"string",
"{",
"return",
"strconv",
".",
"FormatUint",
"(",
"atomic",
".",
"AddUint64",
"(",
"&",
"u",
".",
"nonce",
",",
"1",
")",
",",
"10",
")",
"\n",
"}"
] | // GetNonce is a naive nonce producer that takes the current Unix nano epoch
// and counts upwards.
// This is a naive approach because the nonce bound to the currently used API
// key and as such needs to be synchronised with other instances using the same
// key in order to avoid race conditions. | [
"GetNonce",
"is",
"a",
"naive",
"nonce",
"producer",
"that",
"takes",
"the",
"current",
"Unix",
"nano",
"epoch",
"and",
"counts",
"upwards",
".",
"This",
"is",
"a",
"naive",
"approach",
"because",
"the",
"nonce",
"bound",
"to",
"the",
"currently",
"used",
"API",
"key",
"and",
"as",
"such",
"needs",
"to",
"be",
"synchronised",
"with",
"other",
"instances",
"using",
"the",
"same",
"key",
"in",
"order",
"to",
"avoid",
"race",
"conditions",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/utils/nonce.go#L24-L26 |
152,145 | bitfinexcom/bitfinex-api-go | v2/websocket/api.go | Send | func (c *Client) Send(ctx context.Context, msg interface{}) error {
return c.asynchronous.Send(ctx, msg)
} | go | func (c *Client) Send(ctx context.Context, msg interface{}) error {
return c.asynchronous.Send(ctx, msg)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Send",
"(",
"ctx",
"context",
".",
"Context",
",",
"msg",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"c",
".",
"asynchronous",
".",
"Send",
"(",
"ctx",
",",
"msg",
")",
"\n",
"}"
] | // API for end-users to interact with Bitfinex.
// Send publishes a generic message to the Bitfinex API. | [
"API",
"for",
"end",
"-",
"users",
"to",
"interact",
"with",
"Bitfinex",
".",
"Send",
"publishes",
"a",
"generic",
"message",
"to",
"the",
"Bitfinex",
"API",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/api.go#L17-L19 |
152,146 | bitfinexcom/bitfinex-api-go | v2/websocket/api.go | Subscribe | func (c *Client) Subscribe(ctx context.Context, req *SubscriptionRequest) (string, error) {
c.subscriptions.add(req)
err := c.asynchronous.Send(ctx, req)
if err != nil {
// propagate send error
return "", err
}
return req.SubID, nil
} | go | func (c *Client) Subscribe(ctx context.Context, req *SubscriptionRequest) (string, error) {
c.subscriptions.add(req)
err := c.asynchronous.Send(ctx, req)
if err != nil {
// propagate send error
return "", err
}
return req.SubID, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Subscribe",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"SubscriptionRequest",
")",
"(",
"string",
",",
"error",
")",
"{",
"c",
".",
"subscriptions",
".",
"add",
"(",
"req",
")",
"\n",
"err",
":=",
"c",
".",
"asynchronous",
".",
"Send",
"(",
"ctx",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// propagate send error",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"req",
".",
"SubID",
",",
"nil",
"\n",
"}"
] | // Subscribe sends a subscription request to the Bitfinex API and tracks the subscription status by ID. | [
"Subscribe",
"sends",
"a",
"subscription",
"request",
"to",
"the",
"Bitfinex",
"API",
"and",
"tracks",
"the",
"subscription",
"status",
"by",
"ID",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/api.go#L34-L42 |
152,147 | bitfinexcom/bitfinex-api-go | v2/websocket/api.go | SubscribeTicker | func (c *Client) SubscribeTicker(ctx context.Context, symbol string) (string, error) {
req := &SubscriptionRequest{
SubID: c.nonce.GetNonce(),
Event: EventSubscribe,
Channel: ChanTicker,
Symbol: symbol,
}
return c.Subscribe(ctx, req)
} | go | func (c *Client) SubscribeTicker(ctx context.Context, symbol string) (string, error) {
req := &SubscriptionRequest{
SubID: c.nonce.GetNonce(),
Event: EventSubscribe,
Channel: ChanTicker,
Symbol: symbol,
}
return c.Subscribe(ctx, req)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SubscribeTicker",
"(",
"ctx",
"context",
".",
"Context",
",",
"symbol",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"req",
":=",
"&",
"SubscriptionRequest",
"{",
"SubID",
":",
"c",
".",
"nonce",
".",
"GetNonce",
"(",
")",
",",
"Event",
":",
"EventSubscribe",
",",
"Channel",
":",
"ChanTicker",
",",
"Symbol",
":",
"symbol",
",",
"}",
"\n",
"return",
"c",
".",
"Subscribe",
"(",
"ctx",
",",
"req",
")",
"\n",
"}"
] | // SubscribeTicker sends a subscription request for the ticker. | [
"SubscribeTicker",
"sends",
"a",
"subscription",
"request",
"for",
"the",
"ticker",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/api.go#L45-L53 |
152,148 | bitfinexcom/bitfinex-api-go | v2/websocket/api.go | SubscribeBook | func (c *Client) SubscribeBook(ctx context.Context, symbol string, precision bitfinex.BookPrecision, frequency bitfinex.BookFrequency, priceLevel int) (string, error) {
if priceLevel < 0 {
return "", fmt.Errorf("negative price levels not supported: %d", priceLevel)
}
req := &SubscriptionRequest{
SubID: c.nonce.GetNonce(),
Event: EventSubscribe,
Channel: ChanBook,
Symbol: symbol,
Precision: string(precision),
Len: fmt.Sprintf("%d", priceLevel), // needed for R0?
}
if !bitfinex.IsRawBook(string(precision)) {
req.Frequency = string(frequency)
}
return c.Subscribe(ctx, req)
} | go | func (c *Client) SubscribeBook(ctx context.Context, symbol string, precision bitfinex.BookPrecision, frequency bitfinex.BookFrequency, priceLevel int) (string, error) {
if priceLevel < 0 {
return "", fmt.Errorf("negative price levels not supported: %d", priceLevel)
}
req := &SubscriptionRequest{
SubID: c.nonce.GetNonce(),
Event: EventSubscribe,
Channel: ChanBook,
Symbol: symbol,
Precision: string(precision),
Len: fmt.Sprintf("%d", priceLevel), // needed for R0?
}
if !bitfinex.IsRawBook(string(precision)) {
req.Frequency = string(frequency)
}
return c.Subscribe(ctx, req)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SubscribeBook",
"(",
"ctx",
"context",
".",
"Context",
",",
"symbol",
"string",
",",
"precision",
"bitfinex",
".",
"BookPrecision",
",",
"frequency",
"bitfinex",
".",
"BookFrequency",
",",
"priceLevel",
"int",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"priceLevel",
"<",
"0",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"priceLevel",
")",
"\n",
"}",
"\n",
"req",
":=",
"&",
"SubscriptionRequest",
"{",
"SubID",
":",
"c",
".",
"nonce",
".",
"GetNonce",
"(",
")",
",",
"Event",
":",
"EventSubscribe",
",",
"Channel",
":",
"ChanBook",
",",
"Symbol",
":",
"symbol",
",",
"Precision",
":",
"string",
"(",
"precision",
")",
",",
"Len",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"priceLevel",
")",
",",
"// needed for R0?",
"}",
"\n",
"if",
"!",
"bitfinex",
".",
"IsRawBook",
"(",
"string",
"(",
"precision",
")",
")",
"{",
"req",
".",
"Frequency",
"=",
"string",
"(",
"frequency",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"Subscribe",
"(",
"ctx",
",",
"req",
")",
"\n",
"}"
] | // SubscribeBook sends a subscription request for market data for a given symbol, at a given frequency, with a given precision, returning no more than priceLevels price entries.
// Default values are Precision0, Frequency0, and priceLevels=25. | [
"SubscribeBook",
"sends",
"a",
"subscription",
"request",
"for",
"market",
"data",
"for",
"a",
"given",
"symbol",
"at",
"a",
"given",
"frequency",
"with",
"a",
"given",
"precision",
"returning",
"no",
"more",
"than",
"priceLevels",
"price",
"entries",
".",
"Default",
"values",
"are",
"Precision0",
"Frequency0",
"and",
"priceLevels",
"=",
"25",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/api.go#L68-L84 |
152,149 | bitfinexcom/bitfinex-api-go | v2/websocket/api.go | SubscribeCandles | func (c *Client) SubscribeCandles(ctx context.Context, symbol string, resolution bitfinex.CandleResolution) (string, error) {
req := &SubscriptionRequest{
SubID: c.nonce.GetNonce(),
Event: EventSubscribe,
Channel: ChanCandles,
Key: fmt.Sprintf("trade:%s:%s", resolution, symbol),
}
return c.Subscribe(ctx, req)
} | go | func (c *Client) SubscribeCandles(ctx context.Context, symbol string, resolution bitfinex.CandleResolution) (string, error) {
req := &SubscriptionRequest{
SubID: c.nonce.GetNonce(),
Event: EventSubscribe,
Channel: ChanCandles,
Key: fmt.Sprintf("trade:%s:%s", resolution, symbol),
}
return c.Subscribe(ctx, req)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SubscribeCandles",
"(",
"ctx",
"context",
".",
"Context",
",",
"symbol",
"string",
",",
"resolution",
"bitfinex",
".",
"CandleResolution",
")",
"(",
"string",
",",
"error",
")",
"{",
"req",
":=",
"&",
"SubscriptionRequest",
"{",
"SubID",
":",
"c",
".",
"nonce",
".",
"GetNonce",
"(",
")",
",",
"Event",
":",
"EventSubscribe",
",",
"Channel",
":",
"ChanCandles",
",",
"Key",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"resolution",
",",
"symbol",
")",
",",
"}",
"\n",
"return",
"c",
".",
"Subscribe",
"(",
"ctx",
",",
"req",
")",
"\n",
"}"
] | // SubscribeCandles sends a subscription request for OHLC candles. | [
"SubscribeCandles",
"sends",
"a",
"subscription",
"request",
"for",
"OHLC",
"candles",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/api.go#L87-L95 |
152,150 | bitfinexcom/bitfinex-api-go | v2/websocket/api.go | SubmitOrder | func (c *Client) SubmitOrder(ctx context.Context, order *bitfinex.OrderNewRequest) error {
return c.asynchronous.Send(ctx, order)
} | go | func (c *Client) SubmitOrder(ctx context.Context, order *bitfinex.OrderNewRequest) error {
return c.asynchronous.Send(ctx, order)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SubmitOrder",
"(",
"ctx",
"context",
".",
"Context",
",",
"order",
"*",
"bitfinex",
".",
"OrderNewRequest",
")",
"error",
"{",
"return",
"c",
".",
"asynchronous",
".",
"Send",
"(",
"ctx",
",",
"order",
")",
"\n",
"}"
] | // SubmitOrder sends an order request. | [
"SubmitOrder",
"sends",
"an",
"order",
"request",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/api.go#L106-L108 |
152,151 | bitfinexcom/bitfinex-api-go | v2/websocket/api.go | SubmitCancel | func (c *Client) SubmitCancel(ctx context.Context, cancel *bitfinex.OrderCancelRequest) error {
return c.asynchronous.Send(ctx, cancel)
} | go | func (c *Client) SubmitCancel(ctx context.Context, cancel *bitfinex.OrderCancelRequest) error {
return c.asynchronous.Send(ctx, cancel)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SubmitCancel",
"(",
"ctx",
"context",
".",
"Context",
",",
"cancel",
"*",
"bitfinex",
".",
"OrderCancelRequest",
")",
"error",
"{",
"return",
"c",
".",
"asynchronous",
".",
"Send",
"(",
"ctx",
",",
"cancel",
")",
"\n",
"}"
] | // SubmitCancel sends a cancel request. | [
"SubmitCancel",
"sends",
"a",
"cancel",
"request",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/api.go#L115-L117 |
152,152 | bitfinexcom/bitfinex-api-go | v2/websocket/api.go | LookupSubscription | func (c *Client) LookupSubscription(subID string) (*SubscriptionRequest, error) {
s, err := c.subscriptions.lookupBySubscriptionID(subID)
if err != nil {
return nil, err
}
return s.Request, nil
} | go | func (c *Client) LookupSubscription(subID string) (*SubscriptionRequest, error) {
s, err := c.subscriptions.lookupBySubscriptionID(subID)
if err != nil {
return nil, err
}
return s.Request, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"LookupSubscription",
"(",
"subID",
"string",
")",
"(",
"*",
"SubscriptionRequest",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"c",
".",
"subscriptions",
".",
"lookupBySubscriptionID",
"(",
"subID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"s",
".",
"Request",
",",
"nil",
"\n",
"}"
] | // LookupSubscription looks up a subscription request by ID | [
"LookupSubscription",
"looks",
"up",
"a",
"subscription",
"request",
"by",
"ID"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/api.go#L120-L126 |
152,153 | bitfinexcom/bitfinex-api-go | v2/websocket/transport.go | Send | func (w *ws) Send(ctx context.Context, msg interface{}) error {
if w.ws == nil {
return ErrWSNotConnected
}
bs, err := json.Marshal(msg)
if err != nil {
return err
}
select {
case <- ctx.Done():
return ctx.Err()
case <- w.quit: // ws closed
return fmt.Errorf("websocket connection closed")
default:
}
w.wsLock.Lock()
defer w.wsLock.Unlock()
w.log.Debug("ws->srv: %s", string(bs))
err = w.ws.WriteMessage(websocket.TextMessage, bs)
if err != nil {
return err
}
return nil
} | go | func (w *ws) Send(ctx context.Context, msg interface{}) error {
if w.ws == nil {
return ErrWSNotConnected
}
bs, err := json.Marshal(msg)
if err != nil {
return err
}
select {
case <- ctx.Done():
return ctx.Err()
case <- w.quit: // ws closed
return fmt.Errorf("websocket connection closed")
default:
}
w.wsLock.Lock()
defer w.wsLock.Unlock()
w.log.Debug("ws->srv: %s", string(bs))
err = w.ws.WriteMessage(websocket.TextMessage, bs)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"w",
"*",
"ws",
")",
"Send",
"(",
"ctx",
"context",
".",
"Context",
",",
"msg",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"w",
".",
"ws",
"==",
"nil",
"{",
"return",
"ErrWSNotConnected",
"\n",
"}",
"\n\n",
"bs",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"msg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"ctx",
".",
"Err",
"(",
")",
"\n",
"case",
"<-",
"w",
".",
"quit",
":",
"// ws closed",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"}",
"\n\n",
"w",
".",
"wsLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"w",
".",
"wsLock",
".",
"Unlock",
"(",
")",
"\n",
"w",
".",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"string",
"(",
"bs",
")",
")",
"\n",
"err",
"=",
"w",
".",
"ws",
".",
"WriteMessage",
"(",
"websocket",
".",
"TextMessage",
",",
"bs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Send marshals the given interface and then sends it to the API. This method
// can block so specify a context with timeout if you don't want to wait for too
// long. | [
"Send",
"marshals",
"the",
"given",
"interface",
"and",
"then",
"sends",
"it",
"to",
"the",
"API",
".",
"This",
"method",
"can",
"block",
"so",
"specify",
"a",
"context",
"with",
"timeout",
"if",
"you",
"don",
"t",
"want",
"to",
"wait",
"for",
"too",
"long",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/transport.go#L69-L95 |
152,154 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | Create | func (w *WebsocketAsynchronousFactory) Create() Asynchronous {
return newWs(w.parameters.URL, w.parameters.LogTransport, w.parameters.Logger)
} | go | func (w *WebsocketAsynchronousFactory) Create() Asynchronous {
return newWs(w.parameters.URL, w.parameters.LogTransport, w.parameters.Logger)
} | [
"func",
"(",
"w",
"*",
"WebsocketAsynchronousFactory",
")",
"Create",
"(",
")",
"Asynchronous",
"{",
"return",
"newWs",
"(",
"w",
".",
"parameters",
".",
"URL",
",",
"w",
".",
"parameters",
".",
"LogTransport",
",",
"w",
".",
"parameters",
".",
"Logger",
")",
"\n",
"}"
] | // Create returns a new websocket transport. | [
"Create",
"returns",
"a",
"new",
"websocket",
"transport",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L89-L91 |
152,155 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | Credentials | func (c *Client) Credentials(key string, secret string) *Client {
c.apiKey = key
c.apiSecret = secret
return c
} | go | func (c *Client) Credentials(key string, secret string) *Client {
c.apiKey = key
c.apiSecret = secret
return c
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Credentials",
"(",
"key",
"string",
",",
"secret",
"string",
")",
"*",
"Client",
"{",
"c",
".",
"apiKey",
"=",
"key",
"\n",
"c",
".",
"apiSecret",
"=",
"secret",
"\n",
"return",
"c",
"\n",
"}"
] | // Credentials assigns authentication credentials to a connection request. | [
"Credentials",
"assigns",
"authentication",
"credentials",
"to",
"a",
"connection",
"request",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L132-L136 |
152,156 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | CancelOnDisconnect | func (c *Client) CancelOnDisconnect(cxl bool) *Client {
c.cancelOnDisconnect = cxl
return c
} | go | func (c *Client) CancelOnDisconnect(cxl bool) *Client {
c.cancelOnDisconnect = cxl
return c
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"CancelOnDisconnect",
"(",
"cxl",
"bool",
")",
"*",
"Client",
"{",
"c",
".",
"cancelOnDisconnect",
"=",
"cxl",
"\n",
"return",
"c",
"\n",
"}"
] | // CancelOnDisconnect ensures all orders will be canceled if this API session is disconnected. | [
"CancelOnDisconnect",
"ensures",
"all",
"orders",
"will",
"be",
"canceled",
"if",
"this",
"API",
"session",
"is",
"disconnected",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L139-L142 |
152,157 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | NewWithAsyncFactoryNonce | func NewWithAsyncFactoryNonce(async AsynchronousFactory, nonce utils.NonceGenerator) *Client {
return NewWithParamsAsyncFactoryNonce(NewDefaultParameters(), async, nonce)
} | go | func NewWithAsyncFactoryNonce(async AsynchronousFactory, nonce utils.NonceGenerator) *Client {
return NewWithParamsAsyncFactoryNonce(NewDefaultParameters(), async, nonce)
} | [
"func",
"NewWithAsyncFactoryNonce",
"(",
"async",
"AsynchronousFactory",
",",
"nonce",
"utils",
".",
"NonceGenerator",
")",
"*",
"Client",
"{",
"return",
"NewWithParamsAsyncFactoryNonce",
"(",
"NewDefaultParameters",
"(",
")",
",",
"async",
",",
"nonce",
")",
"\n",
"}"
] | // NewWithAsyncFactoryNonce creates a new default client with a given asynchronous transport factory and nonce generator. | [
"NewWithAsyncFactoryNonce",
"creates",
"a",
"new",
"default",
"client",
"with",
"a",
"given",
"asynchronous",
"transport",
"factory",
"and",
"nonce",
"generator",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L173-L175 |
152,158 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | NewWithParamsNonce | func NewWithParamsNonce(params *Parameters, nonce utils.NonceGenerator) *Client {
return NewWithParamsAsyncFactoryNonce(params, NewWebsocketAsynchronousFactory(params), nonce)
} | go | func NewWithParamsNonce(params *Parameters, nonce utils.NonceGenerator) *Client {
return NewWithParamsAsyncFactoryNonce(params, NewWebsocketAsynchronousFactory(params), nonce)
} | [
"func",
"NewWithParamsNonce",
"(",
"params",
"*",
"Parameters",
",",
"nonce",
"utils",
".",
"NonceGenerator",
")",
"*",
"Client",
"{",
"return",
"NewWithParamsAsyncFactoryNonce",
"(",
"params",
",",
"NewWebsocketAsynchronousFactory",
"(",
"params",
")",
",",
"nonce",
")",
"\n",
"}"
] | // NewWithParamsNonce creates a new default client with a given set of parameters and nonce generator. | [
"NewWithParamsNonce",
"creates",
"a",
"new",
"default",
"client",
"with",
"a",
"given",
"set",
"of",
"parameters",
"and",
"nonce",
"generator",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L178-L180 |
152,159 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | NewWithParamsAsyncFactory | func NewWithParamsAsyncFactory(params *Parameters, async AsynchronousFactory) *Client {
return NewWithParamsAsyncFactoryNonce(params, async, utils.NewEpochNonceGenerator())
} | go | func NewWithParamsAsyncFactory(params *Parameters, async AsynchronousFactory) *Client {
return NewWithParamsAsyncFactoryNonce(params, async, utils.NewEpochNonceGenerator())
} | [
"func",
"NewWithParamsAsyncFactory",
"(",
"params",
"*",
"Parameters",
",",
"async",
"AsynchronousFactory",
")",
"*",
"Client",
"{",
"return",
"NewWithParamsAsyncFactoryNonce",
"(",
"params",
",",
"async",
",",
"utils",
".",
"NewEpochNonceGenerator",
"(",
")",
")",
"\n",
"}"
] | // NewWithParamsAsyncFactory creates a new default client with a given set of parameters and asynchronous transport factory interface. | [
"NewWithParamsAsyncFactory",
"creates",
"a",
"new",
"default",
"client",
"with",
"a",
"given",
"set",
"of",
"parameters",
"and",
"asynchronous",
"transport",
"factory",
"interface",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L183-L185 |
152,160 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | NewWithParamsAsyncFactoryNonce | func NewWithParamsAsyncFactoryNonce(params *Parameters, async AsynchronousFactory, nonce utils.NonceGenerator) *Client {
c := &Client{
asyncFactory: async,
Authentication: NoAuthentication,
factories: make(map[string]messageFactory),
subscriptions: newSubscriptions(params.HeartbeatTimeout, params.Logger),
orderbooks: make(map[string]*Orderbook),
nonce: nonce,
isConnected: false,
parameters: params,
listener: make(chan interface{}),
terminal: false,
resetWebsocket: make(chan bool),
shutdown: make(chan bool),
asynchronous: async.Create(),
log: params.Logger,
}
c.registerPublicFactories()
return c
} | go | func NewWithParamsAsyncFactoryNonce(params *Parameters, async AsynchronousFactory, nonce utils.NonceGenerator) *Client {
c := &Client{
asyncFactory: async,
Authentication: NoAuthentication,
factories: make(map[string]messageFactory),
subscriptions: newSubscriptions(params.HeartbeatTimeout, params.Logger),
orderbooks: make(map[string]*Orderbook),
nonce: nonce,
isConnected: false,
parameters: params,
listener: make(chan interface{}),
terminal: false,
resetWebsocket: make(chan bool),
shutdown: make(chan bool),
asynchronous: async.Create(),
log: params.Logger,
}
c.registerPublicFactories()
return c
} | [
"func",
"NewWithParamsAsyncFactoryNonce",
"(",
"params",
"*",
"Parameters",
",",
"async",
"AsynchronousFactory",
",",
"nonce",
"utils",
".",
"NonceGenerator",
")",
"*",
"Client",
"{",
"c",
":=",
"&",
"Client",
"{",
"asyncFactory",
":",
"async",
",",
"Authentication",
":",
"NoAuthentication",
",",
"factories",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"messageFactory",
")",
",",
"subscriptions",
":",
"newSubscriptions",
"(",
"params",
".",
"HeartbeatTimeout",
",",
"params",
".",
"Logger",
")",
",",
"orderbooks",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Orderbook",
")",
",",
"nonce",
":",
"nonce",
",",
"isConnected",
":",
"false",
",",
"parameters",
":",
"params",
",",
"listener",
":",
"make",
"(",
"chan",
"interface",
"{",
"}",
")",
",",
"terminal",
":",
"false",
",",
"resetWebsocket",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"shutdown",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"asynchronous",
":",
"async",
".",
"Create",
"(",
")",
",",
"log",
":",
"params",
".",
"Logger",
",",
"}",
"\n",
"c",
".",
"registerPublicFactories",
"(",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // NewWithParamsAsyncFactoryNonce creates a new client with a given set of parameters, asynchronous transport factory, and nonce generator interfaces. | [
"NewWithParamsAsyncFactoryNonce",
"creates",
"a",
"new",
"client",
"with",
"a",
"given",
"set",
"of",
"parameters",
"asynchronous",
"transport",
"factory",
"and",
"nonce",
"generator",
"interfaces",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L188-L207 |
152,161 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | Connect | func (c *Client) Connect() error {
c.dumpParams()
c.terminal = false
// wait for reset websocket signals
go c.listenDisconnect()
c.reset()
return c.connect()
} | go | func (c *Client) Connect() error {
c.dumpParams()
c.terminal = false
// wait for reset websocket signals
go c.listenDisconnect()
c.reset()
return c.connect()
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Connect",
"(",
")",
"error",
"{",
"c",
".",
"dumpParams",
"(",
")",
"\n",
"c",
".",
"terminal",
"=",
"false",
"\n",
"// wait for reset websocket signals",
"go",
"c",
".",
"listenDisconnect",
"(",
")",
"\n",
"c",
".",
"reset",
"(",
")",
"\n",
"return",
"c",
".",
"connect",
"(",
")",
"\n",
"}"
] | // Connect to the Bitfinex API, this should only be called once. | [
"Connect",
"to",
"the",
"Bitfinex",
"API",
"this",
"should",
"only",
"be",
"called",
"once",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L287-L294 |
152,162 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | reset | func (c *Client) reset() {
subs := c.subscriptions.Reset()
if subs != nil {
c.resetSubscriptions = subs
}
c.init = true
ws := c.asyncFactory.Create()
c.asynchronous = ws
// listen to data from async
go c.listenUpstream(ws)
} | go | func (c *Client) reset() {
subs := c.subscriptions.Reset()
if subs != nil {
c.resetSubscriptions = subs
}
c.init = true
ws := c.asyncFactory.Create()
c.asynchronous = ws
// listen to data from async
go c.listenUpstream(ws)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"reset",
"(",
")",
"{",
"subs",
":=",
"c",
".",
"subscriptions",
".",
"Reset",
"(",
")",
"\n",
"if",
"subs",
"!=",
"nil",
"{",
"c",
".",
"resetSubscriptions",
"=",
"subs",
"\n",
"}",
"\n",
"c",
".",
"init",
"=",
"true",
"\n",
"ws",
":=",
"c",
".",
"asyncFactory",
".",
"Create",
"(",
")",
"\n",
"c",
".",
"asynchronous",
"=",
"ws",
"\n\n",
"// listen to data from async",
"go",
"c",
".",
"listenUpstream",
"(",
"ws",
")",
"\n",
"}"
] | // reset assumes transport has already died or been closed | [
"reset",
"assumes",
"transport",
"has",
"already",
"died",
"or",
"been",
"closed"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L297-L308 |
152,163 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | listenUpstream | func (c *Client) listenUpstream(ws Asynchronous) {
for {
select {
case <- ws.Done(): // transport shutdown
c.resetWebsocket <- true
return
case msg := <- ws.Listen():
if msg != nil {
// Errors here should be non critical so we just log them.
// log.Printf("[DEBUG]: %s\n", msg)
err := c.handleMessage(msg)
if err != nil {
c.log.Warning(err)
}
}
}
}
} | go | func (c *Client) listenUpstream(ws Asynchronous) {
for {
select {
case <- ws.Done(): // transport shutdown
c.resetWebsocket <- true
return
case msg := <- ws.Listen():
if msg != nil {
// Errors here should be non critical so we just log them.
// log.Printf("[DEBUG]: %s\n", msg)
err := c.handleMessage(msg)
if err != nil {
c.log.Warning(err)
}
}
}
}
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"listenUpstream",
"(",
"ws",
"Asynchronous",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"ws",
".",
"Done",
"(",
")",
":",
"// transport shutdown",
"c",
".",
"resetWebsocket",
"<-",
"true",
"\n",
"return",
"\n",
"case",
"msg",
":=",
"<-",
"ws",
".",
"Listen",
"(",
")",
":",
"if",
"msg",
"!=",
"nil",
"{",
"// Errors here should be non critical so we just log them.",
"// log.Printf(\"[DEBUG]: %s\\n\", msg)",
"err",
":=",
"c",
".",
"handleMessage",
"(",
"msg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"log",
".",
"Warning",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // start this goroutine before connecting, but this should die during a connection failure | [
"start",
"this",
"goroutine",
"before",
"connecting",
"but",
"this",
"should",
"die",
"during",
"a",
"connection",
"failure"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L359-L376 |
152,164 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | killListener | func (c *Client) killListener(e error) {
if c.listener != nil {
if e != nil {
c.listener <- e
}
close(c.listener)
}
} | go | func (c *Client) killListener(e error) {
if c.listener != nil {
if e != nil {
c.listener <- e
}
close(c.listener)
}
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"killListener",
"(",
"e",
"error",
")",
"{",
"if",
"c",
".",
"listener",
"!=",
"nil",
"{",
"if",
"e",
"!=",
"nil",
"{",
"c",
".",
"listener",
"<-",
"e",
"\n",
"}",
"\n",
"close",
"(",
"c",
".",
"listener",
")",
"\n",
"}",
"\n",
"}"
] | // terminal, unrecoverable state. called after async is closed. | [
"terminal",
"unrecoverable",
"state",
".",
"called",
"after",
"async",
"is",
"closed",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L379-L386 |
152,165 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | handleOpen | func (c *Client) handleOpen() error {
if c.hasCredentials() {
err_auth := c.authenticate(context.Background())
if err_auth != nil {
return err_auth
}
} else {
c.checkResubscription()
}
return nil
} | go | func (c *Client) handleOpen() error {
if c.hasCredentials() {
err_auth := c.authenticate(context.Background())
if err_auth != nil {
return err_auth
}
} else {
c.checkResubscription()
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"handleOpen",
"(",
")",
"error",
"{",
"if",
"c",
".",
"hasCredentials",
"(",
")",
"{",
"err_auth",
":=",
"c",
".",
"authenticate",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"if",
"err_auth",
"!=",
"nil",
"{",
"return",
"err_auth",
"\n",
"}",
"\n",
"}",
"else",
"{",
"c",
".",
"checkResubscription",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // called when an info event is received | [
"called",
"when",
"an",
"info",
"event",
"is",
"received"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L478-L488 |
152,166 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | handleAuthAck | func (c *Client) handleAuthAck(auth *AuthEvent) {
if c.Authentication == SuccessfulAuthentication {
err := c.subscriptions.activate(auth.SubID, auth.ChanID)
if err != nil {
c.log.Errorf("could not activate auth subscription: %s", err.Error())
}
c.checkResubscription()
} else {
c.log.Error("authentication failed")
}
} | go | func (c *Client) handleAuthAck(auth *AuthEvent) {
if c.Authentication == SuccessfulAuthentication {
err := c.subscriptions.activate(auth.SubID, auth.ChanID)
if err != nil {
c.log.Errorf("could not activate auth subscription: %s", err.Error())
}
c.checkResubscription()
} else {
c.log.Error("authentication failed")
}
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"handleAuthAck",
"(",
"auth",
"*",
"AuthEvent",
")",
"{",
"if",
"c",
".",
"Authentication",
"==",
"SuccessfulAuthentication",
"{",
"err",
":=",
"c",
".",
"subscriptions",
".",
"activate",
"(",
"auth",
".",
"SubID",
",",
"auth",
".",
"ChanID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"c",
".",
"checkResubscription",
"(",
")",
"\n",
"}",
"else",
"{",
"c",
".",
"log",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // called when an auth event is received | [
"called",
"when",
"an",
"auth",
"event",
"is",
"received"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L491-L501 |
152,167 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | Unsubscribe | func (c *Client) Unsubscribe(ctx context.Context, id string) error {
sub, err := c.subscriptions.lookupBySubscriptionID(id)
if err != nil {
return err
}
// sub is removed from manager on ack from API
return c.sendUnsubscribeMessage(ctx, sub.ChanID)
} | go | func (c *Client) Unsubscribe(ctx context.Context, id string) error {
sub, err := c.subscriptions.lookupBySubscriptionID(id)
if err != nil {
return err
}
// sub is removed from manager on ack from API
return c.sendUnsubscribeMessage(ctx, sub.ChanID)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Unsubscribe",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"error",
"{",
"sub",
",",
"err",
":=",
"c",
".",
"subscriptions",
".",
"lookupBySubscriptionID",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// sub is removed from manager on ack from API",
"return",
"c",
".",
"sendUnsubscribeMessage",
"(",
"ctx",
",",
"sub",
".",
"ChanID",
")",
"\n",
"}"
] | // Unsubscribe looks up an existing subscription by ID and sends an unsubscribe request. | [
"Unsubscribe",
"looks",
"up",
"an",
"existing",
"subscription",
"by",
"ID",
"and",
"sends",
"an",
"unsubscribe",
"request",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L508-L515 |
152,168 | bitfinexcom/bitfinex-api-go | v2/websocket/client.go | authenticate | func (c *Client) authenticate(ctx context.Context, filter ...string) error {
nonce := c.nonce.GetNonce()
payload := "AUTH" + nonce
sig, err := c.sign(payload)
if err != nil {
return err
}
s := &SubscriptionRequest{
Event: "auth",
APIKey: c.apiKey,
AuthSig: sig,
AuthPayload: payload,
AuthNonce: nonce,
Filter: filter,
SubID: nonce,
}
if c.cancelOnDisconnect {
s.DMS = DMSCancelOnDisconnect
}
c.subscriptions.add(s)
if err := c.asynchronous.Send(ctx, s); err != nil {
return err
}
c.Authentication = PendingAuthentication
return nil
} | go | func (c *Client) authenticate(ctx context.Context, filter ...string) error {
nonce := c.nonce.GetNonce()
payload := "AUTH" + nonce
sig, err := c.sign(payload)
if err != nil {
return err
}
s := &SubscriptionRequest{
Event: "auth",
APIKey: c.apiKey,
AuthSig: sig,
AuthPayload: payload,
AuthNonce: nonce,
Filter: filter,
SubID: nonce,
}
if c.cancelOnDisconnect {
s.DMS = DMSCancelOnDisconnect
}
c.subscriptions.add(s)
if err := c.asynchronous.Send(ctx, s); err != nil {
return err
}
c.Authentication = PendingAuthentication
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"authenticate",
"(",
"ctx",
"context",
".",
"Context",
",",
"filter",
"...",
"string",
")",
"error",
"{",
"nonce",
":=",
"c",
".",
"nonce",
".",
"GetNonce",
"(",
")",
"\n",
"payload",
":=",
"\"",
"\"",
"+",
"nonce",
"\n",
"sig",
",",
"err",
":=",
"c",
".",
"sign",
"(",
"payload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
":=",
"&",
"SubscriptionRequest",
"{",
"Event",
":",
"\"",
"\"",
",",
"APIKey",
":",
"c",
".",
"apiKey",
",",
"AuthSig",
":",
"sig",
",",
"AuthPayload",
":",
"payload",
",",
"AuthNonce",
":",
"nonce",
",",
"Filter",
":",
"filter",
",",
"SubID",
":",
"nonce",
",",
"}",
"\n",
"if",
"c",
".",
"cancelOnDisconnect",
"{",
"s",
".",
"DMS",
"=",
"DMSCancelOnDisconnect",
"\n",
"}",
"\n",
"c",
".",
"subscriptions",
".",
"add",
"(",
"s",
")",
"\n\n",
"if",
"err",
":=",
"c",
".",
"asynchronous",
".",
"Send",
"(",
"ctx",
",",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"Authentication",
"=",
"PendingAuthentication",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Authenticate creates the payload for the authentication request and sends it
// to the API. The filters will be applied to the authenticated channel, i.e.
// only subscribe to the filtered messages. | [
"Authenticate",
"creates",
"the",
"payload",
"for",
"the",
"authentication",
"request",
"and",
"sends",
"it",
"to",
"the",
"API",
".",
"The",
"filters",
"will",
"be",
"applied",
"to",
"the",
"authenticated",
"channel",
"i",
".",
"e",
".",
"only",
"subscribe",
"to",
"the",
"filtered",
"messages",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/client.go#L520-L547 |
152,169 | bitfinexcom/bitfinex-api-go | v1/websocket.go | NewWebSocketService | func NewWebSocketService(c *Client) *WebSocketService {
return &WebSocketService{
client: c,
chanMap: make(map[float64]chan []float64),
subscribes: make([]subscribeToChannel, 0),
}
} | go | func NewWebSocketService(c *Client) *WebSocketService {
return &WebSocketService{
client: c,
chanMap: make(map[float64]chan []float64),
subscribes: make([]subscribeToChannel, 0),
}
} | [
"func",
"NewWebSocketService",
"(",
"c",
"*",
"Client",
")",
"*",
"WebSocketService",
"{",
"return",
"&",
"WebSocketService",
"{",
"client",
":",
"c",
",",
"chanMap",
":",
"make",
"(",
"map",
"[",
"float64",
"]",
"chan",
"[",
"]",
"float64",
")",
",",
"subscribes",
":",
"make",
"(",
"[",
"]",
"subscribeToChannel",
",",
"0",
")",
",",
"}",
"\n",
"}"
] | // NewWebSocketService returns a WebSocketService using the given client. | [
"NewWebSocketService",
"returns",
"a",
"WebSocketService",
"using",
"the",
"given",
"client",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/websocket.go#L82-L88 |
152,170 | bitfinexcom/bitfinex-api-go | v1/websocket.go | Connect | func (w *WebSocketService) Connect() error {
var d = websocket.Dialer{
Subprotocols: []string{"p1", "p2"},
ReadBufferSize: 1024,
WriteBufferSize: 1024,
Proxy: http.ProxyFromEnvironment,
}
if w.client.WebSocketTLSSkipVerify {
d.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
ws, _, err := d.Dial(w.client.WebSocketURL, nil)
if err != nil {
return err
}
w.ws = ws
return nil
} | go | func (w *WebSocketService) Connect() error {
var d = websocket.Dialer{
Subprotocols: []string{"p1", "p2"},
ReadBufferSize: 1024,
WriteBufferSize: 1024,
Proxy: http.ProxyFromEnvironment,
}
if w.client.WebSocketTLSSkipVerify {
d.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
ws, _, err := d.Dial(w.client.WebSocketURL, nil)
if err != nil {
return err
}
w.ws = ws
return nil
} | [
"func",
"(",
"w",
"*",
"WebSocketService",
")",
"Connect",
"(",
")",
"error",
"{",
"var",
"d",
"=",
"websocket",
".",
"Dialer",
"{",
"Subprotocols",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"ReadBufferSize",
":",
"1024",
",",
"WriteBufferSize",
":",
"1024",
",",
"Proxy",
":",
"http",
".",
"ProxyFromEnvironment",
",",
"}",
"\n\n",
"if",
"w",
".",
"client",
".",
"WebSocketTLSSkipVerify",
"{",
"d",
".",
"TLSClientConfig",
"=",
"&",
"tls",
".",
"Config",
"{",
"InsecureSkipVerify",
":",
"true",
"}",
"\n",
"}",
"\n\n",
"ws",
",",
"_",
",",
"err",
":=",
"d",
".",
"Dial",
"(",
"w",
".",
"client",
".",
"WebSocketURL",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"w",
".",
"ws",
"=",
"ws",
"\n",
"return",
"nil",
"\n",
"}"
] | // Connect create new bitfinex websocket connection | [
"Connect",
"create",
"new",
"bitfinex",
"websocket",
"connection"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/websocket.go#L91-L109 |
152,171 | bitfinexcom/bitfinex-api-go | v1/client.go | newRequest | func (c *Client) newRequest(method string, refURL string, params url.Values) (*http.Request, error) {
rel, err := url.Parse(refURL)
if err != nil {
return nil, err
}
if params != nil {
rel.RawQuery = params.Encode()
}
var req *http.Request
u := c.BaseURL.ResolveReference(rel)
req, err = http.NewRequest(method, u.String(), nil)
if err != nil {
return nil, err
}
return req, nil
} | go | func (c *Client) newRequest(method string, refURL string, params url.Values) (*http.Request, error) {
rel, err := url.Parse(refURL)
if err != nil {
return nil, err
}
if params != nil {
rel.RawQuery = params.Encode()
}
var req *http.Request
u := c.BaseURL.ResolveReference(rel)
req, err = http.NewRequest(method, u.String(), nil)
if err != nil {
return nil, err
}
return req, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"newRequest",
"(",
"method",
"string",
",",
"refURL",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"rel",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"refURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"params",
"!=",
"nil",
"{",
"rel",
".",
"RawQuery",
"=",
"params",
".",
"Encode",
"(",
")",
"\n",
"}",
"\n",
"var",
"req",
"*",
"http",
".",
"Request",
"\n",
"u",
":=",
"c",
".",
"BaseURL",
".",
"ResolveReference",
"(",
"rel",
")",
"\n",
"req",
",",
"err",
"=",
"http",
".",
"NewRequest",
"(",
"method",
",",
"u",
".",
"String",
"(",
")",
",",
"nil",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"req",
",",
"nil",
"\n",
"}"
] | // NewRequest create new API request. Relative url can be provided in refURL. | [
"NewRequest",
"create",
"new",
"API",
"request",
".",
"Relative",
"url",
"can",
"be",
"provided",
"in",
"refURL",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/client.go#L86-L103 |
152,172 | bitfinexcom/bitfinex-api-go | v1/client.go | newAuthenticatedRequest | func (c *Client) newAuthenticatedRequest(m string, refURL string, data map[string]interface{}) (*http.Request, error) {
req, err := c.newRequest(m, refURL, nil)
if err != nil {
return nil, err
}
nonce := utils.GetNonce()
payload := map[string]interface{}{
"request": "/v1/" + refURL,
"nonce": nonce,
}
for k, v := range data {
payload[k] = v
}
p, err := json.Marshal(payload)
if err != nil {
return nil, err
}
encoded := base64.StdEncoding.EncodeToString(p)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
req.Header.Add("X-BFX-APIKEY", c.APIKey)
req.Header.Add("X-BFX-PAYLOAD", encoded)
sig, err := c.signPayload(encoded)
if err != nil {
return nil, err
}
req.Header.Add("X-BFX-SIGNATURE", sig)
return req, nil
} | go | func (c *Client) newAuthenticatedRequest(m string, refURL string, data map[string]interface{}) (*http.Request, error) {
req, err := c.newRequest(m, refURL, nil)
if err != nil {
return nil, err
}
nonce := utils.GetNonce()
payload := map[string]interface{}{
"request": "/v1/" + refURL,
"nonce": nonce,
}
for k, v := range data {
payload[k] = v
}
p, err := json.Marshal(payload)
if err != nil {
return nil, err
}
encoded := base64.StdEncoding.EncodeToString(p)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
req.Header.Add("X-BFX-APIKEY", c.APIKey)
req.Header.Add("X-BFX-PAYLOAD", encoded)
sig, err := c.signPayload(encoded)
if err != nil {
return nil, err
}
req.Header.Add("X-BFX-SIGNATURE", sig)
return req, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"newAuthenticatedRequest",
"(",
"m",
"string",
",",
"refURL",
"string",
",",
"data",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"newRequest",
"(",
"m",
",",
"refURL",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"nonce",
":=",
"utils",
".",
"GetNonce",
"(",
")",
"\n",
"payload",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"\"",
"\"",
"+",
"refURL",
",",
"\"",
"\"",
":",
"nonce",
",",
"}",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"data",
"{",
"payload",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"p",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"payload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"encoded",
":=",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"p",
")",
"\n\n",
"req",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"c",
".",
"APIKey",
")",
"\n",
"req",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"encoded",
")",
"\n",
"sig",
",",
"err",
":=",
"c",
".",
"signPayload",
"(",
"encoded",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"sig",
")",
"\n\n",
"return",
"req",
",",
"nil",
"\n",
"}"
] | // newAuthenticatedRequest creates new http request for authenticated routes. | [
"newAuthenticatedRequest",
"creates",
"new",
"http",
"request",
"for",
"authenticated",
"routes",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/client.go#L106-L140 |
152,173 | bitfinexcom/bitfinex-api-go | v1/client.go | Auth | func (c *Client) Auth(key string, secret string) *Client {
c.APIKey = key
c.APISecret = secret
return c
} | go | func (c *Client) Auth(key string, secret string) *Client {
c.APIKey = key
c.APISecret = secret
return c
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Auth",
"(",
"key",
"string",
",",
"secret",
"string",
")",
"*",
"Client",
"{",
"c",
".",
"APIKey",
"=",
"key",
"\n",
"c",
".",
"APISecret",
"=",
"secret",
"\n\n",
"return",
"c",
"\n",
"}"
] | // Auth sets api key and secret for usage is requests that requires authentication. | [
"Auth",
"sets",
"api",
"key",
"and",
"secret",
"for",
"usage",
"is",
"requests",
"that",
"requires",
"authentication",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/client.go#L152-L157 |
152,174 | bitfinexcom/bitfinex-api-go | v1/client.go | newResponse | func newResponse(r *http.Response) *Response {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
body = []byte(`Error reading body:` + err.Error())
}
return &Response{r, body}
} | go | func newResponse(r *http.Response) *Response {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
body = []byte(`Error reading body:` + err.Error())
}
return &Response{r, body}
} | [
"func",
"newResponse",
"(",
"r",
"*",
"http",
".",
"Response",
")",
"*",
"Response",
"{",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"body",
"=",
"[",
"]",
"byte",
"(",
"`Error reading body:`",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"Response",
"{",
"r",
",",
"body",
"}",
"\n",
"}"
] | // newResponse creates new wrapper. | [
"newResponse",
"creates",
"new",
"wrapper",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/client.go#L198-L205 |
152,175 | bitfinexcom/bitfinex-api-go | v2/rest/client.go | NewClientWithSynchronousURLNonce | func NewClientWithSynchronousURLNonce(sync Synchronous, url string, nonce utils.NonceGenerator) *Client {
c := &Client{
Synchronous: sync,
nonce: nonce,
}
c.Orders = OrderService{Synchronous: c, requestFactory: c}
c.Book = BookService{Synchronous: c}
c.Candles = CandleService{Synchronous: c}
c.Trades = TradeService{Synchronous: c, requestFactory: c}
c.Tickers = TickerService{Synchronous: c, requestFactory: c}
c.Platform = PlatformService{Synchronous: c}
c.Positions = PositionService{Synchronous: c, requestFactory: c}
c.Wallet = WalletService{Synchronous: c, requestFactory: c}
c.Ledgers = LedgerService{Synchronous: c, requestFactory: c}
return c
} | go | func NewClientWithSynchronousURLNonce(sync Synchronous, url string, nonce utils.NonceGenerator) *Client {
c := &Client{
Synchronous: sync,
nonce: nonce,
}
c.Orders = OrderService{Synchronous: c, requestFactory: c}
c.Book = BookService{Synchronous: c}
c.Candles = CandleService{Synchronous: c}
c.Trades = TradeService{Synchronous: c, requestFactory: c}
c.Tickers = TickerService{Synchronous: c, requestFactory: c}
c.Platform = PlatformService{Synchronous: c}
c.Positions = PositionService{Synchronous: c, requestFactory: c}
c.Wallet = WalletService{Synchronous: c, requestFactory: c}
c.Ledgers = LedgerService{Synchronous: c, requestFactory: c}
return c
} | [
"func",
"NewClientWithSynchronousURLNonce",
"(",
"sync",
"Synchronous",
",",
"url",
"string",
",",
"nonce",
"utils",
".",
"NonceGenerator",
")",
"*",
"Client",
"{",
"c",
":=",
"&",
"Client",
"{",
"Synchronous",
":",
"sync",
",",
"nonce",
":",
"nonce",
",",
"}",
"\n",
"c",
".",
"Orders",
"=",
"OrderService",
"{",
"Synchronous",
":",
"c",
",",
"requestFactory",
":",
"c",
"}",
"\n",
"c",
".",
"Book",
"=",
"BookService",
"{",
"Synchronous",
":",
"c",
"}",
"\n",
"c",
".",
"Candles",
"=",
"CandleService",
"{",
"Synchronous",
":",
"c",
"}",
"\n",
"c",
".",
"Trades",
"=",
"TradeService",
"{",
"Synchronous",
":",
"c",
",",
"requestFactory",
":",
"c",
"}",
"\n",
"c",
".",
"Tickers",
"=",
"TickerService",
"{",
"Synchronous",
":",
"c",
",",
"requestFactory",
":",
"c",
"}",
"\n",
"c",
".",
"Platform",
"=",
"PlatformService",
"{",
"Synchronous",
":",
"c",
"}",
"\n",
"c",
".",
"Positions",
"=",
"PositionService",
"{",
"Synchronous",
":",
"c",
",",
"requestFactory",
":",
"c",
"}",
"\n",
"c",
".",
"Wallet",
"=",
"WalletService",
"{",
"Synchronous",
":",
"c",
",",
"requestFactory",
":",
"c",
"}",
"\n",
"c",
".",
"Ledgers",
"=",
"LedgerService",
"{",
"Synchronous",
":",
"c",
",",
"requestFactory",
":",
"c",
"}",
"\n",
"return",
"c",
"\n",
"}"
] | // mock me in tests | [
"mock",
"me",
"in",
"tests"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/rest/client.go#L88-L103 |
152,176 | bitfinexcom/bitfinex-api-go | v2/websocket/subscriptions.go | Reset | func (s *subscriptions) Reset() []*subscription {
subs := s.reset()
s.lock.Lock()
s.hbActive = false
s.subsBySubID = make(map[string]*subscription)
s.subsByChanID = make(map[int64]*subscription)
s.lock.Unlock()
return subs
} | go | func (s *subscriptions) Reset() []*subscription {
subs := s.reset()
s.lock.Lock()
s.hbActive = false
s.subsBySubID = make(map[string]*subscription)
s.subsByChanID = make(map[int64]*subscription)
s.lock.Unlock()
return subs
} | [
"func",
"(",
"s",
"*",
"subscriptions",
")",
"Reset",
"(",
")",
"[",
"]",
"*",
"subscription",
"{",
"subs",
":=",
"s",
".",
"reset",
"(",
")",
"\n",
"s",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"hbActive",
"=",
"false",
"\n",
"s",
".",
"subsBySubID",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"subscription",
")",
"\n",
"s",
".",
"subsByChanID",
"=",
"make",
"(",
"map",
"[",
"int64",
"]",
"*",
"subscription",
")",
"\n",
"s",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"subs",
"\n",
"}"
] | // Reset clears all subscriptions from the currently managed list, and returns
// a slice of the existing subscriptions prior to reset. Returns nil if no subscriptions exist. | [
"Reset",
"clears",
"all",
"subscriptions",
"from",
"the",
"currently",
"managed",
"list",
"and",
"returns",
"a",
"slice",
"of",
"the",
"existing",
"subscriptions",
"prior",
"to",
"reset",
".",
"Returns",
"nil",
"if",
"no",
"subscriptions",
"exist",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/subscriptions.go#L200-L208 |
152,177 | bitfinexcom/bitfinex-api-go | v2/types.go | MarshalJSON | func (o *OrderCancelRequest) MarshalJSON() ([]byte, error) {
aux := struct {
ID int64 `json:"id,omitempty"`
CID int64 `json:"cid,omitempty"`
CIDDate string `json:"cid_date,omitempty"`
}{
ID: o.ID,
CID: o.CID,
CIDDate: o.CIDDate,
}
body := []interface{}{0, "oc", nil, aux}
return json.Marshal(&body)
} | go | func (o *OrderCancelRequest) MarshalJSON() ([]byte, error) {
aux := struct {
ID int64 `json:"id,omitempty"`
CID int64 `json:"cid,omitempty"`
CIDDate string `json:"cid_date,omitempty"`
}{
ID: o.ID,
CID: o.CID,
CIDDate: o.CIDDate,
}
body := []interface{}{0, "oc", nil, aux}
return json.Marshal(&body)
} | [
"func",
"(",
"o",
"*",
"OrderCancelRequest",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"aux",
":=",
"struct",
"{",
"ID",
"int64",
"`json:\"id,omitempty\"`",
"\n",
"CID",
"int64",
"`json:\"cid,omitempty\"`",
"\n",
"CIDDate",
"string",
"`json:\"cid_date,omitempty\"`",
"\n",
"}",
"{",
"ID",
":",
"o",
".",
"ID",
",",
"CID",
":",
"o",
".",
"CID",
",",
"CIDDate",
":",
"o",
".",
"CIDDate",
",",
"}",
"\n\n",
"body",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"0",
",",
"\"",
"\"",
",",
"nil",
",",
"aux",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"&",
"body",
")",
"\n",
"}"
] | // MarshalJSON converts the order cancel object into the format required by the
// bitfinex websocket service. | [
"MarshalJSON",
"converts",
"the",
"order",
"cancel",
"object",
"into",
"the",
"format",
"required",
"by",
"the",
"bitfinex",
"websocket",
"service",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/types.go#L271-L284 |
152,178 | bitfinexcom/bitfinex-api-go | v2/types.go | NewOrderFromRaw | func NewOrderFromRaw(raw []interface{}) (o *Order, err error) {
if len(raw) == 12 {
o = &Order{
ID: int64(f64ValOrZero(raw[0])),
Symbol: sValOrEmpty(raw[1]),
Amount: f64ValOrZero(raw[2]),
AmountOrig: f64ValOrZero(raw[3]),
Type: sValOrEmpty(raw[4]),
Status: OrderStatus(sValOrEmpty(raw[5])),
Price: f64ValOrZero(raw[6]),
PriceAvg: f64ValOrZero(raw[7]),
MTSUpdated: i64ValOrZero(raw[8]),
// 3 trailing zeroes, what do they map to?
}
} else if len(raw) < 26 {
return o, fmt.Errorf("data slice too short for order: %#v", raw)
} else {
// TODO: API docs say ID, GID, CID, MTS_CREATE, MTS_UPDATE are int but API returns float
o = &Order{
ID: int64(f64ValOrZero(raw[0])),
GID: int64(f64ValOrZero(raw[1])),
CID: int64(f64ValOrZero(raw[2])),
Symbol: sValOrEmpty(raw[3]),
MTSCreated: int64(f64ValOrZero(raw[4])),
MTSUpdated: int64(f64ValOrZero(raw[5])),
Amount: f64ValOrZero(raw[6]),
AmountOrig: f64ValOrZero(raw[7]),
Type: sValOrEmpty(raw[8]),
TypePrev: sValOrEmpty(raw[9]),
MTSTif: int64(f64ValOrZero(raw[10])),
Flags: i64ValOrZero(raw[12]),
Status: OrderStatus(sValOrEmpty(raw[13])),
Price: f64ValOrZero(raw[16]),
PriceAvg: f64ValOrZero(raw[17]),
PriceTrailing: f64ValOrZero(raw[18]),
PriceAuxLimit: f64ValOrZero(raw[19]),
Notify: bValOrFalse(raw[23]),
Hidden: bValOrFalse(raw[24]),
PlacedID: i64ValOrZero(raw[25]),
}
}
return
} | go | func NewOrderFromRaw(raw []interface{}) (o *Order, err error) {
if len(raw) == 12 {
o = &Order{
ID: int64(f64ValOrZero(raw[0])),
Symbol: sValOrEmpty(raw[1]),
Amount: f64ValOrZero(raw[2]),
AmountOrig: f64ValOrZero(raw[3]),
Type: sValOrEmpty(raw[4]),
Status: OrderStatus(sValOrEmpty(raw[5])),
Price: f64ValOrZero(raw[6]),
PriceAvg: f64ValOrZero(raw[7]),
MTSUpdated: i64ValOrZero(raw[8]),
// 3 trailing zeroes, what do they map to?
}
} else if len(raw) < 26 {
return o, fmt.Errorf("data slice too short for order: %#v", raw)
} else {
// TODO: API docs say ID, GID, CID, MTS_CREATE, MTS_UPDATE are int but API returns float
o = &Order{
ID: int64(f64ValOrZero(raw[0])),
GID: int64(f64ValOrZero(raw[1])),
CID: int64(f64ValOrZero(raw[2])),
Symbol: sValOrEmpty(raw[3]),
MTSCreated: int64(f64ValOrZero(raw[4])),
MTSUpdated: int64(f64ValOrZero(raw[5])),
Amount: f64ValOrZero(raw[6]),
AmountOrig: f64ValOrZero(raw[7]),
Type: sValOrEmpty(raw[8]),
TypePrev: sValOrEmpty(raw[9]),
MTSTif: int64(f64ValOrZero(raw[10])),
Flags: i64ValOrZero(raw[12]),
Status: OrderStatus(sValOrEmpty(raw[13])),
Price: f64ValOrZero(raw[16]),
PriceAvg: f64ValOrZero(raw[17]),
PriceTrailing: f64ValOrZero(raw[18]),
PriceAuxLimit: f64ValOrZero(raw[19]),
Notify: bValOrFalse(raw[23]),
Hidden: bValOrFalse(raw[24]),
PlacedID: i64ValOrZero(raw[25]),
}
}
return
} | [
"func",
"NewOrderFromRaw",
"(",
"raw",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"o",
"*",
"Order",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"raw",
")",
"==",
"12",
"{",
"o",
"=",
"&",
"Order",
"{",
"ID",
":",
"int64",
"(",
"f64ValOrZero",
"(",
"raw",
"[",
"0",
"]",
")",
")",
",",
"Symbol",
":",
"sValOrEmpty",
"(",
"raw",
"[",
"1",
"]",
")",
",",
"Amount",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"2",
"]",
")",
",",
"AmountOrig",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"3",
"]",
")",
",",
"Type",
":",
"sValOrEmpty",
"(",
"raw",
"[",
"4",
"]",
")",
",",
"Status",
":",
"OrderStatus",
"(",
"sValOrEmpty",
"(",
"raw",
"[",
"5",
"]",
")",
")",
",",
"Price",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"6",
"]",
")",
",",
"PriceAvg",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"7",
"]",
")",
",",
"MTSUpdated",
":",
"i64ValOrZero",
"(",
"raw",
"[",
"8",
"]",
")",
",",
"// 3 trailing zeroes, what do they map to?",
"}",
"\n",
"}",
"else",
"if",
"len",
"(",
"raw",
")",
"<",
"26",
"{",
"return",
"o",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"else",
"{",
"// TODO: API docs say ID, GID, CID, MTS_CREATE, MTS_UPDATE are int but API returns float",
"o",
"=",
"&",
"Order",
"{",
"ID",
":",
"int64",
"(",
"f64ValOrZero",
"(",
"raw",
"[",
"0",
"]",
")",
")",
",",
"GID",
":",
"int64",
"(",
"f64ValOrZero",
"(",
"raw",
"[",
"1",
"]",
")",
")",
",",
"CID",
":",
"int64",
"(",
"f64ValOrZero",
"(",
"raw",
"[",
"2",
"]",
")",
")",
",",
"Symbol",
":",
"sValOrEmpty",
"(",
"raw",
"[",
"3",
"]",
")",
",",
"MTSCreated",
":",
"int64",
"(",
"f64ValOrZero",
"(",
"raw",
"[",
"4",
"]",
")",
")",
",",
"MTSUpdated",
":",
"int64",
"(",
"f64ValOrZero",
"(",
"raw",
"[",
"5",
"]",
")",
")",
",",
"Amount",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"6",
"]",
")",
",",
"AmountOrig",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"7",
"]",
")",
",",
"Type",
":",
"sValOrEmpty",
"(",
"raw",
"[",
"8",
"]",
")",
",",
"TypePrev",
":",
"sValOrEmpty",
"(",
"raw",
"[",
"9",
"]",
")",
",",
"MTSTif",
":",
"int64",
"(",
"f64ValOrZero",
"(",
"raw",
"[",
"10",
"]",
")",
")",
",",
"Flags",
":",
"i64ValOrZero",
"(",
"raw",
"[",
"12",
"]",
")",
",",
"Status",
":",
"OrderStatus",
"(",
"sValOrEmpty",
"(",
"raw",
"[",
"13",
"]",
")",
")",
",",
"Price",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"16",
"]",
")",
",",
"PriceAvg",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"17",
"]",
")",
",",
"PriceTrailing",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"18",
"]",
")",
",",
"PriceAuxLimit",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"19",
"]",
")",
",",
"Notify",
":",
"bValOrFalse",
"(",
"raw",
"[",
"23",
"]",
")",
",",
"Hidden",
":",
"bValOrFalse",
"(",
"raw",
"[",
"24",
"]",
")",
",",
"PlacedID",
":",
"i64ValOrZero",
"(",
"raw",
"[",
"25",
"]",
")",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // NewOrderFromRaw takes the raw list of values as returned from the websocket
// service and tries to convert it into an Order. | [
"NewOrderFromRaw",
"takes",
"the",
"raw",
"list",
"of",
"values",
"as",
"returned",
"from",
"the",
"websocket",
"service",
"and",
"tries",
"to",
"convert",
"it",
"into",
"an",
"Order",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/types.go#L346-L389 |
152,179 | bitfinexcom/bitfinex-api-go | v2/types.go | NewOrderSnapshotFromRaw | func NewOrderSnapshotFromRaw(raw []interface{}) (s *OrderSnapshot, err error) {
if len(raw) == 0 {
return
}
os := make([]*Order, 0)
switch raw[0].(type) {
case []interface{}:
for _, v := range raw {
if l, ok := v.([]interface{}); ok {
o, err := NewOrderFromRaw(l)
if err != nil {
return s, err
}
os = append(os, o)
}
}
default:
return s, fmt.Errorf("not an order snapshot")
}
s = &OrderSnapshot{Snapshot: os}
return
} | go | func NewOrderSnapshotFromRaw(raw []interface{}) (s *OrderSnapshot, err error) {
if len(raw) == 0 {
return
}
os := make([]*Order, 0)
switch raw[0].(type) {
case []interface{}:
for _, v := range raw {
if l, ok := v.([]interface{}); ok {
o, err := NewOrderFromRaw(l)
if err != nil {
return s, err
}
os = append(os, o)
}
}
default:
return s, fmt.Errorf("not an order snapshot")
}
s = &OrderSnapshot{Snapshot: os}
return
} | [
"func",
"NewOrderSnapshotFromRaw",
"(",
"raw",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"s",
"*",
"OrderSnapshot",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"raw",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"os",
":=",
"make",
"(",
"[",
"]",
"*",
"Order",
",",
"0",
")",
"\n",
"switch",
"raw",
"[",
"0",
"]",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"interface",
"{",
"}",
":",
"for",
"_",
",",
"v",
":=",
"range",
"raw",
"{",
"if",
"l",
",",
"ok",
":=",
"v",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"o",
",",
"err",
":=",
"NewOrderFromRaw",
"(",
"l",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"s",
",",
"err",
"\n",
"}",
"\n",
"os",
"=",
"append",
"(",
"os",
",",
"o",
")",
"\n",
"}",
"\n",
"}",
"\n",
"default",
":",
"return",
"s",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"s",
"=",
"&",
"OrderSnapshot",
"{",
"Snapshot",
":",
"os",
"}",
"\n\n",
"return",
"\n",
"}"
] | // OrderSnapshotFromRaw takes a raw list of values as returned from the websocket
// service and tries to convert it into an OrderSnapshot. | [
"OrderSnapshotFromRaw",
"takes",
"a",
"raw",
"list",
"of",
"values",
"as",
"returned",
"from",
"the",
"websocket",
"service",
"and",
"tries",
"to",
"convert",
"it",
"into",
"an",
"OrderSnapshot",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/types.go#L393-L416 |
152,180 | bitfinexcom/bitfinex-api-go | v2/types.go | NewTradeExecutionUpdateFromRaw | func NewTradeExecutionUpdateFromRaw(raw []interface{}) (o *TradeExecutionUpdate, err error) {
if len(raw) == 4 {
o = &TradeExecutionUpdate{
ID: i64ValOrZero(raw[0]),
MTS: i64ValOrZero(raw[1]),
ExecAmount: f64ValOrZero(raw[2]),
ExecPrice: f64ValOrZero(raw[3]),
}
return
}
if len(raw) == 11 {
o = &TradeExecutionUpdate{
ID: i64ValOrZero(raw[0]),
Pair: sValOrEmpty(raw[1]),
MTS: i64ValOrZero(raw[2]),
OrderID: i64ValOrZero(raw[3]),
ExecAmount: f64ValOrZero(raw[4]),
ExecPrice: f64ValOrZero(raw[5]),
OrderType: sValOrEmpty(raw[6]),
OrderPrice: f64ValOrZero(raw[7]),
Maker: iValOrZero(raw[8]),
Fee: f64ValOrZero(raw[9]),
FeeCurrency: sValOrEmpty(raw[10]),
}
return
}
return o, fmt.Errorf("data slice too short for trade update: %#v", raw)
} | go | func NewTradeExecutionUpdateFromRaw(raw []interface{}) (o *TradeExecutionUpdate, err error) {
if len(raw) == 4 {
o = &TradeExecutionUpdate{
ID: i64ValOrZero(raw[0]),
MTS: i64ValOrZero(raw[1]),
ExecAmount: f64ValOrZero(raw[2]),
ExecPrice: f64ValOrZero(raw[3]),
}
return
}
if len(raw) == 11 {
o = &TradeExecutionUpdate{
ID: i64ValOrZero(raw[0]),
Pair: sValOrEmpty(raw[1]),
MTS: i64ValOrZero(raw[2]),
OrderID: i64ValOrZero(raw[3]),
ExecAmount: f64ValOrZero(raw[4]),
ExecPrice: f64ValOrZero(raw[5]),
OrderType: sValOrEmpty(raw[6]),
OrderPrice: f64ValOrZero(raw[7]),
Maker: iValOrZero(raw[8]),
Fee: f64ValOrZero(raw[9]),
FeeCurrency: sValOrEmpty(raw[10]),
}
return
}
return o, fmt.Errorf("data slice too short for trade update: %#v", raw)
} | [
"func",
"NewTradeExecutionUpdateFromRaw",
"(",
"raw",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"o",
"*",
"TradeExecutionUpdate",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"raw",
")",
"==",
"4",
"{",
"o",
"=",
"&",
"TradeExecutionUpdate",
"{",
"ID",
":",
"i64ValOrZero",
"(",
"raw",
"[",
"0",
"]",
")",
",",
"MTS",
":",
"i64ValOrZero",
"(",
"raw",
"[",
"1",
"]",
")",
",",
"ExecAmount",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"2",
"]",
")",
",",
"ExecPrice",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"3",
"]",
")",
",",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"len",
"(",
"raw",
")",
"==",
"11",
"{",
"o",
"=",
"&",
"TradeExecutionUpdate",
"{",
"ID",
":",
"i64ValOrZero",
"(",
"raw",
"[",
"0",
"]",
")",
",",
"Pair",
":",
"sValOrEmpty",
"(",
"raw",
"[",
"1",
"]",
")",
",",
"MTS",
":",
"i64ValOrZero",
"(",
"raw",
"[",
"2",
"]",
")",
",",
"OrderID",
":",
"i64ValOrZero",
"(",
"raw",
"[",
"3",
"]",
")",
",",
"ExecAmount",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"4",
"]",
")",
",",
"ExecPrice",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"5",
"]",
")",
",",
"OrderType",
":",
"sValOrEmpty",
"(",
"raw",
"[",
"6",
"]",
")",
",",
"OrderPrice",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"7",
"]",
")",
",",
"Maker",
":",
"iValOrZero",
"(",
"raw",
"[",
"8",
"]",
")",
",",
"Fee",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"9",
"]",
")",
",",
"FeeCurrency",
":",
"sValOrEmpty",
"(",
"raw",
"[",
"10",
"]",
")",
",",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"return",
"o",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}"
] | // public trade update just looks like a trade | [
"public",
"trade",
"update",
"just",
"looks",
"like",
"a",
"trade"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/types.go#L586-L613 |
152,181 | bitfinexcom/bitfinex-api-go | v2/types.go | NewMarginInfoFromRaw | func NewMarginInfoFromRaw(raw []interface{}) (o interface{}, err error) {
if len(raw) < 2 {
return o, fmt.Errorf("data slice too short for margin info base: %#v", raw)
}
typ, ok := raw[0].(string)
if !ok {
return o, fmt.Errorf("expected margin info type in first position for margin info but got %#v", raw)
}
if len(raw) == 2 && typ == "base" { // This should be ["base", [...]]
data, ok := raw[1].([]interface{})
if !ok {
return o, fmt.Errorf("expected margin info array in second position for margin info but got %#v", raw)
}
return NewMarginInfoBaseFromRaw(data)
} else if len(raw) == 3 && typ == "sym" { // This should be ["sym", SYMBOL, [...]]
symbol, ok := raw[1].(string)
if !ok {
return o, fmt.Errorf("expected margin info symbol in second position for margin info update but got %#v", raw)
}
data, ok := raw[2].([]interface{})
if !ok {
return o, fmt.Errorf("expected margin info array in third position for margin info update but got %#v", raw)
}
return NewMarginInfoUpdateFromRaw(symbol, data)
}
return nil, fmt.Errorf("invalid margin info type in %#v", raw)
} | go | func NewMarginInfoFromRaw(raw []interface{}) (o interface{}, err error) {
if len(raw) < 2 {
return o, fmt.Errorf("data slice too short for margin info base: %#v", raw)
}
typ, ok := raw[0].(string)
if !ok {
return o, fmt.Errorf("expected margin info type in first position for margin info but got %#v", raw)
}
if len(raw) == 2 && typ == "base" { // This should be ["base", [...]]
data, ok := raw[1].([]interface{})
if !ok {
return o, fmt.Errorf("expected margin info array in second position for margin info but got %#v", raw)
}
return NewMarginInfoBaseFromRaw(data)
} else if len(raw) == 3 && typ == "sym" { // This should be ["sym", SYMBOL, [...]]
symbol, ok := raw[1].(string)
if !ok {
return o, fmt.Errorf("expected margin info symbol in second position for margin info update but got %#v", raw)
}
data, ok := raw[2].([]interface{})
if !ok {
return o, fmt.Errorf("expected margin info array in third position for margin info update but got %#v", raw)
}
return NewMarginInfoUpdateFromRaw(symbol, data)
}
return nil, fmt.Errorf("invalid margin info type in %#v", raw)
} | [
"func",
"NewMarginInfoFromRaw",
"(",
"raw",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"o",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"raw",
")",
"<",
"2",
"{",
"return",
"o",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n\n",
"typ",
",",
"ok",
":=",
"raw",
"[",
"0",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"o",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"raw",
")",
"==",
"2",
"&&",
"typ",
"==",
"\"",
"\"",
"{",
"// This should be [\"base\", [...]]",
"data",
",",
"ok",
":=",
"raw",
"[",
"1",
"]",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"o",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n\n",
"return",
"NewMarginInfoBaseFromRaw",
"(",
"data",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"raw",
")",
"==",
"3",
"&&",
"typ",
"==",
"\"",
"\"",
"{",
"// This should be [\"sym\", SYMBOL, [...]]",
"symbol",
",",
"ok",
":=",
"raw",
"[",
"1",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"o",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n\n",
"data",
",",
"ok",
":=",
"raw",
"[",
"2",
"]",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"o",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n\n",
"return",
"NewMarginInfoUpdateFromRaw",
"(",
"symbol",
",",
"data",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}"
] | // marginInfoFromRaw returns either a MarginInfoBase or MarginInfoUpdate, since
// the Margin Info is split up into a base and per symbol parts. | [
"marginInfoFromRaw",
"returns",
"either",
"a",
"MarginInfoBase",
"or",
"MarginInfoUpdate",
"since",
"the",
"Margin",
"Info",
"is",
"split",
"up",
"into",
"a",
"base",
"and",
"per",
"symbol",
"parts",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/types.go#L768-L800 |
152,182 | bitfinexcom/bitfinex-api-go | v2/types.go | NewLedgerFromRaw | func NewLedgerFromRaw(raw []interface{}) (o *Ledger, err error) {
if len(raw) == 9 {
o = &Ledger{
ID: int64(f64ValOrZero(raw[0])),
Currency: sValOrEmpty(raw[1]),
Nil1: f64ValOrZero(raw[2]),
MTS: i64ValOrZero(raw[3]),
Nil2: f64ValOrZero(raw[4]),
Amount: f64ValOrZero(raw[5]),
Balance: f64ValOrZero(raw[6]),
Nil3: f64ValOrZero(raw[7]),
Description: sValOrEmpty(raw[8]),
// API returns 3 Nil values, what do they map to?
// API documentation says ID is type integer but api returns a string
}
} else
{return o, fmt.Errorf("data slice too short for ledger: %#v", raw)
}
return
} | go | func NewLedgerFromRaw(raw []interface{}) (o *Ledger, err error) {
if len(raw) == 9 {
o = &Ledger{
ID: int64(f64ValOrZero(raw[0])),
Currency: sValOrEmpty(raw[1]),
Nil1: f64ValOrZero(raw[2]),
MTS: i64ValOrZero(raw[3]),
Nil2: f64ValOrZero(raw[4]),
Amount: f64ValOrZero(raw[5]),
Balance: f64ValOrZero(raw[6]),
Nil3: f64ValOrZero(raw[7]),
Description: sValOrEmpty(raw[8]),
// API returns 3 Nil values, what do they map to?
// API documentation says ID is type integer but api returns a string
}
} else
{return o, fmt.Errorf("data slice too short for ledger: %#v", raw)
}
return
} | [
"func",
"NewLedgerFromRaw",
"(",
"raw",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"o",
"*",
"Ledger",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"raw",
")",
"==",
"9",
"{",
"o",
"=",
"&",
"Ledger",
"{",
"ID",
":",
"int64",
"(",
"f64ValOrZero",
"(",
"raw",
"[",
"0",
"]",
")",
")",
",",
"Currency",
":",
"sValOrEmpty",
"(",
"raw",
"[",
"1",
"]",
")",
",",
"Nil1",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"2",
"]",
")",
",",
"MTS",
":",
"i64ValOrZero",
"(",
"raw",
"[",
"3",
"]",
")",
",",
"Nil2",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"4",
"]",
")",
",",
"Amount",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"5",
"]",
")",
",",
"Balance",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"6",
"]",
")",
",",
"Nil3",
":",
"f64ValOrZero",
"(",
"raw",
"[",
"7",
"]",
")",
",",
"Description",
":",
"sValOrEmpty",
"(",
"raw",
"[",
"8",
"]",
")",
",",
"// API returns 3 Nil values, what do they map to?",
"// API documentation says ID is type integer but api returns a string",
"}",
"\n",
"}",
"else",
"{",
"return",
"o",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // NewLedgerFromRaw takes the raw list of values as returned from the websocket
// service and tries to convert it into an Ledger. | [
"NewLedgerFromRaw",
"takes",
"the",
"raw",
"list",
"of",
"values",
"as",
"returned",
"from",
"the",
"websocket",
"service",
"and",
"tries",
"to",
"convert",
"it",
"into",
"an",
"Ledger",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/types.go#L1561-L1580 |
152,183 | bitfinexcom/bitfinex-api-go | v2/types.go | NewLedgerSnapshotFromRaw | func NewLedgerSnapshotFromRaw(raw []interface{}) (s *LedgerSnapshot, err error) {
if len(raw) == 0 {
return s, fmt.Errorf("data slice too short for ledgers: %#v", raw)
}
os := make([]*Ledger, 0)
switch raw[0].(type) {
case []interface{}:
for _, v := range raw {
if l, ok := v.([]interface{}); ok {
o, err := NewLedgerFromRaw(l)
if err != nil {
return s, err
}
os = append(os, o)
}
}
default:
return s, fmt.Errorf("not an ledger snapshot")
}
s = &LedgerSnapshot{Snapshot: os}
return
} | go | func NewLedgerSnapshotFromRaw(raw []interface{}) (s *LedgerSnapshot, err error) {
if len(raw) == 0 {
return s, fmt.Errorf("data slice too short for ledgers: %#v", raw)
}
os := make([]*Ledger, 0)
switch raw[0].(type) {
case []interface{}:
for _, v := range raw {
if l, ok := v.([]interface{}); ok {
o, err := NewLedgerFromRaw(l)
if err != nil {
return s, err
}
os = append(os, o)
}
}
default:
return s, fmt.Errorf("not an ledger snapshot")
}
s = &LedgerSnapshot{Snapshot: os}
return
} | [
"func",
"NewLedgerSnapshotFromRaw",
"(",
"raw",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"s",
"*",
"LedgerSnapshot",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"raw",
")",
"==",
"0",
"{",
"return",
"s",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"raw",
")",
"\n",
"}",
"\n\n",
"os",
":=",
"make",
"(",
"[",
"]",
"*",
"Ledger",
",",
"0",
")",
"\n",
"switch",
"raw",
"[",
"0",
"]",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"interface",
"{",
"}",
":",
"for",
"_",
",",
"v",
":=",
"range",
"raw",
"{",
"if",
"l",
",",
"ok",
":=",
"v",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"o",
",",
"err",
":=",
"NewLedgerFromRaw",
"(",
"l",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"s",
",",
"err",
"\n",
"}",
"\n",
"os",
"=",
"append",
"(",
"os",
",",
"o",
")",
"\n",
"}",
"\n",
"}",
"\n",
"default",
":",
"return",
"s",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"s",
"=",
"&",
"LedgerSnapshot",
"{",
"Snapshot",
":",
"os",
"}",
"\n",
"return",
"\n",
"}"
] | // LedgerSnapshotFromRaw takes a raw list of values as returned from the websocket
// service and tries to convert it into an LedgerSnapshot. | [
"LedgerSnapshotFromRaw",
"takes",
"a",
"raw",
"list",
"of",
"values",
"as",
"returned",
"from",
"the",
"websocket",
"service",
"and",
"tries",
"to",
"convert",
"it",
"into",
"an",
"LedgerSnapshot",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/types.go#L1588-L1610 |
152,184 | bitfinexcom/bitfinex-api-go | v2/rest/platform_status.go | Status | func (p *PlatformService) Status() (bool, error) {
raw, err := p.Request(NewRequestWithMethod("platform/status", "GET"))
if err != nil {
return false, err
}
/*
// raw is an interface type, but we only care about len & index 0
s := make([]int, len(raw))
for i, v := range raw {
s[i] = v.(int)
}
*/
return len(raw) > 0 && raw[0].(float64) == 1, nil
} | go | func (p *PlatformService) Status() (bool, error) {
raw, err := p.Request(NewRequestWithMethod("platform/status", "GET"))
if err != nil {
return false, err
}
/*
// raw is an interface type, but we only care about len & index 0
s := make([]int, len(raw))
for i, v := range raw {
s[i] = v.(int)
}
*/
return len(raw) > 0 && raw[0].(float64) == 1, nil
} | [
"func",
"(",
"p",
"*",
"PlatformService",
")",
"Status",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"raw",
",",
"err",
":=",
"p",
".",
"Request",
"(",
"NewRequestWithMethod",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"/*\n\t\t// raw is an interface type, but we only care about len & index 0\n\t\ts := make([]int, len(raw))\n\t\tfor i, v := range raw {\n\t\t\ts[i] = v.(int)\n\t\t}\n\t*/",
"return",
"len",
"(",
"raw",
")",
">",
"0",
"&&",
"raw",
"[",
"0",
"]",
".",
"(",
"float64",
")",
"==",
"1",
",",
"nil",
"\n",
"}"
] | // Status indicates whether the platform is currently operative or not. | [
"Status",
"indicates",
"whether",
"the",
"platform",
"is",
"currently",
"operative",
"or",
"not",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/rest/platform_status.go#L8-L22 |
152,185 | bitfinexcom/bitfinex-api-go | v2/rest/positions.go | All | func (s *PositionService) All() (*bitfinex.PositionSnapshot, error) {
req, err := s.requestFactory.NewAuthenticatedRequest("positions")
if err != nil {
return nil, err
}
raw, err := s.Request(req)
if err != nil {
return nil, err
}
os, err := bitfinex.NewPositionSnapshotFromRaw(raw)
if err != nil {
return nil, err
}
return os, nil
} | go | func (s *PositionService) All() (*bitfinex.PositionSnapshot, error) {
req, err := s.requestFactory.NewAuthenticatedRequest("positions")
if err != nil {
return nil, err
}
raw, err := s.Request(req)
if err != nil {
return nil, err
}
os, err := bitfinex.NewPositionSnapshotFromRaw(raw)
if err != nil {
return nil, err
}
return os, nil
} | [
"func",
"(",
"s",
"*",
"PositionService",
")",
"All",
"(",
")",
"(",
"*",
"bitfinex",
".",
"PositionSnapshot",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"s",
".",
"requestFactory",
".",
"NewAuthenticatedRequest",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"raw",
",",
"err",
":=",
"s",
".",
"Request",
"(",
"req",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"os",
",",
"err",
":=",
"bitfinex",
".",
"NewPositionSnapshotFromRaw",
"(",
"raw",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"os",
",",
"nil",
"\n",
"}"
] | // All returns all positions for the authenticated account. | [
"All",
"returns",
"all",
"positions",
"for",
"the",
"authenticated",
"account",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/rest/positions.go#L14-L31 |
152,186 | bitfinexcom/bitfinex-api-go | v1/offers.go | New | func (s *OffersService) New(currency string, amount, rate float64, period int64, direction string) (Offer, error) {
payload := map[string]interface{}{
"currency": currency,
"amount": strconv.FormatFloat(amount, 'f', -1, 32),
"rate": strconv.FormatFloat(rate, 'f', -1, 32),
"period": strconv.FormatInt(period, 10),
"direction": direction,
}
req, err := s.client.newAuthenticatedRequest("POST", "offers/new", payload)
if err != nil {
return Offer{}, err
}
var offer = &Offer{}
_, err = s.client.do(req, offer)
if err != nil {
return Offer{}, err
}
return *offer, nil
} | go | func (s *OffersService) New(currency string, amount, rate float64, period int64, direction string) (Offer, error) {
payload := map[string]interface{}{
"currency": currency,
"amount": strconv.FormatFloat(amount, 'f', -1, 32),
"rate": strconv.FormatFloat(rate, 'f', -1, 32),
"period": strconv.FormatInt(period, 10),
"direction": direction,
}
req, err := s.client.newAuthenticatedRequest("POST", "offers/new", payload)
if err != nil {
return Offer{}, err
}
var offer = &Offer{}
_, err = s.client.do(req, offer)
if err != nil {
return Offer{}, err
}
return *offer, nil
} | [
"func",
"(",
"s",
"*",
"OffersService",
")",
"New",
"(",
"currency",
"string",
",",
"amount",
",",
"rate",
"float64",
",",
"period",
"int64",
",",
"direction",
"string",
")",
"(",
"Offer",
",",
"error",
")",
"{",
"payload",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"currency",
",",
"\"",
"\"",
":",
"strconv",
".",
"FormatFloat",
"(",
"amount",
",",
"'f'",
",",
"-",
"1",
",",
"32",
")",
",",
"\"",
"\"",
":",
"strconv",
".",
"FormatFloat",
"(",
"rate",
",",
"'f'",
",",
"-",
"1",
",",
"32",
")",
",",
"\"",
"\"",
":",
"strconv",
".",
"FormatInt",
"(",
"period",
",",
"10",
")",
",",
"\"",
"\"",
":",
"direction",
",",
"}",
"\n\n",
"req",
",",
"err",
":=",
"s",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"payload",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Offer",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"offer",
"=",
"&",
"Offer",
"{",
"}",
"\n",
"_",
",",
"err",
"=",
"s",
".",
"client",
".",
"do",
"(",
"req",
",",
"offer",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Offer",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"*",
"offer",
",",
"nil",
"\n\n",
"}"
] | // Create new offer for LEND or LOAN a currency, use LEND or LOAN constants as direction | [
"Create",
"new",
"offer",
"for",
"LEND",
"or",
"LOAN",
"a",
"currency",
"use",
"LEND",
"or",
"LOAN",
"constants",
"as",
"direction"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/offers.go#L30-L55 |
152,187 | bitfinexcom/bitfinex-api-go | v2/websocket/events.go | handleEvent | func (c *Client) handleEvent(msg []byte) error {
event := &eventType{}
err := json.Unmarshal(msg, event)
if err != nil {
return err
}
//var e interface{}
switch event.Event {
case "info":
i := InfoEvent{}
err = json.Unmarshal(msg, &i)
if err != nil {
return err
}
if i.Code == 0 && i.Version != 0 {
err_open := c.handleOpen()
if err_open != nil {
return err_open
}
}
c.listener <- &i
case "auth":
a := AuthEvent{}
err = json.Unmarshal(msg, &a)
if err != nil {
return err
}
if a.Status != "" && a.Status == "OK" {
c.Authentication = SuccessfulAuthentication
} else {
c.Authentication = RejectedAuthentication
}
c.handleAuthAck(&a)
c.listener <- &a
return nil
case "subscribed":
s := SubscribeEvent{}
err = json.Unmarshal(msg, &s)
if err != nil {
return err
}
err = c.subscriptions.activate(s.SubID, s.ChanID)
if err != nil {
return err
}
c.listener <- &s
return nil
case "unsubscribed":
s := UnsubscribeEvent{}
err = json.Unmarshal(msg, &s)
if err != nil {
return err
}
err_rem := c.subscriptions.removeByChannelID(s.ChanID)
if err_rem != nil {
return err_rem
}
c.listener <- &s
case "error":
er := ErrorEvent{}
err = json.Unmarshal(msg, &er)
if err != nil {
return err
}
c.listener <- &er
case "conf":
ec := ConfEvent{}
err = json.Unmarshal(msg, &ec)
if err != nil {
return err
}
c.listener <- &ec
default:
c.log.Warningf("unknown event: %s", msg)
}
//err = json.Unmarshal(msg, &e)
//TODO raw message isn't ever published
return err
} | go | func (c *Client) handleEvent(msg []byte) error {
event := &eventType{}
err := json.Unmarshal(msg, event)
if err != nil {
return err
}
//var e interface{}
switch event.Event {
case "info":
i := InfoEvent{}
err = json.Unmarshal(msg, &i)
if err != nil {
return err
}
if i.Code == 0 && i.Version != 0 {
err_open := c.handleOpen()
if err_open != nil {
return err_open
}
}
c.listener <- &i
case "auth":
a := AuthEvent{}
err = json.Unmarshal(msg, &a)
if err != nil {
return err
}
if a.Status != "" && a.Status == "OK" {
c.Authentication = SuccessfulAuthentication
} else {
c.Authentication = RejectedAuthentication
}
c.handleAuthAck(&a)
c.listener <- &a
return nil
case "subscribed":
s := SubscribeEvent{}
err = json.Unmarshal(msg, &s)
if err != nil {
return err
}
err = c.subscriptions.activate(s.SubID, s.ChanID)
if err != nil {
return err
}
c.listener <- &s
return nil
case "unsubscribed":
s := UnsubscribeEvent{}
err = json.Unmarshal(msg, &s)
if err != nil {
return err
}
err_rem := c.subscriptions.removeByChannelID(s.ChanID)
if err_rem != nil {
return err_rem
}
c.listener <- &s
case "error":
er := ErrorEvent{}
err = json.Unmarshal(msg, &er)
if err != nil {
return err
}
c.listener <- &er
case "conf":
ec := ConfEvent{}
err = json.Unmarshal(msg, &ec)
if err != nil {
return err
}
c.listener <- &ec
default:
c.log.Warningf("unknown event: %s", msg)
}
//err = json.Unmarshal(msg, &e)
//TODO raw message isn't ever published
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"handleEvent",
"(",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"event",
":=",
"&",
"eventType",
"{",
"}",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"msg",
",",
"event",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"//var e interface{}",
"switch",
"event",
".",
"Event",
"{",
"case",
"\"",
"\"",
":",
"i",
":=",
"InfoEvent",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"msg",
",",
"&",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"i",
".",
"Code",
"==",
"0",
"&&",
"i",
".",
"Version",
"!=",
"0",
"{",
"err_open",
":=",
"c",
".",
"handleOpen",
"(",
")",
"\n",
"if",
"err_open",
"!=",
"nil",
"{",
"return",
"err_open",
"\n",
"}",
"\n",
"}",
"\n",
"c",
".",
"listener",
"<-",
"&",
"i",
"\n",
"case",
"\"",
"\"",
":",
"a",
":=",
"AuthEvent",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"msg",
",",
"&",
"a",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"a",
".",
"Status",
"!=",
"\"",
"\"",
"&&",
"a",
".",
"Status",
"==",
"\"",
"\"",
"{",
"c",
".",
"Authentication",
"=",
"SuccessfulAuthentication",
"\n",
"}",
"else",
"{",
"c",
".",
"Authentication",
"=",
"RejectedAuthentication",
"\n",
"}",
"\n",
"c",
".",
"handleAuthAck",
"(",
"&",
"a",
")",
"\n",
"c",
".",
"listener",
"<-",
"&",
"a",
"\n",
"return",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"s",
":=",
"SubscribeEvent",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"msg",
",",
"&",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"c",
".",
"subscriptions",
".",
"activate",
"(",
"s",
".",
"SubID",
",",
"s",
".",
"ChanID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"listener",
"<-",
"&",
"s",
"\n",
"return",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"s",
":=",
"UnsubscribeEvent",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"msg",
",",
"&",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err_rem",
":=",
"c",
".",
"subscriptions",
".",
"removeByChannelID",
"(",
"s",
".",
"ChanID",
")",
"\n",
"if",
"err_rem",
"!=",
"nil",
"{",
"return",
"err_rem",
"\n",
"}",
"\n",
"c",
".",
"listener",
"<-",
"&",
"s",
"\n",
"case",
"\"",
"\"",
":",
"er",
":=",
"ErrorEvent",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"msg",
",",
"&",
"er",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"listener",
"<-",
"&",
"er",
"\n",
"case",
"\"",
"\"",
":",
"ec",
":=",
"ConfEvent",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"msg",
",",
"&",
"ec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"listener",
"<-",
"&",
"ec",
"\n",
"default",
":",
"c",
".",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"msg",
")",
"\n",
"}",
"\n\n",
"//err = json.Unmarshal(msg, &e)",
"//TODO raw message isn't ever published",
"return",
"err",
"\n",
"}"
] | // onEvent handles all the event messages and connects SubID and ChannelID. | [
"onEvent",
"handles",
"all",
"the",
"event",
"messages",
"and",
"connects",
"SubID",
"and",
"ChannelID",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/events.go#L104-L184 |
152,188 | bitfinexcom/bitfinex-api-go | v1/wallet.go | Transfer | func (c *WalletService) Transfer(amount float64, currency, from, to string) ([]TransferStatus, error) {
payload := map[string]interface{}{
"amount": strconv.FormatFloat(amount, 'f', -1, 32),
"currency": currency,
"walletfrom": from,
"walletto": to,
}
req, err := c.client.newAuthenticatedRequest("GET", "transfer", payload)
if err != nil {
return nil, err
}
status := make([]TransferStatus, 0)
_, err = c.client.do(req, &status)
return status, err
} | go | func (c *WalletService) Transfer(amount float64, currency, from, to string) ([]TransferStatus, error) {
payload := map[string]interface{}{
"amount": strconv.FormatFloat(amount, 'f', -1, 32),
"currency": currency,
"walletfrom": from,
"walletto": to,
}
req, err := c.client.newAuthenticatedRequest("GET", "transfer", payload)
if err != nil {
return nil, err
}
status := make([]TransferStatus, 0)
_, err = c.client.do(req, &status)
return status, err
} | [
"func",
"(",
"c",
"*",
"WalletService",
")",
"Transfer",
"(",
"amount",
"float64",
",",
"currency",
",",
"from",
",",
"to",
"string",
")",
"(",
"[",
"]",
"TransferStatus",
",",
"error",
")",
"{",
"payload",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"strconv",
".",
"FormatFloat",
"(",
"amount",
",",
"'f'",
",",
"-",
"1",
",",
"32",
")",
",",
"\"",
"\"",
":",
"currency",
",",
"\"",
"\"",
":",
"from",
",",
"\"",
"\"",
":",
"to",
",",
"}",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"payload",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"status",
":=",
"make",
"(",
"[",
"]",
"TransferStatus",
",",
"0",
")",
"\n\n",
"_",
",",
"err",
"=",
"c",
".",
"client",
".",
"do",
"(",
"req",
",",
"&",
"status",
")",
"\n\n",
"return",
"status",
",",
"err",
"\n",
"}"
] | // Transfer funds between wallets | [
"Transfer",
"funds",
"between",
"wallets"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/wallet.go#L21-L41 |
152,189 | bitfinexcom/bitfinex-api-go | v1/wallet.go | WithdrawCrypto | func (c *WalletService) WithdrawCrypto(amount float64, currency, wallet, destinationAddress string) ([]WithdrawStatus, error) {
payload := map[string]interface{}{
"amount": strconv.FormatFloat(amount, 'f', -1, 32),
"walletselected": wallet,
"withdraw_type": currency,
"address": destinationAddress,
}
req, err := c.client.newAuthenticatedRequest("GET", "withdraw", payload)
if err != nil {
return nil, err
}
status := make([]WithdrawStatus, 0)
_, err = c.client.do(req, &status)
return status, err
} | go | func (c *WalletService) WithdrawCrypto(amount float64, currency, wallet, destinationAddress string) ([]WithdrawStatus, error) {
payload := map[string]interface{}{
"amount": strconv.FormatFloat(amount, 'f', -1, 32),
"walletselected": wallet,
"withdraw_type": currency,
"address": destinationAddress,
}
req, err := c.client.newAuthenticatedRequest("GET", "withdraw", payload)
if err != nil {
return nil, err
}
status := make([]WithdrawStatus, 0)
_, err = c.client.do(req, &status)
return status, err
} | [
"func",
"(",
"c",
"*",
"WalletService",
")",
"WithdrawCrypto",
"(",
"amount",
"float64",
",",
"currency",
",",
"wallet",
",",
"destinationAddress",
"string",
")",
"(",
"[",
"]",
"WithdrawStatus",
",",
"error",
")",
"{",
"payload",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"strconv",
".",
"FormatFloat",
"(",
"amount",
",",
"'f'",
",",
"-",
"1",
",",
"32",
")",
",",
"\"",
"\"",
":",
"wallet",
",",
"\"",
"\"",
":",
"currency",
",",
"\"",
"\"",
":",
"destinationAddress",
",",
"}",
"\n\n",
"req",
",",
"err",
":=",
"c",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"payload",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"status",
":=",
"make",
"(",
"[",
"]",
"WithdrawStatus",
",",
"0",
")",
"\n\n",
"_",
",",
"err",
"=",
"c",
".",
"client",
".",
"do",
"(",
"req",
",",
"&",
"status",
")",
"\n\n",
"return",
"status",
",",
"err",
"\n\n",
"}"
] | // Withdraw a cryptocurrency to a digital wallet | [
"Withdraw",
"a",
"cryptocurrency",
"to",
"a",
"digital",
"wallet"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/wallet.go#L50-L71 |
152,190 | bitfinexcom/bitfinex-api-go | v2/rest/ledgers.go | Ledgers | func (s *LedgerService) Ledgers(currency string, start int64, end int64, max int32) (*bitfinex.LedgerSnapshot, error) {
if max > 500 {
return nil, fmt.Errorf("Max request limit is higher then 500 : %#v", max)
}
req, err := s.requestFactory.NewAuthenticatedRequestWithData(path.Join("ledgers", currency, "hist"), map[string]interface{}{"start": start, "end": end, "limit": max})
if err != nil {
return nil, err
}
raw, err := s.Request(req)
if err != nil {
return nil, err
}
os, err := bitfinex.NewLedgerSnapshotFromRaw(raw)
if err != nil {
return nil, err
}
return os, nil
} | go | func (s *LedgerService) Ledgers(currency string, start int64, end int64, max int32) (*bitfinex.LedgerSnapshot, error) {
if max > 500 {
return nil, fmt.Errorf("Max request limit is higher then 500 : %#v", max)
}
req, err := s.requestFactory.NewAuthenticatedRequestWithData(path.Join("ledgers", currency, "hist"), map[string]interface{}{"start": start, "end": end, "limit": max})
if err != nil {
return nil, err
}
raw, err := s.Request(req)
if err != nil {
return nil, err
}
os, err := bitfinex.NewLedgerSnapshotFromRaw(raw)
if err != nil {
return nil, err
}
return os, nil
} | [
"func",
"(",
"s",
"*",
"LedgerService",
")",
"Ledgers",
"(",
"currency",
"string",
",",
"start",
"int64",
",",
"end",
"int64",
",",
"max",
"int32",
")",
"(",
"*",
"bitfinex",
".",
"LedgerSnapshot",
",",
"error",
")",
"{",
"if",
"max",
">",
"500",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"max",
")",
"\n",
"}",
"\n\n",
"req",
",",
"err",
":=",
"s",
".",
"requestFactory",
".",
"NewAuthenticatedRequestWithData",
"(",
"path",
".",
"Join",
"(",
"\"",
"\"",
",",
"currency",
",",
"\"",
"\"",
")",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"start",
",",
"\"",
"\"",
":",
"end",
",",
"\"",
"\"",
":",
"max",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"raw",
",",
"err",
":=",
"s",
".",
"Request",
"(",
"req",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"os",
",",
"err",
":=",
"bitfinex",
".",
"NewLedgerSnapshotFromRaw",
"(",
"raw",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"os",
",",
"nil",
"\n",
"}"
] | // All returns all ledgers for the authenticated account. | [
"All",
"returns",
"all",
"ledgers",
"for",
"the",
"authenticated",
"account",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/rest/ledgers.go#L16-L36 |
152,191 | bitfinexcom/bitfinex-api-go | v1/pairs.go | All | func (p *PairsService) All() ([]string, error) {
req, err := p.client.newRequest("GET", "symbols", nil)
if err != nil {
return nil, err
}
var v []string
_, err = p.client.do(req, &v)
if err != nil {
return nil, err
}
return v, nil
} | go | func (p *PairsService) All() ([]string, error) {
req, err := p.client.newRequest("GET", "symbols", nil)
if err != nil {
return nil, err
}
var v []string
_, err = p.client.do(req, &v)
if err != nil {
return nil, err
}
return v, nil
} | [
"func",
"(",
"p",
"*",
"PairsService",
")",
"All",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"p",
".",
"client",
".",
"newRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"v",
"[",
"]",
"string",
"\n\n",
"_",
",",
"err",
"=",
"p",
".",
"client",
".",
"do",
"(",
"req",
",",
"&",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"v",
",",
"nil",
"\n",
"}"
] | // Get all Pair names as array of strings | [
"Get",
"all",
"Pair",
"names",
"as",
"array",
"of",
"strings"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/pairs.go#L8-L22 |
152,192 | bitfinexcom/bitfinex-api-go | v1/pairs.go | AllDetailed | func (p *PairsService) AllDetailed() ([]Pair, error) {
req, err := p.client.newRequest("GET", "symbols_details", nil)
if err != nil {
return nil, err
}
var v []Pair
_, err = p.client.do(req, &v)
if err != nil {
return nil, err
}
return v, nil
} | go | func (p *PairsService) AllDetailed() ([]Pair, error) {
req, err := p.client.newRequest("GET", "symbols_details", nil)
if err != nil {
return nil, err
}
var v []Pair
_, err = p.client.do(req, &v)
if err != nil {
return nil, err
}
return v, nil
} | [
"func",
"(",
"p",
"*",
"PairsService",
")",
"AllDetailed",
"(",
")",
"(",
"[",
"]",
"Pair",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"p",
".",
"client",
".",
"newRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"v",
"[",
"]",
"Pair",
"\n",
"_",
",",
"err",
"=",
"p",
".",
"client",
".",
"do",
"(",
"req",
",",
"&",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"v",
",",
"nil",
"\n",
"}"
] | // Return a list of detailed pairs | [
"Return",
"a",
"list",
"of",
"detailed",
"pairs"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/pairs.go#L37-L50 |
152,193 | bitfinexcom/bitfinex-api-go | v2/websocket/orderbook.go | copySide | func (ob *Orderbook) copySide(side []*bitfinex.BookUpdate) []bitfinex.BookUpdate {
ob.lock.RLock()
defer ob.lock.RUnlock()
var cpy []bitfinex.BookUpdate
for i := 0; i < len(side); i++ {
cpy = append(cpy, *side[i])
}
return cpy
} | go | func (ob *Orderbook) copySide(side []*bitfinex.BookUpdate) []bitfinex.BookUpdate {
ob.lock.RLock()
defer ob.lock.RUnlock()
var cpy []bitfinex.BookUpdate
for i := 0; i < len(side); i++ {
cpy = append(cpy, *side[i])
}
return cpy
} | [
"func",
"(",
"ob",
"*",
"Orderbook",
")",
"copySide",
"(",
"side",
"[",
"]",
"*",
"bitfinex",
".",
"BookUpdate",
")",
"[",
"]",
"bitfinex",
".",
"BookUpdate",
"{",
"ob",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"ob",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"var",
"cpy",
"[",
"]",
"bitfinex",
".",
"BookUpdate",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"side",
")",
";",
"i",
"++",
"{",
"cpy",
"=",
"append",
"(",
"cpy",
",",
"*",
"side",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"return",
"cpy",
"\n",
"}"
] | // return a dereferenced copy of an orderbook side. This is so consumers can access
// the book but not change the values that are used to generate the crc32 checksum | [
"return",
"a",
"dereferenced",
"copy",
"of",
"an",
"orderbook",
"side",
".",
"This",
"is",
"so",
"consumers",
"can",
"access",
"the",
"book",
"but",
"not",
"change",
"the",
"values",
"that",
"are",
"used",
"to",
"generate",
"the",
"crc32",
"checksum"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/websocket/orderbook.go#L21-L29 |
152,194 | bitfinexcom/bitfinex-api-go | v1/credits.go | All | func (c *CreditsService) All() ([]Credit, error) {
req, err := c.client.newAuthenticatedRequest("GET", "credits", nil)
if err != nil {
return nil, err
}
credits := make([]Credit, 0)
_, err = c.client.do(req, &credits)
if err != nil {
return nil, err
}
return credits, nil
} | go | func (c *CreditsService) All() ([]Credit, error) {
req, err := c.client.newAuthenticatedRequest("GET", "credits", nil)
if err != nil {
return nil, err
}
credits := make([]Credit, 0)
_, err = c.client.do(req, &credits)
if err != nil {
return nil, err
}
return credits, nil
} | [
"func",
"(",
"c",
"*",
"CreditsService",
")",
"All",
"(",
")",
"(",
"[",
"]",
"Credit",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"credits",
":=",
"make",
"(",
"[",
"]",
"Credit",
",",
"0",
")",
"\n",
"_",
",",
"err",
"=",
"c",
".",
"client",
".",
"do",
"(",
"req",
",",
"&",
"credits",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"credits",
",",
"nil",
"\n",
"}"
] | // Returns an array of Credit | [
"Returns",
"an",
"array",
"of",
"Credit"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/credits.go#L18-L31 |
152,195 | bitfinexcom/bitfinex-api-go | v1/positions.go | All | func (b *PositionsService) All() ([]Position, error) {
req, err := b.client.newAuthenticatedRequest("POST", "positions", nil)
if err != nil {
return nil, err
}
var positions []Position
_, err = b.client.do(req, &positions)
if err != nil {
return nil, err
}
return positions, nil
} | go | func (b *PositionsService) All() ([]Position, error) {
req, err := b.client.newAuthenticatedRequest("POST", "positions", nil)
if err != nil {
return nil, err
}
var positions []Position
_, err = b.client.do(req, &positions)
if err != nil {
return nil, err
}
return positions, nil
} | [
"func",
"(",
"b",
"*",
"PositionsService",
")",
"All",
"(",
")",
"(",
"[",
"]",
"Position",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"b",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"positions",
"[",
"]",
"Position",
"\n",
"_",
",",
"err",
"=",
"b",
".",
"client",
".",
"do",
"(",
"req",
",",
"&",
"positions",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"positions",
",",
"nil",
"\n",
"}"
] | // All - gets all positions | [
"All",
"-",
"gets",
"all",
"positions"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/positions.go#L35-L48 |
152,196 | bitfinexcom/bitfinex-api-go | v1/positions.go | Claim | func (b *PositionsService) Claim(positionId int, amount string) (Position, error) {
request := map[string]interface{}{
"position_id": positionId,
"amount": amount,
}
req, err := b.client.newAuthenticatedRequest("POST", "position/claim", request)
if err != nil {
return Position{}, err
}
var position = &Position{}
_, err = b.client.do(req, position)
if err != nil {
return Position{}, err
}
return *position, nil
} | go | func (b *PositionsService) Claim(positionId int, amount string) (Position, error) {
request := map[string]interface{}{
"position_id": positionId,
"amount": amount,
}
req, err := b.client.newAuthenticatedRequest("POST", "position/claim", request)
if err != nil {
return Position{}, err
}
var position = &Position{}
_, err = b.client.do(req, position)
if err != nil {
return Position{}, err
}
return *position, nil
} | [
"func",
"(",
"b",
"*",
"PositionsService",
")",
"Claim",
"(",
"positionId",
"int",
",",
"amount",
"string",
")",
"(",
"Position",
",",
"error",
")",
"{",
"request",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"positionId",
",",
"\"",
"\"",
":",
"amount",
",",
"}",
"\n\n",
"req",
",",
"err",
":=",
"b",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"request",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Position",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"position",
"=",
"&",
"Position",
"{",
"}",
"\n\n",
"_",
",",
"err",
"=",
"b",
".",
"client",
".",
"do",
"(",
"req",
",",
"position",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Position",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"*",
"position",
",",
"nil",
"\n",
"}"
] | // Claim a position | [
"Claim",
"a",
"position"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/positions.go#L51-L73 |
152,197 | bitfinexcom/bitfinex-api-go | v2/rest/orders.go | OrderTrades | func (s *OrderService) OrderTrades(symbol string, orderID int64) (*bitfinex.TradeExecutionUpdateSnapshot, error) {
if symbol == "" {
return nil, fmt.Errorf("symbol cannot be empty")
}
key := fmt.Sprintf("%s:%d", symbol, orderID)
req, err := s.requestFactory.NewAuthenticatedRequest(path.Join("order", key, "trades"))
if err != nil {
return nil, err
}
raw, err := s.Request(req)
if err != nil {
return nil, err
}
return bitfinex.NewTradeExecutionUpdateSnapshotFromRaw(raw)
} | go | func (s *OrderService) OrderTrades(symbol string, orderID int64) (*bitfinex.TradeExecutionUpdateSnapshot, error) {
if symbol == "" {
return nil, fmt.Errorf("symbol cannot be empty")
}
key := fmt.Sprintf("%s:%d", symbol, orderID)
req, err := s.requestFactory.NewAuthenticatedRequest(path.Join("order", key, "trades"))
if err != nil {
return nil, err
}
raw, err := s.Request(req)
if err != nil {
return nil, err
}
return bitfinex.NewTradeExecutionUpdateSnapshotFromRaw(raw)
} | [
"func",
"(",
"s",
"*",
"OrderService",
")",
"OrderTrades",
"(",
"symbol",
"string",
",",
"orderID",
"int64",
")",
"(",
"*",
"bitfinex",
".",
"TradeExecutionUpdateSnapshot",
",",
"error",
")",
"{",
"if",
"symbol",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"key",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"symbol",
",",
"orderID",
")",
"\n",
"req",
",",
"err",
":=",
"s",
".",
"requestFactory",
".",
"NewAuthenticatedRequest",
"(",
"path",
".",
"Join",
"(",
"\"",
"\"",
",",
"key",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"raw",
",",
"err",
":=",
"s",
".",
"Request",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"bitfinex",
".",
"NewTradeExecutionUpdateSnapshotFromRaw",
"(",
"raw",
")",
"\n",
"}"
] | // OrderTrades returns a set of executed trades related to an order. | [
"OrderTrades",
"returns",
"a",
"set",
"of",
"executed",
"trades",
"related",
"to",
"an",
"order",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v2/rest/orders.go#L79-L93 |
152,198 | bitfinexcom/bitfinex-api-go | v1/orders.go | CancelAll | func (s *OrderService) CancelAll() error {
req, err := s.client.newAuthenticatedRequest("POST", "order/cancel/all", nil)
if err != nil {
return err
}
_, err = s.client.do(req, nil)
if err != nil {
return err
}
return nil
} | go | func (s *OrderService) CancelAll() error {
req, err := s.client.newAuthenticatedRequest("POST", "order/cancel/all", nil)
if err != nil {
return err
}
_, err = s.client.do(req, nil)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"s",
"*",
"OrderService",
")",
"CancelAll",
"(",
")",
"error",
"{",
"req",
",",
"err",
":=",
"s",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"s",
".",
"client",
".",
"do",
"(",
"req",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // CancelAll active orders for the authenticated account. | [
"CancelAll",
"active",
"orders",
"for",
"the",
"authenticated",
"account",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/orders.go#L63-L75 |
152,199 | bitfinexcom/bitfinex-api-go | v1/orders.go | Create | func (s *OrderService) Create(symbol string, amount float64, price float64, orderType string) (*Order, error) {
var side string
if amount < 0 {
amount = math.Abs(amount)
side = "sell"
} else {
side = "buy"
}
payload := map[string]interface{}{
"symbol": symbol,
"amount": strconv.FormatFloat(amount, 'f', -1, 32),
"price": strconv.FormatFloat(price, 'f', -1, 32),
"side": side,
"type": orderType,
"exchange": "bitfinex",
}
req, err := s.client.newAuthenticatedRequest("POST", "order/new", payload)
if err != nil {
return nil, err
}
order := new(Order)
_, err = s.client.do(req, order)
if err != nil {
return nil, err
}
return order, nil
} | go | func (s *OrderService) Create(symbol string, amount float64, price float64, orderType string) (*Order, error) {
var side string
if amount < 0 {
amount = math.Abs(amount)
side = "sell"
} else {
side = "buy"
}
payload := map[string]interface{}{
"symbol": symbol,
"amount": strconv.FormatFloat(amount, 'f', -1, 32),
"price": strconv.FormatFloat(price, 'f', -1, 32),
"side": side,
"type": orderType,
"exchange": "bitfinex",
}
req, err := s.client.newAuthenticatedRequest("POST", "order/new", payload)
if err != nil {
return nil, err
}
order := new(Order)
_, err = s.client.do(req, order)
if err != nil {
return nil, err
}
return order, nil
} | [
"func",
"(",
"s",
"*",
"OrderService",
")",
"Create",
"(",
"symbol",
"string",
",",
"amount",
"float64",
",",
"price",
"float64",
",",
"orderType",
"string",
")",
"(",
"*",
"Order",
",",
"error",
")",
"{",
"var",
"side",
"string",
"\n",
"if",
"amount",
"<",
"0",
"{",
"amount",
"=",
"math",
".",
"Abs",
"(",
"amount",
")",
"\n",
"side",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"side",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"payload",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"symbol",
",",
"\"",
"\"",
":",
"strconv",
".",
"FormatFloat",
"(",
"amount",
",",
"'f'",
",",
"-",
"1",
",",
"32",
")",
",",
"\"",
"\"",
":",
"strconv",
".",
"FormatFloat",
"(",
"price",
",",
"'f'",
",",
"-",
"1",
",",
"32",
")",
",",
"\"",
"\"",
":",
"side",
",",
"\"",
"\"",
":",
"orderType",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
"\n\n",
"req",
",",
"err",
":=",
"s",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"payload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"order",
":=",
"new",
"(",
"Order",
")",
"\n",
"_",
",",
"err",
"=",
"s",
".",
"client",
".",
"do",
"(",
"req",
",",
"order",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"order",
",",
"nil",
"\n",
"}"
] | // Create a new order. | [
"Create",
"a",
"new",
"order",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/orders.go#L78-L108 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.