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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
11,400 | messagebird/go-rest-api | conversation/api.go | UnmarshalJSON | func (c *Contact) UnmarshalJSON(data []byte) error {
target := struct {
ID string
Href string
MSISDN json.Number
FirstName string
LastName string
CustomDetails map[string]interface{}
CreatedAt *time.Time
UpdatedAt *time.Time
}{}
if err := json.Unmarshal(data, &target); err != nil {
return err
}
// In many cases, the CustomDetails will contain the user ID. As
// CustomDetails has interface{} values, these are unmarshalled as floats.
// Convert them to int64.
// Map key is not a typo: API returns userId and not userID.
if val, ok := target.CustomDetails["userId"]; ok {
var userID float64
if userID, ok = val.(float64); ok {
target.CustomDetails["userId"] = int64(userID)
}
}
*c = Contact{
target.ID,
target.Href,
target.MSISDN.String(),
target.FirstName,
target.LastName,
target.CustomDetails,
target.CreatedAt,
target.UpdatedAt,
}
return nil
} | go | func (c *Contact) UnmarshalJSON(data []byte) error {
target := struct {
ID string
Href string
MSISDN json.Number
FirstName string
LastName string
CustomDetails map[string]interface{}
CreatedAt *time.Time
UpdatedAt *time.Time
}{}
if err := json.Unmarshal(data, &target); err != nil {
return err
}
// In many cases, the CustomDetails will contain the user ID. As
// CustomDetails has interface{} values, these are unmarshalled as floats.
// Convert them to int64.
// Map key is not a typo: API returns userId and not userID.
if val, ok := target.CustomDetails["userId"]; ok {
var userID float64
if userID, ok = val.(float64); ok {
target.CustomDetails["userId"] = int64(userID)
}
}
*c = Contact{
target.ID,
target.Href,
target.MSISDN.String(),
target.FirstName,
target.LastName,
target.CustomDetails,
target.CreatedAt,
target.UpdatedAt,
}
return nil
} | [
"func",
"(",
"c",
"*",
"Contact",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"target",
":=",
"struct",
"{",
"ID",
"string",
"\n",
"Href",
"string",
"\n",
"MSISDN",
"json",
".",
"Number",
"\n",
"FirstName",
"string",
"\n",
"LastName",
"string",
"\n",
"CustomDetails",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"CreatedAt",
"*",
"time",
".",
"Time",
"\n",
"UpdatedAt",
"*",
"time",
".",
"Time",
"\n",
"}",
"{",
"}",
"\n\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"target",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// In many cases, the CustomDetails will contain the user ID. As",
"// CustomDetails has interface{} values, these are unmarshalled as floats.",
"// Convert them to int64.",
"// Map key is not a typo: API returns userId and not userID.",
"if",
"val",
",",
"ok",
":=",
"target",
".",
"CustomDetails",
"[",
"\"",
"\"",
"]",
";",
"ok",
"{",
"var",
"userID",
"float64",
"\n",
"if",
"userID",
",",
"ok",
"=",
"val",
".",
"(",
"float64",
")",
";",
"ok",
"{",
"target",
".",
"CustomDetails",
"[",
"\"",
"\"",
"]",
"=",
"int64",
"(",
"userID",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"*",
"c",
"=",
"Contact",
"{",
"target",
".",
"ID",
",",
"target",
".",
"Href",
",",
"target",
".",
"MSISDN",
".",
"String",
"(",
")",
",",
"target",
".",
"FirstName",
",",
"target",
".",
"LastName",
",",
"target",
".",
"CustomDetails",
",",
"target",
".",
"CreatedAt",
",",
"target",
".",
"UpdatedAt",
",",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON is used to unmarshal the MSISDN to a string rather than an
// int64. The API returns integers, but this client always uses strings.
// Exposing a json.Number doesn't seem nice. | [
"UnmarshalJSON",
"is",
"used",
"to",
"unmarshal",
"the",
"MSISDN",
"to",
"a",
"string",
"rather",
"than",
"an",
"int64",
".",
"The",
"API",
"returns",
"integers",
"but",
"this",
"client",
"always",
"uses",
"strings",
".",
"Exposing",
"a",
"json",
".",
"Number",
"doesn",
"t",
"seem",
"nice",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/conversation/api.go#L224-L263 |
11,401 | messagebird/go-rest-api | conversation/webhook.go | CreateWebhook | func CreateWebhook(c *messagebird.Client, req *WebhookCreateRequest) (*Webhook, error) {
webhook := &Webhook{}
if err := request(c, webhook, http.MethodPost, webhooksPath, req); err != nil {
return nil, err
}
return webhook, nil
} | go | func CreateWebhook(c *messagebird.Client, req *WebhookCreateRequest) (*Webhook, error) {
webhook := &Webhook{}
if err := request(c, webhook, http.MethodPost, webhooksPath, req); err != nil {
return nil, err
}
return webhook, nil
} | [
"func",
"CreateWebhook",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"req",
"*",
"WebhookCreateRequest",
")",
"(",
"*",
"Webhook",
",",
"error",
")",
"{",
"webhook",
":=",
"&",
"Webhook",
"{",
"}",
"\n",
"if",
"err",
":=",
"request",
"(",
"c",
",",
"webhook",
",",
"http",
".",
"MethodPost",
",",
"webhooksPath",
",",
"req",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"webhook",
",",
"nil",
"\n",
"}"
] | // CreateWebhook registers a webhook that is invoked when something interesting
// happens. | [
"CreateWebhook",
"registers",
"a",
"webhook",
"that",
"is",
"invoked",
"when",
"something",
"interesting",
"happens",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/conversation/webhook.go#L17-L24 |
11,402 | messagebird/go-rest-api | conversation/webhook.go | DeleteWebhook | func DeleteWebhook(c *messagebird.Client, id string) error {
return request(c, nil, http.MethodDelete, webhooksPath+"/"+id, nil)
} | go | func DeleteWebhook(c *messagebird.Client, id string) error {
return request(c, nil, http.MethodDelete, webhooksPath+"/"+id, nil)
} | [
"func",
"DeleteWebhook",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"id",
"string",
")",
"error",
"{",
"return",
"request",
"(",
"c",
",",
"nil",
",",
"http",
".",
"MethodDelete",
",",
"webhooksPath",
"+",
"\"",
"\"",
"+",
"id",
",",
"nil",
")",
"\n",
"}"
] | // DeleteWebhook ensures an existing webhook is deleted and no longer
// triggered. If the error is nil, the deletion was successful. | [
"DeleteWebhook",
"ensures",
"an",
"existing",
"webhook",
"is",
"deleted",
"and",
"no",
"longer",
"triggered",
".",
"If",
"the",
"error",
"is",
"nil",
"the",
"deletion",
"was",
"successful",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/conversation/webhook.go#L28-L30 |
11,403 | messagebird/go-rest-api | conversation/webhook.go | ListWebhooks | func ListWebhooks(c *messagebird.Client, options *ListOptions) (*WebhookList, error) {
query := paginationQuery(options)
webhookList := &WebhookList{}
if err := request(c, webhookList, http.MethodGet, webhooksPath+"?"+query, nil); err != nil {
return nil, err
}
return webhookList, nil
} | go | func ListWebhooks(c *messagebird.Client, options *ListOptions) (*WebhookList, error) {
query := paginationQuery(options)
webhookList := &WebhookList{}
if err := request(c, webhookList, http.MethodGet, webhooksPath+"?"+query, nil); err != nil {
return nil, err
}
return webhookList, nil
} | [
"func",
"ListWebhooks",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"options",
"*",
"ListOptions",
")",
"(",
"*",
"WebhookList",
",",
"error",
")",
"{",
"query",
":=",
"paginationQuery",
"(",
"options",
")",
"\n\n",
"webhookList",
":=",
"&",
"WebhookList",
"{",
"}",
"\n",
"if",
"err",
":=",
"request",
"(",
"c",
",",
"webhookList",
",",
"http",
".",
"MethodGet",
",",
"webhooksPath",
"+",
"\"",
"\"",
"+",
"query",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"webhookList",
",",
"nil",
"\n",
"}"
] | // ListWebhooks gets a collection of webhooks. Pagination can be set in options. | [
"ListWebhooks",
"gets",
"a",
"collection",
"of",
"webhooks",
".",
"Pagination",
"can",
"be",
"set",
"in",
"options",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/conversation/webhook.go#L33-L42 |
11,404 | messagebird/go-rest-api | conversation/webhook.go | ReadWebhook | func ReadWebhook(c *messagebird.Client, id string) (*Webhook, error) {
webhook := &Webhook{}
if err := request(c, webhook, http.MethodGet, webhooksPath+"/"+id, nil); err != nil {
return nil, err
}
return webhook, nil
} | go | func ReadWebhook(c *messagebird.Client, id string) (*Webhook, error) {
webhook := &Webhook{}
if err := request(c, webhook, http.MethodGet, webhooksPath+"/"+id, nil); err != nil {
return nil, err
}
return webhook, nil
} | [
"func",
"ReadWebhook",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"id",
"string",
")",
"(",
"*",
"Webhook",
",",
"error",
")",
"{",
"webhook",
":=",
"&",
"Webhook",
"{",
"}",
"\n",
"if",
"err",
":=",
"request",
"(",
"c",
",",
"webhook",
",",
"http",
".",
"MethodGet",
",",
"webhooksPath",
"+",
"\"",
"\"",
"+",
"id",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"webhook",
",",
"nil",
"\n",
"}"
] | // ReadWebhook gets a single webhook based on its ID. | [
"ReadWebhook",
"gets",
"a",
"single",
"webhook",
"based",
"on",
"its",
"ID",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/conversation/webhook.go#L45-L52 |
11,405 | messagebird/go-rest-api | conversation/hsm.go | CurrencyLocalizableHSMParameter | func CurrencyLocalizableHSMParameter(d string, code string, amount int64) *HSMLocalizableParameter {
return &HSMLocalizableParameter{
Default: d,
Currency: &HSMLocalizableParameterCurrency{
Code: code,
Amount: amount,
},
}
} | go | func CurrencyLocalizableHSMParameter(d string, code string, amount int64) *HSMLocalizableParameter {
return &HSMLocalizableParameter{
Default: d,
Currency: &HSMLocalizableParameterCurrency{
Code: code,
Amount: amount,
},
}
} | [
"func",
"CurrencyLocalizableHSMParameter",
"(",
"d",
"string",
",",
"code",
"string",
",",
"amount",
"int64",
")",
"*",
"HSMLocalizableParameter",
"{",
"return",
"&",
"HSMLocalizableParameter",
"{",
"Default",
":",
"d",
",",
"Currency",
":",
"&",
"HSMLocalizableParameterCurrency",
"{",
"Code",
":",
"code",
",",
"Amount",
":",
"amount",
",",
"}",
",",
"}",
"\n",
"}"
] | // CurrencyLocalizableHSMParameter gets a parameter that localizes a currency.
// Code is the currency code in ISO 4217 format and amount is the total amount,
// including cents, multiplied by 1000. E.g. 12.34 becomes 12340. | [
"CurrencyLocalizableHSMParameter",
"gets",
"a",
"parameter",
"that",
"localizes",
"a",
"currency",
".",
"Code",
"is",
"the",
"currency",
"code",
"in",
"ISO",
"4217",
"format",
"and",
"amount",
"is",
"the",
"total",
"amount",
"including",
"cents",
"multiplied",
"by",
"1000",
".",
"E",
".",
"g",
".",
"12",
".",
"34",
"becomes",
"12340",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/conversation/hsm.go#L70-L78 |
11,406 | messagebird/go-rest-api | conversation/hsm.go | DateTimeLocalizableHSMParameter | func DateTimeLocalizableHSMParameter(d string, dateTime time.Time) *HSMLocalizableParameter {
return &HSMLocalizableParameter{
Default: d,
DateTime: &dateTime,
}
} | go | func DateTimeLocalizableHSMParameter(d string, dateTime time.Time) *HSMLocalizableParameter {
return &HSMLocalizableParameter{
Default: d,
DateTime: &dateTime,
}
} | [
"func",
"DateTimeLocalizableHSMParameter",
"(",
"d",
"string",
",",
"dateTime",
"time",
".",
"Time",
")",
"*",
"HSMLocalizableParameter",
"{",
"return",
"&",
"HSMLocalizableParameter",
"{",
"Default",
":",
"d",
",",
"DateTime",
":",
"&",
"dateTime",
",",
"}",
"\n",
"}"
] | // DateTimeLocalizableHSMParameter gets a parameter that localizes a DateTime. | [
"DateTimeLocalizableHSMParameter",
"gets",
"a",
"parameter",
"that",
"localizes",
"a",
"DateTime",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/conversation/hsm.go#L81-L86 |
11,407 | messagebird/go-rest-api | voicemessage/voice_message.go | Read | func Read(c *messagebird.Client, id string) (*VoiceMessage, error) {
message := &VoiceMessage{}
if err := c.Request(message, http.MethodGet, path+"/"+id, nil); err != nil {
return nil, err
}
return message, nil
} | go | func Read(c *messagebird.Client, id string) (*VoiceMessage, error) {
message := &VoiceMessage{}
if err := c.Request(message, http.MethodGet, path+"/"+id, nil); err != nil {
return nil, err
}
return message, nil
} | [
"func",
"Read",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"id",
"string",
")",
"(",
"*",
"VoiceMessage",
",",
"error",
")",
"{",
"message",
":=",
"&",
"VoiceMessage",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"Request",
"(",
"message",
",",
"http",
".",
"MethodGet",
",",
"path",
"+",
"\"",
"\"",
"+",
"id",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"message",
",",
"nil",
"\n",
"}"
] | // Read retrieves the information of an existing VoiceMessage. | [
"Read",
"retrieves",
"the",
"information",
"of",
"an",
"existing",
"VoiceMessage",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voicemessage/voice_message.go#L65-L72 |
11,408 | messagebird/go-rest-api | voicemessage/voice_message.go | List | func List(c *messagebird.Client) (*VoiceMessageList, error) {
messageList := &VoiceMessageList{}
if err := c.Request(messageList, http.MethodGet, path, nil); err != nil {
return nil, err
}
return messageList, nil
} | go | func List(c *messagebird.Client) (*VoiceMessageList, error) {
messageList := &VoiceMessageList{}
if err := c.Request(messageList, http.MethodGet, path, nil); err != nil {
return nil, err
}
return messageList, nil
} | [
"func",
"List",
"(",
"c",
"*",
"messagebird",
".",
"Client",
")",
"(",
"*",
"VoiceMessageList",
",",
"error",
")",
"{",
"messageList",
":=",
"&",
"VoiceMessageList",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"Request",
"(",
"messageList",
",",
"http",
".",
"MethodGet",
",",
"path",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"messageList",
",",
"nil",
"\n",
"}"
] | // List retrieves all VoiceMessages of the user. | [
"List",
"retrieves",
"all",
"VoiceMessages",
"of",
"the",
"user",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voicemessage/voice_message.go#L75-L82 |
11,409 | messagebird/go-rest-api | voicemessage/voice_message.go | Create | func Create(c *messagebird.Client, recipients []string, body string, params *Params) (*VoiceMessage, error) {
requestData, err := requestDataForVoiceMessage(recipients, body, params)
if err != nil {
return nil, err
}
message := &VoiceMessage{}
if err := c.Request(message, http.MethodPost, path, requestData); err != nil {
return nil, err
}
return message, nil
} | go | func Create(c *messagebird.Client, recipients []string, body string, params *Params) (*VoiceMessage, error) {
requestData, err := requestDataForVoiceMessage(recipients, body, params)
if err != nil {
return nil, err
}
message := &VoiceMessage{}
if err := c.Request(message, http.MethodPost, path, requestData); err != nil {
return nil, err
}
return message, nil
} | [
"func",
"Create",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"recipients",
"[",
"]",
"string",
",",
"body",
"string",
",",
"params",
"*",
"Params",
")",
"(",
"*",
"VoiceMessage",
",",
"error",
")",
"{",
"requestData",
",",
"err",
":=",
"requestDataForVoiceMessage",
"(",
"recipients",
",",
"body",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"message",
":=",
"&",
"VoiceMessage",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"Request",
"(",
"message",
",",
"http",
".",
"MethodPost",
",",
"path",
",",
"requestData",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"message",
",",
"nil",
"\n",
"}"
] | // Create a new voice message for one or more recipients. | [
"Create",
"a",
"new",
"voice",
"message",
"for",
"one",
"or",
"more",
"recipients",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voicemessage/voice_message.go#L85-L97 |
11,410 | messagebird/go-rest-api | voice/webhook.go | Webhooks | func Webhooks(client *messagebird.Client) *Paginator {
return newPaginator(client, apiRoot+"/webhooks/", reflect.TypeOf(Webhook{}))
} | go | func Webhooks(client *messagebird.Client) *Paginator {
return newPaginator(client, apiRoot+"/webhooks/", reflect.TypeOf(Webhook{}))
} | [
"func",
"Webhooks",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"*",
"Paginator",
"{",
"return",
"newPaginator",
"(",
"client",
",",
"apiRoot",
"+",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"Webhook",
"{",
"}",
")",
")",
"\n",
"}"
] | // Webhooks returns a paginator over all webhooks. | [
"Webhooks",
"returns",
"a",
"paginator",
"over",
"all",
"webhooks",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/webhook.go#L68-L70 |
11,411 | messagebird/go-rest-api | voice/webhook.go | CreateWebHook | func CreateWebHook(client *messagebird.Client, url, token string) (*Webhook, error) {
data := struct {
URL string `json:"url"`
Token string `json:"token,omitempty"`
}{
URL: url,
Token: token,
}
var resp struct {
Data []Webhook `json:"data"`
}
if err := client.Request(&resp, http.MethodPost, apiRoot+"/webhooks/", data); err != nil {
return nil, err
}
return &resp.Data[0], nil
} | go | func CreateWebHook(client *messagebird.Client, url, token string) (*Webhook, error) {
data := struct {
URL string `json:"url"`
Token string `json:"token,omitempty"`
}{
URL: url,
Token: token,
}
var resp struct {
Data []Webhook `json:"data"`
}
if err := client.Request(&resp, http.MethodPost, apiRoot+"/webhooks/", data); err != nil {
return nil, err
}
return &resp.Data[0], nil
} | [
"func",
"CreateWebHook",
"(",
"client",
"*",
"messagebird",
".",
"Client",
",",
"url",
",",
"token",
"string",
")",
"(",
"*",
"Webhook",
",",
"error",
")",
"{",
"data",
":=",
"struct",
"{",
"URL",
"string",
"`json:\"url\"`",
"\n",
"Token",
"string",
"`json:\"token,omitempty\"`",
"\n",
"}",
"{",
"URL",
":",
"url",
",",
"Token",
":",
"token",
",",
"}",
"\n",
"var",
"resp",
"struct",
"{",
"Data",
"[",
"]",
"Webhook",
"`json:\"data\"`",
"\n",
"}",
"\n",
"if",
"err",
":=",
"client",
".",
"Request",
"(",
"&",
"resp",
",",
"http",
".",
"MethodPost",
",",
"apiRoot",
"+",
"\"",
"\"",
",",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"resp",
".",
"Data",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | // CreateWebHook creates a new webhook the specified url that will be called
// and security token. | [
"CreateWebHook",
"creates",
"a",
"new",
"webhook",
"the",
"specified",
"url",
"that",
"will",
"be",
"called",
"and",
"security",
"token",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/webhook.go#L74-L89 |
11,412 | messagebird/go-rest-api | voice/webhook.go | Update | func (wh *Webhook) Update(client *messagebird.Client) error {
var data struct {
Data []Webhook `json:"data"`
}
if err := client.Request(&data, http.MethodPut, apiRoot+"/webhooks/"+wh.ID, wh); err != nil {
return err
}
*wh = data.Data[0]
return nil
} | go | func (wh *Webhook) Update(client *messagebird.Client) error {
var data struct {
Data []Webhook `json:"data"`
}
if err := client.Request(&data, http.MethodPut, apiRoot+"/webhooks/"+wh.ID, wh); err != nil {
return err
}
*wh = data.Data[0]
return nil
} | [
"func",
"(",
"wh",
"*",
"Webhook",
")",
"Update",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"error",
"{",
"var",
"data",
"struct",
"{",
"Data",
"[",
"]",
"Webhook",
"`json:\"data\"`",
"\n",
"}",
"\n",
"if",
"err",
":=",
"client",
".",
"Request",
"(",
"&",
"data",
",",
"http",
".",
"MethodPut",
",",
"apiRoot",
"+",
"\"",
"\"",
"+",
"wh",
".",
"ID",
",",
"wh",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"wh",
"=",
"data",
".",
"Data",
"[",
"0",
"]",
"\n",
"return",
"nil",
"\n",
"}"
] | // Update syncs hte local state of a webhook to the MessageBird API. | [
"Update",
"syncs",
"hte",
"local",
"state",
"of",
"a",
"webhook",
"to",
"the",
"MessageBird",
"API",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/webhook.go#L92-L101 |
11,413 | messagebird/go-rest-api | voice/webhook.go | Delete | func (wh *Webhook) Delete(client *messagebird.Client) error {
return client.Request(nil, http.MethodDelete, apiRoot+"/webhooks/"+wh.ID, nil)
} | go | func (wh *Webhook) Delete(client *messagebird.Client) error {
return client.Request(nil, http.MethodDelete, apiRoot+"/webhooks/"+wh.ID, nil)
} | [
"func",
"(",
"wh",
"*",
"Webhook",
")",
"Delete",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"error",
"{",
"return",
"client",
".",
"Request",
"(",
"nil",
",",
"http",
".",
"MethodDelete",
",",
"apiRoot",
"+",
"\"",
"\"",
"+",
"wh",
".",
"ID",
",",
"nil",
")",
"\n",
"}"
] | // Delete deletes a webhook. | [
"Delete",
"deletes",
"a",
"webhook",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/webhook.go#L104-L106 |
11,414 | messagebird/go-rest-api | group/group.go | List | func List(c *messagebird.Client, options *ListOptions) (*GroupList, error) {
query, err := listQuery(options)
if err != nil {
return nil, err
}
groupList := &GroupList{}
if err := c.Request(groupList, http.MethodGet, path+"?"+query, nil); err != nil {
return nil, err
}
return groupList, nil
} | go | func List(c *messagebird.Client, options *ListOptions) (*GroupList, error) {
query, err := listQuery(options)
if err != nil {
return nil, err
}
groupList := &GroupList{}
if err := c.Request(groupList, http.MethodGet, path+"?"+query, nil); err != nil {
return nil, err
}
return groupList, nil
} | [
"func",
"List",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"options",
"*",
"ListOptions",
")",
"(",
"*",
"GroupList",
",",
"error",
")",
"{",
"query",
",",
"err",
":=",
"listQuery",
"(",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"groupList",
":=",
"&",
"GroupList",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"Request",
"(",
"groupList",
",",
"http",
".",
"MethodGet",
",",
"path",
"+",
"\"",
"\"",
"+",
"query",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"groupList",
",",
"nil",
"\n",
"}"
] | // List retrieves a paginated list of groups, based on the options provided.
// It's worth noting DefaultListOptions. | [
"List",
"retrieves",
"a",
"paginated",
"list",
"of",
"groups",
"based",
"on",
"the",
"options",
"provided",
".",
"It",
"s",
"worth",
"noting",
"DefaultListOptions",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/group/group.go#L101-L113 |
11,415 | messagebird/go-rest-api | group/group.go | Read | func Read(c *messagebird.Client, id string) (*Group, error) {
group := &Group{}
if err := c.Request(group, http.MethodGet, path+"/"+id, nil); err != nil {
return nil, err
}
return group, nil
} | go | func Read(c *messagebird.Client, id string) (*Group, error) {
group := &Group{}
if err := c.Request(group, http.MethodGet, path+"/"+id, nil); err != nil {
return nil, err
}
return group, nil
} | [
"func",
"Read",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"id",
"string",
")",
"(",
"*",
"Group",
",",
"error",
")",
"{",
"group",
":=",
"&",
"Group",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"Request",
"(",
"group",
",",
"http",
".",
"MethodGet",
",",
"path",
"+",
"\"",
"\"",
"+",
"id",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"group",
",",
"nil",
"\n",
"}"
] | // Read retrieves the information of an existing group. | [
"Read",
"retrieves",
"the",
"information",
"of",
"an",
"existing",
"group",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/group/group.go#L132-L139 |
11,416 | messagebird/go-rest-api | group/group.go | Update | func Update(c *messagebird.Client, id string, request *Request) error {
if err := validateUpdate(request); err != nil {
return err
}
return c.Request(nil, http.MethodPatch, path+"/"+id, request)
} | go | func Update(c *messagebird.Client, id string, request *Request) error {
if err := validateUpdate(request); err != nil {
return err
}
return c.Request(nil, http.MethodPatch, path+"/"+id, request)
} | [
"func",
"Update",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"id",
"string",
",",
"request",
"*",
"Request",
")",
"error",
"{",
"if",
"err",
":=",
"validateUpdate",
"(",
"request",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"Request",
"(",
"nil",
",",
"http",
".",
"MethodPatch",
",",
"path",
"+",
"\"",
"\"",
"+",
"id",
",",
"request",
")",
"\n",
"}"
] | // Update overrides the group with any values provided in request. | [
"Update",
"overrides",
"the",
"group",
"with",
"any",
"values",
"provided",
"in",
"request",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/group/group.go#L142-L148 |
11,417 | messagebird/go-rest-api | group/group.go | AddContacts | func AddContacts(c *messagebird.Client, groupID string, contactIDs []string) error {
if err := validateAddContacts(contactIDs); err != nil {
return err
}
data := addContactsData(contactIDs)
return c.Request(nil, http.MethodPut, path+"/"+groupID+"/"+contactPath, data)
} | go | func AddContacts(c *messagebird.Client, groupID string, contactIDs []string) error {
if err := validateAddContacts(contactIDs); err != nil {
return err
}
data := addContactsData(contactIDs)
return c.Request(nil, http.MethodPut, path+"/"+groupID+"/"+contactPath, data)
} | [
"func",
"AddContacts",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"groupID",
"string",
",",
"contactIDs",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"validateAddContacts",
"(",
"contactIDs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"data",
":=",
"addContactsData",
"(",
"contactIDs",
")",
"\n\n",
"return",
"c",
".",
"Request",
"(",
"nil",
",",
"http",
".",
"MethodPut",
",",
"path",
"+",
"\"",
"\"",
"+",
"groupID",
"+",
"\"",
"\"",
"+",
"contactPath",
",",
"data",
")",
"\n",
"}"
] | // AddContacts adds a maximum of 50 contacts to the group. | [
"AddContacts",
"adds",
"a",
"maximum",
"of",
"50",
"contacts",
"to",
"the",
"group",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/group/group.go#L159-L167 |
11,418 | messagebird/go-rest-api | group/group.go | ListContacts | func ListContacts(c *messagebird.Client, groupID string, options *ListOptions) (*contact.ContactList, error) {
query, err := listQuery(options)
if err != nil {
return nil, err
}
formattedPath := fmt.Sprintf("%s/%s/%s?%s", path, groupID, contactPath, query)
contacts := &contact.ContactList{}
if err = c.Request(contacts, http.MethodGet, formattedPath, nil); err != nil {
return nil, err
}
return contacts, nil
} | go | func ListContacts(c *messagebird.Client, groupID string, options *ListOptions) (*contact.ContactList, error) {
query, err := listQuery(options)
if err != nil {
return nil, err
}
formattedPath := fmt.Sprintf("%s/%s/%s?%s", path, groupID, contactPath, query)
contacts := &contact.ContactList{}
if err = c.Request(contacts, http.MethodGet, formattedPath, nil); err != nil {
return nil, err
}
return contacts, nil
} | [
"func",
"ListContacts",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"groupID",
"string",
",",
"options",
"*",
"ListOptions",
")",
"(",
"*",
"contact",
".",
"ContactList",
",",
"error",
")",
"{",
"query",
",",
"err",
":=",
"listQuery",
"(",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"formattedPath",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"path",
",",
"groupID",
",",
"contactPath",
",",
"query",
")",
"\n\n",
"contacts",
":=",
"&",
"contact",
".",
"ContactList",
"{",
"}",
"\n",
"if",
"err",
"=",
"c",
".",
"Request",
"(",
"contacts",
",",
"http",
".",
"MethodGet",
",",
"formattedPath",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"contacts",
",",
"nil",
"\n",
"}"
] | // ListContacts lists the contacts that are a member of a group. | [
"ListContacts",
"lists",
"the",
"contacts",
"that",
"are",
"a",
"member",
"of",
"a",
"group",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/group/group.go#L199-L213 |
11,419 | messagebird/go-rest-api | group/group.go | RemoveContact | func RemoveContact(c *messagebird.Client, groupID, contactID string) error {
formattedPath := fmt.Sprintf("%s/%s/contacts/%s", path, groupID, contactID)
return c.Request(nil, http.MethodDelete, formattedPath, nil)
} | go | func RemoveContact(c *messagebird.Client, groupID, contactID string) error {
formattedPath := fmt.Sprintf("%s/%s/contacts/%s", path, groupID, contactID)
return c.Request(nil, http.MethodDelete, formattedPath, nil)
} | [
"func",
"RemoveContact",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"groupID",
",",
"contactID",
"string",
")",
"error",
"{",
"formattedPath",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"path",
",",
"groupID",
",",
"contactID",
")",
"\n\n",
"return",
"c",
".",
"Request",
"(",
"nil",
",",
"http",
".",
"MethodDelete",
",",
"formattedPath",
",",
"nil",
")",
"\n",
"}"
] | // RemoveContact removes the contact from a group. If nil is returned, the
// operation was successful. | [
"RemoveContact",
"removes",
"the",
"contact",
"from",
"a",
"group",
".",
"If",
"nil",
"is",
"returned",
"the",
"operation",
"was",
"successful",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/group/group.go#L217-L221 |
11,420 | messagebird/go-rest-api | voice/paginator.go | newPaginator | func newPaginator(client *messagebird.Client, endpoint string, typ reflect.Type) *Paginator {
return &Paginator{
endpoint: endpoint,
nextPage: 1, // Page indices start at 1.
structType: typ,
client: client,
}
} | go | func newPaginator(client *messagebird.Client, endpoint string, typ reflect.Type) *Paginator {
return &Paginator{
endpoint: endpoint,
nextPage: 1, // Page indices start at 1.
structType: typ,
client: client,
}
} | [
"func",
"newPaginator",
"(",
"client",
"*",
"messagebird",
".",
"Client",
",",
"endpoint",
"string",
",",
"typ",
"reflect",
".",
"Type",
")",
"*",
"Paginator",
"{",
"return",
"&",
"Paginator",
"{",
"endpoint",
":",
"endpoint",
",",
"nextPage",
":",
"1",
",",
"// Page indices start at 1.",
"structType",
":",
"typ",
",",
"client",
":",
"client",
",",
"}",
"\n",
"}"
] | // newPaginator creates a new paginator.
//
// endpoint is called with the `page` query parameter until no more pages are
// available.
//
// typ is the non-pointer type of a single element returned by a page. | [
"newPaginator",
"creates",
"a",
"new",
"paginator",
".",
"endpoint",
"is",
"called",
"with",
"the",
"page",
"query",
"parameter",
"until",
"no",
"more",
"pages",
"are",
"available",
".",
"typ",
"is",
"the",
"non",
"-",
"pointer",
"type",
"of",
"a",
"single",
"element",
"returned",
"by",
"a",
"page",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/paginator.go#L29-L36 |
11,421 | messagebird/go-rest-api | voice/paginator.go | Stream | func (pag *Paginator) Stream() <-chan interface{} {
out := make(chan interface{})
go func() {
defer close(out)
for {
page, err := pag.NextPage()
if err != nil {
if err != io.EOF {
out <- err
}
break
}
v := reflect.ValueOf(page)
for i, l := 0, v.Len(); i < l; i++ {
out <- v.Index(i).Interface()
}
}
}()
return out
} | go | func (pag *Paginator) Stream() <-chan interface{} {
out := make(chan interface{})
go func() {
defer close(out)
for {
page, err := pag.NextPage()
if err != nil {
if err != io.EOF {
out <- err
}
break
}
v := reflect.ValueOf(page)
for i, l := 0, v.Len(); i < l; i++ {
out <- v.Index(i).Interface()
}
}
}()
return out
} | [
"func",
"(",
"pag",
"*",
"Paginator",
")",
"Stream",
"(",
")",
"<-",
"chan",
"interface",
"{",
"}",
"{",
"out",
":=",
"make",
"(",
"chan",
"interface",
"{",
"}",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"close",
"(",
"out",
")",
"\n",
"for",
"{",
"page",
",",
"err",
":=",
"pag",
".",
"NextPage",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"!=",
"io",
".",
"EOF",
"{",
"out",
"<-",
"err",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"page",
")",
"\n",
"for",
"i",
",",
"l",
":=",
"0",
",",
"v",
".",
"Len",
"(",
")",
";",
"i",
"<",
"l",
";",
"i",
"++",
"{",
"out",
"<-",
"v",
".",
"Index",
"(",
"i",
")",
".",
"Interface",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // Stream creates a channel which streams the contents of all remaining pages
// ony by one.
//
// The Paginator is consumed in the process, meaning that after elements have
// been received, NextPage will return EOF. It is invalid to mix calls to
// NextPage an Stream, even after the stream channel was closed.
//
// If an error occurs, the next item sent over the channel will be an error
// instead of a regular value. The channel is closed directly after this. | [
"Stream",
"creates",
"a",
"channel",
"which",
"streams",
"the",
"contents",
"of",
"all",
"remaining",
"pages",
"ony",
"by",
"one",
".",
"The",
"Paginator",
"is",
"consumed",
"in",
"the",
"process",
"meaning",
"that",
"after",
"elements",
"have",
"been",
"received",
"NextPage",
"will",
"return",
"EOF",
".",
"It",
"is",
"invalid",
"to",
"mix",
"calls",
"to",
"NextPage",
"an",
"Stream",
"even",
"after",
"the",
"stream",
"channel",
"was",
"closed",
".",
"If",
"an",
"error",
"occurs",
"the",
"next",
"item",
"sent",
"over",
"the",
"channel",
"will",
"be",
"an",
"error",
"instead",
"of",
"a",
"regular",
"value",
".",
"The",
"channel",
"is",
"closed",
"directly",
"after",
"this",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/paginator.go#L90-L109 |
11,422 | messagebird/go-rest-api | voice/callflow.go | CallFlowByID | func CallFlowByID(client *messagebird.Client, id string) (*CallFlow, error) {
var data struct {
Data []CallFlow `json:"data"`
}
if err := client.Request(&data, http.MethodGet, apiRoot+"/call-flows/"+id, nil); err != nil {
return nil, err
}
return &data.Data[0], nil
} | go | func CallFlowByID(client *messagebird.Client, id string) (*CallFlow, error) {
var data struct {
Data []CallFlow `json:"data"`
}
if err := client.Request(&data, http.MethodGet, apiRoot+"/call-flows/"+id, nil); err != nil {
return nil, err
}
return &data.Data[0], nil
} | [
"func",
"CallFlowByID",
"(",
"client",
"*",
"messagebird",
".",
"Client",
",",
"id",
"string",
")",
"(",
"*",
"CallFlow",
",",
"error",
")",
"{",
"var",
"data",
"struct",
"{",
"Data",
"[",
"]",
"CallFlow",
"`json:\"data\"`",
"\n",
"}",
"\n",
"if",
"err",
":=",
"client",
".",
"Request",
"(",
"&",
"data",
",",
"http",
".",
"MethodGet",
",",
"apiRoot",
"+",
"\"",
"\"",
"+",
"id",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"data",
".",
"Data",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | // CallFlowByID fetches a callflow by it's ID.
//
// An error is returned if no such call flow exists or is accessible. | [
"CallFlowByID",
"fetches",
"a",
"callflow",
"by",
"it",
"s",
"ID",
".",
"An",
"error",
"is",
"returned",
"if",
"no",
"such",
"call",
"flow",
"exists",
"or",
"is",
"accessible",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/callflow.go#L116-L124 |
11,423 | messagebird/go-rest-api | voice/callflow.go | CallFlows | func CallFlows(client *messagebird.Client) *Paginator {
return newPaginator(client, apiRoot+"/call-flows/", reflect.TypeOf(CallFlow{}))
} | go | func CallFlows(client *messagebird.Client) *Paginator {
return newPaginator(client, apiRoot+"/call-flows/", reflect.TypeOf(CallFlow{}))
} | [
"func",
"CallFlows",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"*",
"Paginator",
"{",
"return",
"newPaginator",
"(",
"client",
",",
"apiRoot",
"+",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"CallFlow",
"{",
"}",
")",
")",
"\n",
"}"
] | // CallFlows returns a Paginator which iterates over all CallFlows. | [
"CallFlows",
"returns",
"a",
"Paginator",
"which",
"iterates",
"over",
"all",
"CallFlows",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/callflow.go#L127-L129 |
11,424 | messagebird/go-rest-api | voice/callflow.go | Create | func (callflow *CallFlow) Create(client *messagebird.Client) error {
var data struct {
Data []CallFlow `json:"data"`
}
if err := client.Request(&data, http.MethodPost, apiRoot+"/call-flows/", callflow); err != nil {
return err
}
*callflow = data.Data[0]
return nil
} | go | func (callflow *CallFlow) Create(client *messagebird.Client) error {
var data struct {
Data []CallFlow `json:"data"`
}
if err := client.Request(&data, http.MethodPost, apiRoot+"/call-flows/", callflow); err != nil {
return err
}
*callflow = data.Data[0]
return nil
} | [
"func",
"(",
"callflow",
"*",
"CallFlow",
")",
"Create",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"error",
"{",
"var",
"data",
"struct",
"{",
"Data",
"[",
"]",
"CallFlow",
"`json:\"data\"`",
"\n",
"}",
"\n",
"if",
"err",
":=",
"client",
".",
"Request",
"(",
"&",
"data",
",",
"http",
".",
"MethodPost",
",",
"apiRoot",
"+",
"\"",
"\"",
",",
"callflow",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"callflow",
"=",
"data",
".",
"Data",
"[",
"0",
"]",
"\n",
"return",
"nil",
"\n",
"}"
] | // Create creates the callflow remotely.
//
// The callflow is updated in-place. | [
"Create",
"creates",
"the",
"callflow",
"remotely",
".",
"The",
"callflow",
"is",
"updated",
"in",
"-",
"place",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/callflow.go#L134-L143 |
11,425 | messagebird/go-rest-api | voice/callflow.go | Update | func (callflow *CallFlow) Update(client *messagebird.Client) error {
var data struct {
Data []CallFlow `json:"data"`
}
if err := client.Request(&data, http.MethodPut, apiRoot+"/call-flows/"+callflow.ID, callflow); err != nil {
return err
}
*callflow = data.Data[0]
return nil
} | go | func (callflow *CallFlow) Update(client *messagebird.Client) error {
var data struct {
Data []CallFlow `json:"data"`
}
if err := client.Request(&data, http.MethodPut, apiRoot+"/call-flows/"+callflow.ID, callflow); err != nil {
return err
}
*callflow = data.Data[0]
return nil
} | [
"func",
"(",
"callflow",
"*",
"CallFlow",
")",
"Update",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"error",
"{",
"var",
"data",
"struct",
"{",
"Data",
"[",
"]",
"CallFlow",
"`json:\"data\"`",
"\n",
"}",
"\n",
"if",
"err",
":=",
"client",
".",
"Request",
"(",
"&",
"data",
",",
"http",
".",
"MethodPut",
",",
"apiRoot",
"+",
"\"",
"\"",
"+",
"callflow",
".",
"ID",
",",
"callflow",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"callflow",
"=",
"data",
".",
"Data",
"[",
"0",
"]",
"\n",
"return",
"nil",
"\n",
"}"
] | // Update updates the call flow by overwriting it.
//
// An error is returned if no such call flow exists or is accessible. | [
"Update",
"updates",
"the",
"call",
"flow",
"by",
"overwriting",
"it",
".",
"An",
"error",
"is",
"returned",
"if",
"no",
"such",
"call",
"flow",
"exists",
"or",
"is",
"accessible",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/callflow.go#L148-L157 |
11,426 | messagebird/go-rest-api | voice/callflow.go | Delete | func (callflow *CallFlow) Delete(client *messagebird.Client) error {
return client.Request(nil, http.MethodDelete, apiRoot+"/call-flows/"+callflow.ID, nil)
} | go | func (callflow *CallFlow) Delete(client *messagebird.Client) error {
return client.Request(nil, http.MethodDelete, apiRoot+"/call-flows/"+callflow.ID, nil)
} | [
"func",
"(",
"callflow",
"*",
"CallFlow",
")",
"Delete",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"error",
"{",
"return",
"client",
".",
"Request",
"(",
"nil",
",",
"http",
".",
"MethodDelete",
",",
"apiRoot",
"+",
"\"",
"\"",
"+",
"callflow",
".",
"ID",
",",
"nil",
")",
"\n",
"}"
] | // Delete deletes the CallFlow. | [
"Delete",
"deletes",
"the",
"CallFlow",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/callflow.go#L160-L162 |
11,427 | messagebird/go-rest-api | signature/signature.go | stringToTime | func stringToTime(s string) (time.Time, error) {
sec, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return time.Time{}, err
}
return time.Unix(sec, 0), nil
} | go | func stringToTime(s string) (time.Time, error) {
sec, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return time.Time{}, err
}
return time.Unix(sec, 0), nil
} | [
"func",
"stringToTime",
"(",
"s",
"string",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"sec",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"s",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"time",
".",
"Unix",
"(",
"sec",
",",
"0",
")",
",",
"nil",
"\n",
"}"
] | // StringToTime converts from Unicode Epoch encoded timestamps to the time.Time type. | [
"StringToTime",
"converts",
"from",
"Unicode",
"Epoch",
"encoded",
"timestamps",
"to",
"the",
"time",
".",
"Time",
"type",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/signature/signature.go#L46-L52 |
11,428 | messagebird/go-rest-api | signature/signature.go | validTimestamp | func (v *Validator) validTimestamp(ts string) bool {
t, err := stringToTime(ts)
if err != nil {
return false
}
diff := time.Now().Add(ValidityWindow / 2).Sub(t)
return diff < ValidityWindow && diff > 0
} | go | func (v *Validator) validTimestamp(ts string) bool {
t, err := stringToTime(ts)
if err != nil {
return false
}
diff := time.Now().Add(ValidityWindow / 2).Sub(t)
return diff < ValidityWindow && diff > 0
} | [
"func",
"(",
"v",
"*",
"Validator",
")",
"validTimestamp",
"(",
"ts",
"string",
")",
"bool",
"{",
"t",
",",
"err",
":=",
"stringToTime",
"(",
"ts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"diff",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"ValidityWindow",
"/",
"2",
")",
".",
"Sub",
"(",
"t",
")",
"\n",
"return",
"diff",
"<",
"ValidityWindow",
"&&",
"diff",
">",
"0",
"\n",
"}"
] | // validTimestamp validates if the MessageBird-Request-Timestamp is a valid
// date and if the request is older than the validator Period. | [
"validTimestamp",
"validates",
"if",
"the",
"MessageBird",
"-",
"Request",
"-",
"Timestamp",
"is",
"a",
"valid",
"date",
"and",
"if",
"the",
"request",
"is",
"older",
"than",
"the",
"validator",
"Period",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/signature/signature.go#L68-L75 |
11,429 | messagebird/go-rest-api | signature/signature.go | validSignature | func (v *Validator) validSignature(ts, rqp string, b []byte, rs string) bool {
uqp, err := url.Parse("?" + rqp)
if err != nil {
return false
}
es, err := v.calculateSignature(ts, uqp.Query().Encode(), b)
if err != nil {
return false
}
drs, err := base64.StdEncoding.DecodeString(rs)
if err != nil {
return false
}
return hmac.Equal(drs, es)
} | go | func (v *Validator) validSignature(ts, rqp string, b []byte, rs string) bool {
uqp, err := url.Parse("?" + rqp)
if err != nil {
return false
}
es, err := v.calculateSignature(ts, uqp.Query().Encode(), b)
if err != nil {
return false
}
drs, err := base64.StdEncoding.DecodeString(rs)
if err != nil {
return false
}
return hmac.Equal(drs, es)
} | [
"func",
"(",
"v",
"*",
"Validator",
")",
"validSignature",
"(",
"ts",
",",
"rqp",
"string",
",",
"b",
"[",
"]",
"byte",
",",
"rs",
"string",
")",
"bool",
"{",
"uqp",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"\"",
"\"",
"+",
"rqp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"es",
",",
"err",
":=",
"v",
".",
"calculateSignature",
"(",
"ts",
",",
"uqp",
".",
"Query",
"(",
")",
".",
"Encode",
"(",
")",
",",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"drs",
",",
"err",
":=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"rs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"hmac",
".",
"Equal",
"(",
"drs",
",",
"es",
")",
"\n",
"}"
] | // validSignature takes the timestamp, query params and body from the request,
// calculates the expected signature and compares it to the one sent by MessageBird. | [
"validSignature",
"takes",
"the",
"timestamp",
"query",
"params",
"and",
"body",
"from",
"the",
"request",
"calculates",
"the",
"expected",
"signature",
"and",
"compares",
"it",
"to",
"the",
"one",
"sent",
"by",
"MessageBird",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/signature/signature.go#L95-L109 |
11,430 | messagebird/go-rest-api | signature/signature.go | ValidRequest | func (v *Validator) ValidRequest(r *http.Request) error {
ts := r.Header.Get(tsHeader)
rs := r.Header.Get(sHeader)
if ts == "" || rs == "" {
return fmt.Errorf("Unknown host: %s", r.Host)
}
b, _ := ioutil.ReadAll(r.Body)
if v.validTimestamp(ts) == false || v.validSignature(ts, r.URL.RawQuery, b, rs) == false {
return fmt.Errorf("Unknown host: %s", r.Host)
}
r.Body = ioutil.NopCloser(bytes.NewBuffer(b))
return nil
} | go | func (v *Validator) ValidRequest(r *http.Request) error {
ts := r.Header.Get(tsHeader)
rs := r.Header.Get(sHeader)
if ts == "" || rs == "" {
return fmt.Errorf("Unknown host: %s", r.Host)
}
b, _ := ioutil.ReadAll(r.Body)
if v.validTimestamp(ts) == false || v.validSignature(ts, r.URL.RawQuery, b, rs) == false {
return fmt.Errorf("Unknown host: %s", r.Host)
}
r.Body = ioutil.NopCloser(bytes.NewBuffer(b))
return nil
} | [
"func",
"(",
"v",
"*",
"Validator",
")",
"ValidRequest",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"ts",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"tsHeader",
")",
"\n",
"rs",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"sHeader",
")",
"\n",
"if",
"ts",
"==",
"\"",
"\"",
"||",
"rs",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
".",
"Host",
")",
"\n",
"}",
"\n",
"b",
",",
"_",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
".",
"Body",
")",
"\n",
"if",
"v",
".",
"validTimestamp",
"(",
"ts",
")",
"==",
"false",
"||",
"v",
".",
"validSignature",
"(",
"ts",
",",
"r",
".",
"URL",
".",
"RawQuery",
",",
"b",
",",
"rs",
")",
"==",
"false",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
".",
"Host",
")",
"\n",
"}",
"\n",
"r",
".",
"Body",
"=",
"ioutil",
".",
"NopCloser",
"(",
"bytes",
".",
"NewBuffer",
"(",
"b",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // ValidRequest is a method that takes care of the signature validation of
// incoming requests. | [
"ValidRequest",
"is",
"a",
"method",
"that",
"takes",
"care",
"of",
"the",
"signature",
"validation",
"of",
"incoming",
"requests",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/signature/signature.go#L113-L125 |
11,431 | messagebird/go-rest-api | signature/signature.go | Validate | func (v *Validator) Validate(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := v.ValidRequest(r); err != nil {
http.Error(w, "", http.StatusUnauthorized)
return
}
h.ServeHTTP(w, r)
})
} | go | func (v *Validator) Validate(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := v.ValidRequest(r); err != nil {
http.Error(w, "", http.StatusUnauthorized)
return
}
h.ServeHTTP(w, r)
})
} | [
"func",
"(",
"v",
"*",
"Validator",
")",
"Validate",
"(",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"err",
":=",
"v",
".",
"ValidRequest",
"(",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"http",
".",
"Error",
"(",
"w",
",",
"\"",
"\"",
",",
"http",
".",
"StatusUnauthorized",
")",
"\n",
"return",
"\n",
"}",
"\n",
"h",
".",
"ServeHTTP",
"(",
"w",
",",
"r",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Validate is a handler wrapper that takes care of the signature validation of
// incoming requests and rejects them if invalid or pass them on to your handler
// otherwise. | [
"Validate",
"is",
"a",
"handler",
"wrapper",
"that",
"takes",
"care",
"of",
"the",
"signature",
"validation",
"of",
"incoming",
"requests",
"and",
"rejects",
"them",
"if",
"invalid",
"or",
"pass",
"them",
"on",
"to",
"your",
"handler",
"otherwise",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/signature/signature.go#L130-L138 |
11,432 | messagebird/go-rest-api | sms/message.go | Delete | func Delete(c *messagebird.Client, id string) (*Message, error) {
message := &Message{}
if err := c.Request(message, http.MethodDelete, path+"/"+id, nil); err != nil {
return nil, err
}
return message, nil
} | go | func Delete(c *messagebird.Client, id string) (*Message, error) {
message := &Message{}
if err := c.Request(message, http.MethodDelete, path+"/"+id, nil); err != nil {
return nil, err
}
return message, nil
} | [
"func",
"Delete",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"id",
"string",
")",
"(",
"*",
"Message",
",",
"error",
")",
"{",
"message",
":=",
"&",
"Message",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"Request",
"(",
"message",
",",
"http",
".",
"MethodDelete",
",",
"path",
"+",
"\"",
"\"",
"+",
"id",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"message",
",",
"nil",
"\n",
"}"
] | // Cancel sending Scheduled Sms | [
"Cancel",
"sending",
"Scheduled",
"Sms"
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/sms/message.go#L97-L104 |
11,433 | messagebird/go-rest-api | sms/message.go | List | func List(c *messagebird.Client, msgListParams *ListParams) (*MessageList, error) {
messageList := &MessageList{}
params, err := paramsForMessageList(msgListParams)
if err != nil {
return messageList, err
}
if err := c.Request(messageList, http.MethodGet, path+"?"+params.Encode(), nil); err != nil {
return nil, err
}
return messageList, nil
} | go | func List(c *messagebird.Client, msgListParams *ListParams) (*MessageList, error) {
messageList := &MessageList{}
params, err := paramsForMessageList(msgListParams)
if err != nil {
return messageList, err
}
if err := c.Request(messageList, http.MethodGet, path+"?"+params.Encode(), nil); err != nil {
return nil, err
}
return messageList, nil
} | [
"func",
"List",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"msgListParams",
"*",
"ListParams",
")",
"(",
"*",
"MessageList",
",",
"error",
")",
"{",
"messageList",
":=",
"&",
"MessageList",
"{",
"}",
"\n",
"params",
",",
"err",
":=",
"paramsForMessageList",
"(",
"msgListParams",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"messageList",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Request",
"(",
"messageList",
",",
"http",
".",
"MethodGet",
",",
"path",
"+",
"\"",
"\"",
"+",
"params",
".",
"Encode",
"(",
")",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"messageList",
",",
"nil",
"\n",
"}"
] | // List retrieves all messages of the user represented as a MessageList object. | [
"List",
"retrieves",
"all",
"messages",
"of",
"the",
"user",
"represented",
"as",
"a",
"MessageList",
"object",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/sms/message.go#L107-L119 |
11,434 | messagebird/go-rest-api | sms/message.go | Create | func Create(c *messagebird.Client, originator string, recipients []string, body string, msgParams *Params) (*Message, error) {
requestData, err := requestDataForMessage(originator, recipients, body, msgParams)
if err != nil {
return nil, err
}
message := &Message{}
if err := c.Request(message, http.MethodPost, path, requestData); err != nil {
return nil, err
}
return message, nil
} | go | func Create(c *messagebird.Client, originator string, recipients []string, body string, msgParams *Params) (*Message, error) {
requestData, err := requestDataForMessage(originator, recipients, body, msgParams)
if err != nil {
return nil, err
}
message := &Message{}
if err := c.Request(message, http.MethodPost, path, requestData); err != nil {
return nil, err
}
return message, nil
} | [
"func",
"Create",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"originator",
"string",
",",
"recipients",
"[",
"]",
"string",
",",
"body",
"string",
",",
"msgParams",
"*",
"Params",
")",
"(",
"*",
"Message",
",",
"error",
")",
"{",
"requestData",
",",
"err",
":=",
"requestDataForMessage",
"(",
"originator",
",",
"recipients",
",",
"body",
",",
"msgParams",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"message",
":=",
"&",
"Message",
"{",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"Request",
"(",
"message",
",",
"http",
".",
"MethodPost",
",",
"path",
",",
"requestData",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"message",
",",
"nil",
"\n",
"}"
] | // Create creates a new message for one or more recipients. | [
"Create",
"creates",
"a",
"new",
"message",
"for",
"one",
"or",
"more",
"recipients",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/sms/message.go#L122-L134 |
11,435 | messagebird/go-rest-api | sms/message.go | paramsForMessageList | func paramsForMessageList(params *ListParams) (*url.Values, error) {
urlParams := &url.Values{}
if params == nil {
return urlParams, nil
}
if params.Direction != "" {
urlParams.Set("direction", params.Direction)
}
if params.Originator != "" {
urlParams.Set("originator", params.Originator)
}
if params.Limit != 0 {
urlParams.Set("limit", strconv.Itoa(params.Limit))
}
urlParams.Set("offset", strconv.Itoa(params.Offset))
return urlParams, nil
} | go | func paramsForMessageList(params *ListParams) (*url.Values, error) {
urlParams := &url.Values{}
if params == nil {
return urlParams, nil
}
if params.Direction != "" {
urlParams.Set("direction", params.Direction)
}
if params.Originator != "" {
urlParams.Set("originator", params.Originator)
}
if params.Limit != 0 {
urlParams.Set("limit", strconv.Itoa(params.Limit))
}
urlParams.Set("offset", strconv.Itoa(params.Offset))
return urlParams, nil
} | [
"func",
"paramsForMessageList",
"(",
"params",
"*",
"ListParams",
")",
"(",
"*",
"url",
".",
"Values",
",",
"error",
")",
"{",
"urlParams",
":=",
"&",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"if",
"params",
"==",
"nil",
"{",
"return",
"urlParams",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"params",
".",
"Direction",
"!=",
"\"",
"\"",
"{",
"urlParams",
".",
"Set",
"(",
"\"",
"\"",
",",
"params",
".",
"Direction",
")",
"\n",
"}",
"\n",
"if",
"params",
".",
"Originator",
"!=",
"\"",
"\"",
"{",
"urlParams",
".",
"Set",
"(",
"\"",
"\"",
",",
"params",
".",
"Originator",
")",
"\n",
"}",
"\n",
"if",
"params",
".",
"Limit",
"!=",
"0",
"{",
"urlParams",
".",
"Set",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"params",
".",
"Limit",
")",
")",
"\n",
"}",
"\n",
"urlParams",
".",
"Set",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"params",
".",
"Offset",
")",
")",
"\n\n",
"return",
"urlParams",
",",
"nil",
"\n",
"}"
] | // paramsForMessageList converts the specified MessageListParams struct to a
// url.Values pointer and returns it. | [
"paramsForMessageList",
"converts",
"the",
"specified",
"MessageListParams",
"struct",
"to",
"a",
"url",
".",
"Values",
"pointer",
"and",
"returns",
"it",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/sms/message.go#L180-L199 |
11,436 | messagebird/go-rest-api | conversation/message.go | ListMessages | func ListMessages(c *messagebird.Client, conversationID string, options *ListOptions) (*MessageList, error) {
query := paginationQuery(options)
uri := fmt.Sprintf("%s/%s/%s?%s", path, conversationID, messagesPath, query)
messageList := &MessageList{}
if err := request(c, messageList, http.MethodGet, uri, nil); err != nil {
return nil, err
}
return messageList, nil
} | go | func ListMessages(c *messagebird.Client, conversationID string, options *ListOptions) (*MessageList, error) {
query := paginationQuery(options)
uri := fmt.Sprintf("%s/%s/%s?%s", path, conversationID, messagesPath, query)
messageList := &MessageList{}
if err := request(c, messageList, http.MethodGet, uri, nil); err != nil {
return nil, err
}
return messageList, nil
} | [
"func",
"ListMessages",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"conversationID",
"string",
",",
"options",
"*",
"ListOptions",
")",
"(",
"*",
"MessageList",
",",
"error",
")",
"{",
"query",
":=",
"paginationQuery",
"(",
"options",
")",
"\n",
"uri",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"path",
",",
"conversationID",
",",
"messagesPath",
",",
"query",
")",
"\n\n",
"messageList",
":=",
"&",
"MessageList",
"{",
"}",
"\n",
"if",
"err",
":=",
"request",
"(",
"c",
",",
"messageList",
",",
"http",
".",
"MethodGet",
",",
"uri",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"messageList",
",",
"nil",
"\n",
"}"
] | // ListMessages gets a collection of messages from a conversation. Pagination
// can be set in the options. | [
"ListMessages",
"gets",
"a",
"collection",
"of",
"messages",
"from",
"a",
"conversation",
".",
"Pagination",
"can",
"be",
"set",
"in",
"the",
"options",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/conversation/message.go#L31-L41 |
11,437 | messagebird/go-rest-api | conversation/message.go | ReadMessage | func ReadMessage(c *messagebird.Client, messageID string) (*Message, error) {
message := &Message{}
if err := request(c, message, http.MethodGet, messagesPath+"/"+messageID, nil); err != nil {
return nil, err
}
return message, nil
} | go | func ReadMessage(c *messagebird.Client, messageID string) (*Message, error) {
message := &Message{}
if err := request(c, message, http.MethodGet, messagesPath+"/"+messageID, nil); err != nil {
return nil, err
}
return message, nil
} | [
"func",
"ReadMessage",
"(",
"c",
"*",
"messagebird",
".",
"Client",
",",
"messageID",
"string",
")",
"(",
"*",
"Message",
",",
"error",
")",
"{",
"message",
":=",
"&",
"Message",
"{",
"}",
"\n",
"if",
"err",
":=",
"request",
"(",
"c",
",",
"message",
",",
"http",
".",
"MethodGet",
",",
"messagesPath",
"+",
"\"",
"\"",
"+",
"messageID",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"message",
",",
"nil",
"\n",
"}"
] | // ReadMessage gets a single message based on its ID. | [
"ReadMessage",
"gets",
"a",
"single",
"message",
"based",
"on",
"its",
"ID",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/conversation/message.go#L44-L51 |
11,438 | messagebird/go-rest-api | voice/transcription.go | Contents | func (trans *Transcription) Contents(client *messagebird.Client) (string, error) {
req, err := http.NewRequest(http.MethodGet, apiRoot+trans.links["file"], nil)
if err != nil {
return "", err
}
req.Header.Set("Accept", "text/plain")
req.Header.Set("Authorization", "AccessKey "+client.AccessKey)
req.Header.Set("User-Agent", "MessageBird/ApiClient/"+messagebird.ClientVersion+" Go/"+runtime.Version())
resp, err := client.HTTPClient.Do(req)
if err != nil {
return "", err
}
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("bad HTTP status: %d", resp.StatusCode)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
return string(b), err
} | go | func (trans *Transcription) Contents(client *messagebird.Client) (string, error) {
req, err := http.NewRequest(http.MethodGet, apiRoot+trans.links["file"], nil)
if err != nil {
return "", err
}
req.Header.Set("Accept", "text/plain")
req.Header.Set("Authorization", "AccessKey "+client.AccessKey)
req.Header.Set("User-Agent", "MessageBird/ApiClient/"+messagebird.ClientVersion+" Go/"+runtime.Version())
resp, err := client.HTTPClient.Do(req)
if err != nil {
return "", err
}
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("bad HTTP status: %d", resp.StatusCode)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
return string(b), err
} | [
"func",
"(",
"trans",
"*",
"Transcription",
")",
"Contents",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"(",
"string",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"http",
".",
"MethodGet",
",",
"apiRoot",
"+",
"trans",
".",
"links",
"[",
"\"",
"\"",
"]",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"client",
".",
"AccessKey",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"messagebird",
".",
"ClientVersion",
"+",
"\"",
"\"",
"+",
"runtime",
".",
"Version",
"(",
")",
")",
"\n\n",
"resp",
",",
"err",
":=",
"client",
".",
"HTTPClient",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
")",
"\n",
"}",
"\n\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"return",
"string",
"(",
"b",
")",
",",
"err",
"\n",
"}"
] | // Contents gets the transcription file.
//
// This is a plain text file. | [
"Contents",
"gets",
"the",
"transcription",
"file",
".",
"This",
"is",
"a",
"plain",
"text",
"file",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/transcription.go#L74-L94 |
11,439 | messagebird/go-rest-api | voice/call.go | CallByID | func CallByID(client *messagebird.Client, id string) (*Call, error) {
var resp struct {
Data []Call `json:"data"`
}
if err := client.Request(&resp, http.MethodGet, apiRoot+"/calls/"+id, nil); err != nil {
return nil, err
}
return &resp.Data[0], nil
} | go | func CallByID(client *messagebird.Client, id string) (*Call, error) {
var resp struct {
Data []Call `json:"data"`
}
if err := client.Request(&resp, http.MethodGet, apiRoot+"/calls/"+id, nil); err != nil {
return nil, err
}
return &resp.Data[0], nil
} | [
"func",
"CallByID",
"(",
"client",
"*",
"messagebird",
".",
"Client",
",",
"id",
"string",
")",
"(",
"*",
"Call",
",",
"error",
")",
"{",
"var",
"resp",
"struct",
"{",
"Data",
"[",
"]",
"Call",
"`json:\"data\"`",
"\n",
"}",
"\n",
"if",
"err",
":=",
"client",
".",
"Request",
"(",
"&",
"resp",
",",
"http",
".",
"MethodGet",
",",
"apiRoot",
"+",
"\"",
"\"",
"+",
"id",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"resp",
".",
"Data",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | // CallByID fetches a call by it's ID.
//
// An error is returned if no such call flow exists or is accessible. | [
"CallByID",
"fetches",
"a",
"call",
"by",
"it",
"s",
"ID",
".",
"An",
"error",
"is",
"returned",
"if",
"no",
"such",
"call",
"flow",
"exists",
"or",
"is",
"accessible",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/call.go#L109-L117 |
11,440 | messagebird/go-rest-api | voice/call.go | Calls | func Calls(client *messagebird.Client) *Paginator {
return newPaginator(client, apiRoot+"/calls/", reflect.TypeOf(Call{}))
} | go | func Calls(client *messagebird.Client) *Paginator {
return newPaginator(client, apiRoot+"/calls/", reflect.TypeOf(Call{}))
} | [
"func",
"Calls",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"*",
"Paginator",
"{",
"return",
"newPaginator",
"(",
"client",
",",
"apiRoot",
"+",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"Call",
"{",
"}",
")",
")",
"\n",
"}"
] | // Calls returns a Paginator which iterates over all Calls. | [
"Calls",
"returns",
"a",
"Paginator",
"which",
"iterates",
"over",
"all",
"Calls",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/call.go#L120-L122 |
11,441 | messagebird/go-rest-api | voice/call.go | Delete | func (call *Call) Delete(client *messagebird.Client) error {
return client.Request(nil, http.MethodDelete, apiRoot+"/calls/"+call.ID, nil)
} | go | func (call *Call) Delete(client *messagebird.Client) error {
return client.Request(nil, http.MethodDelete, apiRoot+"/calls/"+call.ID, nil)
} | [
"func",
"(",
"call",
"*",
"Call",
")",
"Delete",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"error",
"{",
"return",
"client",
".",
"Request",
"(",
"nil",
",",
"http",
".",
"MethodDelete",
",",
"apiRoot",
"+",
"\"",
"\"",
"+",
"call",
".",
"ID",
",",
"nil",
")",
"\n",
"}"
] | // Delete deletes the Call.
//
// If the call is in progress, it hangs up all legs. | [
"Delete",
"deletes",
"the",
"Call",
".",
"If",
"the",
"call",
"is",
"in",
"progress",
"it",
"hangs",
"up",
"all",
"legs",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/call.go#L159-L161 |
11,442 | messagebird/go-rest-api | voice/call.go | Legs | func (call *Call) Legs(client *messagebird.Client) *Paginator {
return newPaginator(client, fmt.Sprintf("%s/calls/%s/legs", apiRoot, call.ID), reflect.TypeOf(Leg{}))
} | go | func (call *Call) Legs(client *messagebird.Client) *Paginator {
return newPaginator(client, fmt.Sprintf("%s/calls/%s/legs", apiRoot, call.ID), reflect.TypeOf(Leg{}))
} | [
"func",
"(",
"call",
"*",
"Call",
")",
"Legs",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"*",
"Paginator",
"{",
"return",
"newPaginator",
"(",
"client",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"apiRoot",
",",
"call",
".",
"ID",
")",
",",
"reflect",
".",
"TypeOf",
"(",
"Leg",
"{",
"}",
")",
")",
"\n",
"}"
] | // Legs returns a paginator over all Legs associated with a call. | [
"Legs",
"returns",
"a",
"paginator",
"over",
"all",
"Legs",
"associated",
"with",
"a",
"call",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/call.go#L164-L166 |
11,443 | messagebird/go-rest-api | voice/recording.go | Transcriptions | func (rec *Recording) Transcriptions(client *messagebird.Client) *Paginator {
path := rec.links["self"] + "/transcriptions"
return newPaginator(client, path, reflect.TypeOf(Transcription{}))
} | go | func (rec *Recording) Transcriptions(client *messagebird.Client) *Paginator {
path := rec.links["self"] + "/transcriptions"
return newPaginator(client, path, reflect.TypeOf(Transcription{}))
} | [
"func",
"(",
"rec",
"*",
"Recording",
")",
"Transcriptions",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"*",
"Paginator",
"{",
"path",
":=",
"rec",
".",
"links",
"[",
"\"",
"\"",
"]",
"+",
"\"",
"\"",
"\n",
"return",
"newPaginator",
"(",
"client",
",",
"path",
",",
"reflect",
".",
"TypeOf",
"(",
"Transcription",
"{",
"}",
")",
")",
"\n",
"}"
] | // Transcriptions returns a paginator for retrieving all Transcription objects. | [
"Transcriptions",
"returns",
"a",
"paginator",
"for",
"retrieving",
"all",
"Transcription",
"objects",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/recording.go#L97-L100 |
11,444 | messagebird/go-rest-api | voice/recording.go | DownloadFile | func (rec *Recording) DownloadFile(client *messagebird.Client) (io.ReadCloser, error) {
req, err := http.NewRequest(http.MethodGet, apiRoot+rec.links["file"], nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "audio/*")
req.Header.Set("Authorization", "AccessKey "+client.AccessKey)
req.Header.Set("User-Agent", "MessageBird/ApiClient/"+messagebird.ClientVersion+" Go/"+runtime.Version())
resp, err := client.HTTPClient.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("bad HTTP status: %d", resp.StatusCode)
}
return resp.Body, nil
} | go | func (rec *Recording) DownloadFile(client *messagebird.Client) (io.ReadCloser, error) {
req, err := http.NewRequest(http.MethodGet, apiRoot+rec.links["file"], nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "audio/*")
req.Header.Set("Authorization", "AccessKey "+client.AccessKey)
req.Header.Set("User-Agent", "MessageBird/ApiClient/"+messagebird.ClientVersion+" Go/"+runtime.Version())
resp, err := client.HTTPClient.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("bad HTTP status: %d", resp.StatusCode)
}
return resp.Body, nil
} | [
"func",
"(",
"rec",
"*",
"Recording",
")",
"DownloadFile",
"(",
"client",
"*",
"messagebird",
".",
"Client",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"http",
".",
"MethodGet",
",",
"apiRoot",
"+",
"rec",
".",
"links",
"[",
"\"",
"\"",
"]",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"client",
".",
"AccessKey",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"messagebird",
".",
"ClientVersion",
"+",
"\"",
"\"",
"+",
"runtime",
".",
"Version",
"(",
")",
")",
"\n\n",
"resp",
",",
"err",
":=",
"client",
".",
"HTTPClient",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
")",
"\n",
"}",
"\n",
"return",
"resp",
".",
"Body",
",",
"nil",
"\n",
"}"
] | // DownloadFile streams the recorded WAV file. | [
"DownloadFile",
"streams",
"the",
"recorded",
"WAV",
"file",
"."
] | fd48d63984e1cde9946be190d3a34e1a34e75e34 | https://github.com/messagebird/go-rest-api/blob/fd48d63984e1cde9946be190d3a34e1a34e75e34/voice/recording.go#L103-L120 |
11,445 | verdverm/frisby | global.go | SetData | func (G *global_data) SetData(key, value string) *global_data {
if G.Req.Data == nil {
G.Req.Data = make(map[string]string)
}
G.Req.Data[key] = value
return G
} | go | func (G *global_data) SetData(key, value string) *global_data {
if G.Req.Data == nil {
G.Req.Data = make(map[string]string)
}
G.Req.Data[key] = value
return G
} | [
"func",
"(",
"G",
"*",
"global_data",
")",
"SetData",
"(",
"key",
",",
"value",
"string",
")",
"*",
"global_data",
"{",
"if",
"G",
".",
"Req",
".",
"Data",
"==",
"nil",
"{",
"G",
".",
"Req",
".",
"Data",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"G",
".",
"Req",
".",
"Data",
"[",
"key",
"]",
"=",
"value",
"\n",
"return",
"G",
"\n",
"}"
] | // Set a Gorm data for the coming request | [
"Set",
"a",
"Gorm",
"data",
"for",
"the",
"coming",
"request"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/global.go#L88-L94 |
11,446 | verdverm/frisby | global.go | SetDatas | func (G *global_data) SetDatas(datas map[string]string) *global_data {
if G.Req.Data == nil {
G.Req.Data = make(map[string]string)
}
for key, value := range datas {
G.Req.Data[key] = value
}
return G
} | go | func (G *global_data) SetDatas(datas map[string]string) *global_data {
if G.Req.Data == nil {
G.Req.Data = make(map[string]string)
}
for key, value := range datas {
G.Req.Data[key] = value
}
return G
} | [
"func",
"(",
"G",
"*",
"global_data",
")",
"SetDatas",
"(",
"datas",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"global_data",
"{",
"if",
"G",
".",
"Req",
".",
"Data",
"==",
"nil",
"{",
"G",
".",
"Req",
".",
"Data",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"datas",
"{",
"G",
".",
"Req",
".",
"Data",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n",
"return",
"G",
"\n",
"}"
] | // Set several Gorm data for the coming request | [
"Set",
"several",
"Gorm",
"data",
"for",
"the",
"coming",
"request"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/global.go#L97-L105 |
11,447 | verdverm/frisby | global.go | AddFile | func (G *global_data) AddFile(filename string) *global_data {
file, err := os.Open(filename)
if err != nil {
G.AddError("Global", err.Error())
fmt.Println("Error adding file to global")
} else {
fileField := request.FileField{"file", filename, file}
G.Req.Files = append(G.Req.Files, fileField)
}
return G
} | go | func (G *global_data) AddFile(filename string) *global_data {
file, err := os.Open(filename)
if err != nil {
G.AddError("Global", err.Error())
fmt.Println("Error adding file to global")
} else {
fileField := request.FileField{"file", filename, file}
G.Req.Files = append(G.Req.Files, fileField)
}
return G
} | [
"func",
"(",
"G",
"*",
"global_data",
")",
"AddFile",
"(",
"filename",
"string",
")",
"*",
"global_data",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"G",
".",
"AddError",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"fileField",
":=",
"request",
".",
"FileField",
"{",
"\"",
"\"",
",",
"filename",
",",
"file",
"}",
"\n",
"G",
".",
"Req",
".",
"Files",
"=",
"append",
"(",
"G",
".",
"Req",
".",
"Files",
",",
"fileField",
")",
"\n",
"}",
"\n",
"return",
"G",
"\n",
"}"
] | // Add a file to the Gorm data for the coming request | [
"Add",
"a",
"file",
"to",
"the",
"Gorm",
"data",
"for",
"the",
"coming",
"request"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/global.go#L134-L144 |
11,448 | verdverm/frisby | global.go | PrintReport | func (G *global_data) PrintReport() *global_data {
fmt.Printf("\nFor %d requests made\n", G.NumRequest)
if len(G.Errs) == 0 {
fmt.Printf(" All tests passed\n")
} else {
fmt.Printf(" FAILED [%d/%d]\n", G.NumErrored, G.NumAsserts)
for key, val := range G.Errs {
fmt.Printf(" [%s]\n", key)
for _, e := range val {
fmt.Println(" - ", e)
}
}
}
return G
} | go | func (G *global_data) PrintReport() *global_data {
fmt.Printf("\nFor %d requests made\n", G.NumRequest)
if len(G.Errs) == 0 {
fmt.Printf(" All tests passed\n")
} else {
fmt.Printf(" FAILED [%d/%d]\n", G.NumErrored, G.NumAsserts)
for key, val := range G.Errs {
fmt.Printf(" [%s]\n", key)
for _, e := range val {
fmt.Println(" - ", e)
}
}
}
return G
} | [
"func",
"(",
"G",
"*",
"global_data",
")",
"PrintReport",
"(",
")",
"*",
"global_data",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"G",
".",
"NumRequest",
")",
"\n",
"if",
"len",
"(",
"G",
".",
"Errs",
")",
"==",
"0",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"G",
".",
"NumErrored",
",",
"G",
".",
"NumAsserts",
")",
"\n",
"for",
"key",
",",
"val",
":=",
"range",
"G",
".",
"Errs",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"key",
")",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"val",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"e",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"G",
"\n",
"}"
] | // Prints a report for the FrisbyGlobal Object
//
// If there are any errors, they will all be printed as well | [
"Prints",
"a",
"report",
"for",
"the",
"FrisbyGlobal",
"Object",
"If",
"there",
"are",
"any",
"errors",
"they",
"will",
"all",
"be",
"printed",
"as",
"well"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/global.go#L164-L179 |
11,449 | verdverm/frisby | expect.go | Expect | func (F *Frisby) Expect(foo ExpectFunc) *Frisby {
Global.NumAsserts++
if ok, err_str := foo(F); !ok {
F.AddError(err_str)
}
return F
} | go | func (F *Frisby) Expect(foo ExpectFunc) *Frisby {
Global.NumAsserts++
if ok, err_str := foo(F); !ok {
F.AddError(err_str)
}
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"Expect",
"(",
"foo",
"ExpectFunc",
")",
"*",
"Frisby",
"{",
"Global",
".",
"NumAsserts",
"++",
"\n",
"if",
"ok",
",",
"err_str",
":=",
"foo",
"(",
"F",
")",
";",
"!",
"ok",
"{",
"F",
".",
"AddError",
"(",
"err_str",
")",
"\n",
"}",
"\n",
"return",
"F",
"\n",
"}"
] | // Expect Checks according to the given function, which allows you to describe any kind of assertion. | [
"Expect",
"Checks",
"according",
"to",
"the",
"given",
"function",
"which",
"allows",
"you",
"to",
"describe",
"any",
"kind",
"of",
"assertion",
"."
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/expect.go#L16-L22 |
11,450 | verdverm/frisby | expect.go | ExpectStatus | func (F *Frisby) ExpectStatus(code int) *Frisby {
Global.NumAsserts++
status := F.Resp.StatusCode
if status != code {
err_str := fmt.Sprintf("Expected Status %d, but got %d: %q", code, status, F.Resp.Status)
F.AddError(err_str)
}
return F
} | go | func (F *Frisby) ExpectStatus(code int) *Frisby {
Global.NumAsserts++
status := F.Resp.StatusCode
if status != code {
err_str := fmt.Sprintf("Expected Status %d, but got %d: %q", code, status, F.Resp.Status)
F.AddError(err_str)
}
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"ExpectStatus",
"(",
"code",
"int",
")",
"*",
"Frisby",
"{",
"Global",
".",
"NumAsserts",
"++",
"\n",
"status",
":=",
"F",
".",
"Resp",
".",
"StatusCode",
"\n",
"if",
"status",
"!=",
"code",
"{",
"err_str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"code",
",",
"status",
",",
"F",
".",
"Resp",
".",
"Status",
")",
"\n",
"F",
".",
"AddError",
"(",
"err_str",
")",
"\n",
"}",
"\n",
"return",
"F",
"\n",
"}"
] | // Checks the response status code | [
"Checks",
"the",
"response",
"status",
"code"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/expect.go#L25-L33 |
11,451 | verdverm/frisby | expect.go | ExpectHeader | func (F *Frisby) ExpectHeader(key, value string) *Frisby {
Global.NumAsserts++
chk_val := F.Resp.Header.Get(key)
if chk_val == "" {
err_str := fmt.Sprintf("Expected Header %q, but it was missing", key)
F.AddError(err_str)
} else if chk_val != value {
err_str := fmt.Sprintf("Expected Header %q to be %q, but got %q", key, value, chk_val)
F.AddError(err_str)
}
return F
} | go | func (F *Frisby) ExpectHeader(key, value string) *Frisby {
Global.NumAsserts++
chk_val := F.Resp.Header.Get(key)
if chk_val == "" {
err_str := fmt.Sprintf("Expected Header %q, but it was missing", key)
F.AddError(err_str)
} else if chk_val != value {
err_str := fmt.Sprintf("Expected Header %q to be %q, but got %q", key, value, chk_val)
F.AddError(err_str)
}
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"ExpectHeader",
"(",
"key",
",",
"value",
"string",
")",
"*",
"Frisby",
"{",
"Global",
".",
"NumAsserts",
"++",
"\n",
"chk_val",
":=",
"F",
".",
"Resp",
".",
"Header",
".",
"Get",
"(",
"key",
")",
"\n",
"if",
"chk_val",
"==",
"\"",
"\"",
"{",
"err_str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"F",
".",
"AddError",
"(",
"err_str",
")",
"\n",
"}",
"else",
"if",
"chk_val",
"!=",
"value",
"{",
"err_str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"key",
",",
"value",
",",
"chk_val",
")",
"\n",
"F",
".",
"AddError",
"(",
"err_str",
")",
"\n",
"}",
"\n",
"return",
"F",
"\n",
"}"
] | // Checks for header and if values match | [
"Checks",
"for",
"header",
"and",
"if",
"values",
"match"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/expect.go#L36-L47 |
11,452 | verdverm/frisby | expect.go | ExpectContent | func (F *Frisby) ExpectContent(content string) *Frisby {
Global.NumAsserts++
text, err := F.Resp.Text()
if err != nil {
F.AddError(err.Error())
return F
}
contains := strings.Contains(text, content)
if !contains {
err_str := fmt.Sprintf("Expected Body to contain %q, but it was missing", content)
F.AddError(err_str)
}
return F
} | go | func (F *Frisby) ExpectContent(content string) *Frisby {
Global.NumAsserts++
text, err := F.Resp.Text()
if err != nil {
F.AddError(err.Error())
return F
}
contains := strings.Contains(text, content)
if !contains {
err_str := fmt.Sprintf("Expected Body to contain %q, but it was missing", content)
F.AddError(err_str)
}
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"ExpectContent",
"(",
"content",
"string",
")",
"*",
"Frisby",
"{",
"Global",
".",
"NumAsserts",
"++",
"\n",
"text",
",",
"err",
":=",
"F",
".",
"Resp",
".",
"Text",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"F",
".",
"AddError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"F",
"\n",
"}",
"\n",
"contains",
":=",
"strings",
".",
"Contains",
"(",
"text",
",",
"content",
")",
"\n",
"if",
"!",
"contains",
"{",
"err_str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"content",
")",
"\n",
"F",
".",
"AddError",
"(",
"err_str",
")",
"\n",
"}",
"\n",
"return",
"F",
"\n",
"}"
] | // Checks the response body for the given string | [
"Checks",
"the",
"response",
"body",
"for",
"the",
"given",
"string"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/expect.go#L50-L63 |
11,453 | verdverm/frisby | expect.go | PrintBody | func (F *Frisby) PrintBody() *Frisby {
str, err := F.Resp.Text()
if err != nil {
F.AddError(err.Error())
return F
}
fmt.Println(str)
return F
} | go | func (F *Frisby) PrintBody() *Frisby {
str, err := F.Resp.Text()
if err != nil {
F.AddError(err.Error())
return F
}
fmt.Println(str)
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"PrintBody",
"(",
")",
"*",
"Frisby",
"{",
"str",
",",
"err",
":=",
"F",
".",
"Resp",
".",
"Text",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"F",
".",
"AddError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"F",
"\n",
"}",
"\n",
"fmt",
".",
"Println",
"(",
"str",
")",
"\n",
"return",
"F",
"\n",
"}"
] | // Prints the body of the response | [
"Prints",
"the",
"body",
"of",
"the",
"response"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/expect.go#L238-L246 |
11,454 | verdverm/frisby | expect.go | PrintReport | func (F *Frisby) PrintReport() *Frisby {
if len(F.Errs) == 0 {
fmt.Printf("Pass [%s]\n", F.Name)
} else {
fmt.Printf("FAIL [%s]\n", F.Name)
for _, e := range F.Errs {
fmt.Println(" - ", e)
}
}
return F
} | go | func (F *Frisby) PrintReport() *Frisby {
if len(F.Errs) == 0 {
fmt.Printf("Pass [%s]\n", F.Name)
} else {
fmt.Printf("FAIL [%s]\n", F.Name)
for _, e := range F.Errs {
fmt.Println(" - ", e)
}
}
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"PrintReport",
"(",
")",
"*",
"Frisby",
"{",
"if",
"len",
"(",
"F",
".",
"Errs",
")",
"==",
"0",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"F",
".",
"Name",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"F",
".",
"Name",
")",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"F",
".",
"Errs",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"e",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"F",
"\n",
"}"
] | // Prints a report for the Frisby Object
//
// If there are any errors, they will all be printed as well | [
"Prints",
"a",
"report",
"for",
"the",
"Frisby",
"Object",
"If",
"there",
"are",
"any",
"errors",
"they",
"will",
"all",
"be",
"printed",
"as",
"well"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/expect.go#L251-L262 |
11,455 | verdverm/frisby | frisby.go | Get | func (F *Frisby) Get(url string) *Frisby {
F.Method = "GET"
F.Url = url
return F
} | go | func (F *Frisby) Get(url string) *Frisby {
F.Method = "GET"
F.Url = url
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"Get",
"(",
"url",
"string",
")",
"*",
"Frisby",
"{",
"F",
".",
"Method",
"=",
"\"",
"\"",
"\n",
"F",
".",
"Url",
"=",
"url",
"\n",
"return",
"F",
"\n",
"}"
] | // Set the HTTP method to GET for the given URL | [
"Set",
"the",
"HTTP",
"method",
"to",
"GET",
"for",
"the",
"given",
"URL"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/frisby.go#L55-L59 |
11,456 | verdverm/frisby | frisby.go | Post | func (F *Frisby) Post(url string) *Frisby {
F.Method = "POST"
F.Url = url
return F
} | go | func (F *Frisby) Post(url string) *Frisby {
F.Method = "POST"
F.Url = url
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"Post",
"(",
"url",
"string",
")",
"*",
"Frisby",
"{",
"F",
".",
"Method",
"=",
"\"",
"\"",
"\n",
"F",
".",
"Url",
"=",
"url",
"\n",
"return",
"F",
"\n",
"}"
] | // Set the HTTP method to POST for the given URL | [
"Set",
"the",
"HTTP",
"method",
"to",
"POST",
"for",
"the",
"given",
"URL"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/frisby.go#L62-L66 |
11,457 | verdverm/frisby | frisby.go | Put | func (F *Frisby) Put(url string) *Frisby {
F.Method = "PUT"
F.Url = url
return F
} | go | func (F *Frisby) Put(url string) *Frisby {
F.Method = "PUT"
F.Url = url
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"Put",
"(",
"url",
"string",
")",
"*",
"Frisby",
"{",
"F",
".",
"Method",
"=",
"\"",
"\"",
"\n",
"F",
".",
"Url",
"=",
"url",
"\n",
"return",
"F",
"\n",
"}"
] | // Set the HTTP method to PUT for the given URL | [
"Set",
"the",
"HTTP",
"method",
"to",
"PUT",
"for",
"the",
"given",
"URL"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/frisby.go#L69-L73 |
11,458 | verdverm/frisby | frisby.go | Patch | func (F *Frisby) Patch(url string) *Frisby {
F.Method = "PATCH"
F.Url = url
return F
} | go | func (F *Frisby) Patch(url string) *Frisby {
F.Method = "PATCH"
F.Url = url
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"Patch",
"(",
"url",
"string",
")",
"*",
"Frisby",
"{",
"F",
".",
"Method",
"=",
"\"",
"\"",
"\n",
"F",
".",
"Url",
"=",
"url",
"\n",
"return",
"F",
"\n",
"}"
] | // Set the HTTP method to PATCH for the given URL | [
"Set",
"the",
"HTTP",
"method",
"to",
"PATCH",
"for",
"the",
"given",
"URL"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/frisby.go#L76-L80 |
11,459 | verdverm/frisby | frisby.go | Delete | func (F *Frisby) Delete(url string) *Frisby {
F.Method = "DELETE"
F.Url = url
return F
} | go | func (F *Frisby) Delete(url string) *Frisby {
F.Method = "DELETE"
F.Url = url
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"Delete",
"(",
"url",
"string",
")",
"*",
"Frisby",
"{",
"F",
".",
"Method",
"=",
"\"",
"\"",
"\n",
"F",
".",
"Url",
"=",
"url",
"\n",
"return",
"F",
"\n",
"}"
] | // Set the HTTP method to DELETE for the given URL | [
"Set",
"the",
"HTTP",
"method",
"to",
"DELETE",
"for",
"the",
"given",
"URL"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/frisby.go#L83-L87 |
11,460 | verdverm/frisby | frisby.go | Head | func (F *Frisby) Head(url string) *Frisby {
F.Method = "HEAD"
F.Url = url
return F
} | go | func (F *Frisby) Head(url string) *Frisby {
F.Method = "HEAD"
F.Url = url
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"Head",
"(",
"url",
"string",
")",
"*",
"Frisby",
"{",
"F",
".",
"Method",
"=",
"\"",
"\"",
"\n",
"F",
".",
"Url",
"=",
"url",
"\n",
"return",
"F",
"\n",
"}"
] | // Set the HTTP method to HEAD for the given URL | [
"Set",
"the",
"HTTP",
"method",
"to",
"HEAD",
"for",
"the",
"given",
"URL"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/frisby.go#L90-L94 |
11,461 | verdverm/frisby | frisby.go | Options | func (F *Frisby) Options(url string) *Frisby {
F.Method = "OPTIONS"
F.Url = url
return F
} | go | func (F *Frisby) Options(url string) *Frisby {
F.Method = "OPTIONS"
F.Url = url
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"Options",
"(",
"url",
"string",
")",
"*",
"Frisby",
"{",
"F",
".",
"Method",
"=",
"\"",
"\"",
"\n",
"F",
".",
"Url",
"=",
"url",
"\n",
"return",
"F",
"\n",
"}"
] | // Set the HTTP method to OPTIONS for the given URL | [
"Set",
"the",
"HTTP",
"method",
"to",
"OPTIONS",
"for",
"the",
"given",
"URL"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/frisby.go#L97-L101 |
11,462 | verdverm/frisby | frisby.go | SetData | func (F *Frisby) SetData(key, value string) *Frisby {
if F.Req.Data == nil {
F.Req.Data = make(map[string]string)
}
F.Req.Data[key] = value
return F
} | go | func (F *Frisby) SetData(key, value string) *Frisby {
if F.Req.Data == nil {
F.Req.Data = make(map[string]string)
}
F.Req.Data[key] = value
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"SetData",
"(",
"key",
",",
"value",
"string",
")",
"*",
"Frisby",
"{",
"if",
"F",
".",
"Req",
".",
"Data",
"==",
"nil",
"{",
"F",
".",
"Req",
".",
"Data",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"F",
".",
"Req",
".",
"Data",
"[",
"key",
"]",
"=",
"value",
"\n",
"return",
"F",
"\n",
"}"
] | // Set a Form data for the coming request | [
"Set",
"a",
"Form",
"data",
"for",
"the",
"coming",
"request"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/frisby.go#L156-L162 |
11,463 | verdverm/frisby | frisby.go | SetDatas | func (F *Frisby) SetDatas(datas map[string]string) *Frisby {
if F.Req.Data == nil {
F.Req.Data = make(map[string]string)
}
for key, value := range datas {
F.Req.Data[key] = value
}
return F
} | go | func (F *Frisby) SetDatas(datas map[string]string) *Frisby {
if F.Req.Data == nil {
F.Req.Data = make(map[string]string)
}
for key, value := range datas {
F.Req.Data[key] = value
}
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"SetDatas",
"(",
"datas",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"Frisby",
"{",
"if",
"F",
".",
"Req",
".",
"Data",
"==",
"nil",
"{",
"F",
".",
"Req",
".",
"Data",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"datas",
"{",
"F",
".",
"Req",
".",
"Data",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n",
"return",
"F",
"\n",
"}"
] | // Set several Form data for the coming request | [
"Set",
"several",
"Form",
"data",
"for",
"the",
"coming",
"request"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/frisby.go#L165-L173 |
11,464 | verdverm/frisby | frisby.go | AddFile | func (F *Frisby) AddFile(filename string) *Frisby {
file, err := os.Open(filename)
if err != nil {
F.Errs = append(F.Errs, err)
} else {
fileField := request.FileField{
FieldName: defaultFileKey,
FileName: filepath.Base(filename),
File: file}
F.Req.Files = append(F.Req.Files, fileField)
}
return F
} | go | func (F *Frisby) AddFile(filename string) *Frisby {
file, err := os.Open(filename)
if err != nil {
F.Errs = append(F.Errs, err)
} else {
fileField := request.FileField{
FieldName: defaultFileKey,
FileName: filepath.Base(filename),
File: file}
F.Req.Files = append(F.Req.Files, fileField)
}
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"AddFile",
"(",
"filename",
"string",
")",
"*",
"Frisby",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"F",
".",
"Errs",
"=",
"append",
"(",
"F",
".",
"Errs",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"fileField",
":=",
"request",
".",
"FileField",
"{",
"FieldName",
":",
"defaultFileKey",
",",
"FileName",
":",
"filepath",
".",
"Base",
"(",
"filename",
")",
",",
"File",
":",
"file",
"}",
"\n",
"F",
".",
"Req",
".",
"Files",
"=",
"append",
"(",
"F",
".",
"Req",
".",
"Files",
",",
"fileField",
")",
"\n",
"}",
"\n",
"return",
"F",
"\n",
"}"
] | // Add a file to the Form data for the coming request | [
"Add",
"a",
"file",
"to",
"the",
"Form",
"data",
"for",
"the",
"coming",
"request"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/frisby.go#L202-L214 |
11,465 | verdverm/frisby | frisby.go | Send | func (F *Frisby) Send() *Frisby {
Global.NumRequest++
if Global.PrintProgressName {
fmt.Println(F.Name)
} else if Global.PrintProgressDot {
fmt.Printf("")
}
start := time.Now()
var err error
switch F.Method {
case "GET":
F.Resp, err = F.Req.Get(F.Url)
case "POST":
F.Resp, err = F.Req.Post(F.Url)
case "PUT":
F.Resp, err = F.Req.Put(F.Url)
case "PATCH":
F.Resp, err = F.Req.Patch(F.Url)
case "DELETE":
F.Resp, err = F.Req.Delete(F.Url)
case "HEAD":
F.Resp, err = F.Req.Head(F.Url)
case "OPTIONS":
F.Resp, err = F.Req.Options(F.Url)
}
F.ExecutionTime = time.Since(start).Seconds()
if err != nil {
F.Errs = append(F.Errs, err)
}
return F
} | go | func (F *Frisby) Send() *Frisby {
Global.NumRequest++
if Global.PrintProgressName {
fmt.Println(F.Name)
} else if Global.PrintProgressDot {
fmt.Printf("")
}
start := time.Now()
var err error
switch F.Method {
case "GET":
F.Resp, err = F.Req.Get(F.Url)
case "POST":
F.Resp, err = F.Req.Post(F.Url)
case "PUT":
F.Resp, err = F.Req.Put(F.Url)
case "PATCH":
F.Resp, err = F.Req.Patch(F.Url)
case "DELETE":
F.Resp, err = F.Req.Delete(F.Url)
case "HEAD":
F.Resp, err = F.Req.Head(F.Url)
case "OPTIONS":
F.Resp, err = F.Req.Options(F.Url)
}
F.ExecutionTime = time.Since(start).Seconds()
if err != nil {
F.Errs = append(F.Errs, err)
}
return F
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"Send",
"(",
")",
"*",
"Frisby",
"{",
"Global",
".",
"NumRequest",
"++",
"\n",
"if",
"Global",
".",
"PrintProgressName",
"{",
"fmt",
".",
"Println",
"(",
"F",
".",
"Name",
")",
"\n",
"}",
"else",
"if",
"Global",
".",
"PrintProgressDot",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"var",
"err",
"error",
"\n",
"switch",
"F",
".",
"Method",
"{",
"case",
"\"",
"\"",
":",
"F",
".",
"Resp",
",",
"err",
"=",
"F",
".",
"Req",
".",
"Get",
"(",
"F",
".",
"Url",
")",
"\n",
"case",
"\"",
"\"",
":",
"F",
".",
"Resp",
",",
"err",
"=",
"F",
".",
"Req",
".",
"Post",
"(",
"F",
".",
"Url",
")",
"\n",
"case",
"\"",
"\"",
":",
"F",
".",
"Resp",
",",
"err",
"=",
"F",
".",
"Req",
".",
"Put",
"(",
"F",
".",
"Url",
")",
"\n",
"case",
"\"",
"\"",
":",
"F",
".",
"Resp",
",",
"err",
"=",
"F",
".",
"Req",
".",
"Patch",
"(",
"F",
".",
"Url",
")",
"\n",
"case",
"\"",
"\"",
":",
"F",
".",
"Resp",
",",
"err",
"=",
"F",
".",
"Req",
".",
"Delete",
"(",
"F",
".",
"Url",
")",
"\n",
"case",
"\"",
"\"",
":",
"F",
".",
"Resp",
",",
"err",
"=",
"F",
".",
"Req",
".",
"Head",
"(",
"F",
".",
"Url",
")",
"\n",
"case",
"\"",
"\"",
":",
"F",
".",
"Resp",
",",
"err",
"=",
"F",
".",
"Req",
".",
"Options",
"(",
"F",
".",
"Url",
")",
"\n",
"}",
"\n\n",
"F",
".",
"ExecutionTime",
"=",
"time",
".",
"Since",
"(",
"start",
")",
".",
"Seconds",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"F",
".",
"Errs",
"=",
"append",
"(",
"F",
".",
"Errs",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"F",
"\n",
"}"
] | // Send the actual request to the URL | [
"Send",
"the",
"actual",
"request",
"to",
"the",
"URL"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/frisby.go#L235-L270 |
11,466 | verdverm/frisby | frisby.go | Error | func (F *Frisby) Error() error {
if len(F.Errs) > 0 {
return F.Errs[len(F.Errs)-1]
}
return nil
} | go | func (F *Frisby) Error() error {
if len(F.Errs) > 0 {
return F.Errs[len(F.Errs)-1]
}
return nil
} | [
"func",
"(",
"F",
"*",
"Frisby",
")",
"Error",
"(",
")",
"error",
"{",
"if",
"len",
"(",
"F",
".",
"Errs",
")",
">",
"0",
"{",
"return",
"F",
".",
"Errs",
"[",
"len",
"(",
"F",
".",
"Errs",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Get the most recent error for the Frisby object
//
// This function should be called last | [
"Get",
"the",
"most",
"recent",
"error",
"for",
"the",
"Frisby",
"object",
"This",
"function",
"should",
"be",
"called",
"last"
] | b16556248a9a21a8166936e49771527189661abe | https://github.com/verdverm/frisby/blob/b16556248a9a21a8166936e49771527189661abe/frisby.go#L283-L288 |
11,467 | tevino/abool | bool.go | NewBool | func NewBool(ok bool) *AtomicBool {
ab := New()
if ok {
ab.Set()
}
return ab
} | go | func NewBool(ok bool) *AtomicBool {
ab := New()
if ok {
ab.Set()
}
return ab
} | [
"func",
"NewBool",
"(",
"ok",
"bool",
")",
"*",
"AtomicBool",
"{",
"ab",
":=",
"New",
"(",
")",
"\n",
"if",
"ok",
"{",
"ab",
".",
"Set",
"(",
")",
"\n",
"}",
"\n",
"return",
"ab",
"\n",
"}"
] | // NewBool creates an AtomicBool with given default value | [
"NewBool",
"creates",
"an",
"AtomicBool",
"with",
"given",
"default",
"value"
] | 9b9efcf221b50905aab9bbabd3daed56dc10f339 | https://github.com/tevino/abool/blob/9b9efcf221b50905aab9bbabd3daed56dc10f339/bool.go#L13-L19 |
11,468 | tevino/abool | bool.go | SetTo | func (ab *AtomicBool) SetTo(yes bool) {
if yes {
atomic.StoreInt32((*int32)(ab), 1)
} else {
atomic.StoreInt32((*int32)(ab), 0)
}
} | go | func (ab *AtomicBool) SetTo(yes bool) {
if yes {
atomic.StoreInt32((*int32)(ab), 1)
} else {
atomic.StoreInt32((*int32)(ab), 0)
}
} | [
"func",
"(",
"ab",
"*",
"AtomicBool",
")",
"SetTo",
"(",
"yes",
"bool",
")",
"{",
"if",
"yes",
"{",
"atomic",
".",
"StoreInt32",
"(",
"(",
"*",
"int32",
")",
"(",
"ab",
")",
",",
"1",
")",
"\n",
"}",
"else",
"{",
"atomic",
".",
"StoreInt32",
"(",
"(",
"*",
"int32",
")",
"(",
"ab",
")",
",",
"0",
")",
"\n",
"}",
"\n",
"}"
] | // SetTo sets the boolean with given Boolean | [
"SetTo",
"sets",
"the",
"boolean",
"with",
"given",
"Boolean"
] | 9b9efcf221b50905aab9bbabd3daed56dc10f339 | https://github.com/tevino/abool/blob/9b9efcf221b50905aab9bbabd3daed56dc10f339/bool.go#L44-L50 |
11,469 | tevino/abool | bool.go | SetToIf | func (ab *AtomicBool) SetToIf(old, new bool) (set bool) {
var o, n int32
if old {
o = 1
}
if new {
n = 1
}
return atomic.CompareAndSwapInt32((*int32)(ab), o, n)
} | go | func (ab *AtomicBool) SetToIf(old, new bool) (set bool) {
var o, n int32
if old {
o = 1
}
if new {
n = 1
}
return atomic.CompareAndSwapInt32((*int32)(ab), o, n)
} | [
"func",
"(",
"ab",
"*",
"AtomicBool",
")",
"SetToIf",
"(",
"old",
",",
"new",
"bool",
")",
"(",
"set",
"bool",
")",
"{",
"var",
"o",
",",
"n",
"int32",
"\n",
"if",
"old",
"{",
"o",
"=",
"1",
"\n",
"}",
"\n",
"if",
"new",
"{",
"n",
"=",
"1",
"\n",
"}",
"\n",
"return",
"atomic",
".",
"CompareAndSwapInt32",
"(",
"(",
"*",
"int32",
")",
"(",
"ab",
")",
",",
"o",
",",
"n",
")",
"\n",
"}"
] | // SetToIf sets the Boolean to new only if the Boolean matches the old
// Returns whether the set was done | [
"SetToIf",
"sets",
"the",
"Boolean",
"to",
"new",
"only",
"if",
"the",
"Boolean",
"matches",
"the",
"old",
"Returns",
"whether",
"the",
"set",
"was",
"done"
] | 9b9efcf221b50905aab9bbabd3daed56dc10f339 | https://github.com/tevino/abool/blob/9b9efcf221b50905aab9bbabd3daed56dc10f339/bool.go#L54-L63 |
11,470 | square/goprotowrap | wrapper/generate.go | Generate | func Generate(pkg *PackageInfo, importDirs []string, protocCommand string, protocFlags []string, printOnly bool) (err error) {
args := protocFlags[0:len(protocFlags):len(protocFlags)]
files := make([]string, 0, len(pkg.Files))
for _, f := range pkg.Files {
files = append(files, f.FullPath)
}
sort.Strings(files)
args = append(args, files...)
if printOnly {
fmt.Printf("%s %s\n", protocCommand, strings.Join(args, " "))
return nil
}
cmd := exec.Command(protocCommand, args...)
out, err := cmd.CombinedOutput()
if err != nil {
cmdline := fmt.Sprintf("%s %s\n", protocCommand, strings.Join(args, " "))
return fmt.Errorf("error running %v\n%v\nOutput:\n======\n%s======\n", cmdline, err, out)
}
return nil
} | go | func Generate(pkg *PackageInfo, importDirs []string, protocCommand string, protocFlags []string, printOnly bool) (err error) {
args := protocFlags[0:len(protocFlags):len(protocFlags)]
files := make([]string, 0, len(pkg.Files))
for _, f := range pkg.Files {
files = append(files, f.FullPath)
}
sort.Strings(files)
args = append(args, files...)
if printOnly {
fmt.Printf("%s %s\n", protocCommand, strings.Join(args, " "))
return nil
}
cmd := exec.Command(protocCommand, args...)
out, err := cmd.CombinedOutput()
if err != nil {
cmdline := fmt.Sprintf("%s %s\n", protocCommand, strings.Join(args, " "))
return fmt.Errorf("error running %v\n%v\nOutput:\n======\n%s======\n", cmdline, err, out)
}
return nil
} | [
"func",
"Generate",
"(",
"pkg",
"*",
"PackageInfo",
",",
"importDirs",
"[",
"]",
"string",
",",
"protocCommand",
"string",
",",
"protocFlags",
"[",
"]",
"string",
",",
"printOnly",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"args",
":=",
"protocFlags",
"[",
"0",
":",
"len",
"(",
"protocFlags",
")",
":",
"len",
"(",
"protocFlags",
")",
"]",
"\n\n",
"files",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"pkg",
".",
"Files",
")",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"pkg",
".",
"Files",
"{",
"files",
"=",
"append",
"(",
"files",
",",
"f",
".",
"FullPath",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"files",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"files",
"...",
")",
"\n\n",
"if",
"printOnly",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"protocCommand",
",",
"strings",
".",
"Join",
"(",
"args",
",",
"\"",
"\"",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"protocCommand",
",",
"args",
"...",
")",
"\n",
"out",
",",
"err",
":=",
"cmd",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"cmdline",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"protocCommand",
",",
"strings",
".",
"Join",
"(",
"args",
",",
"\"",
"\"",
")",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\\n",
"\\n",
"\\n",
"\"",
",",
"cmdline",
",",
"err",
",",
"out",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Generate does the actual generation of protos. | [
"Generate",
"does",
"the",
"actual",
"generation",
"of",
"protos",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/generate.go#L30-L51 |
11,471 | square/goprotowrap | wrapper/generate.go | CopyAndChangePackage | func CopyAndChangePackage(in, out, pkg string) error {
inf, err := os.Open(in)
if err != nil {
return err
}
defer inf.Close()
outf, err := os.Create(out)
if err != nil {
return err
}
defer outf.Close()
scanner := bufio.NewScanner(inf)
matched := false
for scanner.Scan() {
line := scanner.Text()
if !matched && packageRe.MatchString(line) {
matched = true
line = packageRe.ReplaceAllString(line, fmt.Sprintf("package %s", pkg))
}
fmt.Fprintln(outf, line)
}
if err := scanner.Err(); err != nil {
return err
}
return nil
} | go | func CopyAndChangePackage(in, out, pkg string) error {
inf, err := os.Open(in)
if err != nil {
return err
}
defer inf.Close()
outf, err := os.Create(out)
if err != nil {
return err
}
defer outf.Close()
scanner := bufio.NewScanner(inf)
matched := false
for scanner.Scan() {
line := scanner.Text()
if !matched && packageRe.MatchString(line) {
matched = true
line = packageRe.ReplaceAllString(line, fmt.Sprintf("package %s", pkg))
}
fmt.Fprintln(outf, line)
}
if err := scanner.Err(); err != nil {
return err
}
return nil
} | [
"func",
"CopyAndChangePackage",
"(",
"in",
",",
"out",
",",
"pkg",
"string",
")",
"error",
"{",
"inf",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"in",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"inf",
".",
"Close",
"(",
")",
"\n",
"outf",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"out",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"outf",
".",
"Close",
"(",
")",
"\n",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"inf",
")",
"\n",
"matched",
":=",
"false",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"line",
":=",
"scanner",
".",
"Text",
"(",
")",
"\n",
"if",
"!",
"matched",
"&&",
"packageRe",
".",
"MatchString",
"(",
"line",
")",
"{",
"matched",
"=",
"true",
"\n",
"line",
"=",
"packageRe",
".",
"ReplaceAllString",
"(",
"line",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pkg",
")",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintln",
"(",
"outf",
",",
"line",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"scanner",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CopyAndChangePackage copies file `in` to file `out`, rewriting the
// `package` declaration to `pkg`. | [
"CopyAndChangePackage",
"copies",
"file",
"in",
"to",
"file",
"out",
"rewriting",
"the",
"package",
"declaration",
"to",
"pkg",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/generate.go#L57-L82 |
11,472 | square/goprotowrap | wrapper/packages.go | PackageDir | func (f FileInfo) PackageDir() string {
parts := strings.Split(f.ComputedPackage, ".")
return filepath.Join(parts...)
} | go | func (f FileInfo) PackageDir() string {
parts := strings.Split(f.ComputedPackage, ".")
return filepath.Join(parts...)
} | [
"func",
"(",
"f",
"FileInfo",
")",
"PackageDir",
"(",
")",
"string",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"f",
".",
"ComputedPackage",
",",
"\"",
"\"",
")",
"\n",
"return",
"filepath",
".",
"Join",
"(",
"parts",
"...",
")",
"\n",
"}"
] | // PackageDir returns the desired directory location for the given
// file; ComputedPackage, with dots replaced by slashes. | [
"PackageDir",
"returns",
"the",
"desired",
"directory",
"location",
"for",
"the",
"given",
"file",
";",
"ComputedPackage",
"with",
"dots",
"replaced",
"by",
"slashes",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/packages.go#L51-L54 |
11,473 | square/goprotowrap | wrapper/packages.go | GoPluginOutputFilename | func (f FileInfo) GoPluginOutputFilename() string {
name := f.Name
ext := path.Ext(name)
if ext == ".proto" || ext == ".protodevel" {
name = name[0 : len(name)-len(ext)]
}
return name + ".pb.go"
} | go | func (f FileInfo) GoPluginOutputFilename() string {
name := f.Name
ext := path.Ext(name)
if ext == ".proto" || ext == ".protodevel" {
name = name[0 : len(name)-len(ext)]
}
return name + ".pb.go"
} | [
"func",
"(",
"f",
"FileInfo",
")",
"GoPluginOutputFilename",
"(",
")",
"string",
"{",
"name",
":=",
"f",
".",
"Name",
"\n",
"ext",
":=",
"path",
".",
"Ext",
"(",
"name",
")",
"\n",
"if",
"ext",
"==",
"\"",
"\"",
"||",
"ext",
"==",
"\"",
"\"",
"{",
"name",
"=",
"name",
"[",
"0",
":",
"len",
"(",
"name",
")",
"-",
"len",
"(",
"ext",
")",
"]",
"\n",
"}",
"\n",
"return",
"name",
"+",
"\"",
"\"",
"\n",
"}"
] | // GoPluginOutputFilename returns the filename the vanilla go protoc
// plugin will use when generating output for this file. | [
"GoPluginOutputFilename",
"returns",
"the",
"filename",
"the",
"vanilla",
"go",
"protoc",
"plugin",
"will",
"use",
"when",
"generating",
"output",
"for",
"this",
"file",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/packages.go#L58-L65 |
11,474 | square/goprotowrap | wrapper/packages.go | PackageDir | func (p PackageInfo) PackageDir() string {
parts := strings.Split(p.ComputedPackage, ".")
return filepath.Join(parts...)
} | go | func (p PackageInfo) PackageDir() string {
parts := strings.Split(p.ComputedPackage, ".")
return filepath.Join(parts...)
} | [
"func",
"(",
"p",
"PackageInfo",
")",
"PackageDir",
"(",
")",
"string",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"p",
".",
"ComputedPackage",
",",
"\"",
"\"",
")",
"\n",
"return",
"filepath",
".",
"Join",
"(",
"parts",
"...",
")",
"\n",
"}"
] | // PackageDir returns the desired directory location for the given
// package; ComputedPackage, with dots replaced by slashes. | [
"PackageDir",
"returns",
"the",
"desired",
"directory",
"location",
"for",
"the",
"given",
"package",
";",
"ComputedPackage",
"with",
"dots",
"replaced",
"by",
"slashes",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/packages.go#L81-L84 |
11,475 | square/goprotowrap | wrapper/packages.go | PackageName | func (p PackageInfo) PackageName() string {
parts := strings.Split(p.ComputedPackage, ".")
return parts[len(parts)-1]
} | go | func (p PackageInfo) PackageName() string {
parts := strings.Split(p.ComputedPackage, ".")
return parts[len(parts)-1]
} | [
"func",
"(",
"p",
"PackageInfo",
")",
"PackageName",
"(",
")",
"string",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"p",
".",
"ComputedPackage",
",",
"\"",
"\"",
")",
"\n",
"return",
"parts",
"[",
"len",
"(",
"parts",
")",
"-",
"1",
"]",
"\n",
"}"
] | // PackageName returns the desired package name for the given package;
// whatever follows the last dot in ComputedPackage. | [
"PackageName",
"returns",
"the",
"desired",
"package",
"name",
"for",
"the",
"given",
"package",
";",
"whatever",
"follows",
"the",
"last",
"dot",
"in",
"ComputedPackage",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/packages.go#L88-L91 |
11,476 | square/goprotowrap | wrapper/packages.go | ImportedPackageComputedNames | func (p PackageInfo) ImportedPackageComputedNames() []string {
result := []string{}
seen := map[string]bool{
p.ComputedPackage: true,
}
for _, d := range p.Deps {
pkg := d.ComputedPackage
if seen[pkg] {
continue
}
seen[pkg] = true
result = append(result, pkg)
}
return result
} | go | func (p PackageInfo) ImportedPackageComputedNames() []string {
result := []string{}
seen := map[string]bool{
p.ComputedPackage: true,
}
for _, d := range p.Deps {
pkg := d.ComputedPackage
if seen[pkg] {
continue
}
seen[pkg] = true
result = append(result, pkg)
}
return result
} | [
"func",
"(",
"p",
"PackageInfo",
")",
"ImportedPackageComputedNames",
"(",
")",
"[",
"]",
"string",
"{",
"result",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"seen",
":=",
"map",
"[",
"string",
"]",
"bool",
"{",
"p",
".",
"ComputedPackage",
":",
"true",
",",
"}",
"\n",
"for",
"_",
",",
"d",
":=",
"range",
"p",
".",
"Deps",
"{",
"pkg",
":=",
"d",
".",
"ComputedPackage",
"\n",
"if",
"seen",
"[",
"pkg",
"]",
"{",
"continue",
"\n",
"}",
"\n",
"seen",
"[",
"pkg",
"]",
"=",
"true",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"pkg",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | //ImportedPackageComputedNames returns the list of packages imported by this
//package. | [
"ImportedPackageComputedNames",
"returns",
"the",
"list",
"of",
"packages",
"imported",
"by",
"this",
"package",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/packages.go#L95-L109 |
11,477 | square/goprotowrap | wrapper/packages.go | GetFileInfos | func GetFileInfos(importPaths []string, protos []string, protocCommand string) (info map[string]*FileInfo, err error) {
if len(importPaths) == 0 {
return nil, fmt.Errorf("GetFileInfos: empty importPaths")
}
if len(protos) == 0 {
return nil, fmt.Errorf("GetFileInfos: empty protos")
}
info = map[string]*FileInfo{}
var dir string
dir, err = ioutil.TempDir("", "filedescriptors")
if err != nil {
return nil, err
}
defer func() {
if err2 := os.RemoveAll(dir); err != nil && err2 != nil {
err = err2
}
}()
descriptorFilename := filepath.Join(dir, "all.pb")
args := []string{}
for _, importPath := range importPaths {
args = append(args, "-I", importPath)
}
args = append(args, "--descriptor_set_out="+descriptorFilename)
args = append(args, "--include_imports")
for _, proto := range protos {
args = append(args, proto)
}
fmt.Println("Collecting filedescriptors...")
cmd := exec.Command(protocCommand, args...)
out, err := cmd.CombinedOutput()
if err != nil {
cmdline := fmt.Sprintf("%s %s\n", protocCommand, strings.Join(args, " "))
return nil, fmt.Errorf("error running %v\n%v\nOutput:\n======\n%s======\n", cmdline, err, out)
}
descriptorSetBytes, err := ioutil.ReadFile(descriptorFilename)
if err != nil {
return nil, err
}
descriptorSet := &descriptor.FileDescriptorSet{}
err = proto.Unmarshal(descriptorSetBytes, descriptorSet)
if err != nil {
return nil, err
}
for _, fd := range descriptorSet.File {
fi := &FileInfo{
Name: fd.GetName(),
Package: fd.GetPackage(),
}
for _, dep := range fd.Dependency {
fi.Deps = append(fi.Deps, dep)
}
fi.GoPackage = fd.Options.GetGoPackage()
info[fi.Name] = fi
}
return info, nil
} | go | func GetFileInfos(importPaths []string, protos []string, protocCommand string) (info map[string]*FileInfo, err error) {
if len(importPaths) == 0 {
return nil, fmt.Errorf("GetFileInfos: empty importPaths")
}
if len(protos) == 0 {
return nil, fmt.Errorf("GetFileInfos: empty protos")
}
info = map[string]*FileInfo{}
var dir string
dir, err = ioutil.TempDir("", "filedescriptors")
if err != nil {
return nil, err
}
defer func() {
if err2 := os.RemoveAll(dir); err != nil && err2 != nil {
err = err2
}
}()
descriptorFilename := filepath.Join(dir, "all.pb")
args := []string{}
for _, importPath := range importPaths {
args = append(args, "-I", importPath)
}
args = append(args, "--descriptor_set_out="+descriptorFilename)
args = append(args, "--include_imports")
for _, proto := range protos {
args = append(args, proto)
}
fmt.Println("Collecting filedescriptors...")
cmd := exec.Command(protocCommand, args...)
out, err := cmd.CombinedOutput()
if err != nil {
cmdline := fmt.Sprintf("%s %s\n", protocCommand, strings.Join(args, " "))
return nil, fmt.Errorf("error running %v\n%v\nOutput:\n======\n%s======\n", cmdline, err, out)
}
descriptorSetBytes, err := ioutil.ReadFile(descriptorFilename)
if err != nil {
return nil, err
}
descriptorSet := &descriptor.FileDescriptorSet{}
err = proto.Unmarshal(descriptorSetBytes, descriptorSet)
if err != nil {
return nil, err
}
for _, fd := range descriptorSet.File {
fi := &FileInfo{
Name: fd.GetName(),
Package: fd.GetPackage(),
}
for _, dep := range fd.Dependency {
fi.Deps = append(fi.Deps, dep)
}
fi.GoPackage = fd.Options.GetGoPackage()
info[fi.Name] = fi
}
return info, nil
} | [
"func",
"GetFileInfos",
"(",
"importPaths",
"[",
"]",
"string",
",",
"protos",
"[",
"]",
"string",
",",
"protocCommand",
"string",
")",
"(",
"info",
"map",
"[",
"string",
"]",
"*",
"FileInfo",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"importPaths",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"protos",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"info",
"=",
"map",
"[",
"string",
"]",
"*",
"FileInfo",
"{",
"}",
"\n\n",
"var",
"dir",
"string",
"\n",
"dir",
",",
"err",
"=",
"ioutil",
".",
"TempDir",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err2",
":=",
"os",
".",
"RemoveAll",
"(",
"dir",
")",
";",
"err",
"!=",
"nil",
"&&",
"err2",
"!=",
"nil",
"{",
"err",
"=",
"err2",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"descriptorFilename",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
")",
"\n\n",
"args",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"importPath",
":=",
"range",
"importPaths",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
",",
"importPath",
")",
"\n",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
"+",
"descriptorFilename",
")",
"\n\n",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
")",
"\n\n",
"for",
"_",
",",
"proto",
":=",
"range",
"protos",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"proto",
")",
"\n",
"}",
"\n\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"protocCommand",
",",
"args",
"...",
")",
"\n",
"out",
",",
"err",
":=",
"cmd",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"cmdline",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"protocCommand",
",",
"strings",
".",
"Join",
"(",
"args",
",",
"\"",
"\"",
")",
")",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\\n",
"\\n",
"\\n",
"\"",
",",
"cmdline",
",",
"err",
",",
"out",
")",
"\n",
"}",
"\n",
"descriptorSetBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"descriptorFilename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"descriptorSet",
":=",
"&",
"descriptor",
".",
"FileDescriptorSet",
"{",
"}",
"\n",
"err",
"=",
"proto",
".",
"Unmarshal",
"(",
"descriptorSetBytes",
",",
"descriptorSet",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"fd",
":=",
"range",
"descriptorSet",
".",
"File",
"{",
"fi",
":=",
"&",
"FileInfo",
"{",
"Name",
":",
"fd",
".",
"GetName",
"(",
")",
",",
"Package",
":",
"fd",
".",
"GetPackage",
"(",
")",
",",
"}",
"\n",
"for",
"_",
",",
"dep",
":=",
"range",
"fd",
".",
"Dependency",
"{",
"fi",
".",
"Deps",
"=",
"append",
"(",
"fi",
".",
"Deps",
",",
"dep",
")",
"\n",
"}",
"\n",
"fi",
".",
"GoPackage",
"=",
"fd",
".",
"Options",
".",
"GetGoPackage",
"(",
")",
"\n",
"info",
"[",
"fi",
".",
"Name",
"]",
"=",
"fi",
"\n",
"}",
"\n\n",
"return",
"info",
",",
"nil",
"\n",
"}"
] | // GetFileInfos gets the FileInfo struct for every proto passed in. | [
"GetFileInfos",
"gets",
"the",
"FileInfo",
"struct",
"for",
"every",
"proto",
"passed",
"in",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/packages.go#L112-L177 |
11,478 | square/goprotowrap | wrapper/packages.go | CollectPackages | func CollectPackages(infos map[string]*FileInfo, protos []string, importDirs []string) (map[string]*PackageInfo, error) {
pkgMap := map[string]*PackageInfo{}
// Collect into packages.
for _, info := range infos {
packageInfo, ok := pkgMap[info.ComputedPackage]
if !ok {
packageInfo = &PackageInfo{ComputedPackage: info.ComputedPackage}
pkgMap[info.ComputedPackage] = packageInfo
}
packageInfo.Files = append(packageInfo.Files, info)
}
// Collect deps for each package.
for _, pkg := range pkgMap {
deps := map[string]*FileInfo{}
for _, info := range pkg.Files {
for _, dep := range info.Deps {
deps[dep] = infos[dep]
}
}
for _, dep := range deps {
pkg.Deps = append(pkg.Deps, dep)
}
}
return pkgMap, nil
} | go | func CollectPackages(infos map[string]*FileInfo, protos []string, importDirs []string) (map[string]*PackageInfo, error) {
pkgMap := map[string]*PackageInfo{}
// Collect into packages.
for _, info := range infos {
packageInfo, ok := pkgMap[info.ComputedPackage]
if !ok {
packageInfo = &PackageInfo{ComputedPackage: info.ComputedPackage}
pkgMap[info.ComputedPackage] = packageInfo
}
packageInfo.Files = append(packageInfo.Files, info)
}
// Collect deps for each package.
for _, pkg := range pkgMap {
deps := map[string]*FileInfo{}
for _, info := range pkg.Files {
for _, dep := range info.Deps {
deps[dep] = infos[dep]
}
}
for _, dep := range deps {
pkg.Deps = append(pkg.Deps, dep)
}
}
return pkgMap, nil
} | [
"func",
"CollectPackages",
"(",
"infos",
"map",
"[",
"string",
"]",
"*",
"FileInfo",
",",
"protos",
"[",
"]",
"string",
",",
"importDirs",
"[",
"]",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"PackageInfo",
",",
"error",
")",
"{",
"pkgMap",
":=",
"map",
"[",
"string",
"]",
"*",
"PackageInfo",
"{",
"}",
"\n\n",
"// Collect into packages.",
"for",
"_",
",",
"info",
":=",
"range",
"infos",
"{",
"packageInfo",
",",
"ok",
":=",
"pkgMap",
"[",
"info",
".",
"ComputedPackage",
"]",
"\n",
"if",
"!",
"ok",
"{",
"packageInfo",
"=",
"&",
"PackageInfo",
"{",
"ComputedPackage",
":",
"info",
".",
"ComputedPackage",
"}",
"\n",
"pkgMap",
"[",
"info",
".",
"ComputedPackage",
"]",
"=",
"packageInfo",
"\n",
"}",
"\n",
"packageInfo",
".",
"Files",
"=",
"append",
"(",
"packageInfo",
".",
"Files",
",",
"info",
")",
"\n",
"}",
"\n\n",
"// Collect deps for each package.",
"for",
"_",
",",
"pkg",
":=",
"range",
"pkgMap",
"{",
"deps",
":=",
"map",
"[",
"string",
"]",
"*",
"FileInfo",
"{",
"}",
"\n",
"for",
"_",
",",
"info",
":=",
"range",
"pkg",
".",
"Files",
"{",
"for",
"_",
",",
"dep",
":=",
"range",
"info",
".",
"Deps",
"{",
"deps",
"[",
"dep",
"]",
"=",
"infos",
"[",
"dep",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"dep",
":=",
"range",
"deps",
"{",
"pkg",
".",
"Deps",
"=",
"append",
"(",
"pkg",
".",
"Deps",
",",
"dep",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"pkgMap",
",",
"nil",
"\n",
"}"
] | // CollectPackages returns a map of PackageInfos. | [
"CollectPackages",
"returns",
"a",
"map",
"of",
"PackageInfos",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/packages.go#L224-L251 |
11,479 | square/goprotowrap | wrapper/packages.go | FileDescriptorName | func FileDescriptorName(protoFile string, importDirs []string) string {
isAbs := path.IsAbs(protoFile)
for _, imp := range importDirs {
// Handle import dirs of "." - the FileDescriptorProtos don't have the "./" prefix.
if imp == "." && !isAbs {
if strings.HasPrefix(protoFile, "./") {
return protoFile[2:]
}
return protoFile
}
if strings.HasPrefix(protoFile, imp) {
name := protoFile[len(imp):]
if strings.HasPrefix(name, "/") && imp != "/" {
return name[1:]
}
return name
}
}
panic(fmt.Sprintf("Unable to find import dir for %q", protoFile))
} | go | func FileDescriptorName(protoFile string, importDirs []string) string {
isAbs := path.IsAbs(protoFile)
for _, imp := range importDirs {
// Handle import dirs of "." - the FileDescriptorProtos don't have the "./" prefix.
if imp == "." && !isAbs {
if strings.HasPrefix(protoFile, "./") {
return protoFile[2:]
}
return protoFile
}
if strings.HasPrefix(protoFile, imp) {
name := protoFile[len(imp):]
if strings.HasPrefix(name, "/") && imp != "/" {
return name[1:]
}
return name
}
}
panic(fmt.Sprintf("Unable to find import dir for %q", protoFile))
} | [
"func",
"FileDescriptorName",
"(",
"protoFile",
"string",
",",
"importDirs",
"[",
"]",
"string",
")",
"string",
"{",
"isAbs",
":=",
"path",
".",
"IsAbs",
"(",
"protoFile",
")",
"\n",
"for",
"_",
",",
"imp",
":=",
"range",
"importDirs",
"{",
"// Handle import dirs of \".\" - the FileDescriptorProtos don't have the \"./\" prefix.",
"if",
"imp",
"==",
"\"",
"\"",
"&&",
"!",
"isAbs",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"protoFile",
",",
"\"",
"\"",
")",
"{",
"return",
"protoFile",
"[",
"2",
":",
"]",
"\n",
"}",
"\n",
"return",
"protoFile",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"protoFile",
",",
"imp",
")",
"{",
"name",
":=",
"protoFile",
"[",
"len",
"(",
"imp",
")",
":",
"]",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"name",
",",
"\"",
"\"",
")",
"&&",
"imp",
"!=",
"\"",
"\"",
"{",
"return",
"name",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"return",
"name",
"\n",
"}",
"\n",
"}",
"\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"protoFile",
")",
")",
"\n",
"}"
] | // FileDescriptorName computes the import-dir-relative Name that the
// FileDescriptor for a full filename will have. | [
"FileDescriptorName",
"computes",
"the",
"import",
"-",
"dir",
"-",
"relative",
"Name",
"that",
"the",
"FileDescriptor",
"for",
"a",
"full",
"filename",
"will",
"have",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/packages.go#L255-L274 |
11,480 | square/goprotowrap | wrapper/packages.go | AnnotateFullPaths | func AnnotateFullPaths(infos map[string]*FileInfo, allProtos []string, importDirs []string) {
for _, proto := range allProtos {
name := FileDescriptorName(proto, importDirs)
info, ok := infos[name]
if !ok {
panic(fmt.Sprintf("Unable to find file information for %q", name))
}
info.FullPath = proto
}
} | go | func AnnotateFullPaths(infos map[string]*FileInfo, allProtos []string, importDirs []string) {
for _, proto := range allProtos {
name := FileDescriptorName(proto, importDirs)
info, ok := infos[name]
if !ok {
panic(fmt.Sprintf("Unable to find file information for %q", name))
}
info.FullPath = proto
}
} | [
"func",
"AnnotateFullPaths",
"(",
"infos",
"map",
"[",
"string",
"]",
"*",
"FileInfo",
",",
"allProtos",
"[",
"]",
"string",
",",
"importDirs",
"[",
"]",
"string",
")",
"{",
"for",
"_",
",",
"proto",
":=",
"range",
"allProtos",
"{",
"name",
":=",
"FileDescriptorName",
"(",
"proto",
",",
"importDirs",
")",
"\n",
"info",
",",
"ok",
":=",
"infos",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
")",
")",
"\n",
"}",
"\n",
"info",
".",
"FullPath",
"=",
"proto",
"\n",
"}",
"\n",
"}"
] | // AnnotateFullPaths annotates an existing set of FileInfos with their
// full paths. | [
"AnnotateFullPaths",
"annotates",
"an",
"existing",
"set",
"of",
"FileInfos",
"with",
"their",
"full",
"paths",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/packages.go#L278-L287 |
11,481 | square/goprotowrap | wrapper/flags.go | Int | func (fv FlagValues) Int(name string, defaultValue int) (int, error) {
value, found := fv[name]
if !found {
return defaultValue, nil
}
i, err := strconv.Atoi(value)
if err != nil {
return 0, fmt.Errorf("flag %q: cannot parse integer from %q", name, value)
}
return i, nil
} | go | func (fv FlagValues) Int(name string, defaultValue int) (int, error) {
value, found := fv[name]
if !found {
return defaultValue, nil
}
i, err := strconv.Atoi(value)
if err != nil {
return 0, fmt.Errorf("flag %q: cannot parse integer from %q", name, value)
}
return i, nil
} | [
"func",
"(",
"fv",
"FlagValues",
")",
"Int",
"(",
"name",
"string",
",",
"defaultValue",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"value",
",",
"found",
":=",
"fv",
"[",
"name",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"defaultValue",
",",
"nil",
"\n",
"}",
"\n",
"i",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"value",
")",
"\n",
"}",
"\n",
"return",
"i",
",",
"nil",
"\n",
"}"
] | // Int returns the integer version of a flag, if set. | [
"Int",
"returns",
"the",
"integer",
"version",
"of",
"a",
"flag",
"if",
"set",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/flags.go#L128-L138 |
11,482 | square/goprotowrap | wrapper/flags.go | Bool | func (fv FlagValues) Bool(name string, defaultValue bool) (bool, error) {
value, found := fv[name]
if !found {
return defaultValue, nil
}
switch value {
case "", "t", "T", "true", "True", "1":
return true, nil
case "f", "F", "false", "False", "0":
return false, nil
}
return false, fmt.Errorf("flag %q: cannot parse boolean from %q", name, value)
} | go | func (fv FlagValues) Bool(name string, defaultValue bool) (bool, error) {
value, found := fv[name]
if !found {
return defaultValue, nil
}
switch value {
case "", "t", "T", "true", "True", "1":
return true, nil
case "f", "F", "false", "False", "0":
return false, nil
}
return false, fmt.Errorf("flag %q: cannot parse boolean from %q", name, value)
} | [
"func",
"(",
"fv",
"FlagValues",
")",
"Bool",
"(",
"name",
"string",
",",
"defaultValue",
"bool",
")",
"(",
"bool",
",",
"error",
")",
"{",
"value",
",",
"found",
":=",
"fv",
"[",
"name",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"defaultValue",
",",
"nil",
"\n",
"}",
"\n",
"switch",
"value",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"true",
",",
"nil",
"\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"value",
")",
"\n",
"}"
] | // Bool returns the boolean version of a flag, if set. | [
"Bool",
"returns",
"the",
"boolean",
"version",
"of",
"a",
"flag",
"if",
"set",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/flags.go#L141-L153 |
11,483 | square/goprotowrap | wrapper/flags.go | Has | func (fv FlagValues) Has(name string) bool {
_, found := fv[name]
return found
} | go | func (fv FlagValues) Has(name string) bool {
_, found := fv[name]
return found
} | [
"func",
"(",
"fv",
"FlagValues",
")",
"Has",
"(",
"name",
"string",
")",
"bool",
"{",
"_",
",",
"found",
":=",
"fv",
"[",
"name",
"]",
"\n",
"return",
"found",
"\n",
"}"
] | // Has returns true if the given flag was specified at all. | [
"Has",
"returns",
"true",
"if",
"the",
"given",
"flag",
"was",
"specified",
"at",
"all",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/flags.go#L156-L159 |
11,484 | square/goprotowrap | wrapper/flags.go | String | func (fv FlagValues) String(name string, defaultValue string) string {
value, found := fv[name]
if !found {
return defaultValue
}
return value
} | go | func (fv FlagValues) String(name string, defaultValue string) string {
value, found := fv[name]
if !found {
return defaultValue
}
return value
} | [
"func",
"(",
"fv",
"FlagValues",
")",
"String",
"(",
"name",
"string",
",",
"defaultValue",
"string",
")",
"string",
"{",
"value",
",",
"found",
":=",
"fv",
"[",
"name",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"defaultValue",
"\n",
"}",
"\n",
"return",
"value",
"\n",
"}"
] | // String returns the string version of a flag, if set. | [
"String",
"returns",
"the",
"string",
"version",
"of",
"a",
"flag",
"if",
"set",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/flags.go#L162-L168 |
11,485 | square/goprotowrap | wrapper/wrapper.go | inImportDir | func (w *Wrapper) inImportDir(file string) bool {
for _, imp := range w.ImportDirs {
if strings.HasPrefix(file, imp) {
return true
}
}
return false
} | go | func (w *Wrapper) inImportDir(file string) bool {
for _, imp := range w.ImportDirs {
if strings.HasPrefix(file, imp) {
return true
}
}
return false
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"inImportDir",
"(",
"file",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"imp",
":=",
"range",
"w",
".",
"ImportDirs",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"file",
",",
"imp",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // inImportDir returns true if the given file has a lexicographical
// prefix of one of the import directories. | [
"inImportDir",
"returns",
"true",
"if",
"the",
"given",
"file",
"has",
"a",
"lexicographical",
"prefix",
"of",
"one",
"of",
"the",
"import",
"directories",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/wrapper.go#L141-L148 |
11,486 | square/goprotowrap | wrapper/wrapper.go | importDirsUsed | func (w *Wrapper) importDirsUsed() []string {
used := []string{}
for _, imp := range w.ImportDirs {
for _, proto := range w.ProtoFiles {
if strings.HasPrefix(proto, imp) {
used = append(used, imp)
break
}
}
}
return used
} | go | func (w *Wrapper) importDirsUsed() []string {
used := []string{}
for _, imp := range w.ImportDirs {
for _, proto := range w.ProtoFiles {
if strings.HasPrefix(proto, imp) {
used = append(used, imp)
break
}
}
}
return used
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"importDirsUsed",
"(",
")",
"[",
"]",
"string",
"{",
"used",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"imp",
":=",
"range",
"w",
".",
"ImportDirs",
"{",
"for",
"_",
",",
"proto",
":=",
"range",
"w",
".",
"ProtoFiles",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"proto",
",",
"imp",
")",
"{",
"used",
"=",
"append",
"(",
"used",
",",
"imp",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"used",
"\n",
"}"
] | // importDirsUsed returns the set of import directories that contain
// entries in the set of proto files. | [
"importDirsUsed",
"returns",
"the",
"set",
"of",
"import",
"directories",
"that",
"contain",
"entries",
"in",
"the",
"set",
"of",
"proto",
"files",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/wrapper.go#L152-L163 |
11,487 | square/goprotowrap | wrapper/wrapper.go | PrintStructure | func (w *Wrapper) PrintStructure(writer io.Writer) {
if !w.initCalled {
fmt.Fprintln(writer, "[Not initialized]")
return
}
// Debugging output.
fmt.Fprintln(writer, "> Structure:")
for _, pkg := range w.packagesInOrder() {
fmt.Fprintf(writer, "> %v\n", pkg.ComputedPackage)
fmt.Fprintln(writer, "> files:")
for _, file := range pkg.Files {
fmt.Fprintf(writer, "> %v (%v)\n", file.Name, file.FullPath)
}
fmt.Fprintln(writer, "> deps:")
for _, file := range pkg.Deps {
if file.FullPath != "" {
fmt.Fprintf(writer, "> %v (%v)\n", file.Name, file.FullPath)
} else {
fmt.Fprintf(writer, "> %v\n", file.Name)
}
}
}
} | go | func (w *Wrapper) PrintStructure(writer io.Writer) {
if !w.initCalled {
fmt.Fprintln(writer, "[Not initialized]")
return
}
// Debugging output.
fmt.Fprintln(writer, "> Structure:")
for _, pkg := range w.packagesInOrder() {
fmt.Fprintf(writer, "> %v\n", pkg.ComputedPackage)
fmt.Fprintln(writer, "> files:")
for _, file := range pkg.Files {
fmt.Fprintf(writer, "> %v (%v)\n", file.Name, file.FullPath)
}
fmt.Fprintln(writer, "> deps:")
for _, file := range pkg.Deps {
if file.FullPath != "" {
fmt.Fprintf(writer, "> %v (%v)\n", file.Name, file.FullPath)
} else {
fmt.Fprintf(writer, "> %v\n", file.Name)
}
}
}
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"PrintStructure",
"(",
"writer",
"io",
".",
"Writer",
")",
"{",
"if",
"!",
"w",
".",
"initCalled",
"{",
"fmt",
".",
"Fprintln",
"(",
"writer",
",",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// Debugging output.",
"fmt",
".",
"Fprintln",
"(",
"writer",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"pkg",
":=",
"range",
"w",
".",
"packagesInOrder",
"(",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"writer",
",",
"\"",
"\\n",
"\"",
",",
"pkg",
".",
"ComputedPackage",
")",
"\n",
"fmt",
".",
"Fprintln",
"(",
"writer",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"file",
":=",
"range",
"pkg",
".",
"Files",
"{",
"fmt",
".",
"Fprintf",
"(",
"writer",
",",
"\"",
"\\n",
"\"",
",",
"file",
".",
"Name",
",",
"file",
".",
"FullPath",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintln",
"(",
"writer",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"file",
":=",
"range",
"pkg",
".",
"Deps",
"{",
"if",
"file",
".",
"FullPath",
"!=",
"\"",
"\"",
"{",
"fmt",
".",
"Fprintf",
"(",
"writer",
",",
"\"",
"\\n",
"\"",
",",
"file",
".",
"Name",
",",
"file",
".",
"FullPath",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Fprintf",
"(",
"writer",
",",
"\"",
"\\n",
"\"",
",",
"file",
".",
"Name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // PrintStructure dumps out the computed structure to the given
// io.Writer. | [
"PrintStructure",
"dumps",
"out",
"the",
"computed",
"structure",
"to",
"the",
"given",
"io",
".",
"Writer",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/wrapper.go#L167-L189 |
11,488 | square/goprotowrap | wrapper/wrapper.go | Generate | func (w *Wrapper) Generate() error {
if !w.initCalled {
return errors.New("Init() must be called before Generate()")
}
if w.Parallelism < 1 {
return fmt.Errorf("parallelism cannot be < 1; got %d", w.Parallelism)
}
parallelism := len(w.packages)
if w.Parallelism < parallelism {
parallelism = w.Parallelism
}
pkgChan := make(chan *PackageInfo)
errChan := make(chan error, parallelism)
var wg sync.WaitGroup
wg.Add(parallelism)
for i := 0; i < parallelism; i++ {
go func() {
for pkg := range pkgChan {
fmt.Printf("Generating package %s\n", pkg.ComputedPackage)
if err := Generate(pkg, w.ImportDirs, w.ProtocCommand, w.ProtocFlags, w.PrintOnly); err != nil {
errChan <- fmt.Errorf("error generating package %s: %v\n", pkg.ComputedPackage, err)
}
}
wg.Done()
}()
}
var err error
OUTER:
for _, pkg := range w.packagesInOrder() {
select {
case pkgChan <- pkg:
case err = <-errChan:
break OUTER
}
}
close(pkgChan)
wg.Wait()
select {
case err = <-errChan:
default:
}
return err
} | go | func (w *Wrapper) Generate() error {
if !w.initCalled {
return errors.New("Init() must be called before Generate()")
}
if w.Parallelism < 1 {
return fmt.Errorf("parallelism cannot be < 1; got %d", w.Parallelism)
}
parallelism := len(w.packages)
if w.Parallelism < parallelism {
parallelism = w.Parallelism
}
pkgChan := make(chan *PackageInfo)
errChan := make(chan error, parallelism)
var wg sync.WaitGroup
wg.Add(parallelism)
for i := 0; i < parallelism; i++ {
go func() {
for pkg := range pkgChan {
fmt.Printf("Generating package %s\n", pkg.ComputedPackage)
if err := Generate(pkg, w.ImportDirs, w.ProtocCommand, w.ProtocFlags, w.PrintOnly); err != nil {
errChan <- fmt.Errorf("error generating package %s: %v\n", pkg.ComputedPackage, err)
}
}
wg.Done()
}()
}
var err error
OUTER:
for _, pkg := range w.packagesInOrder() {
select {
case pkgChan <- pkg:
case err = <-errChan:
break OUTER
}
}
close(pkgChan)
wg.Wait()
select {
case err = <-errChan:
default:
}
return err
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"Generate",
"(",
")",
"error",
"{",
"if",
"!",
"w",
".",
"initCalled",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"w",
".",
"Parallelism",
"<",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"w",
".",
"Parallelism",
")",
"\n",
"}",
"\n",
"parallelism",
":=",
"len",
"(",
"w",
".",
"packages",
")",
"\n",
"if",
"w",
".",
"Parallelism",
"<",
"parallelism",
"{",
"parallelism",
"=",
"w",
".",
"Parallelism",
"\n",
"}",
"\n\n",
"pkgChan",
":=",
"make",
"(",
"chan",
"*",
"PackageInfo",
")",
"\n\n",
"errChan",
":=",
"make",
"(",
"chan",
"error",
",",
"parallelism",
")",
"\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"wg",
".",
"Add",
"(",
"parallelism",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"parallelism",
";",
"i",
"++",
"{",
"go",
"func",
"(",
")",
"{",
"for",
"pkg",
":=",
"range",
"pkgChan",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"pkg",
".",
"ComputedPackage",
")",
"\n",
"if",
"err",
":=",
"Generate",
"(",
"pkg",
",",
"w",
".",
"ImportDirs",
",",
"w",
".",
"ProtocCommand",
",",
"w",
".",
"ProtocFlags",
",",
"w",
".",
"PrintOnly",
")",
";",
"err",
"!=",
"nil",
"{",
"errChan",
"<-",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"pkg",
".",
"ComputedPackage",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"wg",
".",
"Done",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"OUTER",
":",
"for",
"_",
",",
"pkg",
":=",
"range",
"w",
".",
"packagesInOrder",
"(",
")",
"{",
"select",
"{",
"case",
"pkgChan",
"<-",
"pkg",
":",
"case",
"err",
"=",
"<-",
"errChan",
":",
"break",
"OUTER",
"\n",
"}",
"\n",
"}",
"\n",
"close",
"(",
"pkgChan",
")",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"select",
"{",
"case",
"err",
"=",
"<-",
"errChan",
":",
"default",
":",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Generate actually generates the output files. | [
"Generate",
"actually",
"generates",
"the",
"output",
"files",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/wrapper.go#L192-L237 |
11,489 | square/goprotowrap | wrapper/wrapper.go | packagesInOrder | func (w *Wrapper) packagesInOrder() []*PackageInfo {
result := make([]*PackageInfo, 0, len(w.packages))
names := make([]string, 0, len(w.packages))
for name := range w.packages {
names = append(names, name)
}
sort.Strings(names)
for _, name := range names {
result = append(result, w.packages[name])
}
return result
} | go | func (w *Wrapper) packagesInOrder() []*PackageInfo {
result := make([]*PackageInfo, 0, len(w.packages))
names := make([]string, 0, len(w.packages))
for name := range w.packages {
names = append(names, name)
}
sort.Strings(names)
for _, name := range names {
result = append(result, w.packages[name])
}
return result
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"packagesInOrder",
"(",
")",
"[",
"]",
"*",
"PackageInfo",
"{",
"result",
":=",
"make",
"(",
"[",
"]",
"*",
"PackageInfo",
",",
"0",
",",
"len",
"(",
"w",
".",
"packages",
")",
")",
"\n",
"names",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"w",
".",
"packages",
")",
")",
"\n",
"for",
"name",
":=",
"range",
"w",
".",
"packages",
"{",
"names",
"=",
"append",
"(",
"names",
",",
"name",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"names",
")",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"w",
".",
"packages",
"[",
"name",
"]",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // packagesInOrder returns the list of packages, sorted by name. | [
"packagesInOrder",
"returns",
"the",
"list",
"of",
"packages",
"sorted",
"by",
"name",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/wrapper.go#L240-L251 |
11,490 | square/goprotowrap | wrapper/wrapper.go | allPackagesInOrder | func (w *Wrapper) allPackagesInOrder() []*PackageInfo {
result := make([]*PackageInfo, 0, len(w.allPackages))
names := make([]string, 0, len(w.allPackages))
for name := range w.allPackages {
names = append(names, name)
}
sort.Strings(names)
for _, name := range names {
result = append(result, w.allPackages[name])
}
return result
} | go | func (w *Wrapper) allPackagesInOrder() []*PackageInfo {
result := make([]*PackageInfo, 0, len(w.allPackages))
names := make([]string, 0, len(w.allPackages))
for name := range w.allPackages {
names = append(names, name)
}
sort.Strings(names)
for _, name := range names {
result = append(result, w.allPackages[name])
}
return result
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"allPackagesInOrder",
"(",
")",
"[",
"]",
"*",
"PackageInfo",
"{",
"result",
":=",
"make",
"(",
"[",
"]",
"*",
"PackageInfo",
",",
"0",
",",
"len",
"(",
"w",
".",
"allPackages",
")",
")",
"\n",
"names",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"w",
".",
"allPackages",
")",
")",
"\n",
"for",
"name",
":=",
"range",
"w",
".",
"allPackages",
"{",
"names",
"=",
"append",
"(",
"names",
",",
"name",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"names",
")",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"w",
".",
"allPackages",
"[",
"name",
"]",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // allPackagesInOrder returns the list of all packages, sorted by name. | [
"allPackagesInOrder",
"returns",
"the",
"list",
"of",
"all",
"packages",
"sorted",
"by",
"name",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/wrapper.go#L254-L265 |
11,491 | square/goprotowrap | wrapper/finding.go | ProtosBelow | func ProtosBelow(dirs []string) ([]string, error) {
protos := []string{}
for _, dir := range dirs {
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && strings.HasSuffix(info.Name(), ".proto") {
protos = append(protos, path)
}
return nil
})
if err != nil {
return nil, err
}
}
return protos, nil
} | go | func ProtosBelow(dirs []string) ([]string, error) {
protos := []string{}
for _, dir := range dirs {
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && strings.HasSuffix(info.Name(), ".proto") {
protos = append(protos, path)
}
return nil
})
if err != nil {
return nil, err
}
}
return protos, nil
} | [
"func",
"ProtosBelow",
"(",
"dirs",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"protos",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"dir",
":=",
"range",
"dirs",
"{",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"dir",
",",
"func",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"info",
".",
"IsDir",
"(",
")",
"&&",
"strings",
".",
"HasSuffix",
"(",
"info",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"protos",
"=",
"append",
"(",
"protos",
",",
"path",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"protos",
",",
"nil",
"\n",
"}"
] | // ProtosBelow returns a slice containing the filenames of all .proto
// files found in or below the given directories. | [
"ProtosBelow",
"returns",
"a",
"slice",
"containing",
"the",
"filenames",
"of",
"all",
".",
"proto",
"files",
"found",
"in",
"or",
"below",
"the",
"given",
"directories",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/finding.go#L29-L46 |
11,492 | square/goprotowrap | wrapper/finding.go | ImportDirsUsed | func ImportDirsUsed(importDirs []string, protos []string) []string {
used := []string{}
for _, imp := range importDirs {
for _, proto := range protos {
if strings.HasPrefix(proto, imp) {
used = append(used, imp)
break
}
}
}
return used
} | go | func ImportDirsUsed(importDirs []string, protos []string) []string {
used := []string{}
for _, imp := range importDirs {
for _, proto := range protos {
if strings.HasPrefix(proto, imp) {
used = append(used, imp)
break
}
}
}
return used
} | [
"func",
"ImportDirsUsed",
"(",
"importDirs",
"[",
"]",
"string",
",",
"protos",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"used",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"imp",
":=",
"range",
"importDirs",
"{",
"for",
"_",
",",
"proto",
":=",
"range",
"protos",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"proto",
",",
"imp",
")",
"{",
"used",
"=",
"append",
"(",
"used",
",",
"imp",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"used",
"\n",
"}"
] | // ImportDirsUsed returns the set of import directories that contain
// entries in the set of proto files. | [
"ImportDirsUsed",
"returns",
"the",
"set",
"of",
"import",
"directories",
"that",
"contain",
"entries",
"in",
"the",
"set",
"of",
"proto",
"files",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/finding.go#L50-L61 |
11,493 | square/goprotowrap | wrapper/finding.go | Disjoint | func Disjoint(existing, additional []string) []string {
set := make(map[string]bool, len(existing)+len(additional))
result := make([]string, 0, len(additional))
for _, proto := range existing {
set[proto] = true
}
for _, proto := range additional {
if set[proto] {
continue
}
set[proto] = true
result = append(result, proto)
}
return result
} | go | func Disjoint(existing, additional []string) []string {
set := make(map[string]bool, len(existing)+len(additional))
result := make([]string, 0, len(additional))
for _, proto := range existing {
set[proto] = true
}
for _, proto := range additional {
if set[proto] {
continue
}
set[proto] = true
result = append(result, proto)
}
return result
} | [
"func",
"Disjoint",
"(",
"existing",
",",
"additional",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"set",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
",",
"len",
"(",
"existing",
")",
"+",
"len",
"(",
"additional",
")",
")",
"\n",
"result",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"additional",
")",
")",
"\n",
"for",
"_",
",",
"proto",
":=",
"range",
"existing",
"{",
"set",
"[",
"proto",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"proto",
":=",
"range",
"additional",
"{",
"if",
"set",
"[",
"proto",
"]",
"{",
"continue",
"\n",
"}",
"\n",
"set",
"[",
"proto",
"]",
"=",
"true",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"proto",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // Disjoint takes a slice of existing .proto files, and a slice of new
// .proto files. It returns a slice containing the subset of the new
// .proto files with distinct paths not in the first set. | [
"Disjoint",
"takes",
"a",
"slice",
"of",
"existing",
".",
"proto",
"files",
"and",
"a",
"slice",
"of",
"new",
".",
"proto",
"files",
".",
"It",
"returns",
"a",
"slice",
"containing",
"the",
"subset",
"of",
"the",
"new",
".",
"proto",
"files",
"with",
"distinct",
"paths",
"not",
"in",
"the",
"first",
"set",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/finding.go#L66-L81 |
11,494 | square/goprotowrap | wrapper/cycles.go | CheckCycles | func (w *Wrapper) CheckCycles() error {
w.sccs = w.tarjan()
cycles := []string{}
for _, scc := range w.sccs {
if len(scc) > 1 {
cycles = append(cycles, w.showComponent(scc))
}
}
if len(cycles) > 0 {
return fmt.Errorf("cycles found:\n%s\n", strings.Join(cycles, "\n"))
}
return nil
} | go | func (w *Wrapper) CheckCycles() error {
w.sccs = w.tarjan()
cycles := []string{}
for _, scc := range w.sccs {
if len(scc) > 1 {
cycles = append(cycles, w.showComponent(scc))
}
}
if len(cycles) > 0 {
return fmt.Errorf("cycles found:\n%s\n", strings.Join(cycles, "\n"))
}
return nil
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"CheckCycles",
"(",
")",
"error",
"{",
"w",
".",
"sccs",
"=",
"w",
".",
"tarjan",
"(",
")",
"\n",
"cycles",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"scc",
":=",
"range",
"w",
".",
"sccs",
"{",
"if",
"len",
"(",
"scc",
")",
">",
"1",
"{",
"cycles",
"=",
"append",
"(",
"cycles",
",",
"w",
".",
"showComponent",
"(",
"scc",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"cycles",
")",
">",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"strings",
".",
"Join",
"(",
"cycles",
",",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CheckCycles checks for proto import structures that would result in
// Go package cycles. | [
"CheckCycles",
"checks",
"for",
"proto",
"import",
"structures",
"that",
"would",
"result",
"in",
"Go",
"package",
"cycles",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/cycles.go#L24-L36 |
11,495 | square/goprotowrap | wrapper/cycles.go | showComponent | func (w *Wrapper) showComponent(pkgs []*PackageInfo) string {
result := []string{}
inCycle := map[string]bool{}
for _, pkg := range pkgs {
inCycle[pkg.ComputedPackage] = true
}
for _, pkg := range pkgs {
for _, other := range pkg.ImportedPackageComputedNames() {
if inCycle[other] {
result = append(result, fmt.Sprintf(" %s --> %s", pkg.ComputedPackage, other))
for _, f := range pkg.Files {
for _, depName := range f.Deps {
dep := w.infos[depName]
if dep.ComputedPackage == other {
result = append(result, fmt.Sprintf(" %s imports %s", f.Name, dep.Name))
}
}
}
}
}
}
return strings.Join(result, "\n")
} | go | func (w *Wrapper) showComponent(pkgs []*PackageInfo) string {
result := []string{}
inCycle := map[string]bool{}
for _, pkg := range pkgs {
inCycle[pkg.ComputedPackage] = true
}
for _, pkg := range pkgs {
for _, other := range pkg.ImportedPackageComputedNames() {
if inCycle[other] {
result = append(result, fmt.Sprintf(" %s --> %s", pkg.ComputedPackage, other))
for _, f := range pkg.Files {
for _, depName := range f.Deps {
dep := w.infos[depName]
if dep.ComputedPackage == other {
result = append(result, fmt.Sprintf(" %s imports %s", f.Name, dep.Name))
}
}
}
}
}
}
return strings.Join(result, "\n")
} | [
"func",
"(",
"w",
"*",
"Wrapper",
")",
"showComponent",
"(",
"pkgs",
"[",
"]",
"*",
"PackageInfo",
")",
"string",
"{",
"result",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"inCycle",
":=",
"map",
"[",
"string",
"]",
"bool",
"{",
"}",
"\n",
"for",
"_",
",",
"pkg",
":=",
"range",
"pkgs",
"{",
"inCycle",
"[",
"pkg",
".",
"ComputedPackage",
"]",
"=",
"true",
"\n",
"}",
"\n",
"for",
"_",
",",
"pkg",
":=",
"range",
"pkgs",
"{",
"for",
"_",
",",
"other",
":=",
"range",
"pkg",
".",
"ImportedPackageComputedNames",
"(",
")",
"{",
"if",
"inCycle",
"[",
"other",
"]",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pkg",
".",
"ComputedPackage",
",",
"other",
")",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"pkg",
".",
"Files",
"{",
"for",
"_",
",",
"depName",
":=",
"range",
"f",
".",
"Deps",
"{",
"dep",
":=",
"w",
".",
"infos",
"[",
"depName",
"]",
"\n",
"if",
"dep",
".",
"ComputedPackage",
"==",
"other",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"f",
".",
"Name",
",",
"dep",
".",
"Name",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"result",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"}"
] | // showComponent returns a string describing why a strongly connected
// component is strongly connected. | [
"showComponent",
"returns",
"a",
"string",
"describing",
"why",
"a",
"strongly",
"connected",
"component",
"is",
"strongly",
"connected",
"."
] | bb93590db2dbd7d818a83f78996e160fa9e3a423 | https://github.com/square/goprotowrap/blob/bb93590db2dbd7d818a83f78996e160fa9e3a423/wrapper/cycles.go#L100-L122 |
11,496 | qor/media | utils.go | IsImageFormat | func IsImageFormat(name string) bool {
_, err := getImageFormat(name)
return err == nil
} | go | func IsImageFormat(name string) bool {
_, err := getImageFormat(name)
return err == nil
} | [
"func",
"IsImageFormat",
"(",
"name",
"string",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"getImageFormat",
"(",
"name",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] | // IsImageFormat check filename is image or not | [
"IsImageFormat",
"check",
"filename",
"is",
"image",
"or",
"not"
] | c3220db68c4b980ae75be2fbd4faf7cd983b9b0f | https://github.com/qor/media/blob/c3220db68c4b980ae75be2fbd4faf7cd983b9b0f/utils.go#L31-L34 |
11,497 | qor/media | media.go | Get | func (option Option) Get(key string) string {
return option[strings.ToUpper(key)]
} | go | func (option Option) Get(key string) string {
return option[strings.ToUpper(key)]
} | [
"func",
"(",
"option",
"Option",
")",
"Get",
"(",
"key",
"string",
")",
"string",
"{",
"return",
"option",
"[",
"strings",
".",
"ToUpper",
"(",
"key",
")",
"]",
"\n",
"}"
] | // get option with name | [
"get",
"option",
"with",
"name"
] | c3220db68c4b980ae75be2fbd4faf7cd983b9b0f | https://github.com/qor/media/blob/c3220db68c4b980ae75be2fbd4faf7cd983b9b0f/media.go#L60-L62 |
11,498 | qor/media | base.go | Value | func (b Base) Value() (driver.Value, error) {
if b.Delete {
return nil, nil
}
results, err := json.Marshal(b)
return string(results), err
} | go | func (b Base) Value() (driver.Value, error) {
if b.Delete {
return nil, nil
}
results, err := json.Marshal(b)
return string(results), err
} | [
"func",
"(",
"b",
"Base",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"if",
"b",
".",
"Delete",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"results",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"b",
")",
"\n",
"return",
"string",
"(",
"results",
")",
",",
"err",
"\n",
"}"
] | // Value return struct's Value | [
"Value",
"return",
"struct",
"s",
"Value"
] | c3220db68c4b980ae75be2fbd4faf7cd983b9b0f | https://github.com/qor/media/blob/c3220db68c4b980ae75be2fbd4faf7cd983b9b0f/base.go#L113-L120 |
11,499 | qor/media | base.go | GetFileName | func (b Base) GetFileName() string {
if b.FileName != "" {
return b.FileName
}
if b.Url != "" {
return filepath.Base(b.Url)
}
return ""
} | go | func (b Base) GetFileName() string {
if b.FileName != "" {
return b.FileName
}
if b.Url != "" {
return filepath.Base(b.Url)
}
return ""
} | [
"func",
"(",
"b",
"Base",
")",
"GetFileName",
"(",
")",
"string",
"{",
"if",
"b",
".",
"FileName",
"!=",
"\"",
"\"",
"{",
"return",
"b",
".",
"FileName",
"\n",
"}",
"\n",
"if",
"b",
".",
"Url",
"!=",
"\"",
"\"",
"{",
"return",
"filepath",
".",
"Base",
"(",
"b",
".",
"Url",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // GetFileName get file's name | [
"GetFileName",
"get",
"file",
"s",
"name"
] | c3220db68c4b980ae75be2fbd4faf7cd983b9b0f | https://github.com/qor/media/blob/c3220db68c4b980ae75be2fbd4faf7cd983b9b0f/base.go#L141-L149 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.