repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6 values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
requilence/integram | context.go | EditMessageText | func (c *Context) EditMessageText(om *OutgoingMessage, text string) error {
if om == nil {
return errors.New("Empty message provided")
}
bot := c.Bot()
if om.ParseMode == "HTML" {
textCleared, err := sanitize.HTMLAllowing(text, []string{"a", "b", "strong", "i", "em", "a", "code", "pre"}, []string{"href"})
if err == nil && textCleared != "" {
text = textCleared
}
}
om.Text = text
prevTextHash := om.TextHash
om.TextHash = om.GetTextHash()
if om.TextHash == prevTextHash {
c.Log().Debugf("EditMessageText – message (_id=%s botid=%v id=%v) not updated text have not changed", om.ID.Hex(), bot.ID, om.MsgID)
return nil
}
_, err := bot.API.Send(tg.EditMessageTextConfig{
BaseEdit: tg.BaseEdit{
ChatID: om.ChatID,
MessageID: om.MsgID,
ReplyMarkup: &tg.InlineKeyboardMarkup{InlineKeyboard: om.InlineKeyboardMarkup.tg()},
},
ParseMode: om.ParseMode,
DisableWebPagePreview: !om.WebPreview,
Text: text,
})
if err != nil {
if err.(tg.Error).IsCantAccessChat() || err.(tg.Error).ChatMigrated() {
if c.Callback != nil && c.Callback.AnsweredAt == nil {
c.AnswerCallbackQuery("Sorry, message can be outdated. Bot can't edit messages created before converting to the Super Group", false)
}
} else if err.(tg.Error).IsAntiFlood() {
c.Log().WithError(err).Warn("TG Anti flood activated")
}
} else {
err = c.db.C("messages").UpdateId(om.ID, bson.M{"$set": bson.M{"texthash": om.TextHash}})
}
return err
} | go | func (c *Context) EditMessageText(om *OutgoingMessage, text string) error {
if om == nil {
return errors.New("Empty message provided")
}
bot := c.Bot()
if om.ParseMode == "HTML" {
textCleared, err := sanitize.HTMLAllowing(text, []string{"a", "b", "strong", "i", "em", "a", "code", "pre"}, []string{"href"})
if err == nil && textCleared != "" {
text = textCleared
}
}
om.Text = text
prevTextHash := om.TextHash
om.TextHash = om.GetTextHash()
if om.TextHash == prevTextHash {
c.Log().Debugf("EditMessageText – message (_id=%s botid=%v id=%v) not updated text have not changed", om.ID.Hex(), bot.ID, om.MsgID)
return nil
}
_, err := bot.API.Send(tg.EditMessageTextConfig{
BaseEdit: tg.BaseEdit{
ChatID: om.ChatID,
MessageID: om.MsgID,
ReplyMarkup: &tg.InlineKeyboardMarkup{InlineKeyboard: om.InlineKeyboardMarkup.tg()},
},
ParseMode: om.ParseMode,
DisableWebPagePreview: !om.WebPreview,
Text: text,
})
if err != nil {
if err.(tg.Error).IsCantAccessChat() || err.(tg.Error).ChatMigrated() {
if c.Callback != nil && c.Callback.AnsweredAt == nil {
c.AnswerCallbackQuery("Sorry, message can be outdated. Bot can't edit messages created before converting to the Super Group", false)
}
} else if err.(tg.Error).IsAntiFlood() {
c.Log().WithError(err).Warn("TG Anti flood activated")
}
} else {
err = c.db.C("messages").UpdateId(om.ID, bson.M{"$set": bson.M{"texthash": om.TextHash}})
}
return err
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"EditMessageText",
"(",
"om",
"*",
"OutgoingMessage",
",",
"text",
"string",
")",
"error",
"{",
"if",
"om",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"Empty message provided\"",
")",
"\n",
"}",
"\n",
... | // EditMessageText edit the text of message previously sent by the bot | [
"EditMessageText",
"edit",
"the",
"text",
"of",
"message",
"previously",
"sent",
"by",
"the",
"bot"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L480-L526 | train |
requilence/integram | context.go | EditMessagesTextWithEventID | func (c *Context) EditMessagesTextWithEventID(eventID string, text string) (edited int, err error) {
var messages []OutgoingMessage
//update MAX_MSGS_TO_UPDATE_WITH_EVENTID last bot messages
c.db.C("messages").Find(bson.M{"botid": c.Bot().ID, "eventid": eventID}).Sort("-_id").Limit(MaxMsgsToUpdateWithEventID).All(&messages)
for _, message := range messages {
err = c.EditMessageText(&message, text)
if err != nil {
c.Log().WithError(err).WithField("eventid", eventID).Error("EditMessagesTextWithEventID")
} else {
edited++
}
}
return edited, err
} | go | func (c *Context) EditMessagesTextWithEventID(eventID string, text string) (edited int, err error) {
var messages []OutgoingMessage
//update MAX_MSGS_TO_UPDATE_WITH_EVENTID last bot messages
c.db.C("messages").Find(bson.M{"botid": c.Bot().ID, "eventid": eventID}).Sort("-_id").Limit(MaxMsgsToUpdateWithEventID).All(&messages)
for _, message := range messages {
err = c.EditMessageText(&message, text)
if err != nil {
c.Log().WithError(err).WithField("eventid", eventID).Error("EditMessagesTextWithEventID")
} else {
edited++
}
}
return edited, err
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"EditMessagesTextWithEventID",
"(",
"eventID",
"string",
",",
"text",
"string",
")",
"(",
"edited",
"int",
",",
"err",
"error",
")",
"{",
"var",
"messages",
"[",
"]",
"OutgoingMessage",
"\n",
"c",
".",
"db",
".",
... | // EditMessagesTextWithEventID edit the last MaxMsgsToUpdateWithEventID messages' text with the corresponding eventID in ALL chats | [
"EditMessagesTextWithEventID",
"edit",
"the",
"last",
"MaxMsgsToUpdateWithEventID",
"messages",
"text",
"with",
"the",
"corresponding",
"eventID",
"in",
"ALL",
"chats"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L529-L542 | train |
requilence/integram | context.go | EditMessageTextWithMessageID | func (c *Context) EditMessageTextWithMessageID(msgID bson.ObjectId, text string) (edited int, err error) {
var message OutgoingMessage
c.db.C("messages").Find(bson.M{"_id": msgID, "botid": c.Bot().ID}).One(&message)
err = c.EditMessageText(&message, text)
if err != nil {
c.Log().WithError(err).WithField("msgid", msgID).Error("EditMessageTextWithMessageID")
} else {
edited++
}
return edited, err
} | go | func (c *Context) EditMessageTextWithMessageID(msgID bson.ObjectId, text string) (edited int, err error) {
var message OutgoingMessage
c.db.C("messages").Find(bson.M{"_id": msgID, "botid": c.Bot().ID}).One(&message)
err = c.EditMessageText(&message, text)
if err != nil {
c.Log().WithError(err).WithField("msgid", msgID).Error("EditMessageTextWithMessageID")
} else {
edited++
}
return edited, err
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"EditMessageTextWithMessageID",
"(",
"msgID",
"bson",
".",
"ObjectId",
",",
"text",
"string",
")",
"(",
"edited",
"int",
",",
"err",
"error",
")",
"{",
"var",
"message",
"OutgoingMessage",
"\n",
"c",
".",
"db",
".",... | // EditMessagesTextWithMessageID edit the one message text with by message BSON ID | [
"EditMessagesTextWithMessageID",
"edit",
"the",
"one",
"message",
"text",
"with",
"by",
"message",
"BSON",
"ID"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L545-L557 | train |
requilence/integram | context.go | EditMessagesWithEventID | func (c *Context) EditMessagesWithEventID(eventID string, fromState string, text string, kb InlineKeyboard) (edited int, err error) {
var messages []OutgoingMessage
f := bson.M{"botid": c.Bot().ID, "eventid": eventID}
if fromState != "" {
f["inlinekeyboardmarkup.state"] = fromState
}
//update MAX_MSGS_TO_UPDATE_WITH_EVENTID last bot messages
c.db.C("messages").Find(f).Sort("-_id").Limit(MaxMsgsToUpdateWithEventID).All(&messages)
for _, message := range messages {
err = c.EditMessageTextAndInlineKeyboard(&message, fromState, text, kb)
if err != nil {
c.Log().WithError(err).WithField("eventid", eventID).Error("EditMessagesWithEventID")
} else {
edited++
}
}
return edited, err
} | go | func (c *Context) EditMessagesWithEventID(eventID string, fromState string, text string, kb InlineKeyboard) (edited int, err error) {
var messages []OutgoingMessage
f := bson.M{"botid": c.Bot().ID, "eventid": eventID}
if fromState != "" {
f["inlinekeyboardmarkup.state"] = fromState
}
//update MAX_MSGS_TO_UPDATE_WITH_EVENTID last bot messages
c.db.C("messages").Find(f).Sort("-_id").Limit(MaxMsgsToUpdateWithEventID).All(&messages)
for _, message := range messages {
err = c.EditMessageTextAndInlineKeyboard(&message, fromState, text, kb)
if err != nil {
c.Log().WithError(err).WithField("eventid", eventID).Error("EditMessagesWithEventID")
} else {
edited++
}
}
return edited, err
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"EditMessagesWithEventID",
"(",
"eventID",
"string",
",",
"fromState",
"string",
",",
"text",
"string",
",",
"kb",
"InlineKeyboard",
")",
"(",
"edited",
"int",
",",
"err",
"error",
")",
"{",
"var",
"messages",
"[",
... | // EditMessagesWithEventID edit the last MaxMsgsToUpdateWithEventID messages' text and inline keyboard with the corresponding eventID in ALL chats | [
"EditMessagesWithEventID",
"edit",
"the",
"last",
"MaxMsgsToUpdateWithEventID",
"messages",
"text",
"and",
"inline",
"keyboard",
"with",
"the",
"corresponding",
"eventID",
"in",
"ALL",
"chats"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L560-L578 | train |
requilence/integram | context.go | DeleteMessagesWithEventID | func (c *Context) DeleteMessagesWithEventID(eventID string) (deleted int, err error) {
var messages []OutgoingMessage
f := bson.M{"botid": c.Bot().ID, "eventid": eventID}
//update MAX_MSGS_TO_UPDATE_WITH_EVENTID last bot messages
c.db.C("messages").Find(f).Sort("-_id").Limit(MaxMsgsToUpdateWithEventID).All(&messages)
for _, message := range messages {
err = c.DeleteMessage(&message)
if err != nil {
c.Log().WithError(err).WithField("eventid", eventID).Error("DeleteMessagesWithEventID")
} else {
deleted++
}
}
return deleted, err
} | go | func (c *Context) DeleteMessagesWithEventID(eventID string) (deleted int, err error) {
var messages []OutgoingMessage
f := bson.M{"botid": c.Bot().ID, "eventid": eventID}
//update MAX_MSGS_TO_UPDATE_WITH_EVENTID last bot messages
c.db.C("messages").Find(f).Sort("-_id").Limit(MaxMsgsToUpdateWithEventID).All(&messages)
for _, message := range messages {
err = c.DeleteMessage(&message)
if err != nil {
c.Log().WithError(err).WithField("eventid", eventID).Error("DeleteMessagesWithEventID")
} else {
deleted++
}
}
return deleted, err
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"DeleteMessagesWithEventID",
"(",
"eventID",
"string",
")",
"(",
"deleted",
"int",
",",
"err",
"error",
")",
"{",
"var",
"messages",
"[",
"]",
"OutgoingMessage",
"\n",
"f",
":=",
"bson",
".",
"M",
"{",
"\"botid\"",
... | // DeleteMessagesWithEventID deletes the last MaxMsgsToUpdateWithEventID messages' text and inline keyboard with the corresponding eventID in ALL chats | [
"DeleteMessagesWithEventID",
"deletes",
"the",
"last",
"MaxMsgsToUpdateWithEventID",
"messages",
"text",
"and",
"inline",
"keyboard",
"with",
"the",
"corresponding",
"eventID",
"in",
"ALL",
"chats"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L581-L596 | train |
requilence/integram | context.go | DeleteMessage | func (c *Context) DeleteMessage(om *OutgoingMessage) error {
bot := c.Bot()
if om.MsgID != 0 {
log.WithField("msgID", om.MsgID).Debug("DeleteMessage")
} else {
om.ChatID = 0
log.WithField("inlineMsgID", om.InlineMsgID).Debug("DeleteMessage")
}
var msg OutgoingMessage
var ci *mgo.ChangeInfo
var err error
ci, err = c.db.C("messages").Find(bson.M{"_id": om.ID}).Apply(mgo.Change{Remove: true}, &msg)
if err != nil {
c.Log().WithError(err).Error("DeleteMessage messages remove error")
}
if msg.BotID == 0 {
c.Log().Warn(fmt.Sprintf("DeleteMessage – message (_id=%s botid=%v id=%v) not found", om.ID, bot.ID, om.MsgID))
return nil
}
if ci.Removed == 0 {
c.Log().Warn(fmt.Sprintf("DeleteMessage – message (_id=%s botid=%v id=%v) not removed ", om.ID, bot.ID, om.MsgID))
return nil
}
_, err = bot.API.Send(tg.DeleteMessageConfig{
ChatID: om.ChatID,
MessageID: om.MsgID,
})
if err != nil {
if err.(tg.Error).IsCantAccessChat() || err.(tg.Error).ChatMigrated() {
if c.Callback != nil {
c.AnswerCallbackQuery("Message can be outdated. Bot can't edit messages created before converting to the Super Group", false)
}
} else if err.(tg.Error).IsAntiFlood() {
c.Log().WithError(err).Warn("TG Anti flood activated")
}
// Oops. error is occurred – revert the original message
c.db.C("messages").Insert(om)
return err
}
return nil
} | go | func (c *Context) DeleteMessage(om *OutgoingMessage) error {
bot := c.Bot()
if om.MsgID != 0 {
log.WithField("msgID", om.MsgID).Debug("DeleteMessage")
} else {
om.ChatID = 0
log.WithField("inlineMsgID", om.InlineMsgID).Debug("DeleteMessage")
}
var msg OutgoingMessage
var ci *mgo.ChangeInfo
var err error
ci, err = c.db.C("messages").Find(bson.M{"_id": om.ID}).Apply(mgo.Change{Remove: true}, &msg)
if err != nil {
c.Log().WithError(err).Error("DeleteMessage messages remove error")
}
if msg.BotID == 0 {
c.Log().Warn(fmt.Sprintf("DeleteMessage – message (_id=%s botid=%v id=%v) not found", om.ID, bot.ID, om.MsgID))
return nil
}
if ci.Removed == 0 {
c.Log().Warn(fmt.Sprintf("DeleteMessage – message (_id=%s botid=%v id=%v) not removed ", om.ID, bot.ID, om.MsgID))
return nil
}
_, err = bot.API.Send(tg.DeleteMessageConfig{
ChatID: om.ChatID,
MessageID: om.MsgID,
})
if err != nil {
if err.(tg.Error).IsCantAccessChat() || err.(tg.Error).ChatMigrated() {
if c.Callback != nil {
c.AnswerCallbackQuery("Message can be outdated. Bot can't edit messages created before converting to the Super Group", false)
}
} else if err.(tg.Error).IsAntiFlood() {
c.Log().WithError(err).Warn("TG Anti flood activated")
}
// Oops. error is occurred – revert the original message
c.db.C("messages").Insert(om)
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"DeleteMessage",
"(",
"om",
"*",
"OutgoingMessage",
")",
"error",
"{",
"bot",
":=",
"c",
".",
"Bot",
"(",
")",
"\n",
"if",
"om",
".",
"MsgID",
"!=",
"0",
"{",
"log",
".",
"WithField",
"(",
"\"msgID\"",
",",
... | // DeleteMessage deletes the outgoing message's text and inline keyboard | [
"DeleteMessage",
"deletes",
"the",
"outgoing",
"message",
"s",
"text",
"and",
"inline",
"keyboard"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L599-L648 | train |
requilence/integram | context.go | EditInlineKeyboard | func (c *Context) EditInlineKeyboard(om *OutgoingMessage, fromState string, kb InlineKeyboard) error {
bot := c.Bot()
if om.MsgID != 0 {
log.WithField("msgID", om.MsgID).Debug("EditMessageTextAndInlineKeyboard")
} else {
om.ChatID = 0
log.WithField("inlineMsgID", om.InlineMsgID).Debug("EditMessageTextAndInlineKeyboard")
}
var msg OutgoingMessage
_, err := c.db.C("messages").Find(bson.M{"_id": om.ID, "$or": []bson.M{{"inlinekeyboardmarkup.state": fromState}, {"inlinekeyboardmarkup": bson.M{"$exists": false}}}}).Apply(mgo.Change{Update: bson.M{"$set": bson.M{"inlinekeyboardmarkup": kb}}}, &msg)
if msg.BotID == 0 {
return fmt.Errorf("EditInlineKeyboard – message (botid=%v id=%v state %s) not found", bot.ID, om.MsgID, fromState)
}
tgKeyboard := kb.tg()
prevTGKeyboard := om.InlineKeyboardMarkup.tg()
if whetherTGInlineKeyboardsAreEqual(prevTGKeyboard, tgKeyboard) {
c.Log().Debugf("EditMessageTextAndInlineKeyboard – message (_id=%s botid=%v id=%v state %s) not updated both text and kb have not changed", om.ID, bot.ID, om.MsgID, fromState)
return nil
}
_, err = bot.API.Send(tg.EditMessageReplyMarkupConfig{
BaseEdit: tg.BaseEdit{
ChatID: om.ChatID,
MessageID: om.MsgID,
InlineMessageID: om.InlineMsgID,
ReplyMarkup: &tg.InlineKeyboardMarkup{InlineKeyboard: tgKeyboard},
},
})
if err != nil {
if err.(tg.Error).IsCantAccessChat() || err.(tg.Error).ChatMigrated() {
if c.Callback != nil {
c.AnswerCallbackQuery("Message can be outdated. Bot can't edit messages created before converting to the Super Group", false)
}
} else if err.(tg.Error).IsAntiFlood() {
c.Log().WithError(err).Warn("TG Anti flood activated")
}
// Oops. error is occurred – revert the original keyboard
err := c.db.C("messages").Update(bson.M{"_id": msg.ID}, bson.M{"$set": bson.M{"inlinekeyboardmarkup": msg.InlineKeyboardMarkup}})
return err
}
return nil
} | go | func (c *Context) EditInlineKeyboard(om *OutgoingMessage, fromState string, kb InlineKeyboard) error {
bot := c.Bot()
if om.MsgID != 0 {
log.WithField("msgID", om.MsgID).Debug("EditMessageTextAndInlineKeyboard")
} else {
om.ChatID = 0
log.WithField("inlineMsgID", om.InlineMsgID).Debug("EditMessageTextAndInlineKeyboard")
}
var msg OutgoingMessage
_, err := c.db.C("messages").Find(bson.M{"_id": om.ID, "$or": []bson.M{{"inlinekeyboardmarkup.state": fromState}, {"inlinekeyboardmarkup": bson.M{"$exists": false}}}}).Apply(mgo.Change{Update: bson.M{"$set": bson.M{"inlinekeyboardmarkup": kb}}}, &msg)
if msg.BotID == 0 {
return fmt.Errorf("EditInlineKeyboard – message (botid=%v id=%v state %s) not found", bot.ID, om.MsgID, fromState)
}
tgKeyboard := kb.tg()
prevTGKeyboard := om.InlineKeyboardMarkup.tg()
if whetherTGInlineKeyboardsAreEqual(prevTGKeyboard, tgKeyboard) {
c.Log().Debugf("EditMessageTextAndInlineKeyboard – message (_id=%s botid=%v id=%v state %s) not updated both text and kb have not changed", om.ID, bot.ID, om.MsgID, fromState)
return nil
}
_, err = bot.API.Send(tg.EditMessageReplyMarkupConfig{
BaseEdit: tg.BaseEdit{
ChatID: om.ChatID,
MessageID: om.MsgID,
InlineMessageID: om.InlineMsgID,
ReplyMarkup: &tg.InlineKeyboardMarkup{InlineKeyboard: tgKeyboard},
},
})
if err != nil {
if err.(tg.Error).IsCantAccessChat() || err.(tg.Error).ChatMigrated() {
if c.Callback != nil {
c.AnswerCallbackQuery("Message can be outdated. Bot can't edit messages created before converting to the Super Group", false)
}
} else if err.(tg.Error).IsAntiFlood() {
c.Log().WithError(err).Warn("TG Anti flood activated")
}
// Oops. error is occurred – revert the original keyboard
err := c.db.C("messages").Update(bson.M{"_id": msg.ID}, bson.M{"$set": bson.M{"inlinekeyboardmarkup": msg.InlineKeyboardMarkup}})
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"EditInlineKeyboard",
"(",
"om",
"*",
"OutgoingMessage",
",",
"fromState",
"string",
",",
"kb",
"InlineKeyboard",
")",
"error",
"{",
"bot",
":=",
"c",
".",
"Bot",
"(",
")",
"\n",
"if",
"om",
".",
"MsgID",
"!=",
... | // EditInlineKeyboard edit the outgoing message's inline keyboard | [
"EditInlineKeyboard",
"edit",
"the",
"outgoing",
"message",
"s",
"inline",
"keyboard"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L732-L780 | train |
requilence/integram | context.go | EditInlineButton | func (c *Context) EditInlineButton(om *OutgoingMessage, kbState string, buttonData string, newButtonText string) error {
return c.EditInlineStateButton(om, kbState, 0, buttonData, 0, newButtonText)
} | go | func (c *Context) EditInlineButton(om *OutgoingMessage, kbState string, buttonData string, newButtonText string) error {
return c.EditInlineStateButton(om, kbState, 0, buttonData, 0, newButtonText)
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"EditInlineButton",
"(",
"om",
"*",
"OutgoingMessage",
",",
"kbState",
"string",
",",
"buttonData",
"string",
",",
"newButtonText",
"string",
")",
"error",
"{",
"return",
"c",
".",
"EditInlineStateButton",
"(",
"om",
",... | // EditInlineButton edit the outgoing message's inline button | [
"EditInlineButton",
"edit",
"the",
"outgoing",
"message",
"s",
"inline",
"button"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L783-L786 | train |
requilence/integram | context.go | EditInlineStateButton | func (c *Context) EditInlineStateButton(om *OutgoingMessage, kbState string, oldButtonState int, buttonData string, newButtonState int, newButtonText string) error {
if oldButtonState > 9 || oldButtonState < 0 {
c.Log().WithField("data", buttonData).WithField("text", newButtonText).Errorf("EditInlineStateButton – oldButtonState must be [0-9], %d recived", oldButtonState)
}
if newButtonState > 9 || newButtonState < 0 {
c.Log().WithField("data", buttonData).WithField("text", newButtonText).Errorf("EditInlineStateButton – newButtonState must be [0-9], %d recived", newButtonState)
}
bot := c.Bot()
var msg OutgoingMessage
c.db.C("messages").Find(bson.M{"_id": om.ID, "inlinekeyboardmarkup.state": kbState}).One(&msg)
// need a more thread safe solution to switch stored keyboard
if msg.BotID == 0 {
return fmt.Errorf("EditInlineButton – message (botid=%v id=%v(%v) state %s) not found", bot.ID, om.MsgID, om.InlineMsgID, kbState)
}
i, j, _ := msg.InlineKeyboardMarkup.Find(buttonData)
if i < 0 {
return fmt.Errorf("EditInlineButton – button %v not found in message (botid=%v id=%v(%v) state %s) not found", buttonData, bot.ID, om.MsgID, om.InlineMsgID, kbState)
}
//first of all – change stored keyboard to avoid simultaneously changing requests
set := bson.M{fmt.Sprintf("inlinekeyboardmarkup.buttons.%d.%d.text", i, j): newButtonText}
if newButtonState != oldButtonState {
set = bson.M{fmt.Sprintf("inlinekeyboardmarkup.buttons.%d.%d.text", i, j): newButtonText, fmt.Sprintf("inlinekeyboardmarkup.buttons.%d.%d.state", i, j): newButtonState}
}
info, err := c.db.C("messages").UpdateAll(bson.M{"_id": msg.ID, "inlinekeyboardmarkup.state": kbState, fmt.Sprintf("inlinekeyboardmarkup.buttons.%d.%d.data", i, j): buttonData}, bson.M{"$set": set})
if info.Updated == 0 {
// another one thread safe check
return fmt.Errorf("EditInlineButton – button[%d][%d] %v not found in message (botid=%v id=%v(%v) state %s) not found", i, j, buttonData, bot.ID, om.MsgID, om.InlineMsgID, kbState)
}
kb := msg.InlineKeyboardMarkup
kb.Buttons[i][j].Text = newButtonText
kb.Buttons[i][j].State = newButtonState
// todo: the stored keyboard can differ from actual because we update the whole keyboard in TG but update only target button locally
// But maybe it's ok...
_, err = bot.API.Send(tg.EditMessageReplyMarkupConfig{
BaseEdit: tg.BaseEdit{
ChatID: om.ChatID,
MessageID: om.MsgID,
InlineMessageID: om.InlineMsgID,
ReplyMarkup: &tg.InlineKeyboardMarkup{InlineKeyboard: kb.tg()},
},
})
if err != nil {
// Oops. error is occurred – revert the original keyboard
err := c.db.C("messages").UpdateId(msg.ID, bson.M{"$set": bson.M{"inlinekeyboardmarkup": msg.InlineKeyboardMarkup}})
return err
}
return nil
} | go | func (c *Context) EditInlineStateButton(om *OutgoingMessage, kbState string, oldButtonState int, buttonData string, newButtonState int, newButtonText string) error {
if oldButtonState > 9 || oldButtonState < 0 {
c.Log().WithField("data", buttonData).WithField("text", newButtonText).Errorf("EditInlineStateButton – oldButtonState must be [0-9], %d recived", oldButtonState)
}
if newButtonState > 9 || newButtonState < 0 {
c.Log().WithField("data", buttonData).WithField("text", newButtonText).Errorf("EditInlineStateButton – newButtonState must be [0-9], %d recived", newButtonState)
}
bot := c.Bot()
var msg OutgoingMessage
c.db.C("messages").Find(bson.M{"_id": om.ID, "inlinekeyboardmarkup.state": kbState}).One(&msg)
// need a more thread safe solution to switch stored keyboard
if msg.BotID == 0 {
return fmt.Errorf("EditInlineButton – message (botid=%v id=%v(%v) state %s) not found", bot.ID, om.MsgID, om.InlineMsgID, kbState)
}
i, j, _ := msg.InlineKeyboardMarkup.Find(buttonData)
if i < 0 {
return fmt.Errorf("EditInlineButton – button %v not found in message (botid=%v id=%v(%v) state %s) not found", buttonData, bot.ID, om.MsgID, om.InlineMsgID, kbState)
}
//first of all – change stored keyboard to avoid simultaneously changing requests
set := bson.M{fmt.Sprintf("inlinekeyboardmarkup.buttons.%d.%d.text", i, j): newButtonText}
if newButtonState != oldButtonState {
set = bson.M{fmt.Sprintf("inlinekeyboardmarkup.buttons.%d.%d.text", i, j): newButtonText, fmt.Sprintf("inlinekeyboardmarkup.buttons.%d.%d.state", i, j): newButtonState}
}
info, err := c.db.C("messages").UpdateAll(bson.M{"_id": msg.ID, "inlinekeyboardmarkup.state": kbState, fmt.Sprintf("inlinekeyboardmarkup.buttons.%d.%d.data", i, j): buttonData}, bson.M{"$set": set})
if info.Updated == 0 {
// another one thread safe check
return fmt.Errorf("EditInlineButton – button[%d][%d] %v not found in message (botid=%v id=%v(%v) state %s) not found", i, j, buttonData, bot.ID, om.MsgID, om.InlineMsgID, kbState)
}
kb := msg.InlineKeyboardMarkup
kb.Buttons[i][j].Text = newButtonText
kb.Buttons[i][j].State = newButtonState
// todo: the stored keyboard can differ from actual because we update the whole keyboard in TG but update only target button locally
// But maybe it's ok...
_, err = bot.API.Send(tg.EditMessageReplyMarkupConfig{
BaseEdit: tg.BaseEdit{
ChatID: om.ChatID,
MessageID: om.MsgID,
InlineMessageID: om.InlineMsgID,
ReplyMarkup: &tg.InlineKeyboardMarkup{InlineKeyboard: kb.tg()},
},
})
if err != nil {
// Oops. error is occurred – revert the original keyboard
err := c.db.C("messages").UpdateId(msg.ID, bson.M{"$set": bson.M{"inlinekeyboardmarkup": msg.InlineKeyboardMarkup}})
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"EditInlineStateButton",
"(",
"om",
"*",
"OutgoingMessage",
",",
"kbState",
"string",
",",
"oldButtonState",
"int",
",",
"buttonData",
"string",
",",
"newButtonState",
"int",
",",
"newButtonText",
"string",
")",
"error",
... | // EditInlineStateButton edit the outgoing message's inline button with a state | [
"EditInlineStateButton",
"edit",
"the",
"outgoing",
"message",
"s",
"inline",
"button",
"with",
"a",
"state"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L789-L847 | train |
requilence/integram | context.go | AnswerInlineQueryWithPM | func (c *Context) AnswerInlineQueryWithPM(text string, parameter string) error {
bot := c.Bot()
_, err := bot.API.AnswerInlineQuery(tg.InlineConfig{IsPersonal: true, InlineQueryID: c.InlineQuery.ID, SwitchPMText: text, SwitchPMParameter: parameter})
n := time.Now()
c.inlineQueryAnsweredAt = &n
return err
} | go | func (c *Context) AnswerInlineQueryWithPM(text string, parameter string) error {
bot := c.Bot()
_, err := bot.API.AnswerInlineQuery(tg.InlineConfig{IsPersonal: true, InlineQueryID: c.InlineQuery.ID, SwitchPMText: text, SwitchPMParameter: parameter})
n := time.Now()
c.inlineQueryAnsweredAt = &n
return err
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"AnswerInlineQueryWithPM",
"(",
"text",
"string",
",",
"parameter",
"string",
")",
"error",
"{",
"bot",
":=",
"c",
".",
"Bot",
"(",
")",
"\n",
"_",
",",
"err",
":=",
"bot",
".",
"API",
".",
"AnswerInlineQuery",
... | // AnswerInlineQueryWithPM answer the inline query that triggered this request with Private Message redirect tip | [
"AnswerInlineQueryWithPM",
"answer",
"the",
"inline",
"query",
"that",
"triggered",
"this",
"request",
"with",
"Private",
"Message",
"redirect",
"tip"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L868-L874 | train |
requilence/integram | context.go | AnswerCallbackQuery | func (c *Context) AnswerCallbackQuery(text string, showAlert bool) error {
if c.Callback == nil {
return errors.New("Callback to answer is not presented")
}
if c.Callback.AnsweredAt != nil {
return errors.New("Callback already answered")
}
bot := c.Bot()
_, err := bot.API.AnswerCallbackQuery(tg.CallbackConfig{CallbackQueryID: c.Callback.ID, Text: text, ShowAlert: showAlert})
if err == nil {
n := time.Now()
c.Callback.AnsweredAt = &n
}
return err
} | go | func (c *Context) AnswerCallbackQuery(text string, showAlert bool) error {
if c.Callback == nil {
return errors.New("Callback to answer is not presented")
}
if c.Callback.AnsweredAt != nil {
return errors.New("Callback already answered")
}
bot := c.Bot()
_, err := bot.API.AnswerCallbackQuery(tg.CallbackConfig{CallbackQueryID: c.Callback.ID, Text: text, ShowAlert: showAlert})
if err == nil {
n := time.Now()
c.Callback.AnsweredAt = &n
}
return err
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"AnswerCallbackQuery",
"(",
"text",
"string",
",",
"showAlert",
"bool",
")",
"error",
"{",
"if",
"c",
".",
"Callback",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"Callback to answer is not presented\"",
")... | // AnswerCallbackQuery answer the inline keyboard callback query that triggered this request with toast or alert | [
"AnswerCallbackQuery",
"answer",
"the",
"inline",
"keyboard",
"callback",
"query",
"that",
"triggered",
"this",
"request",
"with",
"toast",
"or",
"alert"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L883-L900 | train |
requilence/integram | context.go | NewMessage | func (c *Context) NewMessage() *OutgoingMessage {
bot := c.Bot()
msg := &OutgoingMessage{}
msg.BotID = bot.ID
msg.FromID = bot.ID
msg.WebPreview = true
if c.Chat.ID != 0 {
msg.ChatID = c.Chat.ID
} else {
msg.ChatID = c.User.ID
}
msg.ctx = c
return msg
} | go | func (c *Context) NewMessage() *OutgoingMessage {
bot := c.Bot()
msg := &OutgoingMessage{}
msg.BotID = bot.ID
msg.FromID = bot.ID
msg.WebPreview = true
if c.Chat.ID != 0 {
msg.ChatID = c.Chat.ID
} else {
msg.ChatID = c.User.ID
}
msg.ctx = c
return msg
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"NewMessage",
"(",
")",
"*",
"OutgoingMessage",
"{",
"bot",
":=",
"c",
".",
"Bot",
"(",
")",
"\n",
"msg",
":=",
"&",
"OutgoingMessage",
"{",
"}",
"\n",
"msg",
".",
"BotID",
"=",
"bot",
".",
"ID",
"\n",
"msg"... | // NewMessage creates the message targeted to the current chat | [
"NewMessage",
"creates",
"the",
"message",
"targeted",
"to",
"the",
"current",
"chat"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L903-L916 | train |
requilence/integram | context.go | SendAction | func (c *Context) SendAction(s string) error {
_, err := c.Bot().API.Send(tg.NewChatAction(c.Chat.ID, s))
return err
} | go | func (c *Context) SendAction(s string) error {
_, err := c.Bot().API.Send(tg.NewChatAction(c.Chat.ID, s))
return err
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"SendAction",
"(",
"s",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"c",
".",
"Bot",
"(",
")",
".",
"API",
".",
"Send",
"(",
"tg",
".",
"NewChatAction",
"(",
"c",
".",
"Chat",
".",
"ID",
",",
"s"... | // SendAction send the one of "typing", "upload_photo", "record_video", "upload_video", "record_audio", "upload_audio", "upload_document", "find_location" | [
"SendAction",
"send",
"the",
"one",
"of",
"typing",
"upload_photo",
"record_video",
"upload_video",
"record_audio",
"upload_audio",
"upload_document",
"find_location"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L919-L922 | train |
requilence/integram | context.go | DownloadURL | func (c *Context) DownloadURL(url string) (filePath string, err error) {
ext := filepath.Ext(url)
out, err := ioutil.TempFile("", fmt.Sprintf("%d_%d", c.Bot().ID, c.Chat.ID))
if err != nil {
return "", err
}
out.Close()
os.Rename(out.Name(), out.Name()+ext)
out, err = os.OpenFile(out.Name()+ext, os.O_RDWR, 0666)
if err != nil {
return "", err
}
defer out.Close()
resp, err := http.Get(url)
if err != nil {
return "", err
}
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return "", errors.New("non 2xx resp status")
}
defer resp.Body.Close()
_, err = io.Copy(out, resp.Body)
if err != nil {
return "", err
}
return out.Name(), nil
} | go | func (c *Context) DownloadURL(url string) (filePath string, err error) {
ext := filepath.Ext(url)
out, err := ioutil.TempFile("", fmt.Sprintf("%d_%d", c.Bot().ID, c.Chat.ID))
if err != nil {
return "", err
}
out.Close()
os.Rename(out.Name(), out.Name()+ext)
out, err = os.OpenFile(out.Name()+ext, os.O_RDWR, 0666)
if err != nil {
return "", err
}
defer out.Close()
resp, err := http.Get(url)
if err != nil {
return "", err
}
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return "", errors.New("non 2xx resp status")
}
defer resp.Body.Close()
_, err = io.Copy(out, resp.Body)
if err != nil {
return "", err
}
return out.Name(), nil
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"DownloadURL",
"(",
"url",
"string",
")",
"(",
"filePath",
"string",
",",
"err",
"error",
")",
"{",
"ext",
":=",
"filepath",
".",
"Ext",
"(",
"url",
")",
"\n",
"out",
",",
"err",
":=",
"ioutil",
".",
"TempFile... | // DownloadURL downloads the remote URL and returns the local file path | [
"DownloadURL",
"downloads",
"the",
"remote",
"URL",
"and",
"returns",
"the",
"local",
"file",
"path"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L925-L958 | train |
requilence/integram | context.go | RAW | func (wc *WebhookContext) RAW() (*[]byte, error) {
var err error
if wc.body == nil {
wc.firstParse = true
wc.body, err = ioutil.ReadAll(wc.gin.Request.Body)
if err != nil {
return nil, err
}
}
return &wc.body, nil
} | go | func (wc *WebhookContext) RAW() (*[]byte, error) {
var err error
if wc.body == nil {
wc.firstParse = true
wc.body, err = ioutil.ReadAll(wc.gin.Request.Body)
if err != nil {
return nil, err
}
}
return &wc.body, nil
} | [
"func",
"(",
"wc",
"*",
"WebhookContext",
")",
"RAW",
"(",
")",
"(",
"*",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"if",
"wc",
".",
"body",
"==",
"nil",
"{",
"wc",
".",
"firstParse",
"=",
"true",
"\n",
"wc",
".",
... | // RAW returns request's body | [
"RAW",
"returns",
"request",
"s",
"body"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L961-L971 | train |
requilence/integram | context.go | JSON | func (wc *WebhookContext) JSON(out interface{}) error {
var err error
if wc.body == nil {
wc.firstParse = true
wc.body, err = ioutil.ReadAll(wc.gin.Request.Body)
if err != nil {
return err
}
}
err = json.Unmarshal(wc.body, out)
if err != nil && strings.HasPrefix(string(wc.body), "payload=") {
s := string(wc.body)
s, err = uurl.QueryUnescape(s[8:])
if err != nil {
return err
}
err = json.Unmarshal([]byte(s), out)
}
return err
} | go | func (wc *WebhookContext) JSON(out interface{}) error {
var err error
if wc.body == nil {
wc.firstParse = true
wc.body, err = ioutil.ReadAll(wc.gin.Request.Body)
if err != nil {
return err
}
}
err = json.Unmarshal(wc.body, out)
if err != nil && strings.HasPrefix(string(wc.body), "payload=") {
s := string(wc.body)
s, err = uurl.QueryUnescape(s[8:])
if err != nil {
return err
}
err = json.Unmarshal([]byte(s), out)
}
return err
} | [
"func",
"(",
"wc",
"*",
"WebhookContext",
")",
"JSON",
"(",
"out",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"wc",
".",
"body",
"==",
"nil",
"{",
"wc",
".",
"firstParse",
"=",
"true",
"\n",
"wc",
".",
"body",
",... | // JSON decodes the JSON in the request's body to the out interface | [
"JSON",
"decodes",
"the",
"JSON",
"in",
"the",
"request",
"s",
"body",
"to",
"the",
"out",
"interface"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L974-L996 | train |
requilence/integram | context.go | Form | func (wc *WebhookContext) Form() uurl.Values {
//todo: bug, RAW() unavailable after ParseForm()
wc.gin.Request.ParseForm()
return wc.gin.Request.PostForm
} | go | func (wc *WebhookContext) Form() uurl.Values {
//todo: bug, RAW() unavailable after ParseForm()
wc.gin.Request.ParseForm()
return wc.gin.Request.PostForm
} | [
"func",
"(",
"wc",
"*",
"WebhookContext",
")",
"Form",
"(",
")",
"uurl",
".",
"Values",
"{",
"wc",
".",
"gin",
".",
"Request",
".",
"ParseForm",
"(",
")",
"\n",
"return",
"wc",
".",
"gin",
".",
"Request",
".",
"PostForm",
"\n",
"}"
] | // Form decodes the POST form in the request's body to the out interface | [
"Form",
"decodes",
"the",
"POST",
"form",
"in",
"the",
"request",
"s",
"body",
"to",
"the",
"out",
"interface"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/context.go#L999-L1003 | train |
requilence/integram | tgupdates.go | IsEventBotAddedToGroup | func (m *IncomingMessage) IsEventBotAddedToGroup() bool {
if (len(m.NewChatMembers) > 0 && m.NewChatMembers[0].ID == m.BotID) || m.GroupChatCreated || m.SuperGroupChatCreated {
return true
}
return false
} | go | func (m *IncomingMessage) IsEventBotAddedToGroup() bool {
if (len(m.NewChatMembers) > 0 && m.NewChatMembers[0].ID == m.BotID) || m.GroupChatCreated || m.SuperGroupChatCreated {
return true
}
return false
} | [
"func",
"(",
"m",
"*",
"IncomingMessage",
")",
"IsEventBotAddedToGroup",
"(",
")",
"bool",
"{",
"if",
"(",
"len",
"(",
"m",
".",
"NewChatMembers",
")",
">",
"0",
"&&",
"m",
".",
"NewChatMembers",
"[",
"0",
"]",
".",
"ID",
"==",
"m",
".",
"BotID",
"... | // IsEventBotAddedToGroup returns true if user created a new group with bot as member or add the bot to existing group | [
"IsEventBotAddedToGroup",
"returns",
"true",
"if",
"user",
"created",
"a",
"new",
"group",
"with",
"bot",
"as",
"member",
"or",
"add",
"the",
"bot",
"to",
"existing",
"group"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/tgupdates.go#L768-L773 | train |
requilence/integram | tgupdates.go | GetCommand | func (m *IncomingMessage) GetCommand() (string, string) {
text := m.Text
if !strings.HasPrefix(text, "/") {
return "", text
}
r, _ := regexp.Compile("^/([a-zA-Z0-9_]+)(?:@[a-zA-Z0-9_]+)?.?(.*)?$")
match := r.FindStringSubmatch(text)
if len(match) == 3 {
return match[1], match[2]
} else if len(match) == 2 {
return match[1], ""
}
return "", ""
} | go | func (m *IncomingMessage) GetCommand() (string, string) {
text := m.Text
if !strings.HasPrefix(text, "/") {
return "", text
}
r, _ := regexp.Compile("^/([a-zA-Z0-9_]+)(?:@[a-zA-Z0-9_]+)?.?(.*)?$")
match := r.FindStringSubmatch(text)
if len(match) == 3 {
return match[1], match[2]
} else if len(match) == 2 {
return match[1], ""
}
return "", ""
} | [
"func",
"(",
"m",
"*",
"IncomingMessage",
")",
"GetCommand",
"(",
")",
"(",
"string",
",",
"string",
")",
"{",
"text",
":=",
"m",
".",
"Text",
"\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"text",
",",
"\"/\"",
")",
"{",
"return",
"\"\"",
",",... | // GetCommand parses received message text for bot command. Returns the command and after command text if presented | [
"GetCommand",
"parses",
"received",
"message",
"text",
"for",
"bot",
"command",
".",
"Returns",
"the",
"command",
"and",
"after",
"command",
"text",
"if",
"presented"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/tgupdates.go#L776-L791 | train |
requilence/integram | bots.go | Find | func (keyboard *InlineKeyboard) Find(buttonData string) (i, j int, but *InlineButton) {
for i, buttonsRow := range keyboard.Buttons {
for j, button := range buttonsRow {
if button.Data == buttonData {
return i, j, &button
}
}
}
return -1, -1, nil
} | go | func (keyboard *InlineKeyboard) Find(buttonData string) (i, j int, but *InlineButton) {
for i, buttonsRow := range keyboard.Buttons {
for j, button := range buttonsRow {
if button.Data == buttonData {
return i, j, &button
}
}
}
return -1, -1, nil
} | [
"func",
"(",
"keyboard",
"*",
"InlineKeyboard",
")",
"Find",
"(",
"buttonData",
"string",
")",
"(",
"i",
",",
"j",
"int",
",",
"but",
"*",
"InlineButton",
")",
"{",
"for",
"i",
",",
"buttonsRow",
":=",
"range",
"keyboard",
".",
"Buttons",
"{",
"for",
... | // Find the InlineButton in Keyboard by the Data | [
"Find",
"the",
"InlineButton",
"in",
"Keyboard",
"by",
"the",
"Data"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L305-L314 | train |
requilence/integram | bots.go | EditText | func (keyboard *InlineKeyboard) EditText(buttonData string, newText string) {
for i, buttonsRow := range keyboard.Buttons {
for j, button := range buttonsRow {
if button.Data == buttonData {
keyboard.Buttons[i][j].Text = newText
return
}
}
}
} | go | func (keyboard *InlineKeyboard) EditText(buttonData string, newText string) {
for i, buttonsRow := range keyboard.Buttons {
for j, button := range buttonsRow {
if button.Data == buttonData {
keyboard.Buttons[i][j].Text = newText
return
}
}
}
} | [
"func",
"(",
"keyboard",
"*",
"InlineKeyboard",
")",
"EditText",
"(",
"buttonData",
"string",
",",
"newText",
"string",
")",
"{",
"for",
"i",
",",
"buttonsRow",
":=",
"range",
"keyboard",
".",
"Buttons",
"{",
"for",
"j",
",",
"button",
":=",
"range",
"bu... | // EditText find the InlineButton in Keyboard by the Data and change the text of that button | [
"EditText",
"find",
"the",
"InlineButton",
"in",
"Keyboard",
"by",
"the",
"Data",
"and",
"change",
"the",
"text",
"of",
"that",
"button"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L317-L326 | train |
requilence/integram | bots.go | AddPMSwitchButton | func (keyboard *InlineKeyboard) AddPMSwitchButton(b *Bot, text string, param string) {
if len(keyboard.Buttons) > 0 && len(keyboard.Buttons[0]) > 0 && keyboard.Buttons[0][0].Text == text {
return
}
keyboard.PrependRows(InlineButtons{InlineButton{Text: text, URL: b.PMURL(param)}})
} | go | func (keyboard *InlineKeyboard) AddPMSwitchButton(b *Bot, text string, param string) {
if len(keyboard.Buttons) > 0 && len(keyboard.Buttons[0]) > 0 && keyboard.Buttons[0][0].Text == text {
return
}
keyboard.PrependRows(InlineButtons{InlineButton{Text: text, URL: b.PMURL(param)}})
} | [
"func",
"(",
"keyboard",
"*",
"InlineKeyboard",
")",
"AddPMSwitchButton",
"(",
"b",
"*",
"Bot",
",",
"text",
"string",
",",
"param",
"string",
")",
"{",
"if",
"len",
"(",
"keyboard",
".",
"Buttons",
")",
">",
"0",
"&&",
"len",
"(",
"keyboard",
".",
"... | // AddPMSwitchButton add the button to switch to PM as a first row in the InlineKeyboard | [
"AddPMSwitchButton",
"add",
"the",
"button",
"to",
"switch",
"to",
"PM",
"as",
"a",
"first",
"row",
"in",
"the",
"InlineKeyboard"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L329-L334 | train |
requilence/integram | bots.go | FindMessageByEventID | func (c *Context) FindMessageByEventID(id string) (*Message, error) {
if c.Bot() == nil {
return nil, errors.New("Bot not set for the service")
}
return findMessageByEventID(c.db, c.Chat.ID, c.Bot().ID, id)
} | go | func (c *Context) FindMessageByEventID(id string) (*Message, error) {
if c.Bot() == nil {
return nil, errors.New("Bot not set for the service")
}
return findMessageByEventID(c.db, c.Chat.ID, c.Bot().ID, id)
} | [
"func",
"(",
"c",
"*",
"Context",
")",
"FindMessageByEventID",
"(",
"id",
"string",
")",
"(",
"*",
"Message",
",",
"error",
")",
"{",
"if",
"c",
".",
"Bot",
"(",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"Bot not set... | // FindMessageByEventID find message by event id | [
"FindMessageByEventID",
"find",
"message",
"by",
"event",
"id"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L595-L600 | train |
requilence/integram | bots.go | SetChat | func (m *OutgoingMessage) SetChat(id int64) *OutgoingMessage {
m.ChatID = id
return m
} | go | func (m *OutgoingMessage) SetChat(id int64) *OutgoingMessage {
m.ChatID = id
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"SetChat",
"(",
"id",
"int64",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"ChatID",
"=",
"id",
"\n",
"return",
"m",
"\n",
"}"
] | // SetChat sets the target chat to send the message | [
"SetChat",
"sets",
"the",
"target",
"chat",
"to",
"send",
"the",
"message"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L669-L672 | train |
requilence/integram | bots.go | SetDocument | func (m *OutgoingMessage) SetDocument(localPath string, fileName string) *OutgoingMessage {
m.FilePath = localPath
m.FileName = fileName
m.FileType = "document"
return m
} | go | func (m *OutgoingMessage) SetDocument(localPath string, fileName string) *OutgoingMessage {
m.FilePath = localPath
m.FileName = fileName
m.FileType = "document"
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"SetDocument",
"(",
"localPath",
"string",
",",
"fileName",
"string",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"FilePath",
"=",
"localPath",
"\n",
"m",
".",
"FileName",
"=",
"fileName",
"\n",
"m",
".",
"F... | // SetDocument adds the file located at localPath with name fileName to the message | [
"SetDocument",
"adds",
"the",
"file",
"located",
"at",
"localPath",
"with",
"name",
"fileName",
"to",
"the",
"message"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L681-L686 | train |
requilence/integram | bots.go | SetKeyboard | func (m *OutgoingMessage) SetKeyboard(k KeyboardMarkup, selective bool) *OutgoingMessage {
m.Keyboard = true
m.KeyboardMarkup = k.Keyboard()
m.Selective = selective
//todo: here is workaround for QT version. Keyboard with selective is not working
return m
} | go | func (m *OutgoingMessage) SetKeyboard(k KeyboardMarkup, selective bool) *OutgoingMessage {
m.Keyboard = true
m.KeyboardMarkup = k.Keyboard()
m.Selective = selective
//todo: here is workaround for QT version. Keyboard with selective is not working
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"SetKeyboard",
"(",
"k",
"KeyboardMarkup",
",",
"selective",
"bool",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"Keyboard",
"=",
"true",
"\n",
"m",
".",
"KeyboardMarkup",
"=",
"k",
".",
"Keyboard",
"(",
")"... | // SetKeyboard sets the keyboard markup and Selective bool. If Selective is true keyboard will sent only for target users that you must @mention people in text or specify with SetReplyToMsgID | [
"SetKeyboard",
"sets",
"the",
"keyboard",
"markup",
"and",
"Selective",
"bool",
".",
"If",
"Selective",
"is",
"true",
"keyboard",
"will",
"sent",
"only",
"for",
"target",
"users",
"that",
"you",
"must"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L703-L709 | train |
requilence/integram | bots.go | SetInlineKeyboard | func (m *OutgoingMessage) SetInlineKeyboard(k InlineKeyboardMarkup) *OutgoingMessage {
m.InlineKeyboardMarkup = k.Keyboard()
return m
} | go | func (m *OutgoingMessage) SetInlineKeyboard(k InlineKeyboardMarkup) *OutgoingMessage {
m.InlineKeyboardMarkup = k.Keyboard()
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"SetInlineKeyboard",
"(",
"k",
"InlineKeyboardMarkup",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"InlineKeyboardMarkup",
"=",
"k",
".",
"Keyboard",
"(",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // SetInlineKeyboard sets the inline keyboard markup | [
"SetInlineKeyboard",
"sets",
"the",
"inline",
"keyboard",
"markup"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L712-L715 | train |
requilence/integram | bots.go | SetSelective | func (m *OutgoingMessage) SetSelective(b bool) *OutgoingMessage {
m.Selective = b
return m
} | go | func (m *OutgoingMessage) SetSelective(b bool) *OutgoingMessage {
m.Selective = b
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"SetSelective",
"(",
"b",
"bool",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"Selective",
"=",
"b",
"\n",
"return",
"m",
"\n",
"}"
] | // SetSelective sets the Selective mode for the keyboard. If Selective is true keyboard make sure to @mention people in text or specify message to reply with SetReplyToMsgID | [
"SetSelective",
"sets",
"the",
"Selective",
"mode",
"for",
"the",
"keyboard",
".",
"If",
"Selective",
"is",
"true",
"keyboard",
"make",
"sure",
"to"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L718-L721 | train |
requilence/integram | bots.go | SetSilent | func (m *OutgoingMessage) SetSilent(b bool) *OutgoingMessage {
m.Silent = b
return m
} | go | func (m *OutgoingMessage) SetSilent(b bool) *OutgoingMessage {
m.Silent = b
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"SetSilent",
"(",
"b",
"bool",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"Silent",
"=",
"b",
"\n",
"return",
"m",
"\n",
"}"
] | // SetSilent turns off notifications on iOS and make it silent on Android | [
"SetSilent",
"turns",
"off",
"notifications",
"on",
"iOS",
"and",
"make",
"it",
"silent",
"on",
"Android"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L724-L727 | train |
requilence/integram | bots.go | SetOneTimeKeyboard | func (m *OutgoingMessage) SetOneTimeKeyboard(b bool) *OutgoingMessage {
m.OneTimeKeyboard = b
return m
} | go | func (m *OutgoingMessage) SetOneTimeKeyboard(b bool) *OutgoingMessage {
m.OneTimeKeyboard = b
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"SetOneTimeKeyboard",
"(",
"b",
"bool",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"OneTimeKeyboard",
"=",
"b",
"\n",
"return",
"m",
"\n",
"}"
] | // SetOneTimeKeyboard sets the Onetime mode for keyboard. Keyboard will be hided after 1st use | [
"SetOneTimeKeyboard",
"sets",
"the",
"Onetime",
"mode",
"for",
"keyboard",
".",
"Keyboard",
"will",
"be",
"hided",
"after",
"1st",
"use"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L730-L733 | train |
requilence/integram | bots.go | SetResizeKeyboard | func (m *OutgoingMessage) SetResizeKeyboard(b bool) *OutgoingMessage {
m.ResizeKeyboard = b
return m
} | go | func (m *OutgoingMessage) SetResizeKeyboard(b bool) *OutgoingMessage {
m.ResizeKeyboard = b
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"SetResizeKeyboard",
"(",
"b",
"bool",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"ResizeKeyboard",
"=",
"b",
"\n",
"return",
"m",
"\n",
"}"
] | // SetResizeKeyboard sets the ResizeKeyboard to collapse keyboard wrapper to match the actual underneath keyboard | [
"SetResizeKeyboard",
"sets",
"the",
"ResizeKeyboard",
"to",
"collapse",
"keyboard",
"wrapper",
"to",
"match",
"the",
"actual",
"underneath",
"keyboard"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L736-L739 | train |
requilence/integram | bots.go | SetCallbackAction | func (m *OutgoingMessage) SetCallbackAction(handlerFunc interface{}, args ...interface{}) *OutgoingMessage {
m.Message.SetCallbackAction(handlerFunc, args...)
return m
} | go | func (m *OutgoingMessage) SetCallbackAction(handlerFunc interface{}, args ...interface{}) *OutgoingMessage {
m.Message.SetCallbackAction(handlerFunc, args...)
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"SetCallbackAction",
"(",
"handlerFunc",
"interface",
"{",
"}",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"Message",
".",
"SetCallbackAction",
"(",
"handlerFunc",
","... | // SetCallbackAction sets the callback func that will be called when user press inline button with Data field | [
"SetCallbackAction",
"sets",
"the",
"callback",
"func",
"that",
"will",
"be",
"called",
"when",
"user",
"press",
"inline",
"button",
"with",
"Data",
"field"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L751-L754 | train |
requilence/integram | bots.go | Send | func (m *OutgoingMessage) Send() error {
if m.ChatID == 0 {
return errors.New("ChatID is empty")
}
if m.BotID == 0 {
return errors.New("BotID is empty")
}
if m.Text == "" && m.FilePath == "" && m.Location == nil {
return errors.New("Text, FilePath and Location are empty")
}
if m.ctx != nil && m.ctx.messageAnsweredAt == nil {
n := time.Now()
m.ctx.messageAnsweredAt = &n
}
return activeMessageSender.Send(m)
} | go | func (m *OutgoingMessage) Send() error {
if m.ChatID == 0 {
return errors.New("ChatID is empty")
}
if m.BotID == 0 {
return errors.New("BotID is empty")
}
if m.Text == "" && m.FilePath == "" && m.Location == nil {
return errors.New("Text, FilePath and Location are empty")
}
if m.ctx != nil && m.ctx.messageAnsweredAt == nil {
n := time.Now()
m.ctx.messageAnsweredAt = &n
}
return activeMessageSender.Send(m)
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"Send",
"(",
")",
"error",
"{",
"if",
"m",
".",
"ChatID",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"ChatID is empty\"",
")",
"\n",
"}",
"\n",
"if",
"m",
".",
"BotID",
"==",
"0",
"{",
"r... | // Send put the message to the jobs queue | [
"Send",
"put",
"the",
"message",
"to",
"the",
"jobs",
"queue"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L976-L995 | train |
requilence/integram | bots.go | SetSendAfter | func (m *OutgoingMessage) SetSendAfter(after time.Time) *OutgoingMessage {
m.SendAfter = &after
return m
} | go | func (m *OutgoingMessage) SetSendAfter(after time.Time) *OutgoingMessage {
m.SendAfter = &after
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"SetSendAfter",
"(",
"after",
"time",
".",
"Time",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"SendAfter",
"=",
"&",
"after",
"\n",
"return",
"m",
"\n",
"}"
] | // SetSendAfter set the time to send the message | [
"SetSendAfter",
"set",
"the",
"time",
"to",
"send",
"the",
"message"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L998-L1001 | train |
requilence/integram | bots.go | AddEventID | func (m *OutgoingMessage) AddEventID(id ...string) *OutgoingMessage {
m.EventID = append(m.EventID, id...)
return m
} | go | func (m *OutgoingMessage) AddEventID(id ...string) *OutgoingMessage {
m.EventID = append(m.EventID, id...)
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"AddEventID",
"(",
"id",
"...",
"string",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"EventID",
"=",
"append",
"(",
"m",
".",
"EventID",
",",
"id",
"...",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // AddEventID attach one or more event ID. You can use eventid to edit the message in case of additional webhook received or to ignore in case of duplicate | [
"AddEventID",
"attach",
"one",
"or",
"more",
"event",
"ID",
".",
"You",
"can",
"use",
"eventid",
"to",
"edit",
"the",
"message",
"in",
"case",
"of",
"additional",
"webhook",
"received",
"or",
"to",
"ignore",
"in",
"case",
"of",
"duplicate"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L1004-L1007 | train |
requilence/integram | bots.go | SetText | func (m *OutgoingMessage) SetText(text string) *OutgoingMessage {
m.Text = text
return m
} | go | func (m *OutgoingMessage) SetText(text string) *OutgoingMessage {
m.Text = text
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"SetText",
"(",
"text",
"string",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"Text",
"=",
"text",
"\n",
"return",
"m",
"\n",
"}"
] | // SetText set the text of message to sent
// In case of documents and photo messages this text will be used in the caption | [
"SetText",
"set",
"the",
"text",
"of",
"message",
"to",
"sent",
"In",
"case",
"of",
"documents",
"and",
"photo",
"messages",
"this",
"text",
"will",
"be",
"used",
"in",
"the",
"caption"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L1024-L1027 | train |
requilence/integram | bots.go | SetLocation | func (m *OutgoingMessage) SetLocation(latitude, longitude float64) *OutgoingMessage {
m.Location = &Location{Latitude: latitude, Longitude: longitude}
return m
} | go | func (m *OutgoingMessage) SetLocation(latitude, longitude float64) *OutgoingMessage {
m.Location = &Location{Latitude: latitude, Longitude: longitude}
return m
} | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"SetLocation",
"(",
"latitude",
",",
"longitude",
"float64",
")",
"*",
"OutgoingMessage",
"{",
"m",
".",
"Location",
"=",
"&",
"Location",
"{",
"Latitude",
":",
"latitude",
",",
"Longitude",
":",
"longitude",
... | // SetLocation set the location | [
"SetLocation",
"set",
"the",
"location"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L1030-L1033 | train |
requilence/integram | bots.go | GetTextHash | func (m *Message) GetTextHash() string {
if m.Text != "" {
return fmt.Sprintf("%x", md5.Sum([]byte(m.Text)))
}
return ""
} | go | func (m *Message) GetTextHash() string {
if m.Text != "" {
return fmt.Sprintf("%x", md5.Sum([]byte(m.Text)))
}
return ""
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"GetTextHash",
"(",
")",
"string",
"{",
"if",
"m",
".",
"Text",
"!=",
"\"\"",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%x\"",
",",
"md5",
".",
"Sum",
"(",
"[",
"]",
"byte",
"(",
"m",
".",
"Text",
")",... | // GetTextHash generate MD5 hash of message's text | [
"GetTextHash",
"generate",
"MD5",
"hash",
"of",
"message",
"s",
"text"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L1066-L1071 | train |
requilence/integram | bots.go | UpdateEventsID | func (m *Message) UpdateEventsID(db *mgo.Database, eventID ...string) error {
m.EventID = append(m.EventID, eventID...)
f := bson.M{"botid": m.BotID}
if m.InlineMsgID != "" {
f["inlinemsgid"] = m.InlineMsgID
} else {
f["chatid"] = m.ChatID
f["msgid"] = m.MsgID
}
return db.C("messages").Update(f, bson.M{"$addToSet": bson.M{"eventid": bson.M{"$each": eventID}}})
} | go | func (m *Message) UpdateEventsID(db *mgo.Database, eventID ...string) error {
m.EventID = append(m.EventID, eventID...)
f := bson.M{"botid": m.BotID}
if m.InlineMsgID != "" {
f["inlinemsgid"] = m.InlineMsgID
} else {
f["chatid"] = m.ChatID
f["msgid"] = m.MsgID
}
return db.C("messages").Update(f, bson.M{"$addToSet": bson.M{"eventid": bson.M{"$each": eventID}}})
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"UpdateEventsID",
"(",
"db",
"*",
"mgo",
".",
"Database",
",",
"eventID",
"...",
"string",
")",
"error",
"{",
"m",
".",
"EventID",
"=",
"append",
"(",
"m",
".",
"EventID",
",",
"eventID",
"...",
")",
"\n",
"f"... | // UpdateEventsID sets the event id and update it in DB | [
"UpdateEventsID",
"sets",
"the",
"event",
"id",
"and",
"update",
"it",
"in",
"DB"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L1074-L1084 | train |
requilence/integram | bots.go | Update | func (m *Message) Update(db *mgo.Database) error {
if m.ID.Valid() {
return db.C("messages").UpdateId(m.ID, bson.M{"$set": m})
}
return errors.New("Can't update message: ID is not set")
} | go | func (m *Message) Update(db *mgo.Database) error {
if m.ID.Valid() {
return db.C("messages").UpdateId(m.ID, bson.M{"$set": m})
}
return errors.New("Can't update message: ID is not set")
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"Update",
"(",
"db",
"*",
"mgo",
".",
"Database",
")",
"error",
"{",
"if",
"m",
".",
"ID",
".",
"Valid",
"(",
")",
"{",
"return",
"db",
".",
"C",
"(",
"\"messages\"",
")",
".",
"UpdateId",
"(",
"m",
".",
... | // Update will update existing message in DB | [
"Update",
"will",
"update",
"existing",
"message",
"in",
"DB"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L1087-L1093 | train |
requilence/integram | encode.go | decode | func decode(reply []byte, dest interface{}) error {
// Check the type of dest and make sure it is a pointer to something,
// otherwise we can't set its value in any meaningful way.
val := reflect.ValueOf(dest)
if val.Kind() != reflect.Ptr {
return fmt.Errorf("Argument to decode must be pointer. Got %T", dest)
}
// Use the gob package to decode the reply and write the result into
// dest.
buf := bytes.NewBuffer(reply)
dec := gob.NewDecoder(buf)
if err := dec.DecodeValue(val.Elem()); err != nil {
return err
}
return nil
} | go | func decode(reply []byte, dest interface{}) error {
// Check the type of dest and make sure it is a pointer to something,
// otherwise we can't set its value in any meaningful way.
val := reflect.ValueOf(dest)
if val.Kind() != reflect.Ptr {
return fmt.Errorf("Argument to decode must be pointer. Got %T", dest)
}
// Use the gob package to decode the reply and write the result into
// dest.
buf := bytes.NewBuffer(reply)
dec := gob.NewDecoder(buf)
if err := dec.DecodeValue(val.Elem()); err != nil {
return err
}
return nil
} | [
"func",
"decode",
"(",
"reply",
"[",
"]",
"byte",
",",
"dest",
"interface",
"{",
"}",
")",
"error",
"{",
"val",
":=",
"reflect",
".",
"ValueOf",
"(",
"dest",
")",
"\n",
"if",
"val",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"return... | // decode decodes a slice of bytes and scans the value into dest using the gob package.
// All types are supported except recursive data structures and functions. | [
"decode",
"decodes",
"a",
"slice",
"of",
"bytes",
"and",
"scans",
"the",
"value",
"into",
"dest",
"using",
"the",
"gob",
"package",
".",
"All",
"types",
"are",
"supported",
"except",
"recursive",
"data",
"structures",
"and",
"functions",
"."
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/encode.go#L19-L35 | train |
requilence/integram | encode.go | encode | func encode(data interface{}) ([]byte, error) {
if data == nil {
return nil, nil
}
buf := bytes.NewBuffer([]byte{})
enc := gob.NewEncoder(buf)
if err := enc.Encode(data); err != nil {
return nil, err
}
return buf.Bytes(), nil
} | go | func encode(data interface{}) ([]byte, error) {
if data == nil {
return nil, nil
}
buf := bytes.NewBuffer([]byte{})
enc := gob.NewEncoder(buf)
if err := enc.Encode(data); err != nil {
return nil, err
}
return buf.Bytes(), nil
} | [
"func",
"encode",
"(",
"data",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"data",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"[",
"]",
"byte... | // encode encodes data into a slice of bytes using the gob package.
// All types are supported except recursive data structures and functions. | [
"encode",
"encodes",
"data",
"into",
"a",
"slice",
"of",
"bytes",
"using",
"the",
"gob",
"package",
".",
"All",
"types",
"are",
"supported",
"except",
"recursive",
"data",
"structures",
"and",
"functions",
"."
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/encode.go#L39-L49 | train |
requilence/integram | services.go | Bot | func (s *Service) Bot() *Bot {
if bot, exists := botPerService[s.Name]; exists {
return bot
}
log.WithField("service", s.Name).Error("Can't get bot for service")
return nil
} | go | func (s *Service) Bot() *Bot {
if bot, exists := botPerService[s.Name]; exists {
return bot
}
log.WithField("service", s.Name).Error("Can't get bot for service")
return nil
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Bot",
"(",
")",
"*",
"Bot",
"{",
"if",
"bot",
",",
"exists",
":=",
"botPerService",
"[",
"s",
".",
"Name",
"]",
";",
"exists",
"{",
"return",
"bot",
"\n",
"}",
"\n",
"log",
".",
"WithField",
"(",
"\"service... | // Bot returns corresponding bot for the service | [
"Bot",
"returns",
"corresponding",
"bot",
"for",
"the",
"service"
] | 7d85c728a299bf2ad121ae1874c0bd39fc48c231 | https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/services.go#L551-L557 | train |
rakyll/statik | fs/walk.go | Walk | func Walk(hfs http.FileSystem, root string, walkFn filepath.WalkFunc) error {
dh, err := hfs.Open(root)
if err != nil {
return err
}
di, err := dh.Stat()
if err != nil {
return err
}
fis, err := dh.Readdir(-1)
dh.Close()
if err = walkFn(root, di, err); err != nil {
if err == filepath.SkipDir {
return nil
}
return err
}
for _, fi := range fis {
fn := path.Join(root, fi.Name())
if fi.IsDir() {
if err = Walk(hfs, fn, walkFn); err != nil {
if err == filepath.SkipDir {
continue
}
return err
}
continue
}
if err = walkFn(fn, fi, nil); err != nil {
if err == filepath.SkipDir {
continue
}
return err
}
}
return nil
} | go | func Walk(hfs http.FileSystem, root string, walkFn filepath.WalkFunc) error {
dh, err := hfs.Open(root)
if err != nil {
return err
}
di, err := dh.Stat()
if err != nil {
return err
}
fis, err := dh.Readdir(-1)
dh.Close()
if err = walkFn(root, di, err); err != nil {
if err == filepath.SkipDir {
return nil
}
return err
}
for _, fi := range fis {
fn := path.Join(root, fi.Name())
if fi.IsDir() {
if err = Walk(hfs, fn, walkFn); err != nil {
if err == filepath.SkipDir {
continue
}
return err
}
continue
}
if err = walkFn(fn, fi, nil); err != nil {
if err == filepath.SkipDir {
continue
}
return err
}
}
return nil
} | [
"func",
"Walk",
"(",
"hfs",
"http",
".",
"FileSystem",
",",
"root",
"string",
",",
"walkFn",
"filepath",
".",
"WalkFunc",
")",
"error",
"{",
"dh",
",",
"err",
":=",
"hfs",
".",
"Open",
"(",
"root",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return"... | // Walk walks the file tree rooted at root,
// calling walkFn for each file or directory in the tree, including root.
// All errors that arise visiting files and directories are filtered by walkFn.
//
// As with filepath.Walk, if the walkFn returns filepath.SkipDir, then the directory is skipped. | [
"Walk",
"walks",
"the",
"file",
"tree",
"rooted",
"at",
"root",
"calling",
"walkFn",
"for",
"each",
"file",
"or",
"directory",
"in",
"the",
"tree",
"including",
"root",
".",
"All",
"errors",
"that",
"arise",
"visiting",
"files",
"and",
"directories",
"are",
... | 3bac566d30cdbeddef402a80f3d6305860e59f12 | https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/fs/walk.go#L30-L66 | train |
rakyll/statik | fs/walk.go | ReadFile | func ReadFile(hfs http.FileSystem, name string) ([]byte, error) {
fh, err := hfs.Open(name)
if err != nil {
return nil, err
}
var buf bytes.Buffer
_, err = io.Copy(&buf, fh)
fh.Close()
return buf.Bytes(), err
} | go | func ReadFile(hfs http.FileSystem, name string) ([]byte, error) {
fh, err := hfs.Open(name)
if err != nil {
return nil, err
}
var buf bytes.Buffer
_, err = io.Copy(&buf, fh)
fh.Close()
return buf.Bytes(), err
} | [
"func",
"ReadFile",
"(",
"hfs",
"http",
".",
"FileSystem",
",",
"name",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"fh",
",",
"err",
":=",
"hfs",
".",
"Open",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"... | // ReadFile reads the contents of the file of hfs specified by name.
// Just as ioutil.ReadFile does. | [
"ReadFile",
"reads",
"the",
"contents",
"of",
"the",
"file",
"of",
"hfs",
"specified",
"by",
"name",
".",
"Just",
"as",
"ioutil",
".",
"ReadFile",
"does",
"."
] | 3bac566d30cdbeddef402a80f3d6305860e59f12 | https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/fs/walk.go#L70-L79 | train |
rakyll/statik | statik.go | rename | func rename(src, dest string) error {
// Try to rename generated source.
if err := os.Rename(src, dest); err == nil {
return nil
}
// If the rename failed (might do so due to temporary file residing on a
// different device), try to copy byte by byte.
rc, err := os.Open(src)
if err != nil {
return err
}
defer func() {
rc.Close()
os.Remove(src) // ignore the error, source is in tmp.
}()
if _, err = os.Stat(dest); !os.IsNotExist(err) {
if *flagForce {
if err = os.Remove(dest); err != nil {
return fmt.Errorf("file %q could not be deleted", dest)
}
} else {
return fmt.Errorf("file %q already exists; use -f to overwrite", dest)
}
}
wc, err := os.Create(dest)
if err != nil {
return err
}
defer wc.Close()
if _, err = io.Copy(wc, rc); err != nil {
// Delete remains of failed copy attempt.
os.Remove(dest)
}
return err
} | go | func rename(src, dest string) error {
// Try to rename generated source.
if err := os.Rename(src, dest); err == nil {
return nil
}
// If the rename failed (might do so due to temporary file residing on a
// different device), try to copy byte by byte.
rc, err := os.Open(src)
if err != nil {
return err
}
defer func() {
rc.Close()
os.Remove(src) // ignore the error, source is in tmp.
}()
if _, err = os.Stat(dest); !os.IsNotExist(err) {
if *flagForce {
if err = os.Remove(dest); err != nil {
return fmt.Errorf("file %q could not be deleted", dest)
}
} else {
return fmt.Errorf("file %q already exists; use -f to overwrite", dest)
}
}
wc, err := os.Create(dest)
if err != nil {
return err
}
defer wc.Close()
if _, err = io.Copy(wc, rc); err != nil {
// Delete remains of failed copy attempt.
os.Remove(dest)
}
return err
} | [
"func",
"rename",
"(",
"src",
",",
"dest",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"os",
".",
"Rename",
"(",
"src",
",",
"dest",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"rc",
",",
"err",
":=",
"os",
".",
"... | // rename tries to os.Rename, but fall backs to copying from src
// to dest and unlink the source if os.Rename fails. | [
"rename",
"tries",
"to",
"os",
".",
"Rename",
"but",
"fall",
"backs",
"to",
"copying",
"from",
"src",
"to",
"dest",
"and",
"unlink",
"the",
"source",
"if",
"os",
".",
"Rename",
"fails",
"."
] | 3bac566d30cdbeddef402a80f3d6305860e59f12 | https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/statik.go#L78-L115 | train |
rakyll/statik | statik.go | FprintZipData | func FprintZipData(dest *bytes.Buffer, zipData []byte) {
for _, b := range zipData {
if b == '\n' {
dest.WriteString(`\n`)
continue
}
if b == '\\' {
dest.WriteString(`\\`)
continue
}
if b == '"' {
dest.WriteString(`\"`)
continue
}
if (b >= 32 && b <= 126) || b == '\t' {
dest.WriteByte(b)
continue
}
fmt.Fprintf(dest, "\\x%02x", b)
}
} | go | func FprintZipData(dest *bytes.Buffer, zipData []byte) {
for _, b := range zipData {
if b == '\n' {
dest.WriteString(`\n`)
continue
}
if b == '\\' {
dest.WriteString(`\\`)
continue
}
if b == '"' {
dest.WriteString(`\"`)
continue
}
if (b >= 32 && b <= 126) || b == '\t' {
dest.WriteByte(b)
continue
}
fmt.Fprintf(dest, "\\x%02x", b)
}
} | [
"func",
"FprintZipData",
"(",
"dest",
"*",
"bytes",
".",
"Buffer",
",",
"zipData",
"[",
"]",
"byte",
")",
"{",
"for",
"_",
",",
"b",
":=",
"range",
"zipData",
"{",
"if",
"b",
"==",
"'\\n'",
"{",
"dest",
".",
"WriteString",
"(",
"`\\n`",
")",
"\n",
... | // FprintZipData converts zip binary contents to a string literal. | [
"FprintZipData",
"converts",
"zip",
"binary",
"contents",
"to",
"a",
"string",
"literal",
"."
] | 3bac566d30cdbeddef402a80f3d6305860e59f12 | https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/statik.go#L218-L238 | train |
rakyll/statik | fs/fs.go | New | func New() (http.FileSystem, error) {
if zipData == "" {
return nil, errors.New("statik/fs: no zip data registered")
}
zipReader, err := zip.NewReader(strings.NewReader(zipData), int64(len(zipData)))
if err != nil {
return nil, err
}
files := make(map[string]file, len(zipReader.File))
dirs := make(map[string][]string)
fs := &statikFS{files: files, dirs: dirs}
for _, zipFile := range zipReader.File {
fi := zipFile.FileInfo()
f := file{FileInfo: fi, fs: fs}
f.data, err = unzip(zipFile)
if err != nil {
return nil, fmt.Errorf("statik/fs: error unzipping file %q: %s", zipFile.Name, err)
}
files["/"+zipFile.Name] = f
}
for fn := range files {
// go up directories recursively in order to care deep directory
for dn := path.Dir(fn); dn != fn; {
if _, ok := files[dn]; !ok {
files[dn] = file{FileInfo: dirInfo{dn}, fs: fs}
} else {
break
}
fn, dn = dn, path.Dir(dn)
}
}
for fn := range files {
dn := path.Dir(fn)
if fn != dn {
fs.dirs[dn] = append(fs.dirs[dn], path.Base(fn))
}
}
for _, s := range fs.dirs {
sort.Strings(s)
}
return fs, nil
} | go | func New() (http.FileSystem, error) {
if zipData == "" {
return nil, errors.New("statik/fs: no zip data registered")
}
zipReader, err := zip.NewReader(strings.NewReader(zipData), int64(len(zipData)))
if err != nil {
return nil, err
}
files := make(map[string]file, len(zipReader.File))
dirs := make(map[string][]string)
fs := &statikFS{files: files, dirs: dirs}
for _, zipFile := range zipReader.File {
fi := zipFile.FileInfo()
f := file{FileInfo: fi, fs: fs}
f.data, err = unzip(zipFile)
if err != nil {
return nil, fmt.Errorf("statik/fs: error unzipping file %q: %s", zipFile.Name, err)
}
files["/"+zipFile.Name] = f
}
for fn := range files {
// go up directories recursively in order to care deep directory
for dn := path.Dir(fn); dn != fn; {
if _, ok := files[dn]; !ok {
files[dn] = file{FileInfo: dirInfo{dn}, fs: fs}
} else {
break
}
fn, dn = dn, path.Dir(dn)
}
}
for fn := range files {
dn := path.Dir(fn)
if fn != dn {
fs.dirs[dn] = append(fs.dirs[dn], path.Base(fn))
}
}
for _, s := range fs.dirs {
sort.Strings(s)
}
return fs, nil
} | [
"func",
"New",
"(",
")",
"(",
"http",
".",
"FileSystem",
",",
"error",
")",
"{",
"if",
"zipData",
"==",
"\"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"statik/fs: no zip data registered\"",
")",
"\n",
"}",
"\n",
"zipReader",
",",
"err",
... | // New creates a new file system with the registered zip contents data.
// It unzips all files and stores them in an in-memory map. | [
"New",
"creates",
"a",
"new",
"file",
"system",
"with",
"the",
"registered",
"zip",
"contents",
"data",
".",
"It",
"unzips",
"all",
"files",
"and",
"stores",
"them",
"in",
"an",
"in",
"-",
"memory",
"map",
"."
] | 3bac566d30cdbeddef402a80f3d6305860e59f12 | https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/fs/fs.go#L55-L96 | train |
rakyll/statik | fs/fs.go | Open | func (fs *statikFS) Open(name string) (http.File, error) {
name = strings.Replace(name, "//", "/", -1)
if f, ok := fs.files[name]; ok {
return newHTTPFile(f), nil
}
return nil, os.ErrNotExist
} | go | func (fs *statikFS) Open(name string) (http.File, error) {
name = strings.Replace(name, "//", "/", -1)
if f, ok := fs.files[name]; ok {
return newHTTPFile(f), nil
}
return nil, os.ErrNotExist
} | [
"func",
"(",
"fs",
"*",
"statikFS",
")",
"Open",
"(",
"name",
"string",
")",
"(",
"http",
".",
"File",
",",
"error",
")",
"{",
"name",
"=",
"strings",
".",
"Replace",
"(",
"name",
",",
"\"//\"",
",",
"\"/\"",
",",
"-",
"1",
")",
"\n",
"if",
"f"... | // Open returns a file matching the given file name, or os.ErrNotExists if
// no file matching the given file name is found in the archive.
// If a directory is requested, Open returns the file named "index.html"
// in the requested directory, if that file exists. | [
"Open",
"returns",
"a",
"file",
"matching",
"the",
"given",
"file",
"name",
"or",
"os",
".",
"ErrNotExists",
"if",
"no",
"file",
"matching",
"the",
"given",
"file",
"name",
"is",
"found",
"in",
"the",
"archive",
".",
"If",
"a",
"directory",
"is",
"reques... | 3bac566d30cdbeddef402a80f3d6305860e59f12 | https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/fs/fs.go#L124-L130 | train |
rakyll/statik | fs/fs.go | Read | func (f *httpFile) Read(p []byte) (n int, err error) {
if f.reader == nil && f.isDir {
return 0, io.EOF
}
return f.reader.Read(p)
} | go | func (f *httpFile) Read(p []byte) (n int, err error) {
if f.reader == nil && f.isDir {
return 0, io.EOF
}
return f.reader.Read(p)
} | [
"func",
"(",
"f",
"*",
"httpFile",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"f",
".",
"reader",
"==",
"nil",
"&&",
"f",
".",
"isDir",
"{",
"return",
"0",
",",
"io",
".",
"EOF",
"\n"... | // Read reads bytes into p, returns the number of read bytes. | [
"Read",
"reads",
"bytes",
"into",
"p",
"returns",
"the",
"number",
"of",
"read",
"bytes",
"."
] | 3bac566d30cdbeddef402a80f3d6305860e59f12 | https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/fs/fs.go#L150-L155 | train |
rakyll/statik | fs/fs.go | Seek | func (f *httpFile) Seek(offset int64, whence int) (ret int64, err error) {
return f.reader.Seek(offset, whence)
} | go | func (f *httpFile) Seek(offset int64, whence int) (ret int64, err error) {
return f.reader.Seek(offset, whence)
} | [
"func",
"(",
"f",
"*",
"httpFile",
")",
"Seek",
"(",
"offset",
"int64",
",",
"whence",
"int",
")",
"(",
"ret",
"int64",
",",
"err",
"error",
")",
"{",
"return",
"f",
".",
"reader",
".",
"Seek",
"(",
"offset",
",",
"whence",
")",
"\n",
"}"
] | // Seek seeks to the offset. | [
"Seek",
"seeks",
"to",
"the",
"offset",
"."
] | 3bac566d30cdbeddef402a80f3d6305860e59f12 | https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/fs/fs.go#L158-L160 | train |
rakyll/statik | fs/fs.go | Readdir | func (f *httpFile) Readdir(count int) ([]os.FileInfo, error) {
var fis []os.FileInfo
if !f.isDir {
return fis, nil
}
di, ok := f.FileInfo.(dirInfo)
if !ok {
return nil, fmt.Errorf("failed to read directory: %q", f.Name())
}
// If count is positive, the specified number of files will be returned,
// and if negative, all remaining files will be returned.
// The reading position of which file is returned is held in dirIndex.
fnames := f.file.fs.dirs[di.name]
flen := len(fnames)
// If dirIdx reaches the end and the count is a positive value,
// an io.EOF error is returned.
// In other cases, no error will be returned even if, for example,
// you specified more counts than the number of remaining files.
start := f.dirIdx
if start >= flen && count > 0 {
return fis, io.EOF
}
var end int
if count < 0 {
end = flen
} else {
end = start + count
}
if end > flen {
end = flen
}
for i := start; i < end; i++ {
fis = append(fis, f.file.fs.files[path.Join(di.name, fnames[i])].FileInfo)
}
f.dirIdx += len(fis)
return fis, nil
} | go | func (f *httpFile) Readdir(count int) ([]os.FileInfo, error) {
var fis []os.FileInfo
if !f.isDir {
return fis, nil
}
di, ok := f.FileInfo.(dirInfo)
if !ok {
return nil, fmt.Errorf("failed to read directory: %q", f.Name())
}
// If count is positive, the specified number of files will be returned,
// and if negative, all remaining files will be returned.
// The reading position of which file is returned is held in dirIndex.
fnames := f.file.fs.dirs[di.name]
flen := len(fnames)
// If dirIdx reaches the end and the count is a positive value,
// an io.EOF error is returned.
// In other cases, no error will be returned even if, for example,
// you specified more counts than the number of remaining files.
start := f.dirIdx
if start >= flen && count > 0 {
return fis, io.EOF
}
var end int
if count < 0 {
end = flen
} else {
end = start + count
}
if end > flen {
end = flen
}
for i := start; i < end; i++ {
fis = append(fis, f.file.fs.files[path.Join(di.name, fnames[i])].FileInfo)
}
f.dirIdx += len(fis)
return fis, nil
} | [
"func",
"(",
"f",
"*",
"httpFile",
")",
"Readdir",
"(",
"count",
"int",
")",
"(",
"[",
"]",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"var",
"fis",
"[",
"]",
"os",
".",
"FileInfo",
"\n",
"if",
"!",
"f",
".",
"isDir",
"{",
"return",
"fis",
... | // Readdir returns an empty slice of files, directory
// listing is disabled. | [
"Readdir",
"returns",
"an",
"empty",
"slice",
"of",
"files",
"directory",
"listing",
"is",
"disabled",
"."
] | 3bac566d30cdbeddef402a80f3d6305860e59f12 | https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/fs/fs.go#L174-L212 | train |
micro/go-config | source/vault/vault.go | NewSource | func NewSource(opts ...source.Option) source.Source {
options := source.NewOptions(opts...)
// create the client
client, _ := api.NewClient(api.DefaultConfig())
// get and set options
if address := getAddress(options); address != "" {
_ = client.SetAddress(address)
}
if nameSpace := getNameSpace(options); nameSpace != "" {
client.SetNamespace(nameSpace)
}
if token := getToken(options); token != "" {
client.SetToken(token)
}
path := getResourcePath(options)
name := getSecretName(options)
if name == "" {
name = path
}
return &vault{
opts: options,
client: client,
secretPath: path,
secretName: name,
}
} | go | func NewSource(opts ...source.Option) source.Source {
options := source.NewOptions(opts...)
// create the client
client, _ := api.NewClient(api.DefaultConfig())
// get and set options
if address := getAddress(options); address != "" {
_ = client.SetAddress(address)
}
if nameSpace := getNameSpace(options); nameSpace != "" {
client.SetNamespace(nameSpace)
}
if token := getToken(options); token != "" {
client.SetToken(token)
}
path := getResourcePath(options)
name := getSecretName(options)
if name == "" {
name = path
}
return &vault{
opts: options,
client: client,
secretPath: path,
secretName: name,
}
} | [
"func",
"NewSource",
"(",
"opts",
"...",
"source",
".",
"Option",
")",
"source",
".",
"Source",
"{",
"options",
":=",
"source",
".",
"NewOptions",
"(",
"opts",
"...",
")",
"\n",
"client",
",",
"_",
":=",
"api",
".",
"NewClient",
"(",
"api",
".",
"Def... | // NewSource creates a new vault source | [
"NewSource",
"creates",
"a",
"new",
"vault",
"source"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/vault/vault.go#L65-L96 | train |
micro/go-config | source/microcli/options.go | Context | func Context(c *cli.Context) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, contextKey{}, c)
}
} | go | func Context(c *cli.Context) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, contextKey{}, c)
}
} | [
"func",
"Context",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
"."... | // Context sets the microcli context | [
"Context",
"sets",
"the",
"microcli",
"context"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/microcli/options.go#L13-L20 | train |
micro/go-config | source/configmap/options.go | WithNamespace | func WithNamespace(s string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, namespaceKey{}, s)
}
} | go | func WithNamespace(s string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, namespaceKey{}, s)
}
} | [
"func",
"WithNamespace",
"(",
"s",
"string",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Background",
... | // WithNamespace is an option to add namespace of configmap | [
"WithNamespace",
"is",
"an",
"option",
"to",
"add",
"namespace",
"of",
"configmap"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/configmap/options.go#L15-L22 | train |
micro/go-config | source/configmap/options.go | WithName | func WithName(s string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, nameKey{}, s)
}
} | go | func WithName(s string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, nameKey{}, s)
}
} | [
"func",
"WithName",
"(",
"s",
"string",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Background",
"("... | // WithName is an option to add name of configmap | [
"WithName",
"is",
"an",
"option",
"to",
"add",
"name",
"of",
"configmap"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/configmap/options.go#L25-L32 | train |
micro/go-config | source/configmap/options.go | WithConfigPath | func WithConfigPath(s string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, configPathKey{}, s)
}
} | go | func WithConfigPath(s string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, configPathKey{}, s)
}
} | [
"func",
"WithConfigPath",
"(",
"s",
"string",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Background",... | // WithConfigPath option for setting a custom path to kubeconfig | [
"WithConfigPath",
"option",
"for",
"setting",
"a",
"custom",
"path",
"to",
"kubeconfig"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/configmap/options.go#L35-L42 | train |
micro/go-config | source/grpc/options.go | WithAddress | func WithAddress(a string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, addressKey{}, a)
}
} | go | func WithAddress(a string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, addressKey{}, a)
}
} | [
"func",
"WithAddress",
"(",
"a",
"string",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Background",
... | // WithAddress sets the consul address | [
"WithAddress",
"sets",
"the",
"consul",
"address"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/grpc/options.go#L13-L20 | train |
micro/go-config | source/grpc/options.go | WithPath | func WithPath(p string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, pathKey{}, p)
}
} | go | func WithPath(p string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, pathKey{}, p)
}
} | [
"func",
"WithPath",
"(",
"p",
"string",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Background",
"("... | // WithPath sets the key prefix to use | [
"WithPath",
"sets",
"the",
"key",
"prefix",
"to",
"use"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/grpc/options.go#L23-L30 | train |
micro/go-config | source/grpc/options.go | WithTLS | func WithTLS(t *tls.Config) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, tls.Config{}, t)
}
} | go | func WithTLS(t *tls.Config) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, tls.Config{}, t)
}
} | [
"func",
"WithTLS",
"(",
"t",
"*",
"tls",
".",
"Config",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",... | // WithTLS sets the TLS config for the service | [
"WithTLS",
"sets",
"the",
"TLS",
"config",
"for",
"the",
"service"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/grpc/options.go#L33-L40 | train |
micro/go-config | source/memory/options.go | WithChangeSet | func WithChangeSet(cs *source.ChangeSet) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, changeSetKey{}, cs)
}
} | go | func WithChangeSet(cs *source.ChangeSet) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, changeSetKey{}, cs)
}
} | [
"func",
"WithChangeSet",
"(",
"cs",
"*",
"source",
".",
"ChangeSet",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"con... | // WithChangeSet allows a changeset to be set | [
"WithChangeSet",
"allows",
"a",
"changeset",
"to",
"be",
"set"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/memory/options.go#L12-L19 | train |
micro/go-config | source/memory/options.go | WithData | func WithData(d []byte) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, changeSetKey{}, &source.ChangeSet{
Data: d,
Format: "json",
})
}
} | go | func WithData(d []byte) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, changeSetKey{}, &source.ChangeSet{
Data: d,
Format: "json",
})
}
} | [
"func",
"WithData",
"(",
"d",
"[",
"]",
"byte",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Backgr... | // WithData allows the source data to be set | [
"WithData",
"allows",
"the",
"source",
"data",
"to",
"be",
"set"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/memory/options.go#L22-L32 | train |
micro/go-config | reader/json/json.go | NewReader | func NewReader(opts ...reader.Option) reader.Reader {
options := reader.NewOptions(opts...)
return &jsonReader{
json: json.NewEncoder(),
opts: options,
}
} | go | func NewReader(opts ...reader.Option) reader.Reader {
options := reader.NewOptions(opts...)
return &jsonReader{
json: json.NewEncoder(),
opts: options,
}
} | [
"func",
"NewReader",
"(",
"opts",
"...",
"reader",
".",
"Option",
")",
"reader",
".",
"Reader",
"{",
"options",
":=",
"reader",
".",
"NewOptions",
"(",
"opts",
"...",
")",
"\n",
"return",
"&",
"jsonReader",
"{",
"json",
":",
"json",
".",
"NewEncoder",
... | // NewReader creates a json reader | [
"NewReader",
"creates",
"a",
"json",
"reader"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/reader/json/json.go#L77-L83 | train |
micro/go-config | source/configmap/configmap.go | NewSource | func NewSource(opts ...source.Option) source.Source {
var (
options = source.NewOptions(opts...)
name = DefaultName
configPath = DefaultConfigPath
namespace = DefaultNamespace
)
prefix, ok := options.Context.Value(prefixKey{}).(string)
if ok {
name = prefix
}
cfg, ok := options.Context.Value(configPathKey{}).(string)
if ok {
configPath = cfg
}
sname, ok := options.Context.Value(nameKey{}).(string)
if ok {
name = sname
}
ns, ok := options.Context.Value(namespaceKey{}).(string)
if ok {
namespace = ns
}
// TODO handle if the client fails what to do current return does not support error
client, err := getClient(configPath)
return &configmap{
cerr: err,
client: client,
opts: options,
name: name,
configPath: configPath,
namespace: namespace,
}
} | go | func NewSource(opts ...source.Option) source.Source {
var (
options = source.NewOptions(opts...)
name = DefaultName
configPath = DefaultConfigPath
namespace = DefaultNamespace
)
prefix, ok := options.Context.Value(prefixKey{}).(string)
if ok {
name = prefix
}
cfg, ok := options.Context.Value(configPathKey{}).(string)
if ok {
configPath = cfg
}
sname, ok := options.Context.Value(nameKey{}).(string)
if ok {
name = sname
}
ns, ok := options.Context.Value(namespaceKey{}).(string)
if ok {
namespace = ns
}
// TODO handle if the client fails what to do current return does not support error
client, err := getClient(configPath)
return &configmap{
cerr: err,
client: client,
opts: options,
name: name,
configPath: configPath,
namespace: namespace,
}
} | [
"func",
"NewSource",
"(",
"opts",
"...",
"source",
".",
"Option",
")",
"source",
".",
"Source",
"{",
"var",
"(",
"options",
"=",
"source",
".",
"NewOptions",
"(",
"opts",
"...",
")",
"\n",
"name",
"=",
"DefaultName",
"\n",
"configPath",
"=",
"DefaultConf... | // NewSource is a factory function | [
"NewSource",
"is",
"a",
"factory",
"function"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/configmap/configmap.go#L73-L112 | train |
micro/go-config | source/etcd/options.go | WithPrefix | func WithPrefix(p string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, prefixKey{}, p)
}
} | go | func WithPrefix(p string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, prefixKey{}, p)
}
} | [
"func",
"WithPrefix",
"(",
"p",
"string",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Background",
"... | // WithPrefix sets the key prefix to use | [
"WithPrefix",
"sets",
"the",
"key",
"prefix",
"to",
"use"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/etcd/options.go#L30-L37 | train |
micro/go-config | source/etcd/options.go | StripPrefix | func StripPrefix(strip bool) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, stripPrefixKey{}, strip)
}
} | go | func StripPrefix(strip bool) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, stripPrefixKey{}, strip)
}
} | [
"func",
"StripPrefix",
"(",
"strip",
"bool",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Background",
... | // StripPrefix indicates whether to remove the prefix from config entries, or leave it in place. | [
"StripPrefix",
"indicates",
"whether",
"to",
"remove",
"the",
"prefix",
"from",
"config",
"entries",
"or",
"leave",
"it",
"in",
"place",
"."
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/etcd/options.go#L40-L48 | train |
micro/go-config | source/env/options.go | WithStrippedPrefix | func WithStrippedPrefix(p ...string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, strippedPrefixKey{}, appendUnderscore(p))
}
} | go | func WithStrippedPrefix(p ...string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, strippedPrefixKey{}, appendUnderscore(p))
}
} | [
"func",
"WithStrippedPrefix",
"(",
"p",
"...",
"string",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
... | // WithStrippedPrefix sets the environment variable prefixes to scope to.
// These prefixes will be removed from the actual config entries. | [
"WithStrippedPrefix",
"sets",
"the",
"environment",
"variable",
"prefixes",
"to",
"scope",
"to",
".",
"These",
"prefixes",
"will",
"be",
"removed",
"from",
"the",
"actual",
"config",
"entries",
"."
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/env/options.go#L16-L24 | train |
micro/go-config | source/runtimevar/options.go | WithVariable | func WithVariable(v *runtimevar.Variable) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, variableKey{}, v)
}
} | go | func WithVariable(v *runtimevar.Variable) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, variableKey{}, v)
}
} | [
"func",
"WithVariable",
"(",
"v",
"*",
"runtimevar",
".",
"Variable",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"co... | // WithVariable sets the runtimevar.Variable. | [
"WithVariable",
"sets",
"the",
"runtimevar",
".",
"Variable",
"."
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/runtimevar/options.go#L13-L20 | train |
micro/go-config | config.go | LoadFile | func LoadFile(path string) error {
return Load(file.NewSource(
file.WithPath(path),
))
} | go | func LoadFile(path string) error {
return Load(file.NewSource(
file.WithPath(path),
))
} | [
"func",
"LoadFile",
"(",
"path",
"string",
")",
"error",
"{",
"return",
"Load",
"(",
"file",
".",
"NewSource",
"(",
"file",
".",
"WithPath",
"(",
"path",
")",
",",
")",
")",
"\n",
"}"
] | // LoadFile is short hand for creating a file source and loading it | [
"LoadFile",
"is",
"short",
"hand",
"for",
"creating",
"a",
"file",
"source",
"and",
"loading",
"it"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/config.go#L90-L94 | train |
micro/go-config | source/consul/options.go | WithToken | func WithToken(p string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, tokenKey{}, p)
}
} | go | func WithToken(p string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, tokenKey{}, p)
}
} | [
"func",
"WithToken",
"(",
"p",
"string",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Background",
"(... | // WithToken sets the key token to use | [
"WithToken",
"sets",
"the",
"key",
"token",
"to",
"use"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/consul/options.go#L56-L63 | train |
micro/go-config | loader/memory/memory.go | reload | func (m *memory) reload() error {
m.Lock()
// merge sets
set, err := m.opts.Reader.Merge(m.sets...)
if err != nil {
m.Unlock()
return err
}
// set values
m.vals, _ = m.opts.Reader.Values(set)
m.snap = &loader.Snapshot{
ChangeSet: set,
Version: fmt.Sprintf("%d", time.Now().Unix()),
}
m.Unlock()
// update watchers
m.update()
return nil
} | go | func (m *memory) reload() error {
m.Lock()
// merge sets
set, err := m.opts.Reader.Merge(m.sets...)
if err != nil {
m.Unlock()
return err
}
// set values
m.vals, _ = m.opts.Reader.Values(set)
m.snap = &loader.Snapshot{
ChangeSet: set,
Version: fmt.Sprintf("%d", time.Now().Unix()),
}
m.Unlock()
// update watchers
m.update()
return nil
} | [
"func",
"(",
"m",
"*",
"memory",
")",
"reload",
"(",
")",
"error",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"set",
",",
"err",
":=",
"m",
".",
"opts",
".",
"Reader",
".",
"Merge",
"(",
"m",
".",
"sets",
"...",
")",
"\n",
"if",
"err",
"!=",
"n... | // reload reads the sets and creates new values | [
"reload",
"reads",
"the",
"sets",
"and",
"creates",
"new",
"values"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/loader/memory/memory.go#L130-L153 | train |
micro/go-config | loader/memory/memory.go | Snapshot | func (m *memory) Snapshot() (*loader.Snapshot, error) {
if m.loaded() {
m.RLock()
snap := loader.Copy(m.snap)
m.RUnlock()
return snap, nil
}
// not loaded, sync
if err := m.Sync(); err != nil {
return nil, err
}
// make copy
m.RLock()
snap := loader.Copy(m.snap)
m.RUnlock()
return snap, nil
} | go | func (m *memory) Snapshot() (*loader.Snapshot, error) {
if m.loaded() {
m.RLock()
snap := loader.Copy(m.snap)
m.RUnlock()
return snap, nil
}
// not loaded, sync
if err := m.Sync(); err != nil {
return nil, err
}
// make copy
m.RLock()
snap := loader.Copy(m.snap)
m.RUnlock()
return snap, nil
} | [
"func",
"(",
"m",
"*",
"memory",
")",
"Snapshot",
"(",
")",
"(",
"*",
"loader",
".",
"Snapshot",
",",
"error",
")",
"{",
"if",
"m",
".",
"loaded",
"(",
")",
"{",
"m",
".",
"RLock",
"(",
")",
"\n",
"snap",
":=",
"loader",
".",
"Copy",
"(",
"m"... | // Snapshot returns a snapshot of the current loaded config | [
"Snapshot",
"returns",
"a",
"snapshot",
"of",
"the",
"current",
"loaded",
"config"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/loader/memory/memory.go#L173-L192 | train |
micro/go-config | loader/memory/memory.go | Sync | func (m *memory) Sync() error {
var sets []*source.ChangeSet
m.Lock()
// read the source
var gerr []string
for _, source := range m.sources {
ch, err := source.Read()
if err != nil {
gerr = append(gerr, err.Error())
continue
}
sets = append(sets, ch)
}
// merge sets
set, err := m.opts.Reader.Merge(sets...)
if err != nil {
m.Unlock()
return err
}
// set values
vals, err := m.opts.Reader.Values(set)
if err != nil {
m.Unlock()
return err
}
m.vals = vals
m.snap = &loader.Snapshot{
ChangeSet: set,
Version: fmt.Sprintf("%d", time.Now().Unix()),
}
m.Unlock()
// update watchers
m.update()
if len(gerr) > 0 {
return fmt.Errorf("source loading errors: %s", strings.Join(gerr, "\n"))
}
return nil
} | go | func (m *memory) Sync() error {
var sets []*source.ChangeSet
m.Lock()
// read the source
var gerr []string
for _, source := range m.sources {
ch, err := source.Read()
if err != nil {
gerr = append(gerr, err.Error())
continue
}
sets = append(sets, ch)
}
// merge sets
set, err := m.opts.Reader.Merge(sets...)
if err != nil {
m.Unlock()
return err
}
// set values
vals, err := m.opts.Reader.Values(set)
if err != nil {
m.Unlock()
return err
}
m.vals = vals
m.snap = &loader.Snapshot{
ChangeSet: set,
Version: fmt.Sprintf("%d", time.Now().Unix()),
}
m.Unlock()
// update watchers
m.update()
if len(gerr) > 0 {
return fmt.Errorf("source loading errors: %s", strings.Join(gerr, "\n"))
}
return nil
} | [
"func",
"(",
"m",
"*",
"memory",
")",
"Sync",
"(",
")",
"error",
"{",
"var",
"sets",
"[",
"]",
"*",
"source",
".",
"ChangeSet",
"\n",
"m",
".",
"Lock",
"(",
")",
"\n",
"var",
"gerr",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"source",
":=",
... | // Sync loads all the sources, calls the parser and updates the config | [
"Sync",
"loads",
"all",
"the",
"sources",
"calls",
"the",
"parser",
"and",
"updates",
"the",
"config"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/loader/memory/memory.go#L195-L241 | train |
micro/go-config | source/changeset.go | Sum | func (c *ChangeSet) Sum() string {
h := md5.New()
h.Write(c.Data)
return fmt.Sprintf("%x", h.Sum(nil))
} | go | func (c *ChangeSet) Sum() string {
h := md5.New()
h.Write(c.Data)
return fmt.Sprintf("%x", h.Sum(nil))
} | [
"func",
"(",
"c",
"*",
"ChangeSet",
")",
"Sum",
"(",
")",
"string",
"{",
"h",
":=",
"md5",
".",
"New",
"(",
")",
"\n",
"h",
".",
"Write",
"(",
"c",
".",
"Data",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%x\"",
",",
"h",
".",
"Sum",
... | // Sum returns the md5 checksum of the ChangeSet data | [
"Sum",
"returns",
"the",
"md5",
"checksum",
"of",
"the",
"ChangeSet",
"data"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/changeset.go#L9-L13 | train |
micro/go-config | source/options.go | WithEncoder | func WithEncoder(e encoder.Encoder) Option {
return func(o *Options) {
o.Encoder = e
}
} | go | func WithEncoder(e encoder.Encoder) Option {
return func(o *Options) {
o.Encoder = e
}
} | [
"func",
"WithEncoder",
"(",
"e",
"encoder",
".",
"Encoder",
")",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"Options",
")",
"{",
"o",
".",
"Encoder",
"=",
"e",
"\n",
"}",
"\n",
"}"
] | // WithEncoder sets the source encoder | [
"WithEncoder",
"sets",
"the",
"source",
"encoder"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/options.go#L34-L38 | train |
micro/go-config | options.go | WithLoader | func WithLoader(l loader.Loader) Option {
return func(o *Options) {
o.Loader = l
}
} | go | func WithLoader(l loader.Loader) Option {
return func(o *Options) {
o.Loader = l
}
} | [
"func",
"WithLoader",
"(",
"l",
"loader",
".",
"Loader",
")",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"Options",
")",
"{",
"o",
".",
"Loader",
"=",
"l",
"\n",
"}",
"\n",
"}"
] | // WithLoader sets the loader for manager config | [
"WithLoader",
"sets",
"the",
"loader",
"for",
"manager",
"config"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/options.go#L10-L14 | train |
micro/go-config | source/microcli/cli.go | WithContext | func WithContext(ctx *cli.Context, opts ...source.Option) source.Source {
return &cliSource{
ctx: ctx,
opts: source.NewOptions(opts...),
}
} | go | func WithContext(ctx *cli.Context, opts ...source.Option) source.Source {
return &cliSource{
ctx: ctx,
opts: source.NewOptions(opts...),
}
} | [
"func",
"WithContext",
"(",
"ctx",
"*",
"cli",
".",
"Context",
",",
"opts",
"...",
"source",
".",
"Option",
")",
"source",
".",
"Source",
"{",
"return",
"&",
"cliSource",
"{",
"ctx",
":",
"ctx",
",",
"opts",
":",
"source",
".",
"NewOptions",
"(",
"op... | // WithContext returns a new source with the context specified.
// The assumption is that Context is retrieved within an app.Action function. | [
"WithContext",
"returns",
"a",
"new",
"source",
"with",
"the",
"context",
"specified",
".",
"The",
"assumption",
"is",
"that",
"Context",
"is",
"retrieved",
"within",
"an",
"app",
".",
"Action",
"function",
"."
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/microcli/cli.go#L141-L146 | train |
micro/go-config | loader/memory/options.go | WithSource | func WithSource(s source.Source) loader.Option {
return func(o *loader.Options) {
o.Source = append(o.Source, s)
}
} | go | func WithSource(s source.Source) loader.Option {
return func(o *loader.Options) {
o.Source = append(o.Source, s)
}
} | [
"func",
"WithSource",
"(",
"s",
"source",
".",
"Source",
")",
"loader",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"loader",
".",
"Options",
")",
"{",
"o",
".",
"Source",
"=",
"append",
"(",
"o",
".",
"Source",
",",
"s",
")",
"\n",
"}",... | // WithSource appends a source to list of sources | [
"WithSource",
"appends",
"a",
"source",
"to",
"list",
"of",
"sources"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/loader/memory/options.go#L10-L14 | train |
micro/go-config | loader/memory/options.go | WithReader | func WithReader(r reader.Reader) loader.Option {
return func(o *loader.Options) {
o.Reader = r
}
} | go | func WithReader(r reader.Reader) loader.Option {
return func(o *loader.Options) {
o.Reader = r
}
} | [
"func",
"WithReader",
"(",
"r",
"reader",
".",
"Reader",
")",
"loader",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"loader",
".",
"Options",
")",
"{",
"o",
".",
"Reader",
"=",
"r",
"\n",
"}",
"\n",
"}"
] | // WithReader sets the config reader | [
"WithReader",
"sets",
"the",
"config",
"reader"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/loader/memory/options.go#L17-L21 | train |
micro/go-config | source/consul/consul.go | NewSource | func NewSource(opts ...source.Option) source.Source {
options := source.NewOptions(opts...)
// use default config
config := api.DefaultConfig()
// check if there are any addrs
a, ok := options.Context.Value(addressKey{}).(string)
if ok {
addr, port, err := net.SplitHostPort(a)
if ae, ok := err.(*net.AddrError); ok && ae.Err == "missing port in address" {
port = "8500"
addr = a
config.Address = fmt.Sprintf("%s:%s", addr, port)
} else if err == nil {
config.Address = fmt.Sprintf("%s:%s", addr, port)
}
}
dc, ok := options.Context.Value(dcKey{}).(string)
if ok {
config.Datacenter = dc
}
token, ok := options.Context.Value(tokenKey{}).(string)
if ok {
config.Token = token
}
// create the client
client, _ := api.NewClient(config)
prefix := DefaultPrefix
sp := ""
f, ok := options.Context.Value(prefixKey{}).(string)
if ok {
prefix = f
}
if b, ok := options.Context.Value(stripPrefixKey{}).(bool); ok && b {
sp = prefix
}
return &consul{
prefix: prefix,
stripPrefix: sp,
addr: config.Address,
opts: options,
client: client,
}
} | go | func NewSource(opts ...source.Option) source.Source {
options := source.NewOptions(opts...)
// use default config
config := api.DefaultConfig()
// check if there are any addrs
a, ok := options.Context.Value(addressKey{}).(string)
if ok {
addr, port, err := net.SplitHostPort(a)
if ae, ok := err.(*net.AddrError); ok && ae.Err == "missing port in address" {
port = "8500"
addr = a
config.Address = fmt.Sprintf("%s:%s", addr, port)
} else if err == nil {
config.Address = fmt.Sprintf("%s:%s", addr, port)
}
}
dc, ok := options.Context.Value(dcKey{}).(string)
if ok {
config.Datacenter = dc
}
token, ok := options.Context.Value(tokenKey{}).(string)
if ok {
config.Token = token
}
// create the client
client, _ := api.NewClient(config)
prefix := DefaultPrefix
sp := ""
f, ok := options.Context.Value(prefixKey{}).(string)
if ok {
prefix = f
}
if b, ok := options.Context.Value(stripPrefixKey{}).(bool); ok && b {
sp = prefix
}
return &consul{
prefix: prefix,
stripPrefix: sp,
addr: config.Address,
opts: options,
client: client,
}
} | [
"func",
"NewSource",
"(",
"opts",
"...",
"source",
".",
"Option",
")",
"source",
".",
"Source",
"{",
"options",
":=",
"source",
".",
"NewOptions",
"(",
"opts",
"...",
")",
"\n",
"config",
":=",
"api",
".",
"DefaultConfig",
"(",
")",
"\n",
"a",
",",
"... | // NewSource creates a new consul source | [
"NewSource",
"creates",
"a",
"new",
"consul",
"source"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/consul/consul.go#L71-L121 | train |
micro/go-config | source/vault/options.go | WithResourcePath | func WithResourcePath(p string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, resourcePath{}, p)
}
} | go | func WithResourcePath(p string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, resourcePath{}, p)
}
} | [
"func",
"WithResourcePath",
"(",
"p",
"string",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Background... | // WithResourcePath sets the resource that will be access | [
"WithResourcePath",
"sets",
"the",
"resource",
"that",
"will",
"be",
"access"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/vault/options.go#L26-L33 | train |
micro/go-config | source/vault/options.go | WithNameSpace | func WithNameSpace(n string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, nameSpace{}, n)
}
} | go | func WithNameSpace(n string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, nameSpace{}, n)
}
} | [
"func",
"WithNameSpace",
"(",
"n",
"string",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Background",
... | // WithNameSpace sets the namespace that its going to be access | [
"WithNameSpace",
"sets",
"the",
"namespace",
"that",
"its",
"going",
"to",
"be",
"access"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/vault/options.go#L36-L43 | train |
micro/go-config | source/vault/options.go | WithSecretName | func WithSecretName(t string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, secretName{}, t)
}
} | go | func WithSecretName(t string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, secretName{}, t)
}
} | [
"func",
"WithSecretName",
"(",
"t",
"string",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Background",... | // WithSecretName sets the name of the secret to wrap in on a map | [
"WithSecretName",
"sets",
"the",
"name",
"of",
"the",
"secret",
"to",
"wrap",
"in",
"on",
"a",
"map"
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/vault/options.go#L56-L63 | train |
micro/go-config | source/flag/options.go | IncludeUnset | func IncludeUnset(b bool) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, includeUnsetKey{}, true)
}
} | go | func IncludeUnset(b bool) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, includeUnsetKey{}, true)
}
} | [
"func",
"IncludeUnset",
"(",
"b",
"bool",
")",
"source",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"source",
".",
"Options",
")",
"{",
"if",
"o",
".",
"Context",
"==",
"nil",
"{",
"o",
".",
"Context",
"=",
"context",
".",
"Background",
"... | // IncludeUnset toggles the loading of unset flags and their respective default values.
// Default behavior is to ignore any unset flags. | [
"IncludeUnset",
"toggles",
"the",
"loading",
"of",
"unset",
"flags",
"and",
"their",
"respective",
"default",
"values",
".",
"Default",
"behavior",
"is",
"to",
"ignore",
"any",
"unset",
"flags",
"."
] | bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5 | https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/flag/options.go#L13-L20 | train |
andygrunwald/go-jira | user.go | WithMaxResults | func WithMaxResults(maxResults int) userSearchF {
return func(s userSearch) userSearch {
s = append(s, userSearchParam{name: "maxResults", value: fmt.Sprintf("%d", maxResults)})
return s
}
} | go | func WithMaxResults(maxResults int) userSearchF {
return func(s userSearch) userSearch {
s = append(s, userSearchParam{name: "maxResults", value: fmt.Sprintf("%d", maxResults)})
return s
}
} | [
"func",
"WithMaxResults",
"(",
"maxResults",
"int",
")",
"userSearchF",
"{",
"return",
"func",
"(",
"s",
"userSearch",
")",
"userSearch",
"{",
"s",
"=",
"append",
"(",
"s",
",",
"userSearchParam",
"{",
"name",
":",
"\"maxResults\"",
",",
"value",
":",
"fmt... | // WithMaxResults sets the max results to return | [
"WithMaxResults",
"sets",
"the",
"max",
"results",
"to",
"return"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/user.go#L150-L155 | train |
andygrunwald/go-jira | user.go | WithStartAt | func WithStartAt(startAt int) userSearchF {
return func(s userSearch) userSearch {
s = append(s, userSearchParam{name: "startAt", value: fmt.Sprintf("%d", startAt)})
return s
}
} | go | func WithStartAt(startAt int) userSearchF {
return func(s userSearch) userSearch {
s = append(s, userSearchParam{name: "startAt", value: fmt.Sprintf("%d", startAt)})
return s
}
} | [
"func",
"WithStartAt",
"(",
"startAt",
"int",
")",
"userSearchF",
"{",
"return",
"func",
"(",
"s",
"userSearch",
")",
"userSearch",
"{",
"s",
"=",
"append",
"(",
"s",
",",
"userSearchParam",
"{",
"name",
":",
"\"startAt\"",
",",
"value",
":",
"fmt",
".",... | // WithStartAt set the start pager | [
"WithStartAt",
"set",
"the",
"start",
"pager"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/user.go#L158-L163 | train |
andygrunwald/go-jira | user.go | WithActive | func WithActive(active bool) userSearchF {
return func(s userSearch) userSearch {
s = append(s, userSearchParam{name: "includeActive", value: fmt.Sprintf("%t", active)})
return s
}
} | go | func WithActive(active bool) userSearchF {
return func(s userSearch) userSearch {
s = append(s, userSearchParam{name: "includeActive", value: fmt.Sprintf("%t", active)})
return s
}
} | [
"func",
"WithActive",
"(",
"active",
"bool",
")",
"userSearchF",
"{",
"return",
"func",
"(",
"s",
"userSearch",
")",
"userSearch",
"{",
"s",
"=",
"append",
"(",
"s",
",",
"userSearchParam",
"{",
"name",
":",
"\"includeActive\"",
",",
"value",
":",
"fmt",
... | // WithActive sets the active users lookup | [
"WithActive",
"sets",
"the",
"active",
"users",
"lookup"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/user.go#L166-L171 | train |
andygrunwald/go-jira | user.go | WithInactive | func WithInactive(inactive bool) userSearchF {
return func(s userSearch) userSearch {
s = append(s, userSearchParam{name: "includeInactive", value: fmt.Sprintf("%t", inactive)})
return s
}
} | go | func WithInactive(inactive bool) userSearchF {
return func(s userSearch) userSearch {
s = append(s, userSearchParam{name: "includeInactive", value: fmt.Sprintf("%t", inactive)})
return s
}
} | [
"func",
"WithInactive",
"(",
"inactive",
"bool",
")",
"userSearchF",
"{",
"return",
"func",
"(",
"s",
"userSearch",
")",
"userSearch",
"{",
"s",
"=",
"append",
"(",
"s",
",",
"userSearchParam",
"{",
"name",
":",
"\"includeInactive\"",
",",
"value",
":",
"f... | // WithInactive sets the inactive users lookup | [
"WithInactive",
"sets",
"the",
"inactive",
"users",
"lookup"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/user.go#L174-L179 | train |
andygrunwald/go-jira | metaissue.go | GetCreateMeta | func (s *IssueService) GetCreateMeta(projectkeys string) (*CreateMetaInfo, *Response, error) {
return s.GetCreateMetaWithOptions(&GetQueryOptions{ProjectKeys: projectkeys, Expand: "projects.issuetypes.fields"})
} | go | func (s *IssueService) GetCreateMeta(projectkeys string) (*CreateMetaInfo, *Response, error) {
return s.GetCreateMetaWithOptions(&GetQueryOptions{ProjectKeys: projectkeys, Expand: "projects.issuetypes.fields"})
} | [
"func",
"(",
"s",
"*",
"IssueService",
")",
"GetCreateMeta",
"(",
"projectkeys",
"string",
")",
"(",
"*",
"CreateMetaInfo",
",",
"*",
"Response",
",",
"error",
")",
"{",
"return",
"s",
".",
"GetCreateMetaWithOptions",
"(",
"&",
"GetQueryOptions",
"{",
"Proje... | // GetCreateMeta makes the api call to get the meta information required to create a ticket | [
"GetCreateMeta",
"makes",
"the",
"api",
"call",
"to",
"get",
"the",
"meta",
"information",
"required",
"to",
"create",
"a",
"ticket"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/metaissue.go#L46-L48 | train |
andygrunwald/go-jira | metaissue.go | GetCreateMetaWithOptions | func (s *IssueService) GetCreateMetaWithOptions(options *GetQueryOptions) (*CreateMetaInfo, *Response, error) {
apiEndpoint := "rest/api/2/issue/createmeta"
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
if options != nil {
q, err := query.Values(options)
if err != nil {
return nil, nil, err
}
req.URL.RawQuery = q.Encode()
}
meta := new(CreateMetaInfo)
resp, err := s.client.Do(req, meta)
if err != nil {
return nil, resp, err
}
return meta, resp, nil
} | go | func (s *IssueService) GetCreateMetaWithOptions(options *GetQueryOptions) (*CreateMetaInfo, *Response, error) {
apiEndpoint := "rest/api/2/issue/createmeta"
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
if options != nil {
q, err := query.Values(options)
if err != nil {
return nil, nil, err
}
req.URL.RawQuery = q.Encode()
}
meta := new(CreateMetaInfo)
resp, err := s.client.Do(req, meta)
if err != nil {
return nil, resp, err
}
return meta, resp, nil
} | [
"func",
"(",
"s",
"*",
"IssueService",
")",
"GetCreateMetaWithOptions",
"(",
"options",
"*",
"GetQueryOptions",
")",
"(",
"*",
"CreateMetaInfo",
",",
"*",
"Response",
",",
"error",
")",
"{",
"apiEndpoint",
":=",
"\"rest/api/2/issue/createmeta\"",
"\n",
"req",
",... | // GetCreateMetaWithOptions makes the api call to get the meta information without requiring to have a projectKey | [
"GetCreateMetaWithOptions",
"makes",
"the",
"api",
"call",
"to",
"get",
"the",
"meta",
"information",
"without",
"requiring",
"to",
"have",
"a",
"projectKey"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/metaissue.go#L51-L74 | train |
andygrunwald/go-jira | metaissue.go | GetProjectWithName | func (m *CreateMetaInfo) GetProjectWithName(name string) *MetaProject {
for _, m := range m.Projects {
if strings.ToLower(m.Name) == strings.ToLower(name) {
return m
}
}
return nil
} | go | func (m *CreateMetaInfo) GetProjectWithName(name string) *MetaProject {
for _, m := range m.Projects {
if strings.ToLower(m.Name) == strings.ToLower(name) {
return m
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"CreateMetaInfo",
")",
"GetProjectWithName",
"(",
"name",
"string",
")",
"*",
"MetaProject",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"m",
".",
"Projects",
"{",
"if",
"strings",
".",
"ToLower",
"(",
"m",
".",
"Name",
")",
"=="... | // GetProjectWithName returns a project with "name" from the meta information received. If not found, this returns nil.
// The comparison of the name is case insensitive. | [
"GetProjectWithName",
"returns",
"a",
"project",
"with",
"name",
"from",
"the",
"meta",
"information",
"received",
".",
"If",
"not",
"found",
"this",
"returns",
"nil",
".",
"The",
"comparison",
"of",
"the",
"name",
"is",
"case",
"insensitive",
"."
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/metaissue.go#L78-L85 | train |
andygrunwald/go-jira | metaissue.go | GetProjectWithKey | func (m *CreateMetaInfo) GetProjectWithKey(key string) *MetaProject {
for _, m := range m.Projects {
if strings.ToLower(m.Key) == strings.ToLower(key) {
return m
}
}
return nil
} | go | func (m *CreateMetaInfo) GetProjectWithKey(key string) *MetaProject {
for _, m := range m.Projects {
if strings.ToLower(m.Key) == strings.ToLower(key) {
return m
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"CreateMetaInfo",
")",
"GetProjectWithKey",
"(",
"key",
"string",
")",
"*",
"MetaProject",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"m",
".",
"Projects",
"{",
"if",
"strings",
".",
"ToLower",
"(",
"m",
".",
"Key",
")",
"==",
... | // GetProjectWithKey returns a project with "name" from the meta information received. If not found, this returns nil.
// The comparison of the name is case insensitive. | [
"GetProjectWithKey",
"returns",
"a",
"project",
"with",
"name",
"from",
"the",
"meta",
"information",
"received",
".",
"If",
"not",
"found",
"this",
"returns",
"nil",
".",
"The",
"comparison",
"of",
"the",
"name",
"is",
"case",
"insensitive",
"."
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/metaissue.go#L89-L96 | train |
andygrunwald/go-jira | metaissue.go | GetIssueTypeWithName | func (p *MetaProject) GetIssueTypeWithName(name string) *MetaIssueType {
for _, m := range p.IssueTypes {
if strings.ToLower(m.Name) == strings.ToLower(name) {
return m
}
}
return nil
} | go | func (p *MetaProject) GetIssueTypeWithName(name string) *MetaIssueType {
for _, m := range p.IssueTypes {
if strings.ToLower(m.Name) == strings.ToLower(name) {
return m
}
}
return nil
} | [
"func",
"(",
"p",
"*",
"MetaProject",
")",
"GetIssueTypeWithName",
"(",
"name",
"string",
")",
"*",
"MetaIssueType",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"p",
".",
"IssueTypes",
"{",
"if",
"strings",
".",
"ToLower",
"(",
"m",
".",
"Name",
")",
"... | // GetIssueTypeWithName returns an IssueType with name from a given MetaProject. If not found, this returns nil.
// The comparison of the name is case insensitive | [
"GetIssueTypeWithName",
"returns",
"an",
"IssueType",
"with",
"name",
"from",
"a",
"given",
"MetaProject",
".",
"If",
"not",
"found",
"this",
"returns",
"nil",
".",
"The",
"comparison",
"of",
"the",
"name",
"is",
"case",
"insensitive"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/metaissue.go#L100-L107 | train |
andygrunwald/go-jira | metaissue.go | GetAllFields | func (t *MetaIssueType) GetAllFields() (map[string]string, error) {
ret := make(map[string]string)
for key := range t.Fields {
name, err := t.Fields.String(key + "/name")
if err != nil {
return nil, err
}
ret[name] = key
}
return ret, nil
} | go | func (t *MetaIssueType) GetAllFields() (map[string]string, error) {
ret := make(map[string]string)
for key := range t.Fields {
name, err := t.Fields.String(key + "/name")
if err != nil {
return nil, err
}
ret[name] = key
}
return ret, nil
} | [
"func",
"(",
"t",
"*",
"MetaIssueType",
")",
"GetAllFields",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"ret",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"for",
"key",
":=",
"range",
"t",
"... | // GetAllFields returns a map of all the fields for an IssueType. This includes all required and not required.
// The key of the returned map is what you see in the form and the value is how it is representated in the jira schema. | [
"GetAllFields",
"returns",
"a",
"map",
"of",
"all",
"the",
"fields",
"for",
"an",
"IssueType",
".",
"This",
"includes",
"all",
"required",
"and",
"not",
"required",
".",
"The",
"key",
"of",
"the",
"returned",
"map",
"is",
"what",
"you",
"see",
"in",
"the... | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/metaissue.go#L146-L157 | train |
andygrunwald/go-jira | metaissue.go | CheckCompleteAndAvailable | func (t *MetaIssueType) CheckCompleteAndAvailable(config map[string]string) (bool, error) {
mandatory, err := t.GetMandatoryFields()
if err != nil {
return false, err
}
all, err := t.GetAllFields()
if err != nil {
return false, err
}
// check templateconfig against mandatory fields
for key := range mandatory {
if _, okay := config[key]; !okay {
var requiredFields []string
for name := range mandatory {
requiredFields = append(requiredFields, name)
}
return false, fmt.Errorf("Required field not found in provided jira.fields. Required are: %#v", requiredFields)
}
}
// check templateConfig against all fields to verify they are available
for key := range config {
if _, okay := all[key]; !okay {
var availableFields []string
for name := range all {
availableFields = append(availableFields, name)
}
return false, fmt.Errorf("Fields in jira.fields are not available in jira. Available are: %#v", availableFields)
}
}
return true, nil
} | go | func (t *MetaIssueType) CheckCompleteAndAvailable(config map[string]string) (bool, error) {
mandatory, err := t.GetMandatoryFields()
if err != nil {
return false, err
}
all, err := t.GetAllFields()
if err != nil {
return false, err
}
// check templateconfig against mandatory fields
for key := range mandatory {
if _, okay := config[key]; !okay {
var requiredFields []string
for name := range mandatory {
requiredFields = append(requiredFields, name)
}
return false, fmt.Errorf("Required field not found in provided jira.fields. Required are: %#v", requiredFields)
}
}
// check templateConfig against all fields to verify they are available
for key := range config {
if _, okay := all[key]; !okay {
var availableFields []string
for name := range all {
availableFields = append(availableFields, name)
}
return false, fmt.Errorf("Fields in jira.fields are not available in jira. Available are: %#v", availableFields)
}
}
return true, nil
} | [
"func",
"(",
"t",
"*",
"MetaIssueType",
")",
"CheckCompleteAndAvailable",
"(",
"config",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"mandatory",
",",
"err",
":=",
"t",
".",
"GetMandatoryFields",
"(",
")",
"\n",
"if",
... | // CheckCompleteAndAvailable checks if the given fields satisfies the mandatory field required to create a issue for the given type
// And also if the given fields are available. | [
"CheckCompleteAndAvailable",
"checks",
"if",
"the",
"given",
"fields",
"satisfies",
"the",
"mandatory",
"field",
"required",
"to",
"create",
"a",
"issue",
"for",
"the",
"given",
"type",
"And",
"also",
"if",
"the",
"given",
"fields",
"are",
"available",
"."
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/metaissue.go#L161-L194 | train |
andygrunwald/go-jira | component.go | Create | func (s *ComponentService) Create(options *CreateComponentOptions) (*ProjectComponent, *Response, error) {
apiEndpoint := "rest/api/2/component"
req, err := s.client.NewRequest("POST", apiEndpoint, options)
if err != nil {
return nil, nil, err
}
component := new(ProjectComponent)
resp, err := s.client.Do(req, component)
if err != nil {
return nil, resp, NewJiraError(resp, err)
}
return component, resp, nil
} | go | func (s *ComponentService) Create(options *CreateComponentOptions) (*ProjectComponent, *Response, error) {
apiEndpoint := "rest/api/2/component"
req, err := s.client.NewRequest("POST", apiEndpoint, options)
if err != nil {
return nil, nil, err
}
component := new(ProjectComponent)
resp, err := s.client.Do(req, component)
if err != nil {
return nil, resp, NewJiraError(resp, err)
}
return component, resp, nil
} | [
"func",
"(",
"s",
"*",
"ComponentService",
")",
"Create",
"(",
"options",
"*",
"CreateComponentOptions",
")",
"(",
"*",
"ProjectComponent",
",",
"*",
"Response",
",",
"error",
")",
"{",
"apiEndpoint",
":=",
"\"rest/api/2/component\"",
"\n",
"req",
",",
"err",
... | // Create creates a new JIRA component based on the given options. | [
"Create",
"creates",
"a",
"new",
"JIRA",
"component",
"based",
"on",
"the",
"given",
"options",
"."
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/component.go#L23-L38 | train |
andygrunwald/go-jira | issue.go | DownloadAttachment | func (s *IssueService) DownloadAttachment(attachmentID string) (*Response, error) {
apiEndpoint := fmt.Sprintf("secure/attachment/%s/", attachmentID)
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
jerr := NewJiraError(resp, err)
return resp, jerr
}
return resp, nil
} | go | func (s *IssueService) DownloadAttachment(attachmentID string) (*Response, error) {
apiEndpoint := fmt.Sprintf("secure/attachment/%s/", attachmentID)
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
jerr := NewJiraError(resp, err)
return resp, jerr
}
return resp, nil
} | [
"func",
"(",
"s",
"*",
"IssueService",
")",
"DownloadAttachment",
"(",
"attachmentID",
"string",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"apiEndpoint",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"secure/attachment/%s/\"",
",",
"attachmentID",
")",
"\n",
... | // DownloadAttachment returns a Response of an attachment for a given attachmentID.
// The attachment is in the Response.Body of the response.
// This is an io.ReadCloser.
// The caller should close the resp.Body. | [
"DownloadAttachment",
"returns",
"a",
"Response",
"of",
"an",
"attachment",
"for",
"a",
"given",
"attachmentID",
".",
"The",
"attachment",
"is",
"in",
"the",
"Response",
".",
"Body",
"of",
"the",
"response",
".",
"This",
"is",
"an",
"io",
".",
"ReadCloser",
... | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/issue.go#L571-L585 | train |
andygrunwald/go-jira | issue.go | Delete | func (s *IssueService) Delete(issueID string) (*Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s", issueID)
// to enable deletion of subtasks; without this, the request will fail if the issue has subtasks
deletePayload := make(map[string]interface{})
deletePayload["deleteSubtasks"] = "true"
content, _ := json.Marshal(deletePayload)
req, err := s.client.NewRequest("DELETE", apiEndpoint, content)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
return resp, err
} | go | func (s *IssueService) Delete(issueID string) (*Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s", issueID)
// to enable deletion of subtasks; without this, the request will fail if the issue has subtasks
deletePayload := make(map[string]interface{})
deletePayload["deleteSubtasks"] = "true"
content, _ := json.Marshal(deletePayload)
req, err := s.client.NewRequest("DELETE", apiEndpoint, content)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
return resp, err
} | [
"func",
"(",
"s",
"*",
"IssueService",
")",
"Delete",
"(",
"issueID",
"string",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"apiEndpoint",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"rest/api/2/issue/%s\"",
",",
"issueID",
")",
"\n",
"deletePayload",
":=",... | // Delete will delete a specified issue. | [
"Delete",
"will",
"delete",
"a",
"specified",
"issue",
"."
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/issue.go#L1059-L1074 | train |
andygrunwald/go-jira | authentication.go | Authenticated | func (s *AuthenticationService) Authenticated() bool {
if s != nil {
if s.authType == authTypeSession {
return s.client.session != nil
} else if s.authType == authTypeBasic {
return s.username != ""
}
}
return false
} | go | func (s *AuthenticationService) Authenticated() bool {
if s != nil {
if s.authType == authTypeSession {
return s.client.session != nil
} else if s.authType == authTypeBasic {
return s.username != ""
}
}
return false
} | [
"func",
"(",
"s",
"*",
"AuthenticationService",
")",
"Authenticated",
"(",
")",
"bool",
"{",
"if",
"s",
"!=",
"nil",
"{",
"if",
"s",
".",
"authType",
"==",
"authTypeSession",
"{",
"return",
"s",
".",
"client",
".",
"session",
"!=",
"nil",
"\n",
"}",
... | // Authenticated reports if the current Client has authentication details for JIRA | [
"Authenticated",
"reports",
"if",
"the",
"current",
"Client",
"has",
"authentication",
"details",
"for",
"JIRA"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/authentication.go#L104-L114 | train |
andygrunwald/go-jira | filter.go | GetList | func (fs *FilterService) GetList() ([]*Filter, *Response, error) {
options := &GetQueryOptions{}
apiEndpoint := "rest/api/2/filter"
req, err := fs.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
if options != nil {
q, err := query.Values(options)
if err != nil {
return nil, nil, err
}
req.URL.RawQuery = q.Encode()
}
filters := []*Filter{}
resp, err := fs.client.Do(req, &filters)
if err != nil {
jerr := NewJiraError(resp, err)
return nil, resp, jerr
}
return filters, resp, err
} | go | func (fs *FilterService) GetList() ([]*Filter, *Response, error) {
options := &GetQueryOptions{}
apiEndpoint := "rest/api/2/filter"
req, err := fs.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
if options != nil {
q, err := query.Values(options)
if err != nil {
return nil, nil, err
}
req.URL.RawQuery = q.Encode()
}
filters := []*Filter{}
resp, err := fs.client.Do(req, &filters)
if err != nil {
jerr := NewJiraError(resp, err)
return nil, resp, jerr
}
return filters, resp, err
} | [
"func",
"(",
"fs",
"*",
"FilterService",
")",
"GetList",
"(",
")",
"(",
"[",
"]",
"*",
"Filter",
",",
"*",
"Response",
",",
"error",
")",
"{",
"options",
":=",
"&",
"GetQueryOptions",
"{",
"}",
"\n",
"apiEndpoint",
":=",
"\"rest/api/2/filter\"",
"\n",
... | // GetList retrieves all filters from Jira | [
"GetList",
"retrieves",
"all",
"filters",
"from",
"Jira"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/filter.go#L36-L60 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.