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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
go-telegram-bot-api/telegram-bot-api | bot.go | KickChatMember | func (bot *BotAPI) KickChatMember(config KickChatMemberConfig) (APIResponse, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
v.Add("user_id", strconv.Itoa(config.UserID))
if config.U... | go | func (bot *BotAPI) KickChatMember(config KickChatMemberConfig) (APIResponse, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
v.Add("user_id", strconv.Itoa(config.UserID))
if config.U... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"KickChatMember",
"(",
"config",
"KickChatMemberConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"if",
"config",
".",
"SuperGroupUsername",
"==",
"\"",
"\... | // KickChatMember kicks a user from a chat. Note that this only will work
// in supergroups, and requires the bot to be an admin. Also note they
// will be unable to rejoin until they are unbanned. | [
"KickChatMember",
"kicks",
"a",
"user",
"from",
"a",
"chat",
".",
"Note",
"that",
"this",
"only",
"will",
"work",
"in",
"supergroups",
"and",
"requires",
"the",
"bot",
"to",
"be",
"an",
"admin",
".",
"Also",
"note",
"they",
"will",
"be",
"unable",
"to",
... | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L585-L602 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | LeaveChat | func (bot *BotAPI) LeaveChat(config ChatConfig) (APIResponse, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
bot.debugLog("leaveChat", v, nil)
return bot.MakeRequest("leaveChat", v... | go | func (bot *BotAPI) LeaveChat(config ChatConfig) (APIResponse, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
bot.debugLog("leaveChat", v, nil)
return bot.MakeRequest("leaveChat", v... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"LeaveChat",
"(",
"config",
"ChatConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"if",
"config",
".",
"SuperGroupUsername",
"==",
"\"",
"\"",
"{",
"v... | // LeaveChat makes the bot leave the chat. | [
"LeaveChat",
"makes",
"the",
"bot",
"leave",
"the",
"chat",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L605-L617 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | GetChat | func (bot *BotAPI) GetChat(config ChatConfig) (Chat, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
resp, err := bot.MakeRequest("getChat", v)
if err != nil {
return Chat{}, err
... | go | func (bot *BotAPI) GetChat(config ChatConfig) (Chat, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
resp, err := bot.MakeRequest("getChat", v)
if err != nil {
return Chat{}, err
... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"GetChat",
"(",
"config",
"ChatConfig",
")",
"(",
"Chat",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"if",
"config",
".",
"SuperGroupUsername",
"==",
"\"",
"\"",
"{",
"v",
".",... | // GetChat gets information about a chat. | [
"GetChat",
"gets",
"information",
"about",
"a",
"chat",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L620-L640 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | GetChatAdministrators | func (bot *BotAPI) GetChatAdministrators(config ChatConfig) ([]ChatMember, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
resp, err := bot.MakeRequest("getChatAdministrators", v)
if... | go | func (bot *BotAPI) GetChatAdministrators(config ChatConfig) ([]ChatMember, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
resp, err := bot.MakeRequest("getChatAdministrators", v)
if... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"GetChatAdministrators",
"(",
"config",
"ChatConfig",
")",
"(",
"[",
"]",
"ChatMember",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"if",
"config",
".",
"SuperGroupUsername",
"==",
... | // GetChatAdministrators gets a list of administrators in the chat.
//
// If none have been appointed, only the creator will be returned.
// Bots are not shown, even if they are an administrator. | [
"GetChatAdministrators",
"gets",
"a",
"list",
"of",
"administrators",
"in",
"the",
"chat",
".",
"If",
"none",
"have",
"been",
"appointed",
"only",
"the",
"creator",
"will",
"be",
"returned",
".",
"Bots",
"are",
"not",
"shown",
"even",
"if",
"they",
"are",
... | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L646-L666 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | GetChatMembersCount | func (bot *BotAPI) GetChatMembersCount(config ChatConfig) (int, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
resp, err := bot.MakeRequest("getChatMembersCount", v)
if err != nil {... | go | func (bot *BotAPI) GetChatMembersCount(config ChatConfig) (int, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
resp, err := bot.MakeRequest("getChatMembersCount", v)
if err != nil {... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"GetChatMembersCount",
"(",
"config",
"ChatConfig",
")",
"(",
"int",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"if",
"config",
".",
"SuperGroupUsername",
"==",
"\"",
"\"",
"{",
... | // GetChatMembersCount gets the number of users in a chat. | [
"GetChatMembersCount",
"gets",
"the",
"number",
"of",
"users",
"in",
"a",
"chat",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L669-L689 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | GetChatMember | func (bot *BotAPI) GetChatMember(config ChatConfigWithUser) (ChatMember, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
v.Add("user_id", strconv.Itoa(config.UserID))
resp, err := bo... | go | func (bot *BotAPI) GetChatMember(config ChatConfigWithUser) (ChatMember, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
v.Add("user_id", strconv.Itoa(config.UserID))
resp, err := bo... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"GetChatMember",
"(",
"config",
"ChatConfigWithUser",
")",
"(",
"ChatMember",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"if",
"config",
".",
"SuperGroupUsername",
"==",
"\"",
"\"",
... | // GetChatMember gets a specific chat member. | [
"GetChatMember",
"gets",
"a",
"specific",
"chat",
"member",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L692-L713 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | UnbanChatMember | func (bot *BotAPI) UnbanChatMember(config ChatMemberConfig) (APIResponse, error) {
v := url.Values{}
if config.SuperGroupUsername != "" {
v.Add("chat_id", config.SuperGroupUsername)
} else if config.ChannelUsername != "" {
v.Add("chat_id", config.ChannelUsername)
} else {
v.Add("chat_id", strconv.FormatInt(c... | go | func (bot *BotAPI) UnbanChatMember(config ChatMemberConfig) (APIResponse, error) {
v := url.Values{}
if config.SuperGroupUsername != "" {
v.Add("chat_id", config.SuperGroupUsername)
} else if config.ChannelUsername != "" {
v.Add("chat_id", config.ChannelUsername)
} else {
v.Add("chat_id", strconv.FormatInt(c... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"UnbanChatMember",
"(",
"config",
"ChatMemberConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"if",
"config",
".",
"SuperGroupUsername",
"!=",
"\"",
"\"",... | // UnbanChatMember unbans a user from a chat. Note that this only will work
// in supergroups and channels, and requires the bot to be an admin. | [
"UnbanChatMember",
"unbans",
"a",
"user",
"from",
"a",
"chat",
".",
"Note",
"that",
"this",
"only",
"will",
"work",
"in",
"supergroups",
"and",
"channels",
"and",
"requires",
"the",
"bot",
"to",
"be",
"an",
"admin",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L717-L732 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | RestrictChatMember | func (bot *BotAPI) RestrictChatMember(config RestrictChatMemberConfig) (APIResponse, error) {
v := url.Values{}
if config.SuperGroupUsername != "" {
v.Add("chat_id", config.SuperGroupUsername)
} else if config.ChannelUsername != "" {
v.Add("chat_id", config.ChannelUsername)
} else {
v.Add("chat_id", strconv.... | go | func (bot *BotAPI) RestrictChatMember(config RestrictChatMemberConfig) (APIResponse, error) {
v := url.Values{}
if config.SuperGroupUsername != "" {
v.Add("chat_id", config.SuperGroupUsername)
} else if config.ChannelUsername != "" {
v.Add("chat_id", config.ChannelUsername)
} else {
v.Add("chat_id", strconv.... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"RestrictChatMember",
"(",
"config",
"RestrictChatMemberConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"if",
"config",
".",
"SuperGroupUsername",
"!=",
"\... | // RestrictChatMember to restrict a user in a supergroup. The bot must be an
//administrator in the supergroup for this to work and must have the
//appropriate admin rights. Pass True for all boolean parameters to lift
//restrictions from a user. Returns True on success. | [
"RestrictChatMember",
"to",
"restrict",
"a",
"user",
"in",
"a",
"supergroup",
".",
"The",
"bot",
"must",
"be",
"an",
"administrator",
"in",
"the",
"supergroup",
"for",
"this",
"to",
"work",
"and",
"must",
"have",
"the",
"appropriate",
"admin",
"rights",
".",... | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L738-L769 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | PromoteChatMember | func (bot *BotAPI) PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error) {
v := url.Values{}
if config.SuperGroupUsername != "" {
v.Add("chat_id", config.SuperGroupUsername)
} else if config.ChannelUsername != "" {
v.Add("chat_id", config.ChannelUsername)
} else {
v.Add("chat_id", strconv.Fo... | go | func (bot *BotAPI) PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error) {
v := url.Values{}
if config.SuperGroupUsername != "" {
v.Add("chat_id", config.SuperGroupUsername)
} else if config.ChannelUsername != "" {
v.Add("chat_id", config.ChannelUsername)
} else {
v.Add("chat_id", strconv.Fo... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"PromoteChatMember",
"(",
"config",
"PromoteChatMemberConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"if",
"config",
".",
"SuperGroupUsername",
"!=",
"\""... | // PromoteChatMember add admin rights to user | [
"PromoteChatMember",
"add",
"admin",
"rights",
"to",
"user"
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L772-L812 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | GetGameHighScores | func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error) {
v, _ := config.values()
resp, err := bot.MakeRequest(config.method(), v)
if err != nil {
return []GameHighScore{}, err
}
var highScores []GameHighScore
err = json.Unmarshal(resp.Result, &highScores)
return highSc... | go | func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error) {
v, _ := config.values()
resp, err := bot.MakeRequest(config.method(), v)
if err != nil {
return []GameHighScore{}, err
}
var highScores []GameHighScore
err = json.Unmarshal(resp.Result, &highScores)
return highSc... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"GetGameHighScores",
"(",
"config",
"GetGameHighScoresConfig",
")",
"(",
"[",
"]",
"GameHighScore",
",",
"error",
")",
"{",
"v",
",",
"_",
":=",
"config",
".",
"values",
"(",
")",
"\n\n",
"resp",
",",
"err",
":="... | // GetGameHighScores allows you to get the high scores for a game. | [
"GetGameHighScores",
"allows",
"you",
"to",
"get",
"the",
"high",
"scores",
"for",
"a",
"game",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L815-L827 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | AnswerShippingQuery | func (bot *BotAPI) AnswerShippingQuery(config ShippingConfig) (APIResponse, error) {
v := url.Values{}
v.Add("shipping_query_id", config.ShippingQueryID)
v.Add("ok", strconv.FormatBool(config.OK))
if config.OK == true {
data, err := json.Marshal(config.ShippingOptions)
if err != nil {
return APIResponse{}, ... | go | func (bot *BotAPI) AnswerShippingQuery(config ShippingConfig) (APIResponse, error) {
v := url.Values{}
v.Add("shipping_query_id", config.ShippingQueryID)
v.Add("ok", strconv.FormatBool(config.OK))
if config.OK == true {
data, err := json.Marshal(config.ShippingOptions)
if err != nil {
return APIResponse{}, ... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"AnswerShippingQuery",
"(",
"config",
"ShippingConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"v",
".",
"Add",
"(",
"\"",
"\"",
",",
"config",
".",
... | // AnswerShippingQuery allows you to reply to Update with shipping_query parameter. | [
"AnswerShippingQuery",
"allows",
"you",
"to",
"reply",
"to",
"Update",
"with",
"shipping_query",
"parameter",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L830-L848 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | AnswerPreCheckoutQuery | func (bot *BotAPI) AnswerPreCheckoutQuery(config PreCheckoutConfig) (APIResponse, error) {
v := url.Values{}
v.Add("pre_checkout_query_id", config.PreCheckoutQueryID)
v.Add("ok", strconv.FormatBool(config.OK))
if config.OK != true {
v.Add("error", config.ErrorMessage)
}
bot.debugLog("answerPreCheckoutQuery", ... | go | func (bot *BotAPI) AnswerPreCheckoutQuery(config PreCheckoutConfig) (APIResponse, error) {
v := url.Values{}
v.Add("pre_checkout_query_id", config.PreCheckoutQueryID)
v.Add("ok", strconv.FormatBool(config.OK))
if config.OK != true {
v.Add("error", config.ErrorMessage)
}
bot.debugLog("answerPreCheckoutQuery", ... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"AnswerPreCheckoutQuery",
"(",
"config",
"PreCheckoutConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"v",
".",
"Add",
"(",
"\"",
"\"",
",",
"config",
... | // AnswerPreCheckoutQuery allows you to reply to Update with pre_checkout_query. | [
"AnswerPreCheckoutQuery",
"allows",
"you",
"to",
"reply",
"to",
"Update",
"with",
"pre_checkout_query",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L851-L863 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | DeleteMessage | func (bot *BotAPI) DeleteMessage(config DeleteMessageConfig) (APIResponse, error) {
v, err := config.values()
if err != nil {
return APIResponse{}, err
}
bot.debugLog(config.method(), v, nil)
return bot.MakeRequest(config.method(), v)
} | go | func (bot *BotAPI) DeleteMessage(config DeleteMessageConfig) (APIResponse, error) {
v, err := config.values()
if err != nil {
return APIResponse{}, err
}
bot.debugLog(config.method(), v, nil)
return bot.MakeRequest(config.method(), v)
} | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"DeleteMessage",
"(",
"config",
"DeleteMessageConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"... | // DeleteMessage deletes a message in a chat | [
"DeleteMessage",
"deletes",
"a",
"message",
"in",
"a",
"chat"
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L866-L875 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | GetInviteLink | func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
resp, err := bot.MakeRequest("exportChatInviteLink", v)
if err != nil {
... | go | func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) {
v := url.Values{}
if config.SuperGroupUsername == "" {
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
} else {
v.Add("chat_id", config.SuperGroupUsername)
}
resp, err := bot.MakeRequest("exportChatInviteLink", v)
if err != nil {
... | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"GetInviteLink",
"(",
"config",
"ChatConfig",
")",
"(",
"string",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"if",
"config",
".",
"SuperGroupUsername",
"==",
"\"",
"\"",
"{",
"v"... | // GetInviteLink get InviteLink for a chat | [
"GetInviteLink",
"get",
"InviteLink",
"for",
"a",
"chat"
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L878-L896 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | PinChatMessage | func (bot *BotAPI) PinChatMessage(config PinChatMessageConfig) (APIResponse, error) {
v, err := config.values()
if err != nil {
return APIResponse{}, err
}
bot.debugLog(config.method(), v, nil)
return bot.MakeRequest(config.method(), v)
} | go | func (bot *BotAPI) PinChatMessage(config PinChatMessageConfig) (APIResponse, error) {
v, err := config.values()
if err != nil {
return APIResponse{}, err
}
bot.debugLog(config.method(), v, nil)
return bot.MakeRequest(config.method(), v)
} | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"PinChatMessage",
"(",
"config",
"PinChatMessageConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // PinChatMessage pin message in supergroup | [
"PinChatMessage",
"pin",
"message",
"in",
"supergroup"
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L899-L908 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | UnpinChatMessage | func (bot *BotAPI) UnpinChatMessage(config UnpinChatMessageConfig) (APIResponse, error) {
v, err := config.values()
if err != nil {
return APIResponse{}, err
}
bot.debugLog(config.method(), v, nil)
return bot.MakeRequest(config.method(), v)
} | go | func (bot *BotAPI) UnpinChatMessage(config UnpinChatMessageConfig) (APIResponse, error) {
v, err := config.values()
if err != nil {
return APIResponse{}, err
}
bot.debugLog(config.method(), v, nil)
return bot.MakeRequest(config.method(), v)
} | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"UnpinChatMessage",
"(",
"config",
"UnpinChatMessageConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return... | // UnpinChatMessage unpin message in supergroup | [
"UnpinChatMessage",
"unpin",
"message",
"in",
"supergroup"
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L911-L920 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | SetChatTitle | func (bot *BotAPI) SetChatTitle(config SetChatTitleConfig) (APIResponse, error) {
v, err := config.values()
if err != nil {
return APIResponse{}, err
}
bot.debugLog(config.method(), v, nil)
return bot.MakeRequest(config.method(), v)
} | go | func (bot *BotAPI) SetChatTitle(config SetChatTitleConfig) (APIResponse, error) {
v, err := config.values()
if err != nil {
return APIResponse{}, err
}
bot.debugLog(config.method(), v, nil)
return bot.MakeRequest(config.method(), v)
} | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"SetChatTitle",
"(",
"config",
"SetChatTitleConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"AP... | // SetChatTitle change title of chat. | [
"SetChatTitle",
"change",
"title",
"of",
"chat",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L923-L932 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | SetChatDescription | func (bot *BotAPI) SetChatDescription(config SetChatDescriptionConfig) (APIResponse, error) {
v, err := config.values()
if err != nil {
return APIResponse{}, err
}
bot.debugLog(config.method(), v, nil)
return bot.MakeRequest(config.method(), v)
} | go | func (bot *BotAPI) SetChatDescription(config SetChatDescriptionConfig) (APIResponse, error) {
v, err := config.values()
if err != nil {
return APIResponse{}, err
}
bot.debugLog(config.method(), v, nil)
return bot.MakeRequest(config.method(), v)
} | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"SetChatDescription",
"(",
"config",
"SetChatDescriptionConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"re... | // SetChatDescription change description of chat. | [
"SetChatDescription",
"change",
"description",
"of",
"chat",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L935-L944 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | SetChatPhoto | func (bot *BotAPI) SetChatPhoto(config SetChatPhotoConfig) (APIResponse, error) {
params, err := config.params()
if err != nil {
return APIResponse{}, err
}
file := config.getFile()
return bot.UploadFile(config.method(), params, config.name(), file)
} | go | func (bot *BotAPI) SetChatPhoto(config SetChatPhotoConfig) (APIResponse, error) {
params, err := config.params()
if err != nil {
return APIResponse{}, err
}
file := config.getFile()
return bot.UploadFile(config.method(), params, config.name(), file)
} | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"SetChatPhoto",
"(",
"config",
"SetChatPhotoConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"params",
",",
"err",
":=",
"config",
".",
"params",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // SetChatPhoto change photo of chat. | [
"SetChatPhoto",
"change",
"photo",
"of",
"chat",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L947-L956 | train |
go-telegram-bot-api/telegram-bot-api | bot.go | DeleteChatPhoto | func (bot *BotAPI) DeleteChatPhoto(config DeleteChatPhotoConfig) (APIResponse, error) {
v, err := config.values()
if err != nil {
return APIResponse{}, err
}
bot.debugLog(config.method(), v, nil)
return bot.MakeRequest(config.method(), v)
} | go | func (bot *BotAPI) DeleteChatPhoto(config DeleteChatPhotoConfig) (APIResponse, error) {
v, err := config.values()
if err != nil {
return APIResponse{}, err
}
bot.debugLog(config.method(), v, nil)
return bot.MakeRequest(config.method(), v)
} | [
"func",
"(",
"bot",
"*",
"BotAPI",
")",
"DeleteChatPhoto",
"(",
"config",
"DeleteChatPhotoConfig",
")",
"(",
"APIResponse",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",... | // DeleteChatPhoto delete photo of chat. | [
"DeleteChatPhoto",
"delete",
"photo",
"of",
"chat",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/bot.go#L959-L968 | train |
go-telegram-bot-api/telegram-bot-api | configs.go | values | func (chat *BaseChat) values() (url.Values, error) {
v := url.Values{}
if chat.ChannelUsername != "" {
v.Add("chat_id", chat.ChannelUsername)
} else {
v.Add("chat_id", strconv.FormatInt(chat.ChatID, 10))
}
if chat.ReplyToMessageID != 0 {
v.Add("reply_to_message_id", strconv.Itoa(chat.ReplyToMessageID))
}
... | go | func (chat *BaseChat) values() (url.Values, error) {
v := url.Values{}
if chat.ChannelUsername != "" {
v.Add("chat_id", chat.ChannelUsername)
} else {
v.Add("chat_id", strconv.FormatInt(chat.ChatID, 10))
}
if chat.ReplyToMessageID != 0 {
v.Add("reply_to_message_id", strconv.Itoa(chat.ReplyToMessageID))
}
... | [
"func",
"(",
"chat",
"*",
"BaseChat",
")",
"values",
"(",
")",
"(",
"url",
".",
"Values",
",",
"error",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n",
"if",
"chat",
".",
"ChannelUsername",
"!=",
"\"",
"\"",
"{",
"v",
".",
"Add",
"("... | // values returns url.Values representation of BaseChat | [
"values",
"returns",
"url",
".",
"Values",
"representation",
"of",
"BaseChat"
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/configs.go#L75-L99 | train |
go-telegram-bot-api/telegram-bot-api | configs.go | values | func (config MessageConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("text", config.Text)
v.Add("disable_web_page_preview", strconv.FormatBool(config.DisableWebPagePreview))
if config.ParseMode != "" {
v.Add("parse_mode", config.ParseMode)
}
re... | go | func (config MessageConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("text", config.Text)
v.Add("disable_web_page_preview", strconv.FormatBool(config.DisableWebPagePreview))
if config.ParseMode != "" {
v.Add("parse_mode", config.ParseMode)
}
re... | [
"func",
"(",
"config",
"MessageConfig",
")",
"values",
"(",
")",
"(",
"url",
".",
"Values",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"BaseChat",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"v",
","... | // values returns a url.Values representation of MessageConfig. | [
"values",
"returns",
"a",
"url",
".",
"Values",
"representation",
"of",
"MessageConfig",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/configs.go#L200-L212 | train |
go-telegram-bot-api/telegram-bot-api | configs.go | values | func (config ForwardConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("from_chat_id", strconv.FormatInt(config.FromChatID, 10))
v.Add("message_id", strconv.Itoa(config.MessageID))
return v, nil
} | go | func (config ForwardConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("from_chat_id", strconv.FormatInt(config.FromChatID, 10))
v.Add("message_id", strconv.Itoa(config.MessageID))
return v, nil
} | [
"func",
"(",
"config",
"ForwardConfig",
")",
"values",
"(",
")",
"(",
"url",
".",
"Values",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"BaseChat",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"v",
","... | // values returns a url.Values representation of ForwardConfig. | [
"values",
"returns",
"a",
"url",
".",
"Values",
"representation",
"of",
"ForwardConfig",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/configs.go#L228-L236 | train |
go-telegram-bot-api/telegram-bot-api | configs.go | values | func (config DocumentConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID)
if config.Caption != "" {
v.Add("caption", config.Caption)
if config.ParseMode != "" {
v.Add("parse_mode", config.ParseMode)
}
}
return v... | go | func (config DocumentConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID)
if config.Caption != "" {
v.Add("caption", config.Caption)
if config.ParseMode != "" {
v.Add("parse_mode", config.ParseMode)
}
}
return v... | [
"func",
"(",
"config",
"DocumentConfig",
")",
"values",
"(",
")",
"(",
"url",
".",
"Values",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"BaseChat",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"v",
",... | // values returns a url.Values representation of DocumentConfig. | [
"values",
"returns",
"a",
"url",
".",
"Values",
"representation",
"of",
"DocumentConfig",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/configs.go#L372-L387 | train |
go-telegram-bot-api/telegram-bot-api | configs.go | values | func (config StickerConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID)
return v, nil
} | go | func (config StickerConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID)
return v, nil
} | [
"func",
"(",
"config",
"StickerConfig",
")",
"values",
"(",
")",
"(",
"url",
".",
"Values",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"BaseChat",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"v",
","... | // values returns a url.Values representation of StickerConfig. | [
"values",
"returns",
"a",
"url",
".",
"Values",
"representation",
"of",
"StickerConfig",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/configs.go#L419-L428 | train |
go-telegram-bot-api/telegram-bot-api | configs.go | values | func (config VideoConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID)
if config.Duration != 0 {
v.Add("duration", strconv.Itoa(config.Duration))
}
if config.Caption != "" {
v.Add("caption", config.Caption)
if confi... | go | func (config VideoConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID)
if config.Duration != 0 {
v.Add("duration", strconv.Itoa(config.Duration))
}
if config.Caption != "" {
v.Add("caption", config.Caption)
if confi... | [
"func",
"(",
"config",
"VideoConfig",
")",
"values",
"(",
")",
"(",
"url",
".",
"Values",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"BaseChat",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"v",
",",
... | // values returns a url.Values representation of VideoConfig. | [
"values",
"returns",
"a",
"url",
".",
"Values",
"representation",
"of",
"VideoConfig",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/configs.go#L456-L474 | train |
go-telegram-bot-api/telegram-bot-api | configs.go | values | func (config VideoNoteConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID)
if config.Duration != 0 {
v.Add("duration", strconv.Itoa(config.Duration))
}
// Telegram API seems to have a bug, if no length is provided or i... | go | func (config VideoNoteConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add(config.name(), config.FileID)
if config.Duration != 0 {
v.Add("duration", strconv.Itoa(config.Duration))
}
// Telegram API seems to have a bug, if no length is provided or i... | [
"func",
"(",
"config",
"VideoNoteConfig",
")",
"values",
"(",
")",
"(",
"url",
".",
"Values",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"BaseChat",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"v",
"... | // values returns a url.Values representation of VideoNoteConfig. | [
"values",
"returns",
"a",
"url",
".",
"Values",
"representation",
"of",
"VideoNoteConfig",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/configs.go#L561-L578 | train |
go-telegram-bot-api/telegram-bot-api | configs.go | values | func (config LocationConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64))
v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64))
return v, nil
} | go | func (config LocationConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64))
v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64))
return v, nil
} | [
"func",
"(",
"config",
"LocationConfig",
")",
"values",
"(",
")",
"(",
"url",
".",
"Values",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"BaseChat",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"v",
",... | // values returns a url.Values representation of LocationConfig. | [
"values",
"returns",
"a",
"url",
".",
"Values",
"representation",
"of",
"LocationConfig",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/configs.go#L694-L704 | train |
go-telegram-bot-api/telegram-bot-api | configs.go | values | func (config ChatActionConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("action", config.Action)
return v, nil
} | go | func (config ChatActionConfig) values() (url.Values, error) {
v, err := config.BaseChat.values()
if err != nil {
return v, err
}
v.Add("action", config.Action)
return v, nil
} | [
"func",
"(",
"config",
"ChatActionConfig",
")",
"values",
"(",
")",
"(",
"url",
".",
"Values",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"config",
".",
"BaseChat",
".",
"values",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"v",
... | // values returns a url.Values representation of ChatActionConfig. | [
"values",
"returns",
"a",
"url",
".",
"Values",
"representation",
"of",
"ChatActionConfig",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/configs.go#L862-L869 | train |
go-telegram-bot-api/telegram-bot-api | log.go | SetLogger | func SetLogger(logger BotLogger) error {
if logger == nil {
return errors.New("logger is nil")
}
log = logger
return nil
} | go | func SetLogger(logger BotLogger) error {
if logger == nil {
return errors.New("logger is nil")
}
log = logger
return nil
} | [
"func",
"SetLogger",
"(",
"logger",
"BotLogger",
")",
"error",
"{",
"if",
"logger",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"log",
"=",
"logger",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetLogger specifies the logger that the package should use. | [
"SetLogger",
"specifies",
"the",
"logger",
"that",
"the",
"package",
"should",
"use",
"."
] | 87e7035a900c7cb1fd896e5f33b461c96c3ac31e | https://github.com/go-telegram-bot-api/telegram-bot-api/blob/87e7035a900c7cb1fd896e5f33b461c96c3ac31e/log.go#L21-L27 | train |
nsf/termbox-go | termbox_windows.go | prepare_diff_messages | func prepare_diff_messages() {
// clear buffers
diffbuf = diffbuf[:0]
charbuf = charbuf[:0]
var diff diff_msg
gbeg := 0
for y := 0; y < front_buffer.height; y++ {
same := true
line_offset := y * front_buffer.width
for x := 0; x < front_buffer.width; x++ {
cell_offset := line_offset + x
back := &back_... | go | func prepare_diff_messages() {
// clear buffers
diffbuf = diffbuf[:0]
charbuf = charbuf[:0]
var diff diff_msg
gbeg := 0
for y := 0; y < front_buffer.height; y++ {
same := true
line_offset := y * front_buffer.width
for x := 0; x < front_buffer.width; x++ {
cell_offset := line_offset + x
back := &back_... | [
"func",
"prepare_diff_messages",
"(",
")",
"{",
"// clear buffers",
"diffbuf",
"=",
"diffbuf",
"[",
":",
"0",
"]",
"\n",
"charbuf",
"=",
"charbuf",
"[",
":",
"0",
"]",
"\n\n",
"var",
"diff",
"diff_msg",
"\n",
"gbeg",
":=",
"0",
"\n",
"for",
"y",
":=",
... | // compares 'back_buffer' with 'front_buffer' and prepares all changes in the form of
// 'diff_msg's in the 'diff_buf' | [
"compares",
"back_buffer",
"with",
"front_buffer",
"and",
"prepares",
"all",
"changes",
"in",
"the",
"form",
"of",
"diff_msg",
"s",
"in",
"the",
"diff_buf"
] | 288510b9734e30e7966ec2f22b87c5f8e67345e3 | https://github.com/nsf/termbox-go/blob/288510b9734e30e7966ec2f22b87c5f8e67345e3/termbox_windows.go#L577-L615 | train |
nsf/termbox-go | api_windows.go | SetCell | func SetCell(x, y int, ch rune, fg, bg Attribute) {
if x < 0 || x >= back_buffer.width {
return
}
if y < 0 || y >= back_buffer.height {
return
}
back_buffer.cells[y*back_buffer.width+x] = Cell{ch, fg, bg}
} | go | func SetCell(x, y int, ch rune, fg, bg Attribute) {
if x < 0 || x >= back_buffer.width {
return
}
if y < 0 || y >= back_buffer.height {
return
}
back_buffer.cells[y*back_buffer.width+x] = Cell{ch, fg, bg}
} | [
"func",
"SetCell",
"(",
"x",
",",
"y",
"int",
",",
"ch",
"rune",
",",
"fg",
",",
"bg",
"Attribute",
")",
"{",
"if",
"x",
"<",
"0",
"||",
"x",
">=",
"back_buffer",
".",
"width",
"{",
"return",
"\n",
"}",
"\n",
"if",
"y",
"<",
"0",
"||",
"y",
... | // Changes cell's parameters in the internal back buffer at the specified
// position. | [
"Changes",
"cell",
"s",
"parameters",
"in",
"the",
"internal",
"back",
"buffer",
"at",
"the",
"specified",
"position",
"."
] | 288510b9734e30e7966ec2f22b87c5f8e67345e3 | https://github.com/nsf/termbox-go/blob/288510b9734e30e7966ec2f22b87c5f8e67345e3/api_windows.go#L154-L163 | train |
nsf/termbox-go | _demos/editbox.go | Draw | func (eb *EditBox) Draw(x, y, w, h int) {
eb.AdjustVOffset(w)
const coldef = termbox.ColorDefault
fill(x, y, w, h, termbox.Cell{Ch: ' '})
t := eb.text
lx := 0
tabstop := 0
for {
rx := lx - eb.line_voffset
if len(t) == 0 {
break
}
if lx == tabstop {
tabstop += tabstop_length
}
if rx >= w {
... | go | func (eb *EditBox) Draw(x, y, w, h int) {
eb.AdjustVOffset(w)
const coldef = termbox.ColorDefault
fill(x, y, w, h, termbox.Cell{Ch: ' '})
t := eb.text
lx := 0
tabstop := 0
for {
rx := lx - eb.line_voffset
if len(t) == 0 {
break
}
if lx == tabstop {
tabstop += tabstop_length
}
if rx >= w {
... | [
"func",
"(",
"eb",
"*",
"EditBox",
")",
"Draw",
"(",
"x",
",",
"y",
",",
"w",
",",
"h",
"int",
")",
"{",
"eb",
".",
"AdjustVOffset",
"(",
"w",
")",
"\n\n",
"const",
"coldef",
"=",
"termbox",
".",
"ColorDefault",
"\n",
"fill",
"(",
"x",
",",
"y"... | // Draws the EditBox in the given location, 'h' is not used at the moment | [
"Draws",
"the",
"EditBox",
"in",
"the",
"given",
"location",
"h",
"is",
"not",
"used",
"at",
"the",
"moment"
] | 288510b9734e30e7966ec2f22b87c5f8e67345e3 | https://github.com/nsf/termbox-go/blob/288510b9734e30e7966ec2f22b87c5f8e67345e3/_demos/editbox.go#L79-L129 | train |
nsf/termbox-go | _demos/editbox.go | AdjustVOffset | func (eb *EditBox) AdjustVOffset(width int) {
ht := preferred_horizontal_threshold
max_h_threshold := (width - 1) / 2
if ht > max_h_threshold {
ht = max_h_threshold
}
threshold := width - 1
if eb.line_voffset != 0 {
threshold = width - ht
}
if eb.cursor_voffset-eb.line_voffset >= threshold {
eb.line_voff... | go | func (eb *EditBox) AdjustVOffset(width int) {
ht := preferred_horizontal_threshold
max_h_threshold := (width - 1) / 2
if ht > max_h_threshold {
ht = max_h_threshold
}
threshold := width - 1
if eb.line_voffset != 0 {
threshold = width - ht
}
if eb.cursor_voffset-eb.line_voffset >= threshold {
eb.line_voff... | [
"func",
"(",
"eb",
"*",
"EditBox",
")",
"AdjustVOffset",
"(",
"width",
"int",
")",
"{",
"ht",
":=",
"preferred_horizontal_threshold",
"\n",
"max_h_threshold",
":=",
"(",
"width",
"-",
"1",
")",
"/",
"2",
"\n",
"if",
"ht",
">",
"max_h_threshold",
"{",
"ht... | // Adjusts line visual offset to a proper value depending on width | [
"Adjusts",
"line",
"visual",
"offset",
"to",
"a",
"proper",
"value",
"depending",
"on",
"width"
] | 288510b9734e30e7966ec2f22b87c5f8e67345e3 | https://github.com/nsf/termbox-go/blob/288510b9734e30e7966ec2f22b87c5f8e67345e3/_demos/editbox.go#L132-L153 | train |
nsf/termbox-go | api.go | PollEvent | func PollEvent() Event {
// Constant governing macOS specific behavior. See https://github.com/nsf/termbox-go/issues/132
// This is an arbitrary delay which hopefully will be enough time for any lagging
// partial escape sequences to come through.
const esc_wait_delay = 100 * time.Millisecond
var event Event
var... | go | func PollEvent() Event {
// Constant governing macOS specific behavior. See https://github.com/nsf/termbox-go/issues/132
// This is an arbitrary delay which hopefully will be enough time for any lagging
// partial escape sequences to come through.
const esc_wait_delay = 100 * time.Millisecond
var event Event
var... | [
"func",
"PollEvent",
"(",
")",
"Event",
"{",
"// Constant governing macOS specific behavior. See https://github.com/nsf/termbox-go/issues/132",
"// This is an arbitrary delay which hopefully will be enough time for any lagging",
"// partial escape sequences to come through.",
"const",
"esc_wait_... | // Wait for an event and return it. This is a blocking function call. | [
"Wait",
"for",
"an",
"event",
"and",
"return",
"it",
".",
"This",
"is",
"a",
"blocking",
"function",
"call",
"."
] | 288510b9734e30e7966ec2f22b87c5f8e67345e3 | https://github.com/nsf/termbox-go/blob/288510b9734e30e7966ec2f22b87c5f8e67345e3/api.go#L314-L386 | train |
nsf/termbox-go | api.go | Clear | func Clear(fg, bg Attribute) error {
foreground, background = fg, bg
err := update_size_maybe()
back_buffer.clear()
return err
} | go | func Clear(fg, bg Attribute) error {
foreground, background = fg, bg
err := update_size_maybe()
back_buffer.clear()
return err
} | [
"func",
"Clear",
"(",
"fg",
",",
"bg",
"Attribute",
")",
"error",
"{",
"foreground",
",",
"background",
"=",
"fg",
",",
"bg",
"\n",
"err",
":=",
"update_size_maybe",
"(",
")",
"\n",
"back_buffer",
".",
"clear",
"(",
")",
"\n",
"return",
"err",
"\n",
... | // Clears the internal back buffer. | [
"Clears",
"the",
"internal",
"back",
"buffer",
"."
] | 288510b9734e30e7966ec2f22b87c5f8e67345e3 | https://github.com/nsf/termbox-go/blob/288510b9734e30e7966ec2f22b87c5f8e67345e3/api.go#L397-L402 | train |
nsf/termbox-go | api.go | Sync | func Sync() error {
front_buffer.clear()
err := send_clear()
if err != nil {
return err
}
return Flush()
} | go | func Sync() error {
front_buffer.clear()
err := send_clear()
if err != nil {
return err
}
return Flush()
} | [
"func",
"Sync",
"(",
")",
"error",
"{",
"front_buffer",
".",
"clear",
"(",
")",
"\n",
"err",
":=",
"send_clear",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"Flush",
"(",
")",
"\n",
"}"
] | // Sync comes handy when something causes desync between termbox's understanding
// of a terminal buffer and the reality. Such as a third party process. Sync
// forces a complete resync between the termbox and a terminal, it may not be
// visually pretty though. | [
"Sync",
"comes",
"handy",
"when",
"something",
"causes",
"desync",
"between",
"termbox",
"s",
"understanding",
"of",
"a",
"terminal",
"buffer",
"and",
"the",
"reality",
".",
"Such",
"as",
"a",
"third",
"party",
"process",
".",
"Sync",
"forces",
"a",
"complet... | 288510b9734e30e7966ec2f22b87c5f8e67345e3 | https://github.com/nsf/termbox-go/blob/288510b9734e30e7966ec2f22b87c5f8e67345e3/api.go#L489-L497 | train |
tus/tusd | metrics.go | incRequestsTotal | func (m Metrics) incRequestsTotal(method string) {
if ptr, ok := m.RequestsTotal[method]; ok {
atomic.AddUint64(ptr, 1)
}
} | go | func (m Metrics) incRequestsTotal(method string) {
if ptr, ok := m.RequestsTotal[method]; ok {
atomic.AddUint64(ptr, 1)
}
} | [
"func",
"(",
"m",
"Metrics",
")",
"incRequestsTotal",
"(",
"method",
"string",
")",
"{",
"if",
"ptr",
",",
"ok",
":=",
"m",
".",
"RequestsTotal",
"[",
"method",
"]",
";",
"ok",
"{",
"atomic",
".",
"AddUint64",
"(",
"ptr",
",",
"1",
")",
"\n",
"}",
... | // incRequestsTotal increases the counter for this request method atomically by
// one. The method must be one of GET, HEAD, POST, PATCH, DELETE. | [
"incRequestsTotal",
"increases",
"the",
"counter",
"for",
"this",
"request",
"method",
"atomically",
"by",
"one",
".",
"The",
"method",
"must",
"be",
"one",
"of",
"GET",
"HEAD",
"POST",
"PATCH",
"DELETE",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/metrics.go#L27-L31 | train |
tus/tusd | metrics.go | incErrorsTotal | func (m Metrics) incErrorsTotal(err HTTPError) {
ptr := m.ErrorsTotal.retrievePointerFor(err)
atomic.AddUint64(ptr, 1)
} | go | func (m Metrics) incErrorsTotal(err HTTPError) {
ptr := m.ErrorsTotal.retrievePointerFor(err)
atomic.AddUint64(ptr, 1)
} | [
"func",
"(",
"m",
"Metrics",
")",
"incErrorsTotal",
"(",
"err",
"HTTPError",
")",
"{",
"ptr",
":=",
"m",
".",
"ErrorsTotal",
".",
"retrievePointerFor",
"(",
"err",
")",
"\n",
"atomic",
".",
"AddUint64",
"(",
"ptr",
",",
"1",
")",
"\n",
"}"
] | // incErrorsTotal increases the counter for this error atomically by one. | [
"incErrorsTotal",
"increases",
"the",
"counter",
"for",
"this",
"error",
"atomically",
"by",
"one",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/metrics.go#L34-L37 | train |
tus/tusd | metrics.go | incBytesReceived | func (m Metrics) incBytesReceived(delta uint64) {
atomic.AddUint64(m.BytesReceived, delta)
} | go | func (m Metrics) incBytesReceived(delta uint64) {
atomic.AddUint64(m.BytesReceived, delta)
} | [
"func",
"(",
"m",
"Metrics",
")",
"incBytesReceived",
"(",
"delta",
"uint64",
")",
"{",
"atomic",
".",
"AddUint64",
"(",
"m",
".",
"BytesReceived",
",",
"delta",
")",
"\n",
"}"
] | // incBytesReceived increases the number of received bytes atomically be the
// specified number. | [
"incBytesReceived",
"increases",
"the",
"number",
"of",
"received",
"bytes",
"atomically",
"be",
"the",
"specified",
"number",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/metrics.go#L41-L43 | train |
tus/tusd | metrics.go | Load | func (e *ErrorsTotalMap) Load() map[HTTPError]*uint64 {
m := make(map[HTTPError]*uint64, len(e.counter))
e.lock.RLock()
for err, ptr := range e.counter {
httpErr := NewHTTPError(errors.New(err.Message), err.StatusCode)
m[httpErr] = ptr
}
e.lock.RUnlock()
return m
} | go | func (e *ErrorsTotalMap) Load() map[HTTPError]*uint64 {
m := make(map[HTTPError]*uint64, len(e.counter))
e.lock.RLock()
for err, ptr := range e.counter {
httpErr := NewHTTPError(errors.New(err.Message), err.StatusCode)
m[httpErr] = ptr
}
e.lock.RUnlock()
return m
} | [
"func",
"(",
"e",
"*",
"ErrorsTotalMap",
")",
"Load",
"(",
")",
"map",
"[",
"HTTPError",
"]",
"*",
"uint64",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"HTTPError",
"]",
"*",
"uint64",
",",
"len",
"(",
"e",
".",
"counter",
")",
")",
"\n",
"e",
".... | // Load retrieves the map of the counter pointers atomically | [
"Load",
"retrieves",
"the",
"map",
"of",
"the",
"counter",
"pointers",
"atomically"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/metrics.go#L127-L137 | train |
tus/tusd | etcd3locker/locker_options.go | Prefix | func (l *LockerOptions) Prefix() string {
prefix := l.prefix
if !strings.HasPrefix(prefix, "/") {
prefix = "/" + prefix
}
if prefix == "" {
return DefaultPrefix
} else {
return prefix
}
} | go | func (l *LockerOptions) Prefix() string {
prefix := l.prefix
if !strings.HasPrefix(prefix, "/") {
prefix = "/" + prefix
}
if prefix == "" {
return DefaultPrefix
} else {
return prefix
}
} | [
"func",
"(",
"l",
"*",
"LockerOptions",
")",
"Prefix",
"(",
")",
"string",
"{",
"prefix",
":=",
"l",
".",
"prefix",
"\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"prefix",
",",
"\"",
"\"",
")",
"{",
"prefix",
"=",
"\"",
"\"",
"+",
"prefix",
... | // Returns the string prefix used to store keys in etcd3 | [
"Returns",
"the",
"string",
"prefix",
"used",
"to",
"store",
"keys",
"in",
"etcd3"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/etcd3locker/locker_options.go#L45-L56 | train |
tus/tusd | limitedstore/limitedstore.go | New | func New(storeSize int64, dataStore tusd.DataStore, terminater tusd.TerminaterDataStore) *LimitedStore {
return &LimitedStore{
StoreSize: storeSize,
DataStore: dataStore,
terminater: terminater,
uploads: make(map[string]int64),
mutex: new(sync.Mutex),
}
} | go | func New(storeSize int64, dataStore tusd.DataStore, terminater tusd.TerminaterDataStore) *LimitedStore {
return &LimitedStore{
StoreSize: storeSize,
DataStore: dataStore,
terminater: terminater,
uploads: make(map[string]int64),
mutex: new(sync.Mutex),
}
} | [
"func",
"New",
"(",
"storeSize",
"int64",
",",
"dataStore",
"tusd",
".",
"DataStore",
",",
"terminater",
"tusd",
".",
"TerminaterDataStore",
")",
"*",
"LimitedStore",
"{",
"return",
"&",
"LimitedStore",
"{",
"StoreSize",
":",
"storeSize",
",",
"DataStore",
":"... | // New creates a new limited store with the given size as the maximum storage
// size. The wrapped data store needs to implement the TerminaterDataStore
// interface, in order to provide the required Terminate method. | [
"New",
"creates",
"a",
"new",
"limited",
"store",
"with",
"the",
"given",
"size",
"as",
"the",
"maximum",
"storage",
"size",
".",
"The",
"wrapped",
"data",
"store",
"needs",
"to",
"implement",
"the",
"TerminaterDataStore",
"interface",
"in",
"order",
"to",
"... | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/limitedstore/limitedstore.go#L52-L60 | train |
tus/tusd | limitedstore/limitedstore.go | ensureSpace | func (store *LimitedStore) ensureSpace(size int64) error {
if (store.usedSize + size) <= store.StoreSize {
// Enough space is available to store the new upload
return nil
}
sortedUploads := make(pairlist, len(store.uploads))
i := 0
for u, h := range store.uploads {
sortedUploads[i] = pair{u, h}
i++
}
so... | go | func (store *LimitedStore) ensureSpace(size int64) error {
if (store.usedSize + size) <= store.StoreSize {
// Enough space is available to store the new upload
return nil
}
sortedUploads := make(pairlist, len(store.uploads))
i := 0
for u, h := range store.uploads {
sortedUploads[i] = pair{u, h}
i++
}
so... | [
"func",
"(",
"store",
"*",
"LimitedStore",
")",
"ensureSpace",
"(",
"size",
"int64",
")",
"error",
"{",
"if",
"(",
"store",
".",
"usedSize",
"+",
"size",
")",
"<=",
"store",
".",
"StoreSize",
"{",
"// Enough space is available to store the new upload",
"return",... | // Ensure enough space is available to store an upload of the specified size.
// It will terminate uploads until enough space is freed. | [
"Ensure",
"enough",
"space",
"is",
"available",
"to",
"store",
"an",
"upload",
"of",
"the",
"specified",
"size",
".",
"It",
"will",
"terminate",
"uploads",
"until",
"enough",
"space",
"is",
"freed",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/limitedstore/limitedstore.go#L111-L140 | train |
tus/tusd | filestore/filestore.go | newLock | func (store FileStore) newLock(id string) (lockfile.Lockfile, error) {
path, err := filepath.Abs(filepath.Join(store.Path, id+".lock"))
if err != nil {
return lockfile.Lockfile(""), err
}
// We use Lockfile directly instead of lockfile.New to bypass the unnecessary
// check whether the provided path is absolute... | go | func (store FileStore) newLock(id string) (lockfile.Lockfile, error) {
path, err := filepath.Abs(filepath.Join(store.Path, id+".lock"))
if err != nil {
return lockfile.Lockfile(""), err
}
// We use Lockfile directly instead of lockfile.New to bypass the unnecessary
// check whether the provided path is absolute... | [
"func",
"(",
"store",
"FileStore",
")",
"newLock",
"(",
"id",
"string",
")",
"(",
"lockfile",
".",
"Lockfile",
",",
"error",
")",
"{",
"path",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"filepath",
".",
"Join",
"(",
"store",
".",
"Path",
",",
"... | // newLock contructs a new Lockfile instance. | [
"newLock",
"contructs",
"a",
"new",
"Lockfile",
"instance",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/filestore/filestore.go#L189-L199 | train |
tus/tusd | filestore/filestore.go | binPath | func (store FileStore) binPath(id string) string {
return filepath.Join(store.Path, id+".bin")
} | go | func (store FileStore) binPath(id string) string {
return filepath.Join(store.Path, id+".bin")
} | [
"func",
"(",
"store",
"FileStore",
")",
"binPath",
"(",
"id",
"string",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"store",
".",
"Path",
",",
"id",
"+",
"\"",
"\"",
")",
"\n",
"}"
] | // binPath returns the path to the .bin storing the binary data. | [
"binPath",
"returns",
"the",
"path",
"to",
"the",
".",
"bin",
"storing",
"the",
"binary",
"data",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/filestore/filestore.go#L202-L204 | train |
tus/tusd | filestore/filestore.go | infoPath | func (store FileStore) infoPath(id string) string {
return filepath.Join(store.Path, id+".info")
} | go | func (store FileStore) infoPath(id string) string {
return filepath.Join(store.Path, id+".info")
} | [
"func",
"(",
"store",
"FileStore",
")",
"infoPath",
"(",
"id",
"string",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"store",
".",
"Path",
",",
"id",
"+",
"\"",
"\"",
")",
"\n",
"}"
] | // infoPath returns the path to the .info file storing the file's info. | [
"infoPath",
"returns",
"the",
"path",
"to",
"the",
".",
"info",
"file",
"storing",
"the",
"file",
"s",
"info",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/filestore/filestore.go#L207-L209 | train |
tus/tusd | filestore/filestore.go | writeInfo | func (store FileStore) writeInfo(id string, info tusd.FileInfo) error {
data, err := json.Marshal(info)
if err != nil {
return err
}
return ioutil.WriteFile(store.infoPath(id), data, defaultFilePerm)
} | go | func (store FileStore) writeInfo(id string, info tusd.FileInfo) error {
data, err := json.Marshal(info)
if err != nil {
return err
}
return ioutil.WriteFile(store.infoPath(id), data, defaultFilePerm)
} | [
"func",
"(",
"store",
"FileStore",
")",
"writeInfo",
"(",
"id",
"string",
",",
"info",
"tusd",
".",
"FileInfo",
")",
"error",
"{",
"data",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"info",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"e... | // writeInfo updates the entire information. Everything will be overwritten. | [
"writeInfo",
"updates",
"the",
"entire",
"information",
".",
"Everything",
"will",
"be",
"overwritten",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/filestore/filestore.go#L212-L218 | train |
tus/tusd | consullocker/consullocker.go | New | func New(client *consul.Client) *ConsulLocker {
return &ConsulLocker{
Client: client,
locks: make(map[string]*consul.Lock),
mutex: new(sync.RWMutex),
}
} | go | func New(client *consul.Client) *ConsulLocker {
return &ConsulLocker{
Client: client,
locks: make(map[string]*consul.Lock),
mutex: new(sync.RWMutex),
}
} | [
"func",
"New",
"(",
"client",
"*",
"consul",
".",
"Client",
")",
"*",
"ConsulLocker",
"{",
"return",
"&",
"ConsulLocker",
"{",
"Client",
":",
"client",
",",
"locks",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"consul",
".",
"Lock",
")",
",",
... | // New constructs a new locker using the provided client. | [
"New",
"constructs",
"a",
"new",
"locker",
"using",
"the",
"provided",
"client",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/consullocker/consullocker.go#L40-L46 | train |
tus/tusd | unrouted_handler.go | Middleware | func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Allow overriding the HTTP method. The reason for this is
// that some libraries/environments to not support PATCH and
// DELETE requests, e.g. Flash in a browser and... | go | func (handler *UnroutedHandler) Middleware(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Allow overriding the HTTP method. The reason for this is
// that some libraries/environments to not support PATCH and
// DELETE requests, e.g. Flash in a browser and... | [
"func",
"(",
"handler",
"*",
"UnroutedHandler",
")",
"Middleware",
"(",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".... | // Middleware checks various aspects of the request and ensures that it
// conforms with the spec. Also handles method overriding for clients which
// cannot make PATCH AND DELETE requests. If you are using the tusd handlers
// directly you will need to wrap at least the POST and PATCH endpoints in
// this middleware. | [
"Middleware",
"checks",
"various",
"aspects",
"of",
"the",
"request",
"and",
"ensures",
"that",
"it",
"conforms",
"with",
"the",
"spec",
".",
"Also",
"handles",
"method",
"overriding",
"for",
"clients",
"which",
"cannot",
"make",
"PATCH",
"AND",
"DELETE",
"req... | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/unrouted_handler.go#L161-L229 | train |
tus/tusd | unrouted_handler.go | HeadFile | func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request) {
id, err := extractIDFromPath(r.URL.Path)
if err != nil {
handler.sendError(w, r, err)
return
}
if handler.composer.UsesLocker {
locker := handler.composer.Locker
if err := locker.LockUpload(id); err != nil {
handler.send... | go | func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request) {
id, err := extractIDFromPath(r.URL.Path)
if err != nil {
handler.sendError(w, r, err)
return
}
if handler.composer.UsesLocker {
locker := handler.composer.Locker
if err := locker.LockUpload(id); err != nil {
handler.send... | [
"func",
"(",
"handler",
"*",
"UnroutedHandler",
")",
"HeadFile",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"id",
",",
"err",
":=",
"extractIDFromPath",
"(",
"r",
".",
"URL",
".",
"Path",
")",
"\n",
"if"... | // HeadFile returns the length and offset for the HEAD request | [
"HeadFile",
"returns",
"the",
"length",
"and",
"offset",
"for",
"the",
"HEAD",
"request"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/unrouted_handler.go#L356-L409 | train |
tus/tusd | unrouted_handler.go | writeChunk | func (handler *UnroutedHandler) writeChunk(id string, info FileInfo, w http.ResponseWriter, r *http.Request) error {
// Get Content-Length if possible
length := r.ContentLength
offset := info.Offset
// Test if this upload fits into the file's size
if !info.SizeIsDeferred && offset+length > info.Size {
return Er... | go | func (handler *UnroutedHandler) writeChunk(id string, info FileInfo, w http.ResponseWriter, r *http.Request) error {
// Get Content-Length if possible
length := r.ContentLength
offset := info.Offset
// Test if this upload fits into the file's size
if !info.SizeIsDeferred && offset+length > info.Size {
return Er... | [
"func",
"(",
"handler",
"*",
"UnroutedHandler",
")",
"writeChunk",
"(",
"id",
"string",
",",
"info",
"FileInfo",
",",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"// Get Content-Length if possible",
"length",
... | // writeChunk reads the body from the requests r and appends it to the upload
// with the corresponding id. Afterwards, it will set the necessary response
// headers but will not send the response. | [
"writeChunk",
"reads",
"the",
"body",
"from",
"the",
"requests",
"r",
"and",
"appends",
"it",
"to",
"the",
"upload",
"with",
"the",
"corresponding",
"id",
".",
"Afterwards",
"it",
"will",
"set",
"the",
"necessary",
"response",
"headers",
"but",
"will",
"not"... | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/unrouted_handler.go#L502-L560 | train |
tus/tusd | unrouted_handler.go | GetFile | func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request) {
if !handler.composer.UsesGetReader {
handler.sendError(w, r, ErrNotImplemented)
return
}
id, err := extractIDFromPath(r.URL.Path)
if err != nil {
handler.sendError(w, r, err)
return
}
if handler.composer.UsesLocker {
loc... | go | func (handler *UnroutedHandler) GetFile(w http.ResponseWriter, r *http.Request) {
if !handler.composer.UsesGetReader {
handler.sendError(w, r, ErrNotImplemented)
return
}
id, err := extractIDFromPath(r.URL.Path)
if err != nil {
handler.sendError(w, r, err)
return
}
if handler.composer.UsesLocker {
loc... | [
"func",
"(",
"handler",
"*",
"UnroutedHandler",
")",
"GetFile",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"!",
"handler",
".",
"composer",
".",
"UsesGetReader",
"{",
"handler",
".",
"sendError",
"(",
... | // GetFile handles requests to download a file using a GET request. This is not
// part of the specification. | [
"GetFile",
"handles",
"requests",
"to",
"download",
"a",
"file",
"using",
"a",
"GET",
"request",
".",
"This",
"is",
"not",
"part",
"of",
"the",
"specification",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/unrouted_handler.go#L588-L642 | train |
tus/tusd | unrouted_handler.go | DelFile | func (handler *UnroutedHandler) DelFile(w http.ResponseWriter, r *http.Request) {
// Abort the request handling if the required interface is not implemented
if !handler.composer.UsesTerminater {
handler.sendError(w, r, ErrNotImplemented)
return
}
id, err := extractIDFromPath(r.URL.Path)
if err != nil {
hand... | go | func (handler *UnroutedHandler) DelFile(w http.ResponseWriter, r *http.Request) {
// Abort the request handling if the required interface is not implemented
if !handler.composer.UsesTerminater {
handler.sendError(w, r, ErrNotImplemented)
return
}
id, err := extractIDFromPath(r.URL.Path)
if err != nil {
hand... | [
"func",
"(",
"handler",
"*",
"UnroutedHandler",
")",
"DelFile",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"// Abort the request handling if the required interface is not implemented",
"if",
"!",
"handler",
".",
"compos... | // DelFile terminates an upload permanently. | [
"DelFile",
"terminates",
"an",
"upload",
"permanently",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/unrouted_handler.go#L706-L751 | train |
tus/tusd | unrouted_handler.go | sendError | func (handler *UnroutedHandler) sendError(w http.ResponseWriter, r *http.Request, err error) {
// Interpret os.ErrNotExist as 404 Not Found
if os.IsNotExist(err) {
err = ErrNotFound
}
// Errors for read timeouts contain too much information which is not
// necessary for us and makes grouping for the metrics har... | go | func (handler *UnroutedHandler) sendError(w http.ResponseWriter, r *http.Request, err error) {
// Interpret os.ErrNotExist as 404 Not Found
if os.IsNotExist(err) {
err = ErrNotFound
}
// Errors for read timeouts contain too much information which is not
// necessary for us and makes grouping for the metrics har... | [
"func",
"(",
"handler",
"*",
"UnroutedHandler",
")",
"sendError",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
")",
"{",
"// Interpret os.ErrNotExist as 404 Not Found",
"if",
"os",
".",
"IsNotExist",
"(",... | // Send the error in the response body. The status code will be looked up in
// ErrStatusCodes. If none is found 500 Internal Error will be used. | [
"Send",
"the",
"error",
"in",
"the",
"response",
"body",
".",
"The",
"status",
"code",
"will",
"be",
"looked",
"up",
"in",
"ErrStatusCodes",
".",
"If",
"none",
"is",
"found",
"500",
"Internal",
"Error",
"will",
"be",
"used",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/unrouted_handler.go#L755-L787 | train |
tus/tusd | unrouted_handler.go | sendResp | func (handler *UnroutedHandler) sendResp(w http.ResponseWriter, r *http.Request, status int) {
w.WriteHeader(status)
handler.log("ResponseOutgoing", "status", strconv.Itoa(status), "method", r.Method, "path", r.URL.Path)
} | go | func (handler *UnroutedHandler) sendResp(w http.ResponseWriter, r *http.Request, status int) {
w.WriteHeader(status)
handler.log("ResponseOutgoing", "status", strconv.Itoa(status), "method", r.Method, "path", r.URL.Path)
} | [
"func",
"(",
"handler",
"*",
"UnroutedHandler",
")",
"sendResp",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"status",
"int",
")",
"{",
"w",
".",
"WriteHeader",
"(",
"status",
")",
"\n\n",
"handler",
".",
"log",... | // sendResp writes the header to w with the specified status code. | [
"sendResp",
"writes",
"the",
"header",
"to",
"w",
"with",
"the",
"specified",
"status",
"code",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/unrouted_handler.go#L790-L794 | train |
tus/tusd | unrouted_handler.go | absFileURL | func (handler *UnroutedHandler) absFileURL(r *http.Request, id string) string {
if handler.isBasePathAbs {
return handler.basePath + id
}
// Read origin and protocol from request
host, proto := getHostAndProtocol(r, handler.config.RespectForwardedHeaders)
url := proto + "://" + host + handler.basePath + id
r... | go | func (handler *UnroutedHandler) absFileURL(r *http.Request, id string) string {
if handler.isBasePathAbs {
return handler.basePath + id
}
// Read origin and protocol from request
host, proto := getHostAndProtocol(r, handler.config.RespectForwardedHeaders)
url := proto + "://" + host + handler.basePath + id
r... | [
"func",
"(",
"handler",
"*",
"UnroutedHandler",
")",
"absFileURL",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"id",
"string",
")",
"string",
"{",
"if",
"handler",
".",
"isBasePathAbs",
"{",
"return",
"handler",
".",
"basePath",
"+",
"id",
"\n",
"}",
"... | // Make an absolute URLs to the given upload id. If the base path is absolute
// it will be prepended else the host and protocol from the request is used. | [
"Make",
"an",
"absolute",
"URLs",
"to",
"the",
"given",
"upload",
"id",
".",
"If",
"the",
"base",
"path",
"is",
"absolute",
"it",
"will",
"be",
"prepended",
"else",
"the",
"host",
"and",
"protocol",
"from",
"the",
"request",
"is",
"used",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/unrouted_handler.go#L798-L809 | train |
tus/tusd | unrouted_handler.go | sendProgressMessages | func (handler *UnroutedHandler) sendProgressMessages(info FileInfo, reader io.Reader) (io.Reader, chan<- struct{}) {
progress := &progressWriter{
Offset: info.Offset,
}
stop := make(chan struct{}, 1)
reader = io.TeeReader(reader, progress)
go func() {
for {
select {
case <-stop:
info.Offset = atomic... | go | func (handler *UnroutedHandler) sendProgressMessages(info FileInfo, reader io.Reader) (io.Reader, chan<- struct{}) {
progress := &progressWriter{
Offset: info.Offset,
}
stop := make(chan struct{}, 1)
reader = io.TeeReader(reader, progress)
go func() {
for {
select {
case <-stop:
info.Offset = atomic... | [
"func",
"(",
"handler",
"*",
"UnroutedHandler",
")",
"sendProgressMessages",
"(",
"info",
"FileInfo",
",",
"reader",
"io",
".",
"Reader",
")",
"(",
"io",
".",
"Reader",
",",
"chan",
"<-",
"struct",
"{",
"}",
")",
"{",
"progress",
":=",
"&",
"progressWrit... | // sendProgressMessage will send a notification over the UploadProgress channel
// every second, indicating how much data has been transfered to the server.
// It will stop sending these instances once the returned channel has been
// closed. The returned reader should be used to read the request body. | [
"sendProgressMessage",
"will",
"send",
"a",
"notification",
"over",
"the",
"UploadProgress",
"channel",
"every",
"second",
"indicating",
"how",
"much",
"data",
"has",
"been",
"transfered",
"to",
"the",
"server",
".",
"It",
"will",
"stop",
"sending",
"these",
"in... | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/unrouted_handler.go#L824-L846 | train |
tus/tusd | unrouted_handler.go | sizeOfUploads | func (handler *UnroutedHandler) sizeOfUploads(ids []string) (size int64, err error) {
for _, id := range ids {
info, err := handler.composer.Core.GetInfo(id)
if err != nil {
return size, err
}
if info.SizeIsDeferred || info.Offset != info.Size {
err = ErrUploadNotFinished
return size, err
}
size... | go | func (handler *UnroutedHandler) sizeOfUploads(ids []string) (size int64, err error) {
for _, id := range ids {
info, err := handler.composer.Core.GetInfo(id)
if err != nil {
return size, err
}
if info.SizeIsDeferred || info.Offset != info.Size {
err = ErrUploadNotFinished
return size, err
}
size... | [
"func",
"(",
"handler",
"*",
"UnroutedHandler",
")",
"sizeOfUploads",
"(",
"ids",
"[",
"]",
"string",
")",
"(",
"size",
"int64",
",",
"err",
"error",
")",
"{",
"for",
"_",
",",
"id",
":=",
"range",
"ids",
"{",
"info",
",",
"err",
":=",
"handler",
"... | // The get sum of all sizes for a list of upload ids while checking whether
// all of these uploads are finished yet. This is used to calculate the size
// of a final resource. | [
"The",
"get",
"sum",
"of",
"all",
"sizes",
"for",
"a",
"list",
"of",
"upload",
"ids",
"while",
"checking",
"whether",
"all",
"of",
"these",
"uploads",
"are",
"finished",
"yet",
".",
"This",
"is",
"used",
"to",
"calculate",
"the",
"size",
"of",
"a",
"fi... | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/unrouted_handler.go#L889-L905 | train |
tus/tusd | unrouted_handler.go | validateNewUploadLengthHeaders | func (handler *UnroutedHandler) validateNewUploadLengthHeaders(uploadLengthHeader string, uploadDeferLengthHeader string) (uploadLength int64, uploadLengthDeferred bool, err error) {
haveBothLengthHeaders := uploadLengthHeader != "" && uploadDeferLengthHeader != ""
haveInvalidDeferHeader := uploadDeferLengthHeader !=... | go | func (handler *UnroutedHandler) validateNewUploadLengthHeaders(uploadLengthHeader string, uploadDeferLengthHeader string) (uploadLength int64, uploadLengthDeferred bool, err error) {
haveBothLengthHeaders := uploadLengthHeader != "" && uploadDeferLengthHeader != ""
haveInvalidDeferHeader := uploadDeferLengthHeader !=... | [
"func",
"(",
"handler",
"*",
"UnroutedHandler",
")",
"validateNewUploadLengthHeaders",
"(",
"uploadLengthHeader",
"string",
",",
"uploadDeferLengthHeader",
"string",
")",
"(",
"uploadLength",
"int64",
",",
"uploadLengthDeferred",
"bool",
",",
"err",
"error",
")",
"{",... | // Verify that the Upload-Length and Upload-Defer-Length headers are acceptable for creating a
// new upload | [
"Verify",
"that",
"the",
"Upload",
"-",
"Length",
"and",
"Upload",
"-",
"Defer",
"-",
"Length",
"headers",
"are",
"acceptable",
"for",
"creating",
"a",
"new",
"upload"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/unrouted_handler.go#L909-L930 | train |
tus/tusd | unrouted_handler.go | extractIDFromPath | func extractIDFromPath(url string) (string, error) {
result := reExtractFileID.FindStringSubmatch(url)
if len(result) != 2 {
return "", ErrNotFound
}
return result[1], nil
} | go | func extractIDFromPath(url string) (string, error) {
result := reExtractFileID.FindStringSubmatch(url)
if len(result) != 2 {
return "", ErrNotFound
}
return result[1], nil
} | [
"func",
"extractIDFromPath",
"(",
"url",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"result",
":=",
"reExtractFileID",
".",
"FindStringSubmatch",
"(",
"url",
")",
"\n",
"if",
"len",
"(",
"result",
")",
"!=",
"2",
"{",
"return",
"\"",
"\"",
"... | // extractIDFromPath pulls the last segment from the url provided | [
"extractIDFromPath",
"pulls",
"the",
"last",
"segment",
"from",
"the",
"url",
"provided"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/unrouted_handler.go#L1023-L1029 | train |
tus/tusd | gcsstore/gcsservice.go | NewGCSService | func NewGCSService(filename string) (*GCSService, error) {
ctx := context.Background()
client, err := storage.NewClient(ctx, option.WithServiceAccountFile(filename))
if err != nil {
return nil, err
}
service := &GCSService{
Client: client,
}
return service, nil
} | go | func NewGCSService(filename string) (*GCSService, error) {
ctx := context.Background()
client, err := storage.NewClient(ctx, option.WithServiceAccountFile(filename))
if err != nil {
return nil, err
}
service := &GCSService{
Client: client,
}
return service, nil
} | [
"func",
"NewGCSService",
"(",
"filename",
"string",
")",
"(",
"*",
"GCSService",
",",
"error",
")",
"{",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n",
"client",
",",
"err",
":=",
"storage",
".",
"NewClient",
"(",
"ctx",
",",
"option",
".",... | // NewGCSService returns a GCSSerivce object given a GCloud service account file path. | [
"NewGCSService",
"returns",
"a",
"GCSSerivce",
"object",
"given",
"a",
"GCloud",
"service",
"account",
"file",
"path",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/gcsstore/gcsservice.go#L82-L94 | train |
tus/tusd | gcsstore/gcsservice.go | GetObjectSize | func (service *GCSService) GetObjectSize(ctx context.Context, params GCSObjectParams) (int64, error) {
attrs, err := service.GetObjectAttrs(ctx, params)
if err != nil {
return 0, err
}
return attrs.Size, nil
} | go | func (service *GCSService) GetObjectSize(ctx context.Context, params GCSObjectParams) (int64, error) {
attrs, err := service.GetObjectAttrs(ctx, params)
if err != nil {
return 0, err
}
return attrs.Size, nil
} | [
"func",
"(",
"service",
"*",
"GCSService",
")",
"GetObjectSize",
"(",
"ctx",
"context",
".",
"Context",
",",
"params",
"GCSObjectParams",
")",
"(",
"int64",
",",
"error",
")",
"{",
"attrs",
",",
"err",
":=",
"service",
".",
"GetObjectAttrs",
"(",
"ctx",
... | // GetObjectSize returns the byte length of the specified GCS object. | [
"GetObjectSize",
"returns",
"the",
"byte",
"length",
"of",
"the",
"specified",
"GCS",
"object",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/gcsstore/gcsservice.go#L97-L104 | train |
tus/tusd | gcsstore/gcsservice.go | DeleteObjectsWithFilter | func (service *GCSService) DeleteObjectsWithFilter(ctx context.Context, params GCSFilterParams) error {
names, err := service.FilterObjects(ctx, params)
if err != nil {
return err
}
var objectParams GCSObjectParams
for _, name := range names {
objectParams = GCSObjectParams{
Bucket: params.Bucket,
ID: ... | go | func (service *GCSService) DeleteObjectsWithFilter(ctx context.Context, params GCSFilterParams) error {
names, err := service.FilterObjects(ctx, params)
if err != nil {
return err
}
var objectParams GCSObjectParams
for _, name := range names {
objectParams = GCSObjectParams{
Bucket: params.Bucket,
ID: ... | [
"func",
"(",
"service",
"*",
"GCSService",
")",
"DeleteObjectsWithFilter",
"(",
"ctx",
"context",
".",
"Context",
",",
"params",
"GCSFilterParams",
")",
"error",
"{",
"names",
",",
"err",
":=",
"service",
".",
"FilterObjects",
"(",
"ctx",
",",
"params",
")",... | // DeleteObjectWithPrefix will delete objects who match the provided filter parameters. | [
"DeleteObjectWithPrefix",
"will",
"delete",
"objects",
"who",
"match",
"the",
"provided",
"filter",
"parameters",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/gcsstore/gcsservice.go#L107-L127 | train |
tus/tusd | gcsstore/gcsservice.go | compose | func (service *GCSService) compose(ctx context.Context, bucket string, srcs []string, dst string) error {
dstParams := GCSObjectParams{
Bucket: bucket,
ID: dst,
}
objSrcs := make([]*storage.ObjectHandle, len(srcs))
var crc uint32
for i := 0; i < len(srcs); i++ {
objSrcs[i] = service.Client.Bucket(bucket)... | go | func (service *GCSService) compose(ctx context.Context, bucket string, srcs []string, dst string) error {
dstParams := GCSObjectParams{
Bucket: bucket,
ID: dst,
}
objSrcs := make([]*storage.ObjectHandle, len(srcs))
var crc uint32
for i := 0; i < len(srcs); i++ {
objSrcs[i] = service.Client.Bucket(bucket)... | [
"func",
"(",
"service",
"*",
"GCSService",
")",
"compose",
"(",
"ctx",
"context",
".",
"Context",
",",
"bucket",
"string",
",",
"srcs",
"[",
"]",
"string",
",",
"dst",
"string",
")",
"error",
"{",
"dstParams",
":=",
"GCSObjectParams",
"{",
"Bucket",
":",... | // Compose takes a bucket name, a list of initial source names, and a destination string to compose multiple GCS objects together | [
"Compose",
"takes",
"a",
"bucket",
"name",
"a",
"list",
"of",
"initial",
"source",
"names",
"and",
"a",
"destination",
"string",
"to",
"compose",
"multiple",
"GCS",
"objects",
"together"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/gcsstore/gcsservice.go#L132-L186 | train |
tus/tusd | gcsstore/gcsservice.go | ComposeObjects | func (service *GCSService) ComposeObjects(ctx context.Context, params GCSComposeParams) error {
err := service.recursiveCompose(ctx, params.Sources, params, 0)
if err != nil {
return err
}
return nil
} | go | func (service *GCSService) ComposeObjects(ctx context.Context, params GCSComposeParams) error {
err := service.recursiveCompose(ctx, params.Sources, params, 0)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"service",
"*",
"GCSService",
")",
"ComposeObjects",
"(",
"ctx",
"context",
".",
"Context",
",",
"params",
"GCSComposeParams",
")",
"error",
"{",
"err",
":=",
"service",
".",
"recursiveCompose",
"(",
"ctx",
",",
"params",
".",
"Sources",
",",
... | // ComposeObjects composes multiple GCS objects in to a single object.
// Since GCS limits composition to a max of 32 objects, additional logic
// has been added to chunk objects in to groups of 32 and then recursively
// compose those objects together. | [
"ComposeObjects",
"composes",
"multiple",
"GCS",
"objects",
"in",
"to",
"a",
"single",
"object",
".",
"Since",
"GCS",
"limits",
"composition",
"to",
"a",
"max",
"of",
"32",
"objects",
"additional",
"logic",
"has",
"been",
"added",
"to",
"chunk",
"objects",
"... | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/gcsstore/gcsservice.go#L240-L248 | train |
tus/tusd | gcsstore/gcsservice.go | ReadObject | func (service *GCSService) ReadObject(ctx context.Context, params GCSObjectParams) (GCSReader, error) {
r, err := service.Client.Bucket(params.Bucket).Object(params.ID).NewReader(ctx)
if err != nil {
return nil, err
}
return r, nil
} | go | func (service *GCSService) ReadObject(ctx context.Context, params GCSObjectParams) (GCSReader, error) {
r, err := service.Client.Bucket(params.Bucket).Object(params.ID).NewReader(ctx)
if err != nil {
return nil, err
}
return r, nil
} | [
"func",
"(",
"service",
"*",
"GCSService",
")",
"ReadObject",
"(",
"ctx",
"context",
".",
"Context",
",",
"params",
"GCSObjectParams",
")",
"(",
"GCSReader",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"service",
".",
"Client",
".",
"Bucket",
"(",
"... | // ReadObject reads a GCSObjectParams, returning a GCSReader object if successful, and an error otherwise | [
"ReadObject",
"reads",
"a",
"GCSObjectParams",
"returning",
"a",
"GCSReader",
"object",
"if",
"successful",
"and",
"an",
"error",
"otherwise"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/gcsstore/gcsservice.go#L264-L271 | train |
tus/tusd | gcsstore/gcsservice.go | SetObjectMetadata | func (service *GCSService) SetObjectMetadata(ctx context.Context, params GCSObjectParams, metadata map[string]string) error {
attrs := storage.ObjectAttrsToUpdate{
Metadata: metadata,
}
_, err := service.Client.Bucket(params.Bucket).Object(params.ID).Update(ctx, attrs)
return err
} | go | func (service *GCSService) SetObjectMetadata(ctx context.Context, params GCSObjectParams, metadata map[string]string) error {
attrs := storage.ObjectAttrsToUpdate{
Metadata: metadata,
}
_, err := service.Client.Bucket(params.Bucket).Object(params.ID).Update(ctx, attrs)
return err
} | [
"func",
"(",
"service",
"*",
"GCSService",
")",
"SetObjectMetadata",
"(",
"ctx",
"context",
".",
"Context",
",",
"params",
"GCSObjectParams",
",",
"metadata",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"attrs",
":=",
"storage",
".",
"ObjectAttrs... | // SetObjectMetadata reads a GCSObjectParams and a map of metedata, returning a nil on sucess and an error otherwise | [
"SetObjectMetadata",
"reads",
"a",
"GCSObjectParams",
"and",
"a",
"map",
"of",
"metedata",
"returning",
"a",
"nil",
"on",
"sucess",
"and",
"an",
"error",
"otherwise"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/gcsstore/gcsservice.go#L274-L281 | train |
tus/tusd | gcsstore/gcsservice.go | DeleteObject | func (service *GCSService) DeleteObject(ctx context.Context, params GCSObjectParams) error {
return service.Client.Bucket(params.Bucket).Object(params.ID).Delete(ctx)
} | go | func (service *GCSService) DeleteObject(ctx context.Context, params GCSObjectParams) error {
return service.Client.Bucket(params.Bucket).Object(params.ID).Delete(ctx)
} | [
"func",
"(",
"service",
"*",
"GCSService",
")",
"DeleteObject",
"(",
"ctx",
"context",
".",
"Context",
",",
"params",
"GCSObjectParams",
")",
"error",
"{",
"return",
"service",
".",
"Client",
".",
"Bucket",
"(",
"params",
".",
"Bucket",
")",
".",
"Object",... | // DeleteObject deletes the object defined by GCSObjectParams | [
"DeleteObject",
"deletes",
"the",
"object",
"defined",
"by",
"GCSObjectParams"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/gcsstore/gcsservice.go#L284-L286 | train |
tus/tusd | gcsstore/gcsservice.go | WriteObject | func (service *GCSService) WriteObject(ctx context.Context, params GCSObjectParams, r io.Reader) (int64, error) {
obj := service.Client.Bucket(params.Bucket).Object(params.ID)
w := obj.NewWriter(ctx)
n, err := io.Copy(w, r)
if err != nil {
return 0, err
}
err = w.Close()
if err != nil {
if gErr, ok := err... | go | func (service *GCSService) WriteObject(ctx context.Context, params GCSObjectParams, r io.Reader) (int64, error) {
obj := service.Client.Bucket(params.Bucket).Object(params.ID)
w := obj.NewWriter(ctx)
n, err := io.Copy(w, r)
if err != nil {
return 0, err
}
err = w.Close()
if err != nil {
if gErr, ok := err... | [
"func",
"(",
"service",
"*",
"GCSService",
")",
"WriteObject",
"(",
"ctx",
"context",
".",
"Context",
",",
"params",
"GCSObjectParams",
",",
"r",
"io",
".",
"Reader",
")",
"(",
"int64",
",",
"error",
")",
"{",
"obj",
":=",
"service",
".",
"Client",
"."... | // Write object writes the file set out by the GCSObjectParams | [
"Write",
"object",
"writes",
"the",
"file",
"set",
"out",
"by",
"the",
"GCSObjectParams"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/gcsstore/gcsservice.go#L289-L308 | train |
tus/tusd | gcsstore/gcsservice.go | ComposeFrom | func (service *GCSService) ComposeFrom(ctx context.Context, objSrcs []*storage.ObjectHandle, dstParams GCSObjectParams, contentType string) (uint32, error) {
dstObj := service.Client.Bucket(dstParams.Bucket).Object(dstParams.ID)
c := dstObj.ComposerFrom(objSrcs...)
c.ContentType = contentType
_, err := c.Run(ctx)
... | go | func (service *GCSService) ComposeFrom(ctx context.Context, objSrcs []*storage.ObjectHandle, dstParams GCSObjectParams, contentType string) (uint32, error) {
dstObj := service.Client.Bucket(dstParams.Bucket).Object(dstParams.ID)
c := dstObj.ComposerFrom(objSrcs...)
c.ContentType = contentType
_, err := c.Run(ctx)
... | [
"func",
"(",
"service",
"*",
"GCSService",
")",
"ComposeFrom",
"(",
"ctx",
"context",
".",
"Context",
",",
"objSrcs",
"[",
"]",
"*",
"storage",
".",
"ObjectHandle",
",",
"dstParams",
"GCSObjectParams",
",",
"contentType",
"string",
")",
"(",
"uint32",
",",
... | // ComposeFrom composes multiple object types together, | [
"ComposeFrom",
"composes",
"multiple",
"object",
"types",
"together"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/gcsstore/gcsservice.go#L311-L326 | train |
tus/tusd | memorylocker/memorylocker.go | UnlockUpload | func (locker *MemoryLocker) UnlockUpload(id string) error {
locker.mutex.Lock()
// Deleting a non-existing key does not end in unexpected errors or panic
// since this operation results in a no-op
delete(locker.locks, id)
locker.mutex.Unlock()
return nil
} | go | func (locker *MemoryLocker) UnlockUpload(id string) error {
locker.mutex.Lock()
// Deleting a non-existing key does not end in unexpected errors or panic
// since this operation results in a no-op
delete(locker.locks, id)
locker.mutex.Unlock()
return nil
} | [
"func",
"(",
"locker",
"*",
"MemoryLocker",
")",
"UnlockUpload",
"(",
"id",
"string",
")",
"error",
"{",
"locker",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n\n",
"// Deleting a non-existing key does not end in unexpected errors or panic",
"// since this operation results in... | // UnlockUpload releases a lock. If no such lock exists, no error will be returned. | [
"UnlockUpload",
"releases",
"a",
"lock",
".",
"If",
"no",
"such",
"lock",
"exists",
"no",
"error",
"will",
"be",
"returned",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/memorylocker/memorylocker.go#L62-L71 | train |
tus/tusd | gcsstore/gcsstore.go | New | func New(bucket string, service GCSAPI) GCSStore {
return GCSStore{
Bucket: bucket,
Service: service,
}
} | go | func New(bucket string, service GCSAPI) GCSStore {
return GCSStore{
Bucket: bucket,
Service: service,
}
} | [
"func",
"New",
"(",
"bucket",
"string",
",",
"service",
"GCSAPI",
")",
"GCSStore",
"{",
"return",
"GCSStore",
"{",
"Bucket",
":",
"bucket",
",",
"Service",
":",
"service",
",",
"}",
"\n",
"}"
] | // New constructs a new GCS storage backend using the supplied GCS bucket name
// and service object. | [
"New",
"constructs",
"a",
"new",
"GCS",
"storage",
"backend",
"using",
"the",
"supplied",
"GCS",
"bucket",
"name",
"and",
"service",
"object",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/gcsstore/gcsstore.go#L42-L47 | train |
tus/tusd | etcd3locker/locker.go | NewWithPrefix | func NewWithPrefix(client *etcd3.Client, prefix string) (*Etcd3Locker, error) {
lockerOptions := DefaultLockerOptions()
lockerOptions.SetPrefix(prefix)
return NewWithLockerOptions(client, lockerOptions)
} | go | func NewWithPrefix(client *etcd3.Client, prefix string) (*Etcd3Locker, error) {
lockerOptions := DefaultLockerOptions()
lockerOptions.SetPrefix(prefix)
return NewWithLockerOptions(client, lockerOptions)
} | [
"func",
"NewWithPrefix",
"(",
"client",
"*",
"etcd3",
".",
"Client",
",",
"prefix",
"string",
")",
"(",
"*",
"Etcd3Locker",
",",
"error",
")",
"{",
"lockerOptions",
":=",
"DefaultLockerOptions",
"(",
")",
"\n",
"lockerOptions",
".",
"SetPrefix",
"(",
"prefix... | // This method may be used if a different prefix is required for multi-tenant etcd clusters | [
"This",
"method",
"may",
"be",
"used",
"if",
"a",
"different",
"prefix",
"is",
"required",
"for",
"multi",
"-",
"tenant",
"etcd",
"clusters"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/etcd3locker/locker.go#L79-L83 | train |
tus/tusd | composer.go | newStoreComposerFromDataStore | func newStoreComposerFromDataStore(store DataStore) *StoreComposer {
composer := NewStoreComposer()
composer.UseCore(store)
if mod, ok := store.(TerminaterDataStore); ok {
composer.UseTerminater(mod)
}
if mod, ok := store.(FinisherDataStore); ok {
composer.UseFinisher(mod)
}
if mod, ok := store.(LockerDataS... | go | func newStoreComposerFromDataStore(store DataStore) *StoreComposer {
composer := NewStoreComposer()
composer.UseCore(store)
if mod, ok := store.(TerminaterDataStore); ok {
composer.UseTerminater(mod)
}
if mod, ok := store.(FinisherDataStore); ok {
composer.UseFinisher(mod)
}
if mod, ok := store.(LockerDataS... | [
"func",
"newStoreComposerFromDataStore",
"(",
"store",
"DataStore",
")",
"*",
"StoreComposer",
"{",
"composer",
":=",
"NewStoreComposer",
"(",
")",
"\n",
"composer",
".",
"UseCore",
"(",
"store",
")",
"\n\n",
"if",
"mod",
",",
"ok",
":=",
"store",
".",
"(",
... | // newStoreComposerFromDataStore creates a new store composer and attempts to
// extract the extensions for the provided store. This is intended to be used
// for transitioning from data stores to composers. | [
"newStoreComposerFromDataStore",
"creates",
"a",
"new",
"store",
"composer",
"and",
"attempts",
"to",
"extract",
"the",
"extensions",
"for",
"the",
"provided",
"store",
".",
"This",
"is",
"intended",
"to",
"be",
"used",
"for",
"transitioning",
"from",
"data",
"s... | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/composer.go#L31-L55 | train |
tus/tusd | composer.go | Capabilities | func (store *StoreComposer) Capabilities() string {
str := "Core: "
if store.Core != nil {
str += "✓"
} else {
str += "✗"
}
str += ` Terminater: `
if store.UsesTerminater {
str += "✓"
} else {
str += "✗"
}
str += ` Finisher: `
if store.UsesFinisher {
str += "✓"
} else {
str += "✗"
}
str += ` ... | go | func (store *StoreComposer) Capabilities() string {
str := "Core: "
if store.Core != nil {
str += "✓"
} else {
str += "✗"
}
str += ` Terminater: `
if store.UsesTerminater {
str += "✓"
} else {
str += "✗"
}
str += ` Finisher: `
if store.UsesFinisher {
str += "✓"
} else {
str += "✗"
}
str += ` ... | [
"func",
"(",
"store",
"*",
"StoreComposer",
")",
"Capabilities",
"(",
")",
"string",
"{",
"str",
":=",
"\"",
"\"",
"\n\n",
"if",
"store",
".",
"Core",
"!=",
"nil",
"{",
"str",
"+=",
"\"",
"",
"\n",
"}",
"else",
"{",
"str",
"+=",
"\"",
"",
"\n",
... | // Capabilities returns a string representing the provided extensions in a
// human-readable format meant for debugging. | [
"Capabilities",
"returns",
"a",
"string",
"representing",
"the",
"provided",
"extensions",
"in",
"a",
"human",
"-",
"readable",
"format",
"meant",
"for",
"debugging",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/composer.go#L59-L106 | train |
tus/tusd | s3store/s3store.go | New | func New(bucket string, service S3API) S3Store {
return S3Store{
Bucket: bucket,
Service: service,
MaxPartSize: 5 * 1024 * 1024 * 1024,
MinPartSize: 5 * 1024 * 1024,
MaxMultipartParts: 10000,
MaxObjectSize: 5 * 1024 * 1024 * 1024 * 1024,
}
} | go | func New(bucket string, service S3API) S3Store {
return S3Store{
Bucket: bucket,
Service: service,
MaxPartSize: 5 * 1024 * 1024 * 1024,
MinPartSize: 5 * 1024 * 1024,
MaxMultipartParts: 10000,
MaxObjectSize: 5 * 1024 * 1024 * 1024 * 1024,
}
} | [
"func",
"New",
"(",
"bucket",
"string",
",",
"service",
"S3API",
")",
"S3Store",
"{",
"return",
"S3Store",
"{",
"Bucket",
":",
"bucket",
",",
"Service",
":",
"service",
",",
"MaxPartSize",
":",
"5",
"*",
"1024",
"*",
"1024",
"*",
"1024",
",",
"MinPartS... | // New constructs a new storage using the supplied bucket and service object. | [
"New",
"constructs",
"a",
"new",
"storage",
"using",
"the",
"supplied",
"bucket",
"and",
"service",
"object",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/s3store/s3store.go#L147-L156 | train |
tus/tusd | s3store/s3store.go | isAwsError | func isAwsError(err error, code string) bool {
if err, ok := err.(awserr.Error); ok && err.Code() == code {
return true
}
return false
} | go | func isAwsError(err error, code string) bool {
if err, ok := err.(awserr.Error); ok && err.Code() == code {
return true
}
return false
} | [
"func",
"isAwsError",
"(",
"err",
"error",
",",
"code",
"string",
")",
"bool",
"{",
"if",
"err",
",",
"ok",
":=",
"err",
".",
"(",
"awserr",
".",
"Error",
")",
";",
"ok",
"&&",
"err",
".",
"Code",
"(",
")",
"==",
"code",
"{",
"return",
"true",
... | // isAwsError tests whether an error object is an instance of the AWS error
// specified by its code. | [
"isAwsError",
"tests",
"whether",
"an",
"error",
"object",
"is",
"an",
"instance",
"of",
"the",
"AWS",
"error",
"specified",
"by",
"its",
"code",
"."
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/s3store/s3store.go#L676-L681 | train |
tus/tusd | etcd3locker/lock.go | Acquire | func (lock *etcd3Lock) Acquire() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// this is a blocking call; if we receive DeadlineExceeded
// the lock is most likely already taken
if err := lock.Mutex.Lock(ctx); err != nil {
if err == context.DeadlineExceeded {
... | go | func (lock *etcd3Lock) Acquire() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
// this is a blocking call; if we receive DeadlineExceeded
// the lock is most likely already taken
if err := lock.Mutex.Lock(ctx); err != nil {
if err == context.DeadlineExceeded {
... | [
"func",
"(",
"lock",
"*",
"etcd3Lock",
")",
"Acquire",
"(",
")",
"error",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"context",
".",
"Background",
"(",
")",
",",
"5",
"*",
"time",
".",
"Second",
")",
"\n",
"defer",
"cancel",... | // Acquires a lock from etcd3 | [
"Acquires",
"a",
"lock",
"from",
"etcd3"
] | 12f102abf6cbd174b4dc9323672f59c6357b561c | https://github.com/tus/tusd/blob/12f102abf6cbd174b4dc9323672f59c6357b561c/etcd3locker/lock.go#L27-L41 | train |
mitchellh/mapstructure | decode_hooks.go | DecodeHookExec | func DecodeHookExec(
raw DecodeHookFunc,
from reflect.Type, to reflect.Type,
data interface{}) (interface{}, error) {
switch f := typedDecodeHook(raw).(type) {
case DecodeHookFuncType:
return f(from, to, data)
case DecodeHookFuncKind:
return f(from.Kind(), to.Kind(), data)
default:
return nil, errors.New("... | go | func DecodeHookExec(
raw DecodeHookFunc,
from reflect.Type, to reflect.Type,
data interface{}) (interface{}, error) {
switch f := typedDecodeHook(raw).(type) {
case DecodeHookFuncType:
return f(from, to, data)
case DecodeHookFuncKind:
return f(from.Kind(), to.Kind(), data)
default:
return nil, errors.New("... | [
"func",
"DecodeHookExec",
"(",
"raw",
"DecodeHookFunc",
",",
"from",
"reflect",
".",
"Type",
",",
"to",
"reflect",
".",
"Type",
",",
"data",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"switch",
"f",
":=",
"typedDeco... | // DecodeHookExec executes the given decode hook. This should be used
// since it'll naturally degrade to the older backwards compatible DecodeHookFunc
// that took reflect.Kind instead of reflect.Type. | [
"DecodeHookExec",
"executes",
"the",
"given",
"decode",
"hook",
".",
"This",
"should",
"be",
"used",
"since",
"it",
"ll",
"naturally",
"degrade",
"to",
"the",
"older",
"backwards",
"compatible",
"DecodeHookFunc",
"that",
"took",
"reflect",
".",
"Kind",
"instead"... | 3536a929edddb9a5b34bd6861dc4a9647cb459fe | https://github.com/mitchellh/mapstructure/blob/3536a929edddb9a5b34bd6861dc4a9647cb459fe/decode_hooks.go#L39-L51 | train |
mitchellh/mapstructure | decode_hooks.go | ComposeDecodeHookFunc | func ComposeDecodeHookFunc(fs ...DecodeHookFunc) DecodeHookFunc {
return func(
f reflect.Type,
t reflect.Type,
data interface{}) (interface{}, error) {
var err error
for _, f1 := range fs {
data, err = DecodeHookExec(f1, f, t, data)
if err != nil {
return nil, err
}
// Modify the from kind t... | go | func ComposeDecodeHookFunc(fs ...DecodeHookFunc) DecodeHookFunc {
return func(
f reflect.Type,
t reflect.Type,
data interface{}) (interface{}, error) {
var err error
for _, f1 := range fs {
data, err = DecodeHookExec(f1, f, t, data)
if err != nil {
return nil, err
}
// Modify the from kind t... | [
"func",
"ComposeDecodeHookFunc",
"(",
"fs",
"...",
"DecodeHookFunc",
")",
"DecodeHookFunc",
"{",
"return",
"func",
"(",
"f",
"reflect",
".",
"Type",
",",
"t",
"reflect",
".",
"Type",
",",
"data",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",... | // ComposeDecodeHookFunc creates a single DecodeHookFunc that
// automatically composes multiple DecodeHookFuncs.
//
// The composed funcs are called in order, with the result of the
// previous transformation. | [
"ComposeDecodeHookFunc",
"creates",
"a",
"single",
"DecodeHookFunc",
"that",
"automatically",
"composes",
"multiple",
"DecodeHookFuncs",
".",
"The",
"composed",
"funcs",
"are",
"called",
"in",
"order",
"with",
"the",
"result",
"of",
"the",
"previous",
"transformation"... | 3536a929edddb9a5b34bd6861dc4a9647cb459fe | https://github.com/mitchellh/mapstructure/blob/3536a929edddb9a5b34bd6861dc4a9647cb459fe/decode_hooks.go#L58-L79 | train |
mitchellh/mapstructure | decode_hooks.go | StringToTimeDurationHookFunc | func StringToTimeDurationHookFunc() DecodeHookFunc {
return func(
f reflect.Type,
t reflect.Type,
data interface{}) (interface{}, error) {
if f.Kind() != reflect.String {
return data, nil
}
if t != reflect.TypeOf(time.Duration(5)) {
return data, nil
}
// Convert it by parsing
return time.Parse... | go | func StringToTimeDurationHookFunc() DecodeHookFunc {
return func(
f reflect.Type,
t reflect.Type,
data interface{}) (interface{}, error) {
if f.Kind() != reflect.String {
return data, nil
}
if t != reflect.TypeOf(time.Duration(5)) {
return data, nil
}
// Convert it by parsing
return time.Parse... | [
"func",
"StringToTimeDurationHookFunc",
"(",
")",
"DecodeHookFunc",
"{",
"return",
"func",
"(",
"f",
"reflect",
".",
"Type",
",",
"t",
"reflect",
".",
"Type",
",",
"data",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
... | // StringToTimeDurationHookFunc returns a DecodeHookFunc that converts
// strings to time.Duration. | [
"StringToTimeDurationHookFunc",
"returns",
"a",
"DecodeHookFunc",
"that",
"converts",
"strings",
"to",
"time",
".",
"Duration",
"."
] | 3536a929edddb9a5b34bd6861dc4a9647cb459fe | https://github.com/mitchellh/mapstructure/blob/3536a929edddb9a5b34bd6861dc4a9647cb459fe/decode_hooks.go#L103-L118 | train |
mitchellh/mapstructure | decode_hooks.go | StringToIPHookFunc | func StringToIPHookFunc() DecodeHookFunc {
return func(
f reflect.Type,
t reflect.Type,
data interface{}) (interface{}, error) {
if f.Kind() != reflect.String {
return data, nil
}
if t != reflect.TypeOf(net.IP{}) {
return data, nil
}
// Convert it by parsing
ip := net.ParseIP(data.(string))
... | go | func StringToIPHookFunc() DecodeHookFunc {
return func(
f reflect.Type,
t reflect.Type,
data interface{}) (interface{}, error) {
if f.Kind() != reflect.String {
return data, nil
}
if t != reflect.TypeOf(net.IP{}) {
return data, nil
}
// Convert it by parsing
ip := net.ParseIP(data.(string))
... | [
"func",
"StringToIPHookFunc",
"(",
")",
"DecodeHookFunc",
"{",
"return",
"func",
"(",
"f",
"reflect",
".",
"Type",
",",
"t",
"reflect",
".",
"Type",
",",
"data",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"f... | // StringToIPHookFunc returns a DecodeHookFunc that converts
// strings to net.IP | [
"StringToIPHookFunc",
"returns",
"a",
"DecodeHookFunc",
"that",
"converts",
"strings",
"to",
"net",
".",
"IP"
] | 3536a929edddb9a5b34bd6861dc4a9647cb459fe | https://github.com/mitchellh/mapstructure/blob/3536a929edddb9a5b34bd6861dc4a9647cb459fe/decode_hooks.go#L122-L142 | train |
mitchellh/mapstructure | decode_hooks.go | StringToIPNetHookFunc | func StringToIPNetHookFunc() DecodeHookFunc {
return func(
f reflect.Type,
t reflect.Type,
data interface{}) (interface{}, error) {
if f.Kind() != reflect.String {
return data, nil
}
if t != reflect.TypeOf(net.IPNet{}) {
return data, nil
}
// Convert it by parsing
_, net, err := net.ParseCIDR(... | go | func StringToIPNetHookFunc() DecodeHookFunc {
return func(
f reflect.Type,
t reflect.Type,
data interface{}) (interface{}, error) {
if f.Kind() != reflect.String {
return data, nil
}
if t != reflect.TypeOf(net.IPNet{}) {
return data, nil
}
// Convert it by parsing
_, net, err := net.ParseCIDR(... | [
"func",
"StringToIPNetHookFunc",
"(",
")",
"DecodeHookFunc",
"{",
"return",
"func",
"(",
"f",
"reflect",
".",
"Type",
",",
"t",
"reflect",
".",
"Type",
",",
"data",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
... | // StringToIPNetHookFunc returns a DecodeHookFunc that converts
// strings to net.IPNet | [
"StringToIPNetHookFunc",
"returns",
"a",
"DecodeHookFunc",
"that",
"converts",
"strings",
"to",
"net",
".",
"IPNet"
] | 3536a929edddb9a5b34bd6861dc4a9647cb459fe | https://github.com/mitchellh/mapstructure/blob/3536a929edddb9a5b34bd6861dc4a9647cb459fe/decode_hooks.go#L146-L162 | train |
mitchellh/mapstructure | decode_hooks.go | StringToTimeHookFunc | func StringToTimeHookFunc(layout string) DecodeHookFunc {
return func(
f reflect.Type,
t reflect.Type,
data interface{}) (interface{}, error) {
if f.Kind() != reflect.String {
return data, nil
}
if t != reflect.TypeOf(time.Time{}) {
return data, nil
}
// Convert it by parsing
return time.Parse... | go | func StringToTimeHookFunc(layout string) DecodeHookFunc {
return func(
f reflect.Type,
t reflect.Type,
data interface{}) (interface{}, error) {
if f.Kind() != reflect.String {
return data, nil
}
if t != reflect.TypeOf(time.Time{}) {
return data, nil
}
// Convert it by parsing
return time.Parse... | [
"func",
"StringToTimeHookFunc",
"(",
"layout",
"string",
")",
"DecodeHookFunc",
"{",
"return",
"func",
"(",
"f",
"reflect",
".",
"Type",
",",
"t",
"reflect",
".",
"Type",
",",
"data",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
... | // StringToTimeHookFunc returns a DecodeHookFunc that converts
// strings to time.Time. | [
"StringToTimeHookFunc",
"returns",
"a",
"DecodeHookFunc",
"that",
"converts",
"strings",
"to",
"time",
".",
"Time",
"."
] | 3536a929edddb9a5b34bd6861dc4a9647cb459fe | https://github.com/mitchellh/mapstructure/blob/3536a929edddb9a5b34bd6861dc4a9647cb459fe/decode_hooks.go#L166-L181 | train |
mitchellh/mapstructure | decode_hooks.go | WeaklyTypedHook | func WeaklyTypedHook(
f reflect.Kind,
t reflect.Kind,
data interface{}) (interface{}, error) {
dataVal := reflect.ValueOf(data)
switch t {
case reflect.String:
switch f {
case reflect.Bool:
if dataVal.Bool() {
return "1", nil
}
return "0", nil
case reflect.Float32:
return strconv.FormatFloat... | go | func WeaklyTypedHook(
f reflect.Kind,
t reflect.Kind,
data interface{}) (interface{}, error) {
dataVal := reflect.ValueOf(data)
switch t {
case reflect.String:
switch f {
case reflect.Bool:
if dataVal.Bool() {
return "1", nil
}
return "0", nil
case reflect.Float32:
return strconv.FormatFloat... | [
"func",
"WeaklyTypedHook",
"(",
"f",
"reflect",
".",
"Kind",
",",
"t",
"reflect",
".",
"Kind",
",",
"data",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"dataVal",
":=",
"reflect",
".",
"ValueOf",
"(",
"data",
")",
... | // WeaklyTypedHook is a DecodeHookFunc which adds support for weak typing to
// the decoder.
//
// Note that this is significantly different from the WeaklyTypedInput option
// of the DecoderConfig. | [
"WeaklyTypedHook",
"is",
"a",
"DecodeHookFunc",
"which",
"adds",
"support",
"for",
"weak",
"typing",
"to",
"the",
"decoder",
".",
"Note",
"that",
"this",
"is",
"significantly",
"different",
"from",
"the",
"WeaklyTypedInput",
"option",
"of",
"the",
"DecoderConfig",... | 3536a929edddb9a5b34bd6861dc4a9647cb459fe | https://github.com/mitchellh/mapstructure/blob/3536a929edddb9a5b34bd6861dc4a9647cb459fe/decode_hooks.go#L188-L217 | train |
mitchellh/mapstructure | mapstructure.go | Decode | func Decode(input interface{}, output interface{}) error {
config := &DecoderConfig{
Metadata: nil,
Result: output,
}
decoder, err := NewDecoder(config)
if err != nil {
return err
}
return decoder.Decode(input)
} | go | func Decode(input interface{}, output interface{}) error {
config := &DecoderConfig{
Metadata: nil,
Result: output,
}
decoder, err := NewDecoder(config)
if err != nil {
return err
}
return decoder.Decode(input)
} | [
"func",
"Decode",
"(",
"input",
"interface",
"{",
"}",
",",
"output",
"interface",
"{",
"}",
")",
"error",
"{",
"config",
":=",
"&",
"DecoderConfig",
"{",
"Metadata",
":",
"nil",
",",
"Result",
":",
"output",
",",
"}",
"\n\n",
"decoder",
",",
"err",
... | // Decode takes an input structure and uses reflection to translate it to
// the output structure. output must be a pointer to a map or struct. | [
"Decode",
"takes",
"an",
"input",
"structure",
"and",
"uses",
"reflection",
"to",
"translate",
"it",
"to",
"the",
"output",
"structure",
".",
"output",
"must",
"be",
"a",
"pointer",
"to",
"a",
"map",
"or",
"struct",
"."
] | 3536a929edddb9a5b34bd6861dc4a9647cb459fe | https://github.com/mitchellh/mapstructure/blob/3536a929edddb9a5b34bd6861dc4a9647cb459fe/mapstructure.go#L119-L131 | train |
mitchellh/mapstructure | mapstructure.go | NewDecoder | func NewDecoder(config *DecoderConfig) (*Decoder, error) {
val := reflect.ValueOf(config.Result)
if val.Kind() != reflect.Ptr {
return nil, errors.New("result must be a pointer")
}
val = val.Elem()
if !val.CanAddr() {
return nil, errors.New("result must be addressable (a pointer)")
}
if config.Metadata != ... | go | func NewDecoder(config *DecoderConfig) (*Decoder, error) {
val := reflect.ValueOf(config.Result)
if val.Kind() != reflect.Ptr {
return nil, errors.New("result must be a pointer")
}
val = val.Elem()
if !val.CanAddr() {
return nil, errors.New("result must be addressable (a pointer)")
}
if config.Metadata != ... | [
"func",
"NewDecoder",
"(",
"config",
"*",
"DecoderConfig",
")",
"(",
"*",
"Decoder",
",",
"error",
")",
"{",
"val",
":=",
"reflect",
".",
"ValueOf",
"(",
"config",
".",
"Result",
")",
"\n",
"if",
"val",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
... | // NewDecoder returns a new decoder for the given configuration. Once
// a decoder has been returned, the same configuration must not be used
// again. | [
"NewDecoder",
"returns",
"a",
"new",
"decoder",
"for",
"the",
"given",
"configuration",
".",
"Once",
"a",
"decoder",
"has",
"been",
"returned",
"the",
"same",
"configuration",
"must",
"not",
"be",
"used",
"again",
"."
] | 3536a929edddb9a5b34bd6861dc4a9647cb459fe | https://github.com/mitchellh/mapstructure/blob/3536a929edddb9a5b34bd6861dc4a9647cb459fe/mapstructure.go#L187-L217 | train |
mitchellh/mapstructure | error.go | WrappedErrors | func (e *Error) WrappedErrors() []error {
if e == nil {
return nil
}
result := make([]error, len(e.Errors))
for i, e := range e.Errors {
result[i] = errors.New(e)
}
return result
} | go | func (e *Error) WrappedErrors() []error {
if e == nil {
return nil
}
result := make([]error, len(e.Errors))
for i, e := range e.Errors {
result[i] = errors.New(e)
}
return result
} | [
"func",
"(",
"e",
"*",
"Error",
")",
"WrappedErrors",
"(",
")",
"[",
"]",
"error",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"result",
":=",
"make",
"(",
"[",
"]",
"error",
",",
"len",
"(",
"e",
".",
"Errors",
")",
... | // WrappedErrors implements the errwrap.Wrapper interface to make this
// return value more useful with the errwrap and go-multierror libraries. | [
"WrappedErrors",
"implements",
"the",
"errwrap",
".",
"Wrapper",
"interface",
"to",
"make",
"this",
"return",
"value",
"more",
"useful",
"with",
"the",
"errwrap",
"and",
"go",
"-",
"multierror",
"libraries",
"."
] | 3536a929edddb9a5b34bd6861dc4a9647cb459fe | https://github.com/mitchellh/mapstructure/blob/3536a929edddb9a5b34bd6861dc4a9647cb459fe/error.go#L30-L41 | train |
perkeep/perkeep | pkg/gpgchallenge/gpg.go | rateLimit | func (cs *Server) rateLimit(keyID, claimedIP string) (isSpammer bool) {
cs.whiteListMu.Lock()
if _, ok := cs.whiteList[keyID+"-"+claimedIP]; ok {
cs.whiteListMu.Unlock()
return false
}
cs.whiteListMu.Unlock()
// If they haven't successfully challenged us before, they look suspicious.
cs.keyIDSeenMu.Lock()
la... | go | func (cs *Server) rateLimit(keyID, claimedIP string) (isSpammer bool) {
cs.whiteListMu.Lock()
if _, ok := cs.whiteList[keyID+"-"+claimedIP]; ok {
cs.whiteListMu.Unlock()
return false
}
cs.whiteListMu.Unlock()
// If they haven't successfully challenged us before, they look suspicious.
cs.keyIDSeenMu.Lock()
la... | [
"func",
"(",
"cs",
"*",
"Server",
")",
"rateLimit",
"(",
"keyID",
",",
"claimedIP",
"string",
")",
"(",
"isSpammer",
"bool",
")",
"{",
"cs",
".",
"whiteListMu",
".",
"Lock",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"cs",
".",
"whiteList",
"[",
... | // rateLimit uses the cs.limiter to make sure that any client that hasn't
// previously successfully challenged us is rate limited. It also keeps track of
// clients that haven't successfully challenged, and it returns true if such a
// client should be considered a spammer. | [
"rateLimit",
"uses",
"the",
"cs",
".",
"limiter",
"to",
"make",
"sure",
"that",
"any",
"client",
"that",
"hasn",
"t",
"previously",
"successfully",
"challenged",
"us",
"is",
"rate",
"limited",
".",
"It",
"also",
"keeps",
"track",
"of",
"clients",
"that",
"... | e28bbbd1588d64df8ab7a82393afd39d64c061f7 | https://github.com/perkeep/perkeep/blob/e28bbbd1588d64df8ab7a82393afd39d64c061f7/pkg/gpgchallenge/gpg.go#L343-L390 | train |
perkeep/perkeep | pkg/gpgchallenge/gpg.go | NewClient | func NewClient(keyRing, keyId, challengeIP string) (*Client, error) {
signer, err := secretKeyEntity(keyRing, keyId)
if err != nil {
return nil, fmt.Errorf("could not get signer %v from keyRing %v: %v", keyId, keyRing, err)
}
cl := &Client{
keyRing: keyRing,
keyId: keyId,
signer: signer,
ch... | go | func NewClient(keyRing, keyId, challengeIP string) (*Client, error) {
signer, err := secretKeyEntity(keyRing, keyId)
if err != nil {
return nil, fmt.Errorf("could not get signer %v from keyRing %v: %v", keyId, keyRing, err)
}
cl := &Client{
keyRing: keyRing,
keyId: keyId,
signer: signer,
ch... | [
"func",
"NewClient",
"(",
"keyRing",
",",
"keyId",
",",
"challengeIP",
"string",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"signer",
",",
"err",
":=",
"secretKeyEntity",
"(",
"keyRing",
",",
"keyId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"... | // NewClient returns a Client. keyRing and keyId are the GPG key ring and key ID
// used to fulfill the challenge. challengeIP is the address that client proves
// that it owns, by answering the challenge the server sends at this address. | [
"NewClient",
"returns",
"a",
"Client",
".",
"keyRing",
"and",
"keyId",
"are",
"the",
"GPG",
"key",
"ring",
"and",
"key",
"ID",
"used",
"to",
"fulfill",
"the",
"challenge",
".",
"challengeIP",
"is",
"the",
"address",
"that",
"client",
"proves",
"that",
"it"... | e28bbbd1588d64df8ab7a82393afd39d64c061f7 | https://github.com/perkeep/perkeep/blob/e28bbbd1588d64df8ab7a82393afd39d64c061f7/pkg/gpgchallenge/gpg.go#L515-L532 | train |
perkeep/perkeep | pkg/gpgchallenge/gpg.go | Handler | func (cl *Client) Handler() (prefix string, h http.Handler) {
return clientHandlerPrefix, cl.handler
} | go | func (cl *Client) Handler() (prefix string, h http.Handler) {
return clientHandlerPrefix, cl.handler
} | [
"func",
"(",
"cl",
"*",
"Client",
")",
"Handler",
"(",
")",
"(",
"prefix",
"string",
",",
"h",
"http",
".",
"Handler",
")",
"{",
"return",
"clientHandlerPrefix",
",",
"cl",
".",
"handler",
"\n",
"}"
] | // Handler returns the client's handler, that should be registered with an HTTPS
// server for the returned prefix, for the client to be able to receive the
// challenge. | [
"Handler",
"returns",
"the",
"client",
"s",
"handler",
"that",
"should",
"be",
"registered",
"with",
"an",
"HTTPS",
"server",
"for",
"the",
"returned",
"prefix",
"for",
"the",
"client",
"to",
"be",
"able",
"to",
"receive",
"the",
"challenge",
"."
] | e28bbbd1588d64df8ab7a82393afd39d64c061f7 | https://github.com/perkeep/perkeep/blob/e28bbbd1588d64df8ab7a82393afd39d64c061f7/pkg/gpgchallenge/gpg.go#L537-L539 | train |
perkeep/perkeep | pkg/gpgchallenge/gpg.go | listenSelfCheck | func (cl *Client) listenSelfCheck(serverAddr string) error {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
ServerName: cl.challengeIP + SNISuffix,
},
}
httpClient := &http.Client{
Transport: tr,
}
errc := make(chan error, 1)
respc := make(chan *http.Response, 1... | go | func (cl *Client) listenSelfCheck(serverAddr string) error {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
ServerName: cl.challengeIP + SNISuffix,
},
}
httpClient := &http.Client{
Transport: tr,
}
errc := make(chan error, 1)
respc := make(chan *http.Response, 1... | [
"func",
"(",
"cl",
"*",
"Client",
")",
"listenSelfCheck",
"(",
"serverAddr",
"string",
")",
"error",
"{",
"tr",
":=",
"&",
"http",
".",
"Transport",
"{",
"TLSClientConfig",
":",
"&",
"tls",
".",
"Config",
"{",
"InsecureSkipVerify",
":",
"true",
",",
"Ser... | // listenSelfCheck tests whether the client is ready to receive a challenge,
// i.e. that the caller has registered the client's handler with a server. | [
"listenSelfCheck",
"tests",
"whether",
"the",
"client",
"is",
"ready",
"to",
"receive",
"a",
"challenge",
"i",
".",
"e",
".",
"that",
"the",
"caller",
"has",
"registered",
"the",
"client",
"s",
"handler",
"with",
"a",
"server",
"."
] | e28bbbd1588d64df8ab7a82393afd39d64c061f7 | https://github.com/perkeep/perkeep/blob/e28bbbd1588d64df8ab7a82393afd39d64c061f7/pkg/gpgchallenge/gpg.go#L576-L612 | train |
perkeep/perkeep | pkg/blobserver/proxycache/proxycache.go | New | func New(maxBytes int64, cache, origin blobserver.Storage) *Storage {
sto := &Storage{
origin: origin,
cache: cache,
lru: lru.NewUnlocked(0),
maxCacheBytes: maxBytes,
}
return sto
} | go | func New(maxBytes int64, cache, origin blobserver.Storage) *Storage {
sto := &Storage{
origin: origin,
cache: cache,
lru: lru.NewUnlocked(0),
maxCacheBytes: maxBytes,
}
return sto
} | [
"func",
"New",
"(",
"maxBytes",
"int64",
",",
"cache",
",",
"origin",
"blobserver",
".",
"Storage",
")",
"*",
"Storage",
"{",
"sto",
":=",
"&",
"Storage",
"{",
"origin",
":",
"origin",
",",
"cache",
":",
"cache",
",",
"lru",
":",
"lru",
".",
"NewUnlo... | // New returns a proxycache blob storage that reads from cache,
// then origin, populating cache as needed, up to a total of maxBytes. | [
"New",
"returns",
"a",
"proxycache",
"blob",
"storage",
"that",
"reads",
"from",
"cache",
"then",
"origin",
"populating",
"cache",
"as",
"needed",
"up",
"to",
"a",
"total",
"of",
"maxBytes",
"."
] | e28bbbd1588d64df8ab7a82393afd39d64c061f7 | https://github.com/perkeep/perkeep/blob/e28bbbd1588d64df8ab7a82393afd39d64c061f7/pkg/blobserver/proxycache/proxycache.go#L77-L85 | train |
perkeep/perkeep | pkg/blobserver/proxycache/proxycache.go | removeOldest | func (sto *Storage) removeOldest() bool {
ctx := context.TODO()
k, v := sto.lru.RemoveOldest()
if v == nil {
return false
}
sb := v.(blob.SizedRef)
// TODO: run these without sto.mu held in background
// goroutine? at least pass a context?
err := sto.cache.RemoveBlobs(ctx, []blob.Ref{sb.Ref})
if err != nil {... | go | func (sto *Storage) removeOldest() bool {
ctx := context.TODO()
k, v := sto.lru.RemoveOldest()
if v == nil {
return false
}
sb := v.(blob.SizedRef)
// TODO: run these without sto.mu held in background
// goroutine? at least pass a context?
err := sto.cache.RemoveBlobs(ctx, []blob.Ref{sb.Ref})
if err != nil {... | [
"func",
"(",
"sto",
"*",
"Storage",
")",
"removeOldest",
"(",
")",
"bool",
"{",
"ctx",
":=",
"context",
".",
"TODO",
"(",
")",
"\n",
"k",
",",
"v",
":=",
"sto",
".",
"lru",
".",
"RemoveOldest",
"(",
")",
"\n",
"if",
"v",
"==",
"nil",
"{",
"retu... | // must hold sto.mu.
// Reports whether an item was removed. | [
"must",
"hold",
"sto",
".",
"mu",
".",
"Reports",
"whether",
"an",
"item",
"was",
"removed",
"."
] | e28bbbd1588d64df8ab7a82393afd39d64c061f7 | https://github.com/perkeep/perkeep/blob/e28bbbd1588d64df8ab7a82393afd39d64c061f7/pkg/blobserver/proxycache/proxycache.go#L113-L133 | train |
perkeep/perkeep | server/perkeepd/ui/goui/dirchildren/dirchildren.go | New | func New(authToken, parentDir string, limit int,
updadeSearchSession func(string), triggerRender func()) *js.Object {
parentDirbr, ok := blob.Parse(parentDir)
if !ok {
dom.GetWindow().Alert(fmt.Sprintf("invalid parentDir blobRef: %q", parentDir))
return nil
}
return js.MakeWrapper(&Query{
ParentDir: ... | go | func New(authToken, parentDir string, limit int,
updadeSearchSession func(string), triggerRender func()) *js.Object {
parentDirbr, ok := blob.Parse(parentDir)
if !ok {
dom.GetWindow().Alert(fmt.Sprintf("invalid parentDir blobRef: %q", parentDir))
return nil
}
return js.MakeWrapper(&Query{
ParentDir: ... | [
"func",
"New",
"(",
"authToken",
",",
"parentDir",
"string",
",",
"limit",
"int",
",",
"updadeSearchSession",
"func",
"(",
"string",
")",
",",
"triggerRender",
"func",
"(",
")",
")",
"*",
"js",
".",
"Object",
"{",
"parentDirbr",
",",
"ok",
":=",
"blob",
... | // New returns a new Query as a javascript object, of nil if parentDir is not a
// valid blobRef. | [
"New",
"returns",
"a",
"new",
"Query",
"as",
"a",
"javascript",
"object",
"of",
"nil",
"if",
"parentDir",
"is",
"not",
"a",
"valid",
"blobRef",
"."
] | e28bbbd1588d64df8ab7a82393afd39d64c061f7 | https://github.com/perkeep/perkeep/blob/e28bbbd1588d64df8ab7a82393afd39d64c061f7/server/perkeepd/ui/goui/dirchildren/dirchildren.go#L72-L86 | train |
perkeep/perkeep | server/perkeepd/ui/goui/dirchildren/dirchildren.go | Get | func (q *Query) Get() {
if q.isComplete {
return
}
if q.pending {
return
}
q.pending = true
go func() {
if err := q.get(); err != nil {
dom.GetWindow().Alert(fmt.Sprintf("%v", err))
return
}
q.TriggerRender()
}()
} | go | func (q *Query) Get() {
if q.isComplete {
return
}
if q.pending {
return
}
q.pending = true
go func() {
if err := q.get(); err != nil {
dom.GetWindow().Alert(fmt.Sprintf("%v", err))
return
}
q.TriggerRender()
}()
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Get",
"(",
")",
"{",
"if",
"q",
".",
"isComplete",
"{",
"return",
"\n",
"}",
"\n",
"if",
"q",
".",
"pending",
"{",
"return",
"\n",
"}",
"\n",
"q",
".",
"pending",
"=",
"true",
"\n",
"go",
"func",
"(",
")"... | // Get asynchronously sends the query, if one is not already in flight, or being
// processed. It runs q.UpdateSearchSession once the results have been received and
// merged with q.Blobs and q.Meta. It runs q.TriggerRender to refresh the DOM with
// the new results in the search session. | [
"Get",
"asynchronously",
"sends",
"the",
"query",
"if",
"one",
"is",
"not",
"already",
"in",
"flight",
"or",
"being",
"processed",
".",
"It",
"runs",
"q",
".",
"UpdateSearchSession",
"once",
"the",
"results",
"have",
"been",
"received",
"and",
"merged",
"wit... | e28bbbd1588d64df8ab7a82393afd39d64c061f7 | https://github.com/perkeep/perkeep/blob/e28bbbd1588d64df8ab7a82393afd39d64c061f7/server/perkeepd/ui/goui/dirchildren/dirchildren.go#L114-L129 | train |
perkeep/perkeep | pkg/sorted/mysql/mysqlkv.go | newKVDB | func newKVDB(cfg jsonconfig.Obj) (sorted.KeyValue, error) {
var (
user = cfg.RequiredString("user")
database = cfg.RequiredString("database")
host = cfg.OptionalString("host", "")
password = cfg.OptionalString("password", "")
)
if err := cfg.Validate(); err != nil {
return nil, err
}
if !validDat... | go | func newKVDB(cfg jsonconfig.Obj) (sorted.KeyValue, error) {
var (
user = cfg.RequiredString("user")
database = cfg.RequiredString("database")
host = cfg.OptionalString("host", "")
password = cfg.OptionalString("password", "")
)
if err := cfg.Validate(); err != nil {
return nil, err
}
if !validDat... | [
"func",
"newKVDB",
"(",
"cfg",
"jsonconfig",
".",
"Obj",
")",
"(",
"sorted",
".",
"KeyValue",
",",
"error",
")",
"{",
"var",
"(",
"user",
"=",
"cfg",
".",
"RequiredString",
"(",
"\"",
"\"",
")",
"\n",
"database",
"=",
"cfg",
".",
"RequiredString",
"(... | // newKVDB returns an unusable KeyValue, with a database, but no tables yet. It
// should be followed by Wipe or finalize. | [
"newKVDB",
"returns",
"an",
"unusable",
"KeyValue",
"with",
"a",
"database",
"but",
"no",
"tables",
"yet",
".",
"It",
"should",
"be",
"followed",
"by",
"Wipe",
"or",
"finalize",
"."
] | e28bbbd1588d64df8ab7a82393afd39d64c061f7 | https://github.com/perkeep/perkeep/blob/e28bbbd1588d64df8ab7a82393afd39d64c061f7/pkg/sorted/mysql/mysqlkv.go#L45-L94 | train |
perkeep/perkeep | pkg/sorted/mysql/mysqlkv.go | Wipe | func (kv *keyValue) Wipe() error {
if _, err := kv.db.Exec("DROP TABLE IF EXISTS " + kv.database + ".rows"); err != nil {
return err
}
if _, err := kv.db.Exec("DROP TABLE IF EXISTS " + kv.database + ".meta"); err != nil {
return err
}
return kv.finalize()
} | go | func (kv *keyValue) Wipe() error {
if _, err := kv.db.Exec("DROP TABLE IF EXISTS " + kv.database + ".rows"); err != nil {
return err
}
if _, err := kv.db.Exec("DROP TABLE IF EXISTS " + kv.database + ".meta"); err != nil {
return err
}
return kv.finalize()
} | [
"func",
"(",
"kv",
"*",
"keyValue",
")",
"Wipe",
"(",
")",
"error",
"{",
"if",
"_",
",",
"err",
":=",
"kv",
".",
"db",
".",
"Exec",
"(",
"\"",
"\"",
"+",
"kv",
".",
"database",
"+",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"... | // Wipe resets the KeyValue by dropping and recreating the database tables. | [
"Wipe",
"resets",
"the",
"KeyValue",
"by",
"dropping",
"and",
"recreating",
"the",
"database",
"tables",
"."
] | e28bbbd1588d64df8ab7a82393afd39d64c061f7 | https://github.com/perkeep/perkeep/blob/e28bbbd1588d64df8ab7a82393afd39d64c061f7/pkg/sorted/mysql/mysqlkv.go#L97-L105 | train |
perkeep/perkeep | pkg/sorted/mysql/mysqlkv.go | finalize | func (kv *keyValue) finalize() error {
if err := createTables(kv.db, kv.database); err != nil {
return err
}
if err := kv.ping(); err != nil {
return fmt.Errorf("MySQL db unreachable: %v", err)
}
version, err := kv.SchemaVersion()
if err != nil {
return fmt.Errorf("error getting current database schema ve... | go | func (kv *keyValue) finalize() error {
if err := createTables(kv.db, kv.database); err != nil {
return err
}
if err := kv.ping(); err != nil {
return fmt.Errorf("MySQL db unreachable: %v", err)
}
version, err := kv.SchemaVersion()
if err != nil {
return fmt.Errorf("error getting current database schema ve... | [
"func",
"(",
"kv",
"*",
"keyValue",
")",
"finalize",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"createTables",
"(",
"kv",
".",
"db",
",",
"kv",
".",
"database",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
... | // finalize should be called on a keyValue initialized with newKVDB. | [
"finalize",
"should",
"be",
"called",
"on",
"a",
"keyValue",
"initialized",
"with",
"newKVDB",
"."
] | e28bbbd1588d64df8ab7a82393afd39d64c061f7 | https://github.com/perkeep/perkeep/blob/e28bbbd1588d64df8ab7a82393afd39d64c061f7/pkg/sorted/mysql/mysqlkv.go#L108-L146 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.