repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
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",
"(",
"\"",
"\"",
... | // 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.mess... | 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.mess... | [
"func",
"(",
"m",
"*",
"OutgoingMessage",
")",
"Send",
"(",
")",
"error",
"{",
"if",
"m",
".",
"ChatID",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"m",
".",
"BotID",
"==",
"0",
"{",
"return",... | // 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",
"(",
"\"",
"\"",
",",
"md5",
".",
"Sum",
"(",
"[",
"]",
"byte",
"(",
"m",
".",
"Tex... | // 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{"$ad... | 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{"$ad... | [
"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",
"(",
"\"",
"\"",
")",
".",
"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)
}
... | 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)
}
... | [
"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",
".",
"Valu... | // 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",
"(",
"\"",
"\... | // 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 ... | 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 ... | [
"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
}
de... | 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
}
de... | [
"func",
"rename",
"(",
"src",
",",
"dest",
"string",
")",
"error",
"{",
"// Try to rename generated source.",
"if",
"err",
":=",
"os",
".",
"Rename",
"(",
"src",
",",
"dest",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"// If t... | // 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.WriteByt... | 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.WriteByt... | [
"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... | 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... | [
"func",
"New",
"(",
")",
"(",
"http",
".",
"FileSystem",
",",
"error",
")",
"{",
"if",
"zipData",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"zipReader",
",",
"err",
":=",
"zip",
".... | // 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",
"i... | // 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 ... | 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 ... | [
"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); n... | 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); n... | [
"func",
"NewSource",
"(",
"opts",
"...",
"source",
".",
"Option",
")",
"source",
".",
"Source",
"{",
"options",
":=",
"source",
".",
"NewOptions",
"(",
"opts",
"...",
")",
"\n\n",
"// create the client",
"client",
",",
"_",
":=",
"api",
".",
"NewClient",
... | // 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... | 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... | [
"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()
... | 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()
... | [
"func",
"(",
"m",
"*",
"memory",
")",
"reload",
"(",
")",
"error",
"{",
"m",
".",
"Lock",
"(",
")",
"\n\n",
"// merge sets",
"set",
",",
"err",
":=",
"m",
".",
"opts",
".",
"Reader",
".",
"Merge",
"(",
"m",
".",
"sets",
"...",
")",
"\n",
"if",
... | // 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.M... | 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.M... | [
"func",
"(",
"m",
"*",
"memory",
")",
"Sync",
"(",
")",
"error",
"{",
"var",
"sets",
"[",
"]",
"*",
"source",
".",
"ChangeSet",
"\n\n",
"m",
".",
"Lock",
"(",
")",
"\n\n",
"// read the source",
"var",
"gerr",
"[",
"]",
"string",
"\n\n",
"for",
"_",... | // 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",
"(",
"\"",
"\"",
",",
"h",
".",
"Su... | // 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.AddrErr... | 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.AddrErr... | [
"func",
"NewSource",
"(",
"opts",
"...",
"source",
".",
"Option",
")",
"source",
".",
"Source",
"{",
"options",
":=",
"source",
".",
"NewOptions",
"(",
"opts",
"...",
")",
"\n\n",
"// use default config",
"config",
":=",
"api",
".",
"DefaultConfig",
"(",
"... | // 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",
":",
"\"",
"\"",
",",
"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",
":",
"\"",
"\"",
",",
"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",
":",
"\"",
"\"",
",",
"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",
":",
"\"",
"\"",
",",
"value",
":",
"fmt",
".... | // 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 ... | 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 ... | [
"func",
"(",
"s",
"*",
"IssueService",
")",
"GetCreateMetaWithOptions",
"(",
"options",
"*",
"GetQueryOptions",
")",
"(",
"*",
"CreateMetaInfo",
",",
"*",
"Response",
",",
"error",
")",
"{",
"apiEndpoint",
":=",
"\"",
"\"",
"\n\n",
"req",
",",
"err",
":=",... | // 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 mandato... | 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 mandato... | [
"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, ... | 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, ... | [
"func",
"(",
"s",
"*",
"ComponentService",
")",
"Create",
"(",
"options",
"*",
"CreateComponentOptions",
")",
"(",
"*",
"ProjectComponent",
",",
"*",
"Response",
",",
"error",
")",
"{",
"apiEndpoint",
":=",
"\"",
"\"",
"\n",
"req",
",",
"err",
":=",
"s",... | // 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 := NewJiraEr... | 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 := NewJiraEr... | [
"func",
"(",
"s",
"*",
"IssueService",
")",
"DownloadAttachment",
"(",
"attachmentID",
"string",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"apiEndpoint",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"attachmentID",
")",
"\n",
"req",
",",
... | // 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"
cont... | 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"
cont... | [
"func",
"(",
"s",
"*",
"IssueService",
")",
"Delete",
"(",
"issueID",
"string",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"apiEndpoint",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"issueID",
")",
"\n\n",
"// to enable deletion of subtasks;... | // 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... | 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... | [
"func",
"(",
"fs",
"*",
"FilterService",
")",
"GetList",
"(",
")",
"(",
"[",
"]",
"*",
"Filter",
",",
"*",
"Response",
",",
"error",
")",
"{",
"options",
":=",
"&",
"GetQueryOptions",
"{",
"}",
"\n",
"apiEndpoint",
":=",
"\"",
"\"",
"\n",
"req",
",... | // 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 |
andygrunwald/go-jira | filter.go | GetFavouriteList | func (fs *FilterService) GetFavouriteList() ([]*Filter, *Response, error) {
apiEndpoint := "rest/api/2/filter/favourite"
req, err := fs.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
filters := []*Filter{}
resp, err := fs.client.Do(req, &filters)
if err != nil {
jerr := New... | go | func (fs *FilterService) GetFavouriteList() ([]*Filter, *Response, error) {
apiEndpoint := "rest/api/2/filter/favourite"
req, err := fs.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
filters := []*Filter{}
resp, err := fs.client.Do(req, &filters)
if err != nil {
jerr := New... | [
"func",
"(",
"fs",
"*",
"FilterService",
")",
"GetFavouriteList",
"(",
")",
"(",
"[",
"]",
"*",
"Filter",
",",
"*",
"Response",
",",
"error",
")",
"{",
"apiEndpoint",
":=",
"\"",
"\"",
"\n",
"req",
",",
"err",
":=",
"fs",
".",
"client",
".",
"NewRe... | // GetFavouriteList retrieves the user's favourited filters from Jira | [
"GetFavouriteList",
"retrieves",
"the",
"user",
"s",
"favourited",
"filters",
"from",
"Jira"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/filter.go#L63-L76 | train |
andygrunwald/go-jira | filter.go | Get | func (fs *FilterService) Get(filterID int) (*Filter, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/filter/%d", filterID)
req, err := fs.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
filter := new(Filter)
resp, err := fs.client.Do(req, filter)
if err != nil {
j... | go | func (fs *FilterService) Get(filterID int) (*Filter, *Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/filter/%d", filterID)
req, err := fs.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
filter := new(Filter)
resp, err := fs.client.Do(req, filter)
if err != nil {
j... | [
"func",
"(",
"fs",
"*",
"FilterService",
")",
"Get",
"(",
"filterID",
"int",
")",
"(",
"*",
"Filter",
",",
"*",
"Response",
",",
"error",
")",
"{",
"apiEndpoint",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"filterID",
")",
"\n",
"req",
",",... | // Get retrieves a single Filter from Jira | [
"Get",
"retrieves",
"a",
"single",
"Filter",
"from",
"Jira"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/filter.go#L79-L93 | train |
andygrunwald/go-jira | error.go | NewJiraError | func NewJiraError(resp *Response, httpError error) error {
if resp == nil {
return errors.Wrap(httpError, "No response returned")
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return errors.Wrap(err, httpError.Error())
}
jerr := Error{HTTPError: httpError}
contentType := ... | go | func NewJiraError(resp *Response, httpError error) error {
if resp == nil {
return errors.Wrap(httpError, "No response returned")
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return errors.Wrap(err, httpError.Error())
}
jerr := Error{HTTPError: httpError}
contentType := ... | [
"func",
"NewJiraError",
"(",
"resp",
"*",
"Response",
",",
"httpError",
"error",
")",
"error",
"{",
"if",
"resp",
"==",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"httpError",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"defer",
"resp",
".",
"Bod... | // NewJiraError creates a new jira Error | [
"NewJiraError",
"creates",
"a",
"new",
"jira",
"Error"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/error.go#L22-L48 | train |
andygrunwald/go-jira | error.go | Error | func (e *Error) Error() string {
if len(e.ErrorMessages) > 0 {
// return fmt.Sprintf("%v", e.HTTPError)
return fmt.Sprintf("%s: %v", e.ErrorMessages[0], e.HTTPError)
}
if len(e.Errors) > 0 {
for key, value := range e.Errors {
return fmt.Sprintf("%s - %s: %v", key, value, e.HTTPError)
}
}
return e.HTTPEr... | go | func (e *Error) Error() string {
if len(e.ErrorMessages) > 0 {
// return fmt.Sprintf("%v", e.HTTPError)
return fmt.Sprintf("%s: %v", e.ErrorMessages[0], e.HTTPError)
}
if len(e.Errors) > 0 {
for key, value := range e.Errors {
return fmt.Sprintf("%s - %s: %v", key, value, e.HTTPError)
}
}
return e.HTTPEr... | [
"func",
"(",
"e",
"*",
"Error",
")",
"Error",
"(",
")",
"string",
"{",
"if",
"len",
"(",
"e",
".",
"ErrorMessages",
")",
">",
"0",
"{",
"// return fmt.Sprintf(\"%v\", e.HTTPError)",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"Erro... | // Error is a short string representing the error | [
"Error",
"is",
"a",
"short",
"string",
"representing",
"the",
"error"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/error.go#L51-L62 | train |
andygrunwald/go-jira | error.go | LongError | func (e *Error) LongError() string {
var msg bytes.Buffer
if e.HTTPError != nil {
msg.WriteString("Original:\n")
msg.WriteString(e.HTTPError.Error())
msg.WriteString("\n")
}
if len(e.ErrorMessages) > 0 {
msg.WriteString("Messages:\n")
for _, v := range e.ErrorMessages {
msg.WriteString(" - ")
msg.Wr... | go | func (e *Error) LongError() string {
var msg bytes.Buffer
if e.HTTPError != nil {
msg.WriteString("Original:\n")
msg.WriteString(e.HTTPError.Error())
msg.WriteString("\n")
}
if len(e.ErrorMessages) > 0 {
msg.WriteString("Messages:\n")
for _, v := range e.ErrorMessages {
msg.WriteString(" - ")
msg.Wr... | [
"func",
"(",
"e",
"*",
"Error",
")",
"LongError",
"(",
")",
"string",
"{",
"var",
"msg",
"bytes",
".",
"Buffer",
"\n",
"if",
"e",
".",
"HTTPError",
"!=",
"nil",
"{",
"msg",
".",
"WriteString",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"msg",
".",
"Write... | // LongError is a full representation of the error as a string | [
"LongError",
"is",
"a",
"full",
"representation",
"of",
"the",
"error",
"as",
"a",
"string"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/error.go#L65-L90 | train |
andygrunwald/go-jira | jira.go | NewRequest | func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error) {
rel, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
// Relative URLs should be specified without a preceding slash since baseURL will have the trailing slash
rel.Path = strings.TrimLeft(rel.Path, "/")
u :=... | go | func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error) {
rel, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
// Relative URLs should be specified without a preceding slash since baseURL will have the trailing slash
rel.Path = strings.TrimLeft(rel.Path, "/")
u :=... | [
"func",
"(",
"c",
"*",
"Client",
")",
"NewRequest",
"(",
"method",
",",
"urlStr",
"string",
",",
"body",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"rel",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"url... | // NewRequest creates an API request.
// A relative URL can be provided in urlStr, in which case it is resolved relative to the baseURL of the Client.
// If specified, the value pointed to by body is JSON encoded and included as the request body. | [
"NewRequest",
"creates",
"an",
"API",
"request",
".",
"A",
"relative",
"URL",
"can",
"be",
"provided",
"in",
"urlStr",
"in",
"which",
"case",
"it",
"is",
"resolved",
"relative",
"to",
"the",
"baseURL",
"of",
"the",
"Client",
".",
"If",
"specified",
"the",
... | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/jira.go#L131-L173 | train |
andygrunwald/go-jira | jira.go | RoundTrip | func (t *BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) {
req2 := cloneRequest(req) // per RoundTripper contract
req2.SetBasicAuth(t.Username, t.Password)
return t.transport().RoundTrip(req2)
} | go | func (t *BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) {
req2 := cloneRequest(req) // per RoundTripper contract
req2.SetBasicAuth(t.Username, t.Password)
return t.transport().RoundTrip(req2)
} | [
"func",
"(",
"t",
"*",
"BasicAuthTransport",
")",
"RoundTrip",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"req2",
":=",
"cloneRequest",
"(",
"req",
")",
"// per RoundTripper contract",
"\n\n",
... | // RoundTrip implements the RoundTripper interface. We just add the
// basic auth and return the RoundTripper for this transport type. | [
"RoundTrip",
"implements",
"the",
"RoundTripper",
"interface",
".",
"We",
"just",
"add",
"the",
"basic",
"auth",
"and",
"return",
"the",
"RoundTripper",
"for",
"this",
"transport",
"type",
"."
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/jira.go#L325-L330 | train |
andygrunwald/go-jira | jira.go | RoundTrip | func (t *CookieAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if t.SessionObject == nil {
err := t.setSessionObject()
if err != nil {
return nil, errors.Wrap(err, "cookieauth: no session object has been set")
}
}
req2 := cloneRequest(req) // per RoundTripper contract
for _, cookie :... | go | func (t *CookieAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if t.SessionObject == nil {
err := t.setSessionObject()
if err != nil {
return nil, errors.Wrap(err, "cookieauth: no session object has been set")
}
}
req2 := cloneRequest(req) // per RoundTripper contract
for _, cookie :... | [
"func",
"(",
"t",
"*",
"CookieAuthTransport",
")",
"RoundTrip",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"if",
"t",
".",
"SessionObject",
"==",
"nil",
"{",
"err",
":=",
"t",
".",
"setS... | // RoundTrip adds the session object to the request. | [
"RoundTrip",
"adds",
"the",
"session",
"object",
"to",
"the",
"request",
"."
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/jira.go#L370-L387 | train |
andygrunwald/go-jira | jira.go | buildAuthRequest | func (t *CookieAuthTransport) buildAuthRequest() (*http.Request, error) {
body := struct {
Username string `json:"username"`
Password string `json:"password"`
}{
t.Username,
t.Password,
}
b := new(bytes.Buffer)
json.NewEncoder(b).Encode(body)
req, err := http.NewRequest("POST", t.AuthURL, b)
if err != ... | go | func (t *CookieAuthTransport) buildAuthRequest() (*http.Request, error) {
body := struct {
Username string `json:"username"`
Password string `json:"password"`
}{
t.Username,
t.Password,
}
b := new(bytes.Buffer)
json.NewEncoder(b).Encode(body)
req, err := http.NewRequest("POST", t.AuthURL, b)
if err != ... | [
"func",
"(",
"t",
"*",
"CookieAuthTransport",
")",
"buildAuthRequest",
"(",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"body",
":=",
"struct",
"{",
"Username",
"string",
"`json:\"username\"`",
"\n",
"Password",
"string",
"`json:\"password\"... | // getAuthRequest assembles the request to get the authenticated cookie | [
"getAuthRequest",
"assembles",
"the",
"request",
"to",
"get",
"the",
"authenticated",
"cookie"
] | 15b3b5364390d5c1d72f2b065f01c778cb0ccd18 | https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/jira.go#L416-L435 | train |
gpmgo/gopm | modules/base/tool.go | IsDir | func IsDir(dir string) bool {
f, e := os.Stat(dir)
if e != nil {
return false
}
return f.IsDir()
} | go | func IsDir(dir string) bool {
f, e := os.Stat(dir)
if e != nil {
return false
}
return f.IsDir()
} | [
"func",
"IsDir",
"(",
"dir",
"string",
")",
"bool",
"{",
"f",
",",
"e",
":=",
"os",
".",
"Stat",
"(",
"dir",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"f",
".",
"IsDir",
"(",
")",
"\n",
"}"
] | // IsDir returns true if given path is a directory,
// or returns false when it's a file or does not exist. | [
"IsDir",
"returns",
"true",
"if",
"given",
"path",
"is",
"a",
"directory",
"or",
"returns",
"false",
"when",
"it",
"s",
"a",
"file",
"or",
"does",
"not",
"exist",
"."
] | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L54-L60 | train |
gpmgo/gopm | modules/base/tool.go | Copy | func Copy(src, dest string) error {
// Gather file information to set back later.
si, err := os.Lstat(src)
if err != nil {
return err
}
// Handle symbolic link.
if si.Mode()&os.ModeSymlink != 0 {
target, err := os.Readlink(src)
if err != nil {
return err
}
// NOTE: os.Chmod and os.Chtimes don't reco... | go | func Copy(src, dest string) error {
// Gather file information to set back later.
si, err := os.Lstat(src)
if err != nil {
return err
}
// Handle symbolic link.
if si.Mode()&os.ModeSymlink != 0 {
target, err := os.Readlink(src)
if err != nil {
return err
}
// NOTE: os.Chmod and os.Chtimes don't reco... | [
"func",
"Copy",
"(",
"src",
",",
"dest",
"string",
")",
"error",
"{",
"// Gather file information to set back later.",
"si",
",",
"err",
":=",
"os",
".",
"Lstat",
"(",
"src",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
... | // Copy copies file from source to target path. | [
"Copy",
"copies",
"file",
"from",
"source",
"to",
"target",
"path",
"."
] | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L118-L157 | train |
gpmgo/gopm | modules/base/tool.go | CopyDir | func CopyDir(srcPath, destPath string, filters ...func(filePath string) bool) error {
// Check if target directory exists.
if IsExist(destPath) {
return errors.New("file or directory alreay exists: " + destPath)
}
err := os.MkdirAll(destPath, os.ModePerm)
if err != nil {
return err
}
// Gather directory in... | go | func CopyDir(srcPath, destPath string, filters ...func(filePath string) bool) error {
// Check if target directory exists.
if IsExist(destPath) {
return errors.New("file or directory alreay exists: " + destPath)
}
err := os.MkdirAll(destPath, os.ModePerm)
if err != nil {
return err
}
// Gather directory in... | [
"func",
"CopyDir",
"(",
"srcPath",
",",
"destPath",
"string",
",",
"filters",
"...",
"func",
"(",
"filePath",
"string",
")",
"bool",
")",
"error",
"{",
"// Check if target directory exists.",
"if",
"IsExist",
"(",
"destPath",
")",
"{",
"return",
"errors",
".",... | // CopyDir copy files recursively from source to target directory.
//
// The filter accepts a function that process the path info.
// and should return true for need to filter.
//
// It returns error when error occurs in underlying functions. | [
"CopyDir",
"copy",
"files",
"recursively",
"from",
"source",
"to",
"target",
"directory",
".",
"The",
"filter",
"accepts",
"a",
"function",
"that",
"process",
"the",
"path",
"info",
".",
"and",
"should",
"return",
"true",
"for",
"need",
"to",
"filter",
".",
... | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L165-L203 | train |
gpmgo/gopm | modules/base/tool.go | ExecCmdDirBytes | func ExecCmdDirBytes(dir, cmdName string, args ...string) ([]byte, []byte, error) {
bufOut := new(bytes.Buffer)
bufErr := new(bytes.Buffer)
cmd := exec.Command(cmdName, args...)
cmd.Dir = dir
cmd.Stdout = bufOut
cmd.Stderr = bufErr
err := cmd.Run()
return bufOut.Bytes(), bufErr.Bytes(), err
} | go | func ExecCmdDirBytes(dir, cmdName string, args ...string) ([]byte, []byte, error) {
bufOut := new(bytes.Buffer)
bufErr := new(bytes.Buffer)
cmd := exec.Command(cmdName, args...)
cmd.Dir = dir
cmd.Stdout = bufOut
cmd.Stderr = bufErr
err := cmd.Run()
return bufOut.Bytes(), bufErr.Bytes(), err
} | [
"func",
"ExecCmdDirBytes",
"(",
"dir",
",",
"cmdName",
"string",
",",
"args",
"...",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"bufOut",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"bufErr",
":=",... | // ExecCmdDirBytes executes system command in given directory
// and return stdout, stderr in bytes type, along with possible error. | [
"ExecCmdDirBytes",
"executes",
"system",
"command",
"in",
"given",
"directory",
"and",
"return",
"stdout",
"stderr",
"in",
"bytes",
"type",
"along",
"with",
"possible",
"error",
"."
] | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L207-L218 | train |
gpmgo/gopm | modules/base/tool.go | ExecCmdBytes | func ExecCmdBytes(cmdName string, args ...string) ([]byte, []byte, error) {
return ExecCmdDirBytes("", cmdName, args...)
} | go | func ExecCmdBytes(cmdName string, args ...string) ([]byte, []byte, error) {
return ExecCmdDirBytes("", cmdName, args...)
} | [
"func",
"ExecCmdBytes",
"(",
"cmdName",
"string",
",",
"args",
"...",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"ExecCmdDirBytes",
"(",
"\"",
"\"",
",",
"cmdName",
",",
"args",
"...",
")",
"\n",
... | // ExecCmdBytes executes system command
// and return stdout, stderr in bytes type, along with possible error. | [
"ExecCmdBytes",
"executes",
"system",
"command",
"and",
"return",
"stdout",
"stderr",
"in",
"bytes",
"type",
"along",
"with",
"possible",
"error",
"."
] | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L222-L224 | train |
gpmgo/gopm | modules/base/tool.go | ExecCmdDir | func ExecCmdDir(dir, cmdName string, args ...string) (string, string, error) {
bufOut, bufErr, err := ExecCmdDirBytes(dir, cmdName, args...)
return string(bufOut), string(bufErr), err
} | go | func ExecCmdDir(dir, cmdName string, args ...string) (string, string, error) {
bufOut, bufErr, err := ExecCmdDirBytes(dir, cmdName, args...)
return string(bufOut), string(bufErr), err
} | [
"func",
"ExecCmdDir",
"(",
"dir",
",",
"cmdName",
"string",
",",
"args",
"...",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"bufOut",
",",
"bufErr",
",",
"err",
":=",
"ExecCmdDirBytes",
"(",
"dir",
",",
"cmdName",
",",
"args",
... | // ExecCmdDir executes system command in given directory
// and return stdout, stderr in string type, along with possible error. | [
"ExecCmdDir",
"executes",
"system",
"command",
"in",
"given",
"directory",
"and",
"return",
"stdout",
"stderr",
"in",
"string",
"type",
"along",
"with",
"possible",
"error",
"."
] | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L228-L231 | train |
gpmgo/gopm | modules/base/tool.go | ExecCmd | func ExecCmd(cmdName string, args ...string) (string, string, error) {
return ExecCmdDir("", cmdName, args...)
} | go | func ExecCmd(cmdName string, args ...string) (string, string, error) {
return ExecCmdDir("", cmdName, args...)
} | [
"func",
"ExecCmd",
"(",
"cmdName",
"string",
",",
"args",
"...",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"return",
"ExecCmdDir",
"(",
"\"",
"\"",
",",
"cmdName",
",",
"args",
"...",
")",
"\n",
"}"
] | // ExecCmd executes system command
// and return stdout, stderr in string type, along with possible error. | [
"ExecCmd",
"executes",
"system",
"command",
"and",
"return",
"stdout",
"stderr",
"in",
"string",
"type",
"along",
"with",
"possible",
"error",
"."
] | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L235-L237 | train |
gpmgo/gopm | modules/base/tool.go | IsSliceContainsStr | func IsSliceContainsStr(sl []string, str string) bool {
str = strings.ToLower(str)
for _, s := range sl {
if strings.ToLower(s) == str {
return true
}
}
return false
} | go | func IsSliceContainsStr(sl []string, str string) bool {
str = strings.ToLower(str)
for _, s := range sl {
if strings.ToLower(s) == str {
return true
}
}
return false
} | [
"func",
"IsSliceContainsStr",
"(",
"sl",
"[",
"]",
"string",
",",
"str",
"string",
")",
"bool",
"{",
"str",
"=",
"strings",
".",
"ToLower",
"(",
"str",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"sl",
"{",
"if",
"strings",
".",
"ToLower",
"(",... | // IsSliceContainsStr returns true if the string exists in given slice. | [
"IsSliceContainsStr",
"returns",
"true",
"if",
"the",
"string",
"exists",
"in",
"given",
"slice",
"."
] | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L300-L308 | train |
gpmgo/gopm | modules/base/tool.go | ToStr | func ToStr(value interface{}, args ...int) (s string) {
switch v := value.(type) {
case bool:
s = strconv.FormatBool(v)
case float32:
s = strconv.FormatFloat(float64(v), 'f', argInt(args).Get(0, -1), argInt(args).Get(1, 32))
case float64:
s = strconv.FormatFloat(v, 'f', argInt(args).Get(0, -1), argInt(args).G... | go | func ToStr(value interface{}, args ...int) (s string) {
switch v := value.(type) {
case bool:
s = strconv.FormatBool(v)
case float32:
s = strconv.FormatFloat(float64(v), 'f', argInt(args).Get(0, -1), argInt(args).Get(1, 32))
case float64:
s = strconv.FormatFloat(v, 'f', argInt(args).Get(0, -1), argInt(args).G... | [
"func",
"ToStr",
"(",
"value",
"interface",
"{",
"}",
",",
"args",
"...",
"int",
")",
"(",
"s",
"string",
")",
"{",
"switch",
"v",
":=",
"value",
".",
"(",
"type",
")",
"{",
"case",
"bool",
":",
"s",
"=",
"strconv",
".",
"FormatBool",
"(",
"v",
... | // Convert any type to string. | [
"Convert",
"any",
"type",
"to",
"string",
"."
] | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L711-L747 | train |
gpmgo/gopm | modules/base/tool.go | GetTempDir | func GetTempDir() string {
return path.Join(os.TempDir(), ToStr(time.Now().Nanosecond()))
} | go | func GetTempDir() string {
return path.Join(os.TempDir(), ToStr(time.Now().Nanosecond()))
} | [
"func",
"GetTempDir",
"(",
")",
"string",
"{",
"return",
"path",
".",
"Join",
"(",
"os",
".",
"TempDir",
"(",
")",
",",
"ToStr",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Nanosecond",
"(",
")",
")",
")",
"\n",
"}"
] | //GetTempDir generates and returns time-based unique temporary path. | [
"GetTempDir",
"generates",
"and",
"returns",
"time",
"-",
"based",
"unique",
"temporary",
"path",
"."
] | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L761-L763 | train |
gpmgo/gopm | modules/base/tool.go | HttpGetBytes | func HttpGetBytes(client *http.Client, url string, header http.Header) ([]byte, error) {
rc, err := HttpGet(client, url, header)
if err != nil {
return nil, err
}
defer rc.Close()
return ioutil.ReadAll(rc)
} | go | func HttpGetBytes(client *http.Client, url string, header http.Header) ([]byte, error) {
rc, err := HttpGet(client, url, header)
if err != nil {
return nil, err
}
defer rc.Close()
return ioutil.ReadAll(rc)
} | [
"func",
"HttpGetBytes",
"(",
"client",
"*",
"http",
".",
"Client",
",",
"url",
"string",
",",
"header",
"http",
".",
"Header",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"rc",
",",
"err",
":=",
"HttpGet",
"(",
"client",
",",
"url",
",",
... | // HttpGetBytes gets the specified resource. ErrNotFound is returned if the server
// responds with status 404. | [
"HttpGetBytes",
"gets",
"the",
"specified",
"resource",
".",
"ErrNotFound",
"is",
"returned",
"if",
"the",
"server",
"responds",
"with",
"status",
"404",
"."
] | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L796-L803 | train |
gpmgo/gopm | modules/goconfig/conf.go | newConfigFile | func newConfigFile(fileNames []string) *ConfigFile {
c := new(ConfigFile)
c.fileNames = fileNames
c.data = make(map[string]map[string]string)
c.keyList = make(map[string][]string)
c.sectionComments = make(map[string]string)
c.keyComments = make(map[string]map[string]string)
c.BlockMode = true
return c
} | go | func newConfigFile(fileNames []string) *ConfigFile {
c := new(ConfigFile)
c.fileNames = fileNames
c.data = make(map[string]map[string]string)
c.keyList = make(map[string][]string)
c.sectionComments = make(map[string]string)
c.keyComments = make(map[string]map[string]string)
c.BlockMode = true
return c
} | [
"func",
"newConfigFile",
"(",
"fileNames",
"[",
"]",
"string",
")",
"*",
"ConfigFile",
"{",
"c",
":=",
"new",
"(",
"ConfigFile",
")",
"\n",
"c",
".",
"fileNames",
"=",
"fileNames",
"\n",
"c",
".",
"data",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
... | // newConfigFile creates an empty configuration representation. | [
"newConfigFile",
"creates",
"an",
"empty",
"configuration",
"representation",
"."
] | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L69-L78 | train |
gpmgo/gopm | modules/goconfig/conf.go | DeleteKey | func (c *ConfigFile) DeleteKey(section, key string) bool {
// Blank section name represents DEFAULT section.
if len(section) == 0 {
section = DEFAULT_SECTION
}
// Check if section exists.
if _, ok := c.data[section]; !ok {
return false
}
// Check if key exists.
if _, ok := c.data[section][key]; ok {
del... | go | func (c *ConfigFile) DeleteKey(section, key string) bool {
// Blank section name represents DEFAULT section.
if len(section) == 0 {
section = DEFAULT_SECTION
}
// Check if section exists.
if _, ok := c.data[section]; !ok {
return false
}
// Check if key exists.
if _, ok := c.data[section][key]; ok {
del... | [
"func",
"(",
"c",
"*",
"ConfigFile",
")",
"DeleteKey",
"(",
"section",
",",
"key",
"string",
")",
"bool",
"{",
"// Blank section name represents DEFAULT section.",
"if",
"len",
"(",
"section",
")",
"==",
"0",
"{",
"section",
"=",
"DEFAULT_SECTION",
"\n",
"}",
... | // DeleteKey deletes the key in given section.
// It returns true if the key was deleted,
// or returns false if the section or key didn't exist. | [
"DeleteKey",
"deletes",
"the",
"key",
"in",
"given",
"section",
".",
"It",
"returns",
"true",
"if",
"the",
"key",
"was",
"deleted",
"or",
"returns",
"false",
"if",
"the",
"section",
"or",
"key",
"didn",
"t",
"exist",
"."
] | 7edb73a0f439c016ee40b6608bc271c7fc4462e9 | https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L116-L145 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.