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", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "findMessageByEventID", "(", "c", ".", "db", ",", "c", ".", "Chat", ".", "ID", ",", "c", ".", "Bot", "(", ")", ".", "ID", ",", "id", ")", "\n", "}" ]
// 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", ".", "FileType", "=", "\"", "\"", "\n", "return", "m", "\n", "}" ]
// 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", "(", ")", "\n", "m", ".", "Selective", "=", "selective", "\n", "//todo: here is workaround for QT version. Keyboard with selective is not working", "return", "m", "\n", "}" ]
// 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", ",", "args", "...", ")", "\n", "return", "m", "\n", "}" ]
// SetCallbackAction sets the callback func that will be called when user press inline button with Data field
[ "SetCallbackAction", "sets", "the", "callback", "func", "that", "will", "be", "called", "when", "user", "press", "inline", "button", "with", "Data", "field" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L751-L754
train
requilence/integram
bots.go
Send
func (m *OutgoingMessage) Send() error { if m.ChatID == 0 { return errors.New("ChatID is empty") } if m.BotID == 0 { return errors.New("BotID is empty") } if m.Text == "" && m.FilePath == "" && m.Location == nil { return errors.New("Text, FilePath and Location are empty") } if m.ctx != nil && m.ctx.messageAnsweredAt == nil { n := time.Now() m.ctx.messageAnsweredAt = &n } return activeMessageSender.Send(m) }
go
func (m *OutgoingMessage) Send() error { if m.ChatID == 0 { return errors.New("ChatID is empty") } if m.BotID == 0 { return errors.New("BotID is empty") } if m.Text == "" && m.FilePath == "" && m.Location == nil { return errors.New("Text, FilePath and Location are empty") } if m.ctx != nil && m.ctx.messageAnsweredAt == nil { n := time.Now() m.ctx.messageAnsweredAt = &n } return activeMessageSender.Send(m) }
[ "func", "(", "m", "*", "OutgoingMessage", ")", "Send", "(", ")", "error", "{", "if", "m", ".", "ChatID", "==", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "m", ".", "BotID", "==", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "m", ".", "Text", "==", "\"", "\"", "&&", "m", ".", "FilePath", "==", "\"", "\"", "&&", "m", ".", "Location", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "m", ".", "ctx", "!=", "nil", "&&", "m", ".", "ctx", ".", "messageAnsweredAt", "==", "nil", "{", "n", ":=", "time", ".", "Now", "(", ")", "\n", "m", ".", "ctx", ".", "messageAnsweredAt", "=", "&", "n", "\n", "}", "\n\n", "return", "activeMessageSender", ".", "Send", "(", "m", ")", "\n", "}" ]
// 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", "}", "\n", "return", "m", "\n", "}" ]
// 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", ".", "Text", ")", ")", ")", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// GetTextHash generate MD5 hash of message's text
[ "GetTextHash", "generate", "MD5", "hash", "of", "message", "s", "text" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L1066-L1071
train
requilence/integram
bots.go
UpdateEventsID
func (m *Message) UpdateEventsID(db *mgo.Database, eventID ...string) error { m.EventID = append(m.EventID, eventID...) f := bson.M{"botid": m.BotID} if m.InlineMsgID != "" { f["inlinemsgid"] = m.InlineMsgID } else { f["chatid"] = m.ChatID f["msgid"] = m.MsgID } return db.C("messages").Update(f, bson.M{"$addToSet": bson.M{"eventid": bson.M{"$each": eventID}}}) }
go
func (m *Message) UpdateEventsID(db *mgo.Database, eventID ...string) error { m.EventID = append(m.EventID, eventID...) f := bson.M{"botid": m.BotID} if m.InlineMsgID != "" { f["inlinemsgid"] = m.InlineMsgID } else { f["chatid"] = m.ChatID f["msgid"] = m.MsgID } return db.C("messages").Update(f, bson.M{"$addToSet": bson.M{"eventid": bson.M{"$each": eventID}}}) }
[ "func", "(", "m", "*", "Message", ")", "UpdateEventsID", "(", "db", "*", "mgo", ".", "Database", ",", "eventID", "...", "string", ")", "error", "{", "m", ".", "EventID", "=", "append", "(", "m", ".", "EventID", ",", "eventID", "...", ")", "\n", "f", ":=", "bson", ".", "M", "{", "\"", "\"", ":", "m", ".", "BotID", "}", "\n", "if", "m", ".", "InlineMsgID", "!=", "\"", "\"", "{", "f", "[", "\"", "\"", "]", "=", "m", ".", "InlineMsgID", "\n", "}", "else", "{", "f", "[", "\"", "\"", "]", "=", "m", ".", "ChatID", "\n", "f", "[", "\"", "\"", "]", "=", "m", ".", "MsgID", "\n", "}", "\n", "return", "db", ".", "C", "(", "\"", "\"", ")", ".", "Update", "(", "f", ",", "bson", ".", "M", "{", "\"", "\"", ":", "bson", ".", "M", "{", "\"", "\"", ":", "bson", ".", "M", "{", "\"", "\"", ":", "eventID", "}", "}", "}", ")", "\n", "}" ]
// 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", ".", "ID", ",", "bson", ".", "M", "{", "\"", "\"", ":", "m", "}", ")", "\n", "}", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
// Update will update existing message in DB
[ "Update", "will", "update", "existing", "message", "in", "DB" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/bots.go#L1087-L1093
train
requilence/integram
encode.go
decode
func decode(reply []byte, dest interface{}) error { // Check the type of dest and make sure it is a pointer to something, // otherwise we can't set its value in any meaningful way. val := reflect.ValueOf(dest) if val.Kind() != reflect.Ptr { return fmt.Errorf("Argument to decode must be pointer. Got %T", dest) } // Use the gob package to decode the reply and write the result into // dest. buf := bytes.NewBuffer(reply) dec := gob.NewDecoder(buf) if err := dec.DecodeValue(val.Elem()); err != nil { return err } return nil }
go
func decode(reply []byte, dest interface{}) error { // Check the type of dest and make sure it is a pointer to something, // otherwise we can't set its value in any meaningful way. val := reflect.ValueOf(dest) if val.Kind() != reflect.Ptr { return fmt.Errorf("Argument to decode must be pointer. Got %T", dest) } // Use the gob package to decode the reply and write the result into // dest. buf := bytes.NewBuffer(reply) dec := gob.NewDecoder(buf) if err := dec.DecodeValue(val.Elem()); err != nil { return err } return nil }
[ "func", "decode", "(", "reply", "[", "]", "byte", ",", "dest", "interface", "{", "}", ")", "error", "{", "// 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", ")", "\n", "if", "val", ".", "Kind", "(", ")", "!=", "reflect", ".", "Ptr", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dest", ")", "\n", "}", "\n\n", "// Use the gob package to decode the reply and write the result into", "// dest.", "buf", ":=", "bytes", ".", "NewBuffer", "(", "reply", ")", "\n", "dec", ":=", "gob", ".", "NewDecoder", "(", "buf", ")", "\n", "if", "err", ":=", "dec", ".", "DecodeValue", "(", "val", ".", "Elem", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", "{", "}", ")", "\n", "enc", ":=", "gob", ".", "NewEncoder", "(", "buf", ")", "\n", "if", "err", ":=", "enc", ".", "Encode", "(", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "buf", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// 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", "(", "\"", "\"", ",", "s", ".", "Name", ")", ".", "Error", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}" ]
// Bot returns corresponding bot for the service
[ "Bot", "returns", "corresponding", "bot", "for", "the", "service" ]
7d85c728a299bf2ad121ae1874c0bd39fc48c231
https://github.com/requilence/integram/blob/7d85c728a299bf2ad121ae1874c0bd39fc48c231/services.go#L551-L557
train
rakyll/statik
fs/walk.go
Walk
func Walk(hfs http.FileSystem, root string, walkFn filepath.WalkFunc) error { dh, err := hfs.Open(root) if err != nil { return err } di, err := dh.Stat() if err != nil { return err } fis, err := dh.Readdir(-1) dh.Close() if err = walkFn(root, di, err); err != nil { if err == filepath.SkipDir { return nil } return err } for _, fi := range fis { fn := path.Join(root, fi.Name()) if fi.IsDir() { if err = Walk(hfs, fn, walkFn); err != nil { if err == filepath.SkipDir { continue } return err } continue } if err = walkFn(fn, fi, nil); err != nil { if err == filepath.SkipDir { continue } return err } } return nil }
go
func Walk(hfs http.FileSystem, root string, walkFn filepath.WalkFunc) error { dh, err := hfs.Open(root) if err != nil { return err } di, err := dh.Stat() if err != nil { return err } fis, err := dh.Readdir(-1) dh.Close() if err = walkFn(root, di, err); err != nil { if err == filepath.SkipDir { return nil } return err } for _, fi := range fis { fn := path.Join(root, fi.Name()) if fi.IsDir() { if err = Walk(hfs, fn, walkFn); err != nil { if err == filepath.SkipDir { continue } return err } continue } if err = walkFn(fn, fi, nil); err != nil { if err == filepath.SkipDir { continue } return err } } return nil }
[ "func", "Walk", "(", "hfs", "http", ".", "FileSystem", ",", "root", "string", ",", "walkFn", "filepath", ".", "WalkFunc", ")", "error", "{", "dh", ",", "err", ":=", "hfs", ".", "Open", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "di", ",", "err", ":=", "dh", ".", "Stat", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "fis", ",", "err", ":=", "dh", ".", "Readdir", "(", "-", "1", ")", "\n", "dh", ".", "Close", "(", ")", "\n", "if", "err", "=", "walkFn", "(", "root", ",", "di", ",", "err", ")", ";", "err", "!=", "nil", "{", "if", "err", "==", "filepath", ".", "SkipDir", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "for", "_", ",", "fi", ":=", "range", "fis", "{", "fn", ":=", "path", ".", "Join", "(", "root", ",", "fi", ".", "Name", "(", ")", ")", "\n", "if", "fi", ".", "IsDir", "(", ")", "{", "if", "err", "=", "Walk", "(", "hfs", ",", "fn", ",", "walkFn", ")", ";", "err", "!=", "nil", "{", "if", "err", "==", "filepath", ".", "SkipDir", "{", "continue", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "continue", "\n", "}", "\n", "if", "err", "=", "walkFn", "(", "fn", ",", "fi", ",", "nil", ")", ";", "err", "!=", "nil", "{", "if", "err", "==", "filepath", ".", "SkipDir", "{", "continue", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", "filtered", "by", "walkFn", ".", "As", "with", "filepath", ".", "Walk", "if", "the", "walkFn", "returns", "filepath", ".", "SkipDir", "then", "the", "directory", "is", "skipped", "." ]
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", "nil", ",", "err", "\n", "}", "\n", "var", "buf", "bytes", ".", "Buffer", "\n", "_", ",", "err", "=", "io", ".", "Copy", "(", "&", "buf", ",", "fh", ")", "\n", "fh", ".", "Close", "(", ")", "\n", "return", "buf", ".", "Bytes", "(", ")", ",", "err", "\n", "}" ]
// ReadFile reads the contents of the file of hfs specified by name. // Just as ioutil.ReadFile does.
[ "ReadFile", "reads", "the", "contents", "of", "the", "file", "of", "hfs", "specified", "by", "name", ".", "Just", "as", "ioutil", ".", "ReadFile", "does", "." ]
3bac566d30cdbeddef402a80f3d6305860e59f12
https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/fs/walk.go#L70-L79
train
rakyll/statik
statik.go
rename
func rename(src, dest string) error { // Try to rename generated source. if err := os.Rename(src, dest); err == nil { return nil } // If the rename failed (might do so due to temporary file residing on a // different device), try to copy byte by byte. rc, err := os.Open(src) if err != nil { return err } defer func() { rc.Close() os.Remove(src) // ignore the error, source is in tmp. }() if _, err = os.Stat(dest); !os.IsNotExist(err) { if *flagForce { if err = os.Remove(dest); err != nil { return fmt.Errorf("file %q could not be deleted", dest) } } else { return fmt.Errorf("file %q already exists; use -f to overwrite", dest) } } wc, err := os.Create(dest) if err != nil { return err } defer wc.Close() if _, err = io.Copy(wc, rc); err != nil { // Delete remains of failed copy attempt. os.Remove(dest) } return err }
go
func rename(src, dest string) error { // Try to rename generated source. if err := os.Rename(src, dest); err == nil { return nil } // If the rename failed (might do so due to temporary file residing on a // different device), try to copy byte by byte. rc, err := os.Open(src) if err != nil { return err } defer func() { rc.Close() os.Remove(src) // ignore the error, source is in tmp. }() if _, err = os.Stat(dest); !os.IsNotExist(err) { if *flagForce { if err = os.Remove(dest); err != nil { return fmt.Errorf("file %q could not be deleted", dest) } } else { return fmt.Errorf("file %q already exists; use -f to overwrite", dest) } } wc, err := os.Create(dest) if err != nil { return err } defer wc.Close() if _, err = io.Copy(wc, rc); err != nil { // Delete remains of failed copy attempt. os.Remove(dest) } return err }
[ "func", "rename", "(", "src", ",", "dest", "string", ")", "error", "{", "// Try to rename generated source.", "if", "err", ":=", "os", ".", "Rename", "(", "src", ",", "dest", ")", ";", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "// 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", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "rc", ".", "Close", "(", ")", "\n", "os", ".", "Remove", "(", "src", ")", "// ignore the error, source is in tmp.", "\n", "}", "(", ")", "\n\n", "if", "_", ",", "err", "=", "os", ".", "Stat", "(", "dest", ")", ";", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "if", "*", "flagForce", "{", "if", "err", "=", "os", ".", "Remove", "(", "dest", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dest", ")", "\n", "}", "\n", "}", "else", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dest", ")", "\n", "}", "\n", "}", "\n\n", "wc", ",", "err", ":=", "os", ".", "Create", "(", "dest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "wc", ".", "Close", "(", ")", "\n\n", "if", "_", ",", "err", "=", "io", ".", "Copy", "(", "wc", ",", "rc", ")", ";", "err", "!=", "nil", "{", "// Delete remains of failed copy attempt.", "os", ".", "Remove", "(", "dest", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// rename tries to os.Rename, but fall backs to copying from src // to dest and unlink the source if os.Rename fails.
[ "rename", "tries", "to", "os", ".", "Rename", "but", "fall", "backs", "to", "copying", "from", "src", "to", "dest", "and", "unlink", "the", "source", "if", "os", ".", "Rename", "fails", "." ]
3bac566d30cdbeddef402a80f3d6305860e59f12
https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/statik.go#L78-L115
train
rakyll/statik
statik.go
FprintZipData
func FprintZipData(dest *bytes.Buffer, zipData []byte) { for _, b := range zipData { if b == '\n' { dest.WriteString(`\n`) continue } if b == '\\' { dest.WriteString(`\\`) continue } if b == '"' { dest.WriteString(`\"`) continue } if (b >= 32 && b <= 126) || b == '\t' { dest.WriteByte(b) continue } fmt.Fprintf(dest, "\\x%02x", b) } }
go
func FprintZipData(dest *bytes.Buffer, zipData []byte) { for _, b := range zipData { if b == '\n' { dest.WriteString(`\n`) continue } if b == '\\' { dest.WriteString(`\\`) continue } if b == '"' { dest.WriteString(`\"`) continue } if (b >= 32 && b <= 126) || b == '\t' { dest.WriteByte(b) continue } fmt.Fprintf(dest, "\\x%02x", b) } }
[ "func", "FprintZipData", "(", "dest", "*", "bytes", ".", "Buffer", ",", "zipData", "[", "]", "byte", ")", "{", "for", "_", ",", "b", ":=", "range", "zipData", "{", "if", "b", "==", "'\\n'", "{", "dest", ".", "WriteString", "(", "`\\n`", ")", "\n", "continue", "\n", "}", "\n", "if", "b", "==", "'\\\\'", "{", "dest", ".", "WriteString", "(", "`\\\\`", ")", "\n", "continue", "\n", "}", "\n", "if", "b", "==", "'\"'", "{", "dest", ".", "WriteString", "(", "`\\\"`", ")", "\n", "continue", "\n", "}", "\n", "if", "(", "b", ">=", "32", "&&", "b", "<=", "126", ")", "||", "b", "==", "'\\t'", "{", "dest", ".", "WriteByte", "(", "b", ")", "\n", "continue", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "dest", ",", "\"", "\\\\", "\"", ",", "b", ")", "\n", "}", "\n", "}" ]
// FprintZipData converts zip binary contents to a string literal.
[ "FprintZipData", "converts", "zip", "binary", "contents", "to", "a", "string", "literal", "." ]
3bac566d30cdbeddef402a80f3d6305860e59f12
https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/statik.go#L218-L238
train
rakyll/statik
fs/fs.go
New
func New() (http.FileSystem, error) { if zipData == "" { return nil, errors.New("statik/fs: no zip data registered") } zipReader, err := zip.NewReader(strings.NewReader(zipData), int64(len(zipData))) if err != nil { return nil, err } files := make(map[string]file, len(zipReader.File)) dirs := make(map[string][]string) fs := &statikFS{files: files, dirs: dirs} for _, zipFile := range zipReader.File { fi := zipFile.FileInfo() f := file{FileInfo: fi, fs: fs} f.data, err = unzip(zipFile) if err != nil { return nil, fmt.Errorf("statik/fs: error unzipping file %q: %s", zipFile.Name, err) } files["/"+zipFile.Name] = f } for fn := range files { // go up directories recursively in order to care deep directory for dn := path.Dir(fn); dn != fn; { if _, ok := files[dn]; !ok { files[dn] = file{FileInfo: dirInfo{dn}, fs: fs} } else { break } fn, dn = dn, path.Dir(dn) } } for fn := range files { dn := path.Dir(fn) if fn != dn { fs.dirs[dn] = append(fs.dirs[dn], path.Base(fn)) } } for _, s := range fs.dirs { sort.Strings(s) } return fs, nil }
go
func New() (http.FileSystem, error) { if zipData == "" { return nil, errors.New("statik/fs: no zip data registered") } zipReader, err := zip.NewReader(strings.NewReader(zipData), int64(len(zipData))) if err != nil { return nil, err } files := make(map[string]file, len(zipReader.File)) dirs := make(map[string][]string) fs := &statikFS{files: files, dirs: dirs} for _, zipFile := range zipReader.File { fi := zipFile.FileInfo() f := file{FileInfo: fi, fs: fs} f.data, err = unzip(zipFile) if err != nil { return nil, fmt.Errorf("statik/fs: error unzipping file %q: %s", zipFile.Name, err) } files["/"+zipFile.Name] = f } for fn := range files { // go up directories recursively in order to care deep directory for dn := path.Dir(fn); dn != fn; { if _, ok := files[dn]; !ok { files[dn] = file{FileInfo: dirInfo{dn}, fs: fs} } else { break } fn, dn = dn, path.Dir(dn) } } for fn := range files { dn := path.Dir(fn) if fn != dn { fs.dirs[dn] = append(fs.dirs[dn], path.Base(fn)) } } for _, s := range fs.dirs { sort.Strings(s) } return fs, nil }
[ "func", "New", "(", ")", "(", "http", ".", "FileSystem", ",", "error", ")", "{", "if", "zipData", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "zipReader", ",", "err", ":=", "zip", ".", "NewReader", "(", "strings", ".", "NewReader", "(", "zipData", ")", ",", "int64", "(", "len", "(", "zipData", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "files", ":=", "make", "(", "map", "[", "string", "]", "file", ",", "len", "(", "zipReader", ".", "File", ")", ")", "\n", "dirs", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "fs", ":=", "&", "statikFS", "{", "files", ":", "files", ",", "dirs", ":", "dirs", "}", "\n", "for", "_", ",", "zipFile", ":=", "range", "zipReader", ".", "File", "{", "fi", ":=", "zipFile", ".", "FileInfo", "(", ")", "\n", "f", ":=", "file", "{", "FileInfo", ":", "fi", ",", "fs", ":", "fs", "}", "\n", "f", ".", "data", ",", "err", "=", "unzip", "(", "zipFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "zipFile", ".", "Name", ",", "err", ")", "\n", "}", "\n", "files", "[", "\"", "\"", "+", "zipFile", ".", "Name", "]", "=", "f", "\n", "}", "\n", "for", "fn", ":=", "range", "files", "{", "// go up directories recursively in order to care deep directory", "for", "dn", ":=", "path", ".", "Dir", "(", "fn", ")", ";", "dn", "!=", "fn", ";", "{", "if", "_", ",", "ok", ":=", "files", "[", "dn", "]", ";", "!", "ok", "{", "files", "[", "dn", "]", "=", "file", "{", "FileInfo", ":", "dirInfo", "{", "dn", "}", ",", "fs", ":", "fs", "}", "\n", "}", "else", "{", "break", "\n", "}", "\n", "fn", ",", "dn", "=", "dn", ",", "path", ".", "Dir", "(", "dn", ")", "\n", "}", "\n", "}", "\n", "for", "fn", ":=", "range", "files", "{", "dn", ":=", "path", ".", "Dir", "(", "fn", ")", "\n", "if", "fn", "!=", "dn", "{", "fs", ".", "dirs", "[", "dn", "]", "=", "append", "(", "fs", ".", "dirs", "[", "dn", "]", ",", "path", ".", "Base", "(", "fn", ")", ")", "\n", "}", "\n", "}", "\n", "for", "_", ",", "s", ":=", "range", "fs", ".", "dirs", "{", "sort", ".", "Strings", "(", "s", ")", "\n", "}", "\n", "return", "fs", ",", "nil", "\n", "}" ]
// New creates a new file system with the registered zip contents data. // It unzips all files and stores them in an in-memory map.
[ "New", "creates", "a", "new", "file", "system", "with", "the", "registered", "zip", "contents", "data", ".", "It", "unzips", "all", "files", "and", "stores", "them", "in", "an", "in", "-", "memory", "map", "." ]
3bac566d30cdbeddef402a80f3d6305860e59f12
https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/fs/fs.go#L55-L96
train
rakyll/statik
fs/fs.go
Open
func (fs *statikFS) Open(name string) (http.File, error) { name = strings.Replace(name, "//", "/", -1) if f, ok := fs.files[name]; ok { return newHTTPFile(f), nil } return nil, os.ErrNotExist }
go
func (fs *statikFS) Open(name string) (http.File, error) { name = strings.Replace(name, "//", "/", -1) if f, ok := fs.files[name]; ok { return newHTTPFile(f), nil } return nil, os.ErrNotExist }
[ "func", "(", "fs", "*", "statikFS", ")", "Open", "(", "name", "string", ")", "(", "http", ".", "File", ",", "error", ")", "{", "name", "=", "strings", ".", "Replace", "(", "name", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "if", "f", ",", "ok", ":=", "fs", ".", "files", "[", "name", "]", ";", "ok", "{", "return", "newHTTPFile", "(", "f", ")", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "os", ".", "ErrNotExist", "\n", "}" ]
// 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", "requested", "Open", "returns", "the", "file", "named", "index", ".", "html", "in", "the", "requested", "directory", "if", "that", "file", "exists", "." ]
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", "}", "\n", "return", "f", ".", "reader", ".", "Read", "(", "p", ")", "\n", "}" ]
// Read reads bytes into p, returns the number of read bytes.
[ "Read", "reads", "bytes", "into", "p", "returns", "the", "number", "of", "read", "bytes", "." ]
3bac566d30cdbeddef402a80f3d6305860e59f12
https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/fs/fs.go#L150-L155
train
rakyll/statik
fs/fs.go
Seek
func (f *httpFile) Seek(offset int64, whence int) (ret int64, err error) { return f.reader.Seek(offset, whence) }
go
func (f *httpFile) Seek(offset int64, whence int) (ret int64, err error) { return f.reader.Seek(offset, whence) }
[ "func", "(", "f", "*", "httpFile", ")", "Seek", "(", "offset", "int64", ",", "whence", "int", ")", "(", "ret", "int64", ",", "err", "error", ")", "{", "return", "f", ".", "reader", ".", "Seek", "(", "offset", ",", "whence", ")", "\n", "}" ]
// Seek seeks to the offset.
[ "Seek", "seeks", "to", "the", "offset", "." ]
3bac566d30cdbeddef402a80f3d6305860e59f12
https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/fs/fs.go#L158-L160
train
rakyll/statik
fs/fs.go
Readdir
func (f *httpFile) Readdir(count int) ([]os.FileInfo, error) { var fis []os.FileInfo if !f.isDir { return fis, nil } di, ok := f.FileInfo.(dirInfo) if !ok { return nil, fmt.Errorf("failed to read directory: %q", f.Name()) } // If count is positive, the specified number of files will be returned, // and if negative, all remaining files will be returned. // The reading position of which file is returned is held in dirIndex. fnames := f.file.fs.dirs[di.name] flen := len(fnames) // If dirIdx reaches the end and the count is a positive value, // an io.EOF error is returned. // In other cases, no error will be returned even if, for example, // you specified more counts than the number of remaining files. start := f.dirIdx if start >= flen && count > 0 { return fis, io.EOF } var end int if count < 0 { end = flen } else { end = start + count } if end > flen { end = flen } for i := start; i < end; i++ { fis = append(fis, f.file.fs.files[path.Join(di.name, fnames[i])].FileInfo) } f.dirIdx += len(fis) return fis, nil }
go
func (f *httpFile) Readdir(count int) ([]os.FileInfo, error) { var fis []os.FileInfo if !f.isDir { return fis, nil } di, ok := f.FileInfo.(dirInfo) if !ok { return nil, fmt.Errorf("failed to read directory: %q", f.Name()) } // If count is positive, the specified number of files will be returned, // and if negative, all remaining files will be returned. // The reading position of which file is returned is held in dirIndex. fnames := f.file.fs.dirs[di.name] flen := len(fnames) // If dirIdx reaches the end and the count is a positive value, // an io.EOF error is returned. // In other cases, no error will be returned even if, for example, // you specified more counts than the number of remaining files. start := f.dirIdx if start >= flen && count > 0 { return fis, io.EOF } var end int if count < 0 { end = flen } else { end = start + count } if end > flen { end = flen } for i := start; i < end; i++ { fis = append(fis, f.file.fs.files[path.Join(di.name, fnames[i])].FileInfo) } f.dirIdx += len(fis) return fis, nil }
[ "func", "(", "f", "*", "httpFile", ")", "Readdir", "(", "count", "int", ")", "(", "[", "]", "os", ".", "FileInfo", ",", "error", ")", "{", "var", "fis", "[", "]", "os", ".", "FileInfo", "\n", "if", "!", "f", ".", "isDir", "{", "return", "fis", ",", "nil", "\n", "}", "\n", "di", ",", "ok", ":=", "f", ".", "FileInfo", ".", "(", "dirInfo", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "f", ".", "Name", "(", ")", ")", "\n", "}", "\n\n", "// If count is positive, the specified number of files will be returned,", "// and if negative, all remaining files will be returned.", "// The reading position of which file is returned is held in dirIndex.", "fnames", ":=", "f", ".", "file", ".", "fs", ".", "dirs", "[", "di", ".", "name", "]", "\n", "flen", ":=", "len", "(", "fnames", ")", "\n\n", "// If dirIdx reaches the end and the count is a positive value,", "// an io.EOF error is returned.", "// In other cases, no error will be returned even if, for example,", "// you specified more counts than the number of remaining files.", "start", ":=", "f", ".", "dirIdx", "\n", "if", "start", ">=", "flen", "&&", "count", ">", "0", "{", "return", "fis", ",", "io", ".", "EOF", "\n", "}", "\n", "var", "end", "int", "\n", "if", "count", "<", "0", "{", "end", "=", "flen", "\n", "}", "else", "{", "end", "=", "start", "+", "count", "\n", "}", "\n", "if", "end", ">", "flen", "{", "end", "=", "flen", "\n", "}", "\n", "for", "i", ":=", "start", ";", "i", "<", "end", ";", "i", "++", "{", "fis", "=", "append", "(", "fis", ",", "f", ".", "file", ".", "fs", ".", "files", "[", "path", ".", "Join", "(", "di", ".", "name", ",", "fnames", "[", "i", "]", ")", "]", ".", "FileInfo", ")", "\n", "}", "\n", "f", ".", "dirIdx", "+=", "len", "(", "fis", ")", "\n", "return", "fis", ",", "nil", "\n", "}" ]
// Readdir returns an empty slice of files, directory // listing is disabled.
[ "Readdir", "returns", "an", "empty", "slice", "of", "files", "directory", "listing", "is", "disabled", "." ]
3bac566d30cdbeddef402a80f3d6305860e59f12
https://github.com/rakyll/statik/blob/3bac566d30cdbeddef402a80f3d6305860e59f12/fs/fs.go#L174-L212
train
micro/go-config
source/vault/vault.go
NewSource
func NewSource(opts ...source.Option) source.Source { options := source.NewOptions(opts...) // create the client client, _ := api.NewClient(api.DefaultConfig()) // get and set options if address := getAddress(options); address != "" { _ = client.SetAddress(address) } if nameSpace := getNameSpace(options); nameSpace != "" { client.SetNamespace(nameSpace) } if token := getToken(options); token != "" { client.SetToken(token) } path := getResourcePath(options) name := getSecretName(options) if name == "" { name = path } return &vault{ opts: options, client: client, secretPath: path, secretName: name, } }
go
func NewSource(opts ...source.Option) source.Source { options := source.NewOptions(opts...) // create the client client, _ := api.NewClient(api.DefaultConfig()) // get and set options if address := getAddress(options); address != "" { _ = client.SetAddress(address) } if nameSpace := getNameSpace(options); nameSpace != "" { client.SetNamespace(nameSpace) } if token := getToken(options); token != "" { client.SetToken(token) } path := getResourcePath(options) name := getSecretName(options) if name == "" { name = path } return &vault{ opts: options, client: client, secretPath: path, secretName: name, } }
[ "func", "NewSource", "(", "opts", "...", "source", ".", "Option", ")", "source", ".", "Source", "{", "options", ":=", "source", ".", "NewOptions", "(", "opts", "...", ")", "\n\n", "// create the client", "client", ",", "_", ":=", "api", ".", "NewClient", "(", "api", ".", "DefaultConfig", "(", ")", ")", "\n\n", "// get and set options", "if", "address", ":=", "getAddress", "(", "options", ")", ";", "address", "!=", "\"", "\"", "{", "_", "=", "client", ".", "SetAddress", "(", "address", ")", "\n", "}", "\n\n", "if", "nameSpace", ":=", "getNameSpace", "(", "options", ")", ";", "nameSpace", "!=", "\"", "\"", "{", "client", ".", "SetNamespace", "(", "nameSpace", ")", "\n", "}", "\n\n", "if", "token", ":=", "getToken", "(", "options", ")", ";", "token", "!=", "\"", "\"", "{", "client", ".", "SetToken", "(", "token", ")", "\n", "}", "\n\n", "path", ":=", "getResourcePath", "(", "options", ")", "\n", "name", ":=", "getSecretName", "(", "options", ")", "\n", "if", "name", "==", "\"", "\"", "{", "name", "=", "path", "\n", "}", "\n\n", "return", "&", "vault", "{", "opts", ":", "options", ",", "client", ":", "client", ",", "secretPath", ":", "path", ",", "secretName", ":", "name", ",", "}", "\n", "}" ]
// 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", ".", "Background", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "contextKey", "{", "}", ",", "c", ")", "\n", "}", "\n", "}" ]
// 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", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "namespaceKey", "{", "}", ",", "s", ")", "\n", "}", "\n", "}" ]
// 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", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "nameKey", "{", "}", ",", "s", ")", "\n", "}", "\n", "}" ]
// 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", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "configPathKey", "{", "}", ",", "s", ")", "\n", "}", "\n", "}" ]
// 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", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "addressKey", "{", "}", ",", "a", ")", "\n", "}", "\n", "}" ]
// 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", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "pathKey", "{", "}", ",", "p", ")", "\n", "}", "\n", "}" ]
// 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", ".", "Background", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "tls", ".", "Config", "{", "}", ",", "t", ")", "\n", "}", "\n", "}" ]
// 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", "=", "context", ".", "Background", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "changeSetKey", "{", "}", ",", "cs", ")", "\n", "}", "\n", "}" ]
// 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", ".", "Background", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "changeSetKey", "{", "}", ",", "&", "source", ".", "ChangeSet", "{", "Data", ":", "d", ",", "Format", ":", "\"", "\"", ",", "}", ")", "\n", "}", "\n", "}" ]
// 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", "(", ")", ",", "opts", ":", "options", ",", "}", "\n", "}" ]
// NewReader creates a json reader
[ "NewReader", "creates", "a", "json", "reader" ]
bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5
https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/reader/json/json.go#L77-L83
train
micro/go-config
source/configmap/configmap.go
NewSource
func NewSource(opts ...source.Option) source.Source { var ( options = source.NewOptions(opts...) name = DefaultName configPath = DefaultConfigPath namespace = DefaultNamespace ) prefix, ok := options.Context.Value(prefixKey{}).(string) if ok { name = prefix } cfg, ok := options.Context.Value(configPathKey{}).(string) if ok { configPath = cfg } sname, ok := options.Context.Value(nameKey{}).(string) if ok { name = sname } ns, ok := options.Context.Value(namespaceKey{}).(string) if ok { namespace = ns } // TODO handle if the client fails what to do current return does not support error client, err := getClient(configPath) return &configmap{ cerr: err, client: client, opts: options, name: name, configPath: configPath, namespace: namespace, } }
go
func NewSource(opts ...source.Option) source.Source { var ( options = source.NewOptions(opts...) name = DefaultName configPath = DefaultConfigPath namespace = DefaultNamespace ) prefix, ok := options.Context.Value(prefixKey{}).(string) if ok { name = prefix } cfg, ok := options.Context.Value(configPathKey{}).(string) if ok { configPath = cfg } sname, ok := options.Context.Value(nameKey{}).(string) if ok { name = sname } ns, ok := options.Context.Value(namespaceKey{}).(string) if ok { namespace = ns } // TODO handle if the client fails what to do current return does not support error client, err := getClient(configPath) return &configmap{ cerr: err, client: client, opts: options, name: name, configPath: configPath, namespace: namespace, } }
[ "func", "NewSource", "(", "opts", "...", "source", ".", "Option", ")", "source", ".", "Source", "{", "var", "(", "options", "=", "source", ".", "NewOptions", "(", "opts", "...", ")", "\n", "name", "=", "DefaultName", "\n", "configPath", "=", "DefaultConfigPath", "\n", "namespace", "=", "DefaultNamespace", "\n", ")", "\n\n", "prefix", ",", "ok", ":=", "options", ".", "Context", ".", "Value", "(", "prefixKey", "{", "}", ")", ".", "(", "string", ")", "\n", "if", "ok", "{", "name", "=", "prefix", "\n", "}", "\n\n", "cfg", ",", "ok", ":=", "options", ".", "Context", ".", "Value", "(", "configPathKey", "{", "}", ")", ".", "(", "string", ")", "\n", "if", "ok", "{", "configPath", "=", "cfg", "\n", "}", "\n\n", "sname", ",", "ok", ":=", "options", ".", "Context", ".", "Value", "(", "nameKey", "{", "}", ")", ".", "(", "string", ")", "\n", "if", "ok", "{", "name", "=", "sname", "\n", "}", "\n\n", "ns", ",", "ok", ":=", "options", ".", "Context", ".", "Value", "(", "namespaceKey", "{", "}", ")", ".", "(", "string", ")", "\n", "if", "ok", "{", "namespace", "=", "ns", "\n", "}", "\n\n", "// TODO handle if the client fails what to do current return does not support error", "client", ",", "err", ":=", "getClient", "(", "configPath", ")", "\n\n", "return", "&", "configmap", "{", "cerr", ":", "err", ",", "client", ":", "client", ",", "opts", ":", "options", ",", "name", ":", "name", ",", "configPath", ":", "configPath", ",", "namespace", ":", "namespace", ",", "}", "\n", "}" ]
// 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", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "prefixKey", "{", "}", ",", "p", ")", "\n", "}", "\n", "}" ]
// 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", "(", ")", "\n", "}", "\n\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "stripPrefixKey", "{", "}", ",", "strip", ")", "\n", "}", "\n", "}" ]
// 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", ".", "Background", "(", ")", "\n", "}", "\n\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "strippedPrefixKey", "{", "}", ",", "appendUnderscore", "(", "p", ")", ")", "\n", "}", "\n", "}" ]
// 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", "=", "context", ".", "Background", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "variableKey", "{", "}", ",", "v", ")", "\n", "}", "\n", "}" ]
// 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", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "tokenKey", "{", "}", ",", "p", ")", "\n", "}", "\n", "}" ]
// WithToken sets the key token to use
[ "WithToken", "sets", "the", "key", "token", "to", "use" ]
bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5
https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/source/consul/options.go#L56-L63
train
micro/go-config
loader/memory/memory.go
reload
func (m *memory) reload() error { m.Lock() // merge sets set, err := m.opts.Reader.Merge(m.sets...) if err != nil { m.Unlock() return err } // set values m.vals, _ = m.opts.Reader.Values(set) m.snap = &loader.Snapshot{ ChangeSet: set, Version: fmt.Sprintf("%d", time.Now().Unix()), } m.Unlock() // update watchers m.update() return nil }
go
func (m *memory) reload() error { m.Lock() // merge sets set, err := m.opts.Reader.Merge(m.sets...) if err != nil { m.Unlock() return err } // set values m.vals, _ = m.opts.Reader.Values(set) m.snap = &loader.Snapshot{ ChangeSet: set, Version: fmt.Sprintf("%d", time.Now().Unix()), } m.Unlock() // update watchers m.update() return nil }
[ "func", "(", "m", "*", "memory", ")", "reload", "(", ")", "error", "{", "m", ".", "Lock", "(", ")", "\n\n", "// merge sets", "set", ",", "err", ":=", "m", ".", "opts", ".", "Reader", ".", "Merge", "(", "m", ".", "sets", "...", ")", "\n", "if", "err", "!=", "nil", "{", "m", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", "}", "\n\n", "// set values", "m", ".", "vals", ",", "_", "=", "m", ".", "opts", ".", "Reader", ".", "Values", "(", "set", ")", "\n", "m", ".", "snap", "=", "&", "loader", ".", "Snapshot", "{", "ChangeSet", ":", "set", ",", "Version", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "time", ".", "Now", "(", ")", ".", "Unix", "(", ")", ")", ",", "}", "\n\n", "m", ".", "Unlock", "(", ")", "\n\n", "// update watchers", "m", ".", "update", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// reload reads the sets and creates new values
[ "reload", "reads", "the", "sets", "and", "creates", "new", "values" ]
bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5
https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/loader/memory/memory.go#L130-L153
train
micro/go-config
loader/memory/memory.go
Snapshot
func (m *memory) Snapshot() (*loader.Snapshot, error) { if m.loaded() { m.RLock() snap := loader.Copy(m.snap) m.RUnlock() return snap, nil } // not loaded, sync if err := m.Sync(); err != nil { return nil, err } // make copy m.RLock() snap := loader.Copy(m.snap) m.RUnlock() return snap, nil }
go
func (m *memory) Snapshot() (*loader.Snapshot, error) { if m.loaded() { m.RLock() snap := loader.Copy(m.snap) m.RUnlock() return snap, nil } // not loaded, sync if err := m.Sync(); err != nil { return nil, err } // make copy m.RLock() snap := loader.Copy(m.snap) m.RUnlock() return snap, nil }
[ "func", "(", "m", "*", "memory", ")", "Snapshot", "(", ")", "(", "*", "loader", ".", "Snapshot", ",", "error", ")", "{", "if", "m", ".", "loaded", "(", ")", "{", "m", ".", "RLock", "(", ")", "\n", "snap", ":=", "loader", ".", "Copy", "(", "m", ".", "snap", ")", "\n", "m", ".", "RUnlock", "(", ")", "\n", "return", "snap", ",", "nil", "\n", "}", "\n\n", "// not loaded, sync", "if", "err", ":=", "m", ".", "Sync", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// make copy", "m", ".", "RLock", "(", ")", "\n", "snap", ":=", "loader", ".", "Copy", "(", "m", ".", "snap", ")", "\n", "m", ".", "RUnlock", "(", ")", "\n\n", "return", "snap", ",", "nil", "\n", "}" ]
// Snapshot returns a snapshot of the current loaded config
[ "Snapshot", "returns", "a", "snapshot", "of", "the", "current", "loaded", "config" ]
bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5
https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/loader/memory/memory.go#L173-L192
train
micro/go-config
loader/memory/memory.go
Sync
func (m *memory) Sync() error { var sets []*source.ChangeSet m.Lock() // read the source var gerr []string for _, source := range m.sources { ch, err := source.Read() if err != nil { gerr = append(gerr, err.Error()) continue } sets = append(sets, ch) } // merge sets set, err := m.opts.Reader.Merge(sets...) if err != nil { m.Unlock() return err } // set values vals, err := m.opts.Reader.Values(set) if err != nil { m.Unlock() return err } m.vals = vals m.snap = &loader.Snapshot{ ChangeSet: set, Version: fmt.Sprintf("%d", time.Now().Unix()), } m.Unlock() // update watchers m.update() if len(gerr) > 0 { return fmt.Errorf("source loading errors: %s", strings.Join(gerr, "\n")) } return nil }
go
func (m *memory) Sync() error { var sets []*source.ChangeSet m.Lock() // read the source var gerr []string for _, source := range m.sources { ch, err := source.Read() if err != nil { gerr = append(gerr, err.Error()) continue } sets = append(sets, ch) } // merge sets set, err := m.opts.Reader.Merge(sets...) if err != nil { m.Unlock() return err } // set values vals, err := m.opts.Reader.Values(set) if err != nil { m.Unlock() return err } m.vals = vals m.snap = &loader.Snapshot{ ChangeSet: set, Version: fmt.Sprintf("%d", time.Now().Unix()), } m.Unlock() // update watchers m.update() if len(gerr) > 0 { return fmt.Errorf("source loading errors: %s", strings.Join(gerr, "\n")) } return nil }
[ "func", "(", "m", "*", "memory", ")", "Sync", "(", ")", "error", "{", "var", "sets", "[", "]", "*", "source", ".", "ChangeSet", "\n\n", "m", ".", "Lock", "(", ")", "\n\n", "// read the source", "var", "gerr", "[", "]", "string", "\n\n", "for", "_", ",", "source", ":=", "range", "m", ".", "sources", "{", "ch", ",", "err", ":=", "source", ".", "Read", "(", ")", "\n", "if", "err", "!=", "nil", "{", "gerr", "=", "append", "(", "gerr", ",", "err", ".", "Error", "(", ")", ")", "\n", "continue", "\n", "}", "\n", "sets", "=", "append", "(", "sets", ",", "ch", ")", "\n", "}", "\n\n", "// merge sets", "set", ",", "err", ":=", "m", ".", "opts", ".", "Reader", ".", "Merge", "(", "sets", "...", ")", "\n", "if", "err", "!=", "nil", "{", "m", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", "}", "\n\n", "// set values", "vals", ",", "err", ":=", "m", ".", "opts", ".", "Reader", ".", "Values", "(", "set", ")", "\n", "if", "err", "!=", "nil", "{", "m", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", "}", "\n", "m", ".", "vals", "=", "vals", "\n", "m", ".", "snap", "=", "&", "loader", ".", "Snapshot", "{", "ChangeSet", ":", "set", ",", "Version", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "time", ".", "Now", "(", ")", ".", "Unix", "(", ")", ")", ",", "}", "\n\n", "m", ".", "Unlock", "(", ")", "\n\n", "// update watchers", "m", ".", "update", "(", ")", "\n\n", "if", "len", "(", "gerr", ")", ">", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "gerr", ",", "\"", "\\n", "\"", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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", ".", "Sum", "(", "nil", ")", ")", "\n", "}" ]
// 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", "(", "opts", "...", ")", ",", "}", "\n", "}" ]
// 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", "}", "\n", "}" ]
// WithSource appends a source to list of sources
[ "WithSource", "appends", "a", "source", "to", "list", "of", "sources" ]
bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5
https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/loader/memory/options.go#L10-L14
train
micro/go-config
loader/memory/options.go
WithReader
func WithReader(r reader.Reader) loader.Option { return func(o *loader.Options) { o.Reader = r } }
go
func WithReader(r reader.Reader) loader.Option { return func(o *loader.Options) { o.Reader = r } }
[ "func", "WithReader", "(", "r", "reader", ".", "Reader", ")", "loader", ".", "Option", "{", "return", "func", "(", "o", "*", "loader", ".", "Options", ")", "{", "o", ".", "Reader", "=", "r", "\n", "}", "\n", "}" ]
// WithReader sets the config reader
[ "WithReader", "sets", "the", "config", "reader" ]
bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5
https://github.com/micro/go-config/blob/bb7d57b8c5fa63763357fdd6a484f0f7adb11ed5/loader/memory/options.go#L17-L21
train
micro/go-config
source/consul/consul.go
NewSource
func NewSource(opts ...source.Option) source.Source { options := source.NewOptions(opts...) // use default config config := api.DefaultConfig() // check if there are any addrs a, ok := options.Context.Value(addressKey{}).(string) if ok { addr, port, err := net.SplitHostPort(a) if ae, ok := err.(*net.AddrError); ok && ae.Err == "missing port in address" { port = "8500" addr = a config.Address = fmt.Sprintf("%s:%s", addr, port) } else if err == nil { config.Address = fmt.Sprintf("%s:%s", addr, port) } } dc, ok := options.Context.Value(dcKey{}).(string) if ok { config.Datacenter = dc } token, ok := options.Context.Value(tokenKey{}).(string) if ok { config.Token = token } // create the client client, _ := api.NewClient(config) prefix := DefaultPrefix sp := "" f, ok := options.Context.Value(prefixKey{}).(string) if ok { prefix = f } if b, ok := options.Context.Value(stripPrefixKey{}).(bool); ok && b { sp = prefix } return &consul{ prefix: prefix, stripPrefix: sp, addr: config.Address, opts: options, client: client, } }
go
func NewSource(opts ...source.Option) source.Source { options := source.NewOptions(opts...) // use default config config := api.DefaultConfig() // check if there are any addrs a, ok := options.Context.Value(addressKey{}).(string) if ok { addr, port, err := net.SplitHostPort(a) if ae, ok := err.(*net.AddrError); ok && ae.Err == "missing port in address" { port = "8500" addr = a config.Address = fmt.Sprintf("%s:%s", addr, port) } else if err == nil { config.Address = fmt.Sprintf("%s:%s", addr, port) } } dc, ok := options.Context.Value(dcKey{}).(string) if ok { config.Datacenter = dc } token, ok := options.Context.Value(tokenKey{}).(string) if ok { config.Token = token } // create the client client, _ := api.NewClient(config) prefix := DefaultPrefix sp := "" f, ok := options.Context.Value(prefixKey{}).(string) if ok { prefix = f } if b, ok := options.Context.Value(stripPrefixKey{}).(bool); ok && b { sp = prefix } return &consul{ prefix: prefix, stripPrefix: sp, addr: config.Address, opts: options, client: client, } }
[ "func", "NewSource", "(", "opts", "...", "source", ".", "Option", ")", "source", ".", "Source", "{", "options", ":=", "source", ".", "NewOptions", "(", "opts", "...", ")", "\n\n", "// use default config", "config", ":=", "api", ".", "DefaultConfig", "(", ")", "\n\n", "// check if there are any addrs", "a", ",", "ok", ":=", "options", ".", "Context", ".", "Value", "(", "addressKey", "{", "}", ")", ".", "(", "string", ")", "\n", "if", "ok", "{", "addr", ",", "port", ",", "err", ":=", "net", ".", "SplitHostPort", "(", "a", ")", "\n", "if", "ae", ",", "ok", ":=", "err", ".", "(", "*", "net", ".", "AddrError", ")", ";", "ok", "&&", "ae", ".", "Err", "==", "\"", "\"", "{", "port", "=", "\"", "\"", "\n", "addr", "=", "a", "\n", "config", ".", "Address", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "addr", ",", "port", ")", "\n", "}", "else", "if", "err", "==", "nil", "{", "config", ".", "Address", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "addr", ",", "port", ")", "\n", "}", "\n", "}", "\n\n", "dc", ",", "ok", ":=", "options", ".", "Context", ".", "Value", "(", "dcKey", "{", "}", ")", ".", "(", "string", ")", "\n", "if", "ok", "{", "config", ".", "Datacenter", "=", "dc", "\n", "}", "\n\n", "token", ",", "ok", ":=", "options", ".", "Context", ".", "Value", "(", "tokenKey", "{", "}", ")", ".", "(", "string", ")", "\n", "if", "ok", "{", "config", ".", "Token", "=", "token", "\n", "}", "\n\n", "// create the client", "client", ",", "_", ":=", "api", ".", "NewClient", "(", "config", ")", "\n\n", "prefix", ":=", "DefaultPrefix", "\n", "sp", ":=", "\"", "\"", "\n", "f", ",", "ok", ":=", "options", ".", "Context", ".", "Value", "(", "prefixKey", "{", "}", ")", ".", "(", "string", ")", "\n", "if", "ok", "{", "prefix", "=", "f", "\n", "}", "\n\n", "if", "b", ",", "ok", ":=", "options", ".", "Context", ".", "Value", "(", "stripPrefixKey", "{", "}", ")", ".", "(", "bool", ")", ";", "ok", "&&", "b", "{", "sp", "=", "prefix", "\n", "}", "\n\n", "return", "&", "consul", "{", "prefix", ":", "prefix", ",", "stripPrefix", ":", "sp", ",", "addr", ":", "config", ".", "Address", ",", "opts", ":", "options", ",", "client", ":", "client", ",", "}", "\n", "}" ]
// 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", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "resourcePath", "{", "}", ",", "p", ")", "\n", "}", "\n", "}" ]
// 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", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "nameSpace", "{", "}", ",", "n", ")", "\n", "}", "\n", "}" ]
// 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", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "secretName", "{", "}", ",", "t", ")", "\n", "}", "\n", "}" ]
// 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", "(", ")", "\n", "}", "\n", "o", ".", "Context", "=", "context", ".", "WithValue", "(", "o", ".", "Context", ",", "includeUnsetKey", "{", "}", ",", "true", ")", "\n", "}", "\n", "}" ]
// 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", ".", "Sprintf", "(", "\"", "\"", ",", "maxResults", ")", "}", ")", "\n", "return", "s", "\n", "}", "\n", "}" ]
// 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", ".", "Sprintf", "(", "\"", "\"", ",", "startAt", ")", "}", ")", "\n", "return", "s", "\n", "}", "\n", "}" ]
// 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", ".", "Sprintf", "(", "\"", "\"", ",", "active", ")", "}", ")", "\n", "return", "s", "\n", "}", "\n", "}" ]
// 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", ".", "Sprintf", "(", "\"", "\"", ",", "inactive", ")", "}", ")", "\n", "return", "s", "\n", "}", "\n", "}" ]
// 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", "{", "ProjectKeys", ":", "projectkeys", ",", "Expand", ":", "\"", "\"", "}", ")", "\n", "}" ]
// GetCreateMeta makes the api call to get the meta information required to create a ticket
[ "GetCreateMeta", "makes", "the", "api", "call", "to", "get", "the", "meta", "information", "required", "to", "create", "a", "ticket" ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/metaissue.go#L46-L48
train
andygrunwald/go-jira
metaissue.go
GetCreateMetaWithOptions
func (s *IssueService) GetCreateMetaWithOptions(options *GetQueryOptions) (*CreateMetaInfo, *Response, error) { apiEndpoint := "rest/api/2/issue/createmeta" req, err := s.client.NewRequest("GET", apiEndpoint, nil) if err != nil { return nil, nil, err } if options != nil { q, err := query.Values(options) if err != nil { return nil, nil, err } req.URL.RawQuery = q.Encode() } meta := new(CreateMetaInfo) resp, err := s.client.Do(req, meta) if err != nil { return nil, resp, err } return meta, resp, nil }
go
func (s *IssueService) GetCreateMetaWithOptions(options *GetQueryOptions) (*CreateMetaInfo, *Response, error) { apiEndpoint := "rest/api/2/issue/createmeta" req, err := s.client.NewRequest("GET", apiEndpoint, nil) if err != nil { return nil, nil, err } if options != nil { q, err := query.Values(options) if err != nil { return nil, nil, err } req.URL.RawQuery = q.Encode() } meta := new(CreateMetaInfo) resp, err := s.client.Do(req, meta) if err != nil { return nil, resp, err } return meta, resp, nil }
[ "func", "(", "s", "*", "IssueService", ")", "GetCreateMetaWithOptions", "(", "options", "*", "GetQueryOptions", ")", "(", "*", "CreateMetaInfo", ",", "*", "Response", ",", "error", ")", "{", "apiEndpoint", ":=", "\"", "\"", "\n\n", "req", ",", "err", ":=", "s", ".", "client", ".", "NewRequest", "(", "\"", "\"", ",", "apiEndpoint", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "if", "options", "!=", "nil", "{", "q", ",", "err", ":=", "query", ".", "Values", "(", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "req", ".", "URL", ".", "RawQuery", "=", "q", ".", "Encode", "(", ")", "\n", "}", "\n\n", "meta", ":=", "new", "(", "CreateMetaInfo", ")", "\n", "resp", ",", "err", ":=", "s", ".", "client", ".", "Do", "(", "req", ",", "meta", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "resp", ",", "err", "\n", "}", "\n\n", "return", "meta", ",", "resp", ",", "nil", "\n", "}" ]
// 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", ")", "==", "strings", ".", "ToLower", "(", "name", ")", "{", "return", "m", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", ")", "==", "strings", ".", "ToLower", "(", "key", ")", "{", "return", "m", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", ")", "==", "strings", ".", "ToLower", "(", "name", ")", "{", "return", "m", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", ".", "Fields", "{", "name", ",", "err", ":=", "t", ".", "Fields", ".", "String", "(", "key", "+", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "ret", "[", "name", "]", "=", "key", "\n", "}", "\n", "return", "ret", ",", "nil", "\n", "}" ]
// 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", "form", "and", "the", "value", "is", "how", "it", "is", "representated", "in", "the", "jira", "schema", "." ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/metaissue.go#L146-L157
train
andygrunwald/go-jira
metaissue.go
CheckCompleteAndAvailable
func (t *MetaIssueType) CheckCompleteAndAvailable(config map[string]string) (bool, error) { mandatory, err := t.GetMandatoryFields() if err != nil { return false, err } all, err := t.GetAllFields() if err != nil { return false, err } // check templateconfig against mandatory fields for key := range mandatory { if _, okay := config[key]; !okay { var requiredFields []string for name := range mandatory { requiredFields = append(requiredFields, name) } return false, fmt.Errorf("Required field not found in provided jira.fields. Required are: %#v", requiredFields) } } // check templateConfig against all fields to verify they are available for key := range config { if _, okay := all[key]; !okay { var availableFields []string for name := range all { availableFields = append(availableFields, name) } return false, fmt.Errorf("Fields in jira.fields are not available in jira. Available are: %#v", availableFields) } } return true, nil }
go
func (t *MetaIssueType) CheckCompleteAndAvailable(config map[string]string) (bool, error) { mandatory, err := t.GetMandatoryFields() if err != nil { return false, err } all, err := t.GetAllFields() if err != nil { return false, err } // check templateconfig against mandatory fields for key := range mandatory { if _, okay := config[key]; !okay { var requiredFields []string for name := range mandatory { requiredFields = append(requiredFields, name) } return false, fmt.Errorf("Required field not found in provided jira.fields. Required are: %#v", requiredFields) } } // check templateConfig against all fields to verify they are available for key := range config { if _, okay := all[key]; !okay { var availableFields []string for name := range all { availableFields = append(availableFields, name) } return false, fmt.Errorf("Fields in jira.fields are not available in jira. Available are: %#v", availableFields) } } return true, nil }
[ "func", "(", "t", "*", "MetaIssueType", ")", "CheckCompleteAndAvailable", "(", "config", "map", "[", "string", "]", "string", ")", "(", "bool", ",", "error", ")", "{", "mandatory", ",", "err", ":=", "t", ".", "GetMandatoryFields", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "all", ",", "err", ":=", "t", ".", "GetAllFields", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "// check templateconfig against mandatory fields", "for", "key", ":=", "range", "mandatory", "{", "if", "_", ",", "okay", ":=", "config", "[", "key", "]", ";", "!", "okay", "{", "var", "requiredFields", "[", "]", "string", "\n", "for", "name", ":=", "range", "mandatory", "{", "requiredFields", "=", "append", "(", "requiredFields", ",", "name", ")", "\n", "}", "\n", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "requiredFields", ")", "\n", "}", "\n", "}", "\n\n", "// check templateConfig against all fields to verify they are available", "for", "key", ":=", "range", "config", "{", "if", "_", ",", "okay", ":=", "all", "[", "key", "]", ";", "!", "okay", "{", "var", "availableFields", "[", "]", "string", "\n", "for", "name", ":=", "range", "all", "{", "availableFields", "=", "append", "(", "availableFields", ",", "name", ")", "\n", "}", "\n", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "availableFields", ")", "\n", "}", "\n", "}", "\n\n", "return", "true", ",", "nil", "\n", "}" ]
// CheckCompleteAndAvailable checks if the given fields satisfies the mandatory field required to create a issue for the given type // And also if the given fields are available.
[ "CheckCompleteAndAvailable", "checks", "if", "the", "given", "fields", "satisfies", "the", "mandatory", "field", "required", "to", "create", "a", "issue", "for", "the", "given", "type", "And", "also", "if", "the", "given", "fields", "are", "available", "." ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/metaissue.go#L161-L194
train
andygrunwald/go-jira
component.go
Create
func (s *ComponentService) Create(options *CreateComponentOptions) (*ProjectComponent, *Response, error) { apiEndpoint := "rest/api/2/component" req, err := s.client.NewRequest("POST", apiEndpoint, options) if err != nil { return nil, nil, err } component := new(ProjectComponent) resp, err := s.client.Do(req, component) if err != nil { return nil, resp, NewJiraError(resp, err) } return component, resp, nil }
go
func (s *ComponentService) Create(options *CreateComponentOptions) (*ProjectComponent, *Response, error) { apiEndpoint := "rest/api/2/component" req, err := s.client.NewRequest("POST", apiEndpoint, options) if err != nil { return nil, nil, err } component := new(ProjectComponent) resp, err := s.client.Do(req, component) if err != nil { return nil, resp, NewJiraError(resp, err) } return component, resp, nil }
[ "func", "(", "s", "*", "ComponentService", ")", "Create", "(", "options", "*", "CreateComponentOptions", ")", "(", "*", "ProjectComponent", ",", "*", "Response", ",", "error", ")", "{", "apiEndpoint", ":=", "\"", "\"", "\n", "req", ",", "err", ":=", "s", ".", "client", ".", "NewRequest", "(", "\"", "\"", ",", "apiEndpoint", ",", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "component", ":=", "new", "(", "ProjectComponent", ")", "\n", "resp", ",", "err", ":=", "s", ".", "client", ".", "Do", "(", "req", ",", "component", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "resp", ",", "NewJiraError", "(", "resp", ",", "err", ")", "\n", "}", "\n\n", "return", "component", ",", "resp", ",", "nil", "\n", "}" ]
// Create creates a new JIRA component based on the given options.
[ "Create", "creates", "a", "new", "JIRA", "component", "based", "on", "the", "given", "options", "." ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/component.go#L23-L38
train
andygrunwald/go-jira
issue.go
DownloadAttachment
func (s *IssueService) DownloadAttachment(attachmentID string) (*Response, error) { apiEndpoint := fmt.Sprintf("secure/attachment/%s/", attachmentID) req, err := s.client.NewRequest("GET", apiEndpoint, nil) if err != nil { return nil, err } resp, err := s.client.Do(req, nil) if err != nil { jerr := NewJiraError(resp, err) return resp, jerr } return resp, nil }
go
func (s *IssueService) DownloadAttachment(attachmentID string) (*Response, error) { apiEndpoint := fmt.Sprintf("secure/attachment/%s/", attachmentID) req, err := s.client.NewRequest("GET", apiEndpoint, nil) if err != nil { return nil, err } resp, err := s.client.Do(req, nil) if err != nil { jerr := NewJiraError(resp, err) return resp, jerr } return resp, nil }
[ "func", "(", "s", "*", "IssueService", ")", "DownloadAttachment", "(", "attachmentID", "string", ")", "(", "*", "Response", ",", "error", ")", "{", "apiEndpoint", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "attachmentID", ")", "\n", "req", ",", "err", ":=", "s", ".", "client", ".", "NewRequest", "(", "\"", "\"", ",", "apiEndpoint", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "resp", ",", "err", ":=", "s", ".", "client", ".", "Do", "(", "req", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "jerr", ":=", "NewJiraError", "(", "resp", ",", "err", ")", "\n", "return", "resp", ",", "jerr", "\n", "}", "\n\n", "return", "resp", ",", "nil", "\n", "}" ]
// DownloadAttachment returns a Response of an attachment for a given attachmentID. // The attachment is in the Response.Body of the response. // This is an io.ReadCloser. // The caller should close the resp.Body.
[ "DownloadAttachment", "returns", "a", "Response", "of", "an", "attachment", "for", "a", "given", "attachmentID", ".", "The", "attachment", "is", "in", "the", "Response", ".", "Body", "of", "the", "response", ".", "This", "is", "an", "io", ".", "ReadCloser", ".", "The", "caller", "should", "close", "the", "resp", ".", "Body", "." ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/issue.go#L571-L585
train
andygrunwald/go-jira
issue.go
Delete
func (s *IssueService) Delete(issueID string) (*Response, error) { apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s", issueID) // to enable deletion of subtasks; without this, the request will fail if the issue has subtasks deletePayload := make(map[string]interface{}) deletePayload["deleteSubtasks"] = "true" content, _ := json.Marshal(deletePayload) req, err := s.client.NewRequest("DELETE", apiEndpoint, content) if err != nil { return nil, err } resp, err := s.client.Do(req, nil) return resp, err }
go
func (s *IssueService) Delete(issueID string) (*Response, error) { apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s", issueID) // to enable deletion of subtasks; without this, the request will fail if the issue has subtasks deletePayload := make(map[string]interface{}) deletePayload["deleteSubtasks"] = "true" content, _ := json.Marshal(deletePayload) req, err := s.client.NewRequest("DELETE", apiEndpoint, content) if err != nil { return nil, err } resp, err := s.client.Do(req, nil) return resp, err }
[ "func", "(", "s", "*", "IssueService", ")", "Delete", "(", "issueID", "string", ")", "(", "*", "Response", ",", "error", ")", "{", "apiEndpoint", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "issueID", ")", "\n\n", "// to enable deletion of subtasks; without this, the request will fail if the issue has subtasks", "deletePayload", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "deletePayload", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "content", ",", "_", ":=", "json", ".", "Marshal", "(", "deletePayload", ")", "\n\n", "req", ",", "err", ":=", "s", ".", "client", ".", "NewRequest", "(", "\"", "\"", ",", "apiEndpoint", ",", "content", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "resp", ",", "err", ":=", "s", ".", "client", ".", "Do", "(", "req", ",", "nil", ")", "\n", "return", "resp", ",", "err", "\n", "}" ]
// 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", "}", "else", "if", "s", ".", "authType", "==", "authTypeBasic", "{", "return", "s", ".", "username", "!=", "\"", "\"", "\n", "}", "\n\n", "}", "\n", "return", "false", "\n", "}" ]
// Authenticated reports if the current Client has authentication details for JIRA
[ "Authenticated", "reports", "if", "the", "current", "Client", "has", "authentication", "details", "for", "JIRA" ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/authentication.go#L104-L114
train
andygrunwald/go-jira
filter.go
GetList
func (fs *FilterService) GetList() ([]*Filter, *Response, error) { options := &GetQueryOptions{} apiEndpoint := "rest/api/2/filter" req, err := fs.client.NewRequest("GET", apiEndpoint, nil) if err != nil { return nil, nil, err } if options != nil { q, err := query.Values(options) if err != nil { return nil, nil, err } req.URL.RawQuery = q.Encode() } filters := []*Filter{} resp, err := fs.client.Do(req, &filters) if err != nil { jerr := NewJiraError(resp, err) return nil, resp, jerr } return filters, resp, err }
go
func (fs *FilterService) GetList() ([]*Filter, *Response, error) { options := &GetQueryOptions{} apiEndpoint := "rest/api/2/filter" req, err := fs.client.NewRequest("GET", apiEndpoint, nil) if err != nil { return nil, nil, err } if options != nil { q, err := query.Values(options) if err != nil { return nil, nil, err } req.URL.RawQuery = q.Encode() } filters := []*Filter{} resp, err := fs.client.Do(req, &filters) if err != nil { jerr := NewJiraError(resp, err) return nil, resp, jerr } return filters, resp, err }
[ "func", "(", "fs", "*", "FilterService", ")", "GetList", "(", ")", "(", "[", "]", "*", "Filter", ",", "*", "Response", ",", "error", ")", "{", "options", ":=", "&", "GetQueryOptions", "{", "}", "\n", "apiEndpoint", ":=", "\"", "\"", "\n", "req", ",", "err", ":=", "fs", ".", "client", ".", "NewRequest", "(", "\"", "\"", ",", "apiEndpoint", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "if", "options", "!=", "nil", "{", "q", ",", "err", ":=", "query", ".", "Values", "(", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "req", ".", "URL", ".", "RawQuery", "=", "q", ".", "Encode", "(", ")", "\n", "}", "\n\n", "filters", ":=", "[", "]", "*", "Filter", "{", "}", "\n", "resp", ",", "err", ":=", "fs", ".", "client", ".", "Do", "(", "req", ",", "&", "filters", ")", "\n", "if", "err", "!=", "nil", "{", "jerr", ":=", "NewJiraError", "(", "resp", ",", "err", ")", "\n", "return", "nil", ",", "resp", ",", "jerr", "\n", "}", "\n", "return", "filters", ",", "resp", ",", "err", "\n", "}" ]
// GetList retrieves all filters from Jira
[ "GetList", "retrieves", "all", "filters", "from", "Jira" ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/filter.go#L36-L60
train
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 := NewJiraError(resp, err) return nil, resp, jerr } return filters, resp, err }
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 := NewJiraError(resp, err) return nil, resp, jerr } return filters, resp, err }
[ "func", "(", "fs", "*", "FilterService", ")", "GetFavouriteList", "(", ")", "(", "[", "]", "*", "Filter", ",", "*", "Response", ",", "error", ")", "{", "apiEndpoint", ":=", "\"", "\"", "\n", "req", ",", "err", ":=", "fs", ".", "client", ".", "NewRequest", "(", "\"", "\"", ",", "apiEndpoint", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "filters", ":=", "[", "]", "*", "Filter", "{", "}", "\n", "resp", ",", "err", ":=", "fs", ".", "client", ".", "Do", "(", "req", ",", "&", "filters", ")", "\n", "if", "err", "!=", "nil", "{", "jerr", ":=", "NewJiraError", "(", "resp", ",", "err", ")", "\n", "return", "nil", ",", "resp", ",", "jerr", "\n", "}", "\n", "return", "filters", ",", "resp", ",", "err", "\n", "}" ]
// 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 { jerr := NewJiraError(resp, err) return nil, resp, jerr } return filter, resp, err }
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 { jerr := NewJiraError(resp, err) return nil, resp, jerr } return filter, resp, err }
[ "func", "(", "fs", "*", "FilterService", ")", "Get", "(", "filterID", "int", ")", "(", "*", "Filter", ",", "*", "Response", ",", "error", ")", "{", "apiEndpoint", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "filterID", ")", "\n", "req", ",", "err", ":=", "fs", ".", "client", ".", "NewRequest", "(", "\"", "\"", ",", "apiEndpoint", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "filter", ":=", "new", "(", "Filter", ")", "\n", "resp", ",", "err", ":=", "fs", ".", "client", ".", "Do", "(", "req", ",", "filter", ")", "\n", "if", "err", "!=", "nil", "{", "jerr", ":=", "NewJiraError", "(", "resp", ",", "err", ")", "\n", "return", "nil", ",", "resp", ",", "jerr", "\n", "}", "\n\n", "return", "filter", ",", "resp", ",", "err", "\n", "}" ]
// 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 := resp.Header.Get("Content-Type") if strings.HasPrefix(contentType, "application/json") { err = json.Unmarshal(body, &jerr) if err != nil { httpError = errors.Wrap(errors.New("Could not parse JSON"), httpError.Error()) return errors.Wrap(err, httpError.Error()) } } else { if httpError == nil { return fmt.Errorf("Got Response Status %s:%s", resp.Status, string(body)) } return errors.Wrap(httpError, fmt.Sprintf("%s: %s", resp.Status, string(body))) } return &jerr }
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 := resp.Header.Get("Content-Type") if strings.HasPrefix(contentType, "application/json") { err = json.Unmarshal(body, &jerr) if err != nil { httpError = errors.Wrap(errors.New("Could not parse JSON"), httpError.Error()) return errors.Wrap(err, httpError.Error()) } } else { if httpError == nil { return fmt.Errorf("Got Response Status %s:%s", resp.Status, string(body)) } return errors.Wrap(httpError, fmt.Sprintf("%s: %s", resp.Status, string(body))) } return &jerr }
[ "func", "NewJiraError", "(", "resp", "*", "Response", ",", "httpError", "error", ")", "error", "{", "if", "resp", "==", "nil", "{", "return", "errors", ".", "Wrap", "(", "httpError", ",", "\"", "\"", ")", "\n", "}", "\n\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "body", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "resp", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "httpError", ".", "Error", "(", ")", ")", "\n", "}", "\n", "jerr", ":=", "Error", "{", "HTTPError", ":", "httpError", "}", "\n", "contentType", ":=", "resp", ".", "Header", ".", "Get", "(", "\"", "\"", ")", "\n", "if", "strings", ".", "HasPrefix", "(", "contentType", ",", "\"", "\"", ")", "{", "err", "=", "json", ".", "Unmarshal", "(", "body", ",", "&", "jerr", ")", "\n", "if", "err", "!=", "nil", "{", "httpError", "=", "errors", ".", "Wrap", "(", "errors", ".", "New", "(", "\"", "\"", ")", ",", "httpError", ".", "Error", "(", ")", ")", "\n", "return", "errors", ".", "Wrap", "(", "err", ",", "httpError", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "else", "{", "if", "httpError", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "resp", ".", "Status", ",", "string", "(", "body", ")", ")", "\n", "}", "\n", "return", "errors", ".", "Wrap", "(", "httpError", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "resp", ".", "Status", ",", "string", "(", "body", ")", ")", ")", "\n", "}", "\n\n", "return", "&", "jerr", "\n", "}" ]
// 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.HTTPError.Error() }
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.HTTPError.Error() }
[ "func", "(", "e", "*", "Error", ")", "Error", "(", ")", "string", "{", "if", "len", "(", "e", ".", "ErrorMessages", ")", ">", "0", "{", "// return fmt.Sprintf(\"%v\", e.HTTPError)", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "ErrorMessages", "[", "0", "]", ",", "e", ".", "HTTPError", ")", "\n", "}", "\n", "if", "len", "(", "e", ".", "Errors", ")", ">", "0", "{", "for", "key", ",", "value", ":=", "range", "e", ".", "Errors", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "key", ",", "value", ",", "e", ".", "HTTPError", ")", "\n", "}", "\n", "}", "\n", "return", "e", ".", "HTTPError", ".", "Error", "(", ")", "\n", "}" ]
// 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.WriteString(v) msg.WriteString("\n") } } if len(e.Errors) > 0 { for key, value := range e.Errors { msg.WriteString(" - ") msg.WriteString(key) msg.WriteString(" - ") msg.WriteString(value) msg.WriteString("\n") } } return msg.String() }
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.WriteString(v) msg.WriteString("\n") } } if len(e.Errors) > 0 { for key, value := range e.Errors { msg.WriteString(" - ") msg.WriteString(key) msg.WriteString(" - ") msg.WriteString(value) msg.WriteString("\n") } } return msg.String() }
[ "func", "(", "e", "*", "Error", ")", "LongError", "(", ")", "string", "{", "var", "msg", "bytes", ".", "Buffer", "\n", "if", "e", ".", "HTTPError", "!=", "nil", "{", "msg", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "msg", ".", "WriteString", "(", "e", ".", "HTTPError", ".", "Error", "(", ")", ")", "\n", "msg", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "}", "\n", "if", "len", "(", "e", ".", "ErrorMessages", ")", ">", "0", "{", "msg", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "for", "_", ",", "v", ":=", "range", "e", ".", "ErrorMessages", "{", "msg", ".", "WriteString", "(", "\"", "\"", ")", "\n", "msg", ".", "WriteString", "(", "v", ")", "\n", "msg", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "e", ".", "Errors", ")", ">", "0", "{", "for", "key", ",", "value", ":=", "range", "e", ".", "Errors", "{", "msg", ".", "WriteString", "(", "\"", "\"", ")", "\n", "msg", ".", "WriteString", "(", "key", ")", "\n", "msg", ".", "WriteString", "(", "\"", "\"", ")", "\n", "msg", ".", "WriteString", "(", "value", ")", "\n", "msg", ".", "WriteString", "(", "\"", "\\n", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "msg", ".", "String", "(", ")", "\n", "}" ]
// 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 := c.baseURL.ResolveReference(rel) var buf io.ReadWriter if body != nil { buf = new(bytes.Buffer) err = json.NewEncoder(buf).Encode(body) if err != nil { return nil, err } } req, err := http.NewRequest(method, u.String(), buf) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") // Set authentication information if c.Authentication.authType == authTypeSession { // Set session cookie if there is one if c.session != nil { for _, cookie := range c.session.Cookies { req.AddCookie(cookie) } } } else if c.Authentication.authType == authTypeBasic { // Set basic auth information if c.Authentication.username != "" { req.SetBasicAuth(c.Authentication.username, c.Authentication.password) } } return req, nil }
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 := c.baseURL.ResolveReference(rel) var buf io.ReadWriter if body != nil { buf = new(bytes.Buffer) err = json.NewEncoder(buf).Encode(body) if err != nil { return nil, err } } req, err := http.NewRequest(method, u.String(), buf) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") // Set authentication information if c.Authentication.authType == authTypeSession { // Set session cookie if there is one if c.session != nil { for _, cookie := range c.session.Cookies { req.AddCookie(cookie) } } } else if c.Authentication.authType == authTypeBasic { // Set basic auth information if c.Authentication.username != "" { req.SetBasicAuth(c.Authentication.username, c.Authentication.password) } } return req, nil }
[ "func", "(", "c", "*", "Client", ")", "NewRequest", "(", "method", ",", "urlStr", "string", ",", "body", "interface", "{", "}", ")", "(", "*", "http", ".", "Request", ",", "error", ")", "{", "rel", ",", "err", ":=", "url", ".", "Parse", "(", "urlStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// Relative URLs should be specified without a preceding slash since baseURL will have the trailing slash", "rel", ".", "Path", "=", "strings", ".", "TrimLeft", "(", "rel", ".", "Path", ",", "\"", "\"", ")", "\n\n", "u", ":=", "c", ".", "baseURL", ".", "ResolveReference", "(", "rel", ")", "\n\n", "var", "buf", "io", ".", "ReadWriter", "\n", "if", "body", "!=", "nil", "{", "buf", "=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "err", "=", "json", ".", "NewEncoder", "(", "buf", ")", ".", "Encode", "(", "body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "method", ",", "u", ".", "String", "(", ")", ",", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "// Set authentication information", "if", "c", ".", "Authentication", ".", "authType", "==", "authTypeSession", "{", "// Set session cookie if there is one", "if", "c", ".", "session", "!=", "nil", "{", "for", "_", ",", "cookie", ":=", "range", "c", ".", "session", ".", "Cookies", "{", "req", ".", "AddCookie", "(", "cookie", ")", "\n", "}", "\n", "}", "\n", "}", "else", "if", "c", ".", "Authentication", ".", "authType", "==", "authTypeBasic", "{", "// Set basic auth information", "if", "c", ".", "Authentication", ".", "username", "!=", "\"", "\"", "{", "req", ".", "SetBasicAuth", "(", "c", ".", "Authentication", ".", "username", ",", "c", ".", "Authentication", ".", "password", ")", "\n", "}", "\n", "}", "\n\n", "return", "req", ",", "nil", "\n", "}" ]
// 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", "value", "pointed", "to", "by", "body", "is", "JSON", "encoded", "and", "included", "as", "the", "request", "body", "." ]
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", "req2", ".", "SetBasicAuth", "(", "t", ".", "Username", ",", "t", ".", "Password", ")", "\n", "return", "t", ".", "transport", "(", ")", ".", "RoundTrip", "(", "req2", ")", "\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 := range t.SessionObject { // Don't add an empty value cookie to the request if cookie.Value != "" { req2.AddCookie(cookie) } } return t.transport().RoundTrip(req2) }
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 := range t.SessionObject { // Don't add an empty value cookie to the request if cookie.Value != "" { req2.AddCookie(cookie) } } return t.transport().RoundTrip(req2) }
[ "func", "(", "t", "*", "CookieAuthTransport", ")", "RoundTrip", "(", "req", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "if", "t", ".", "SessionObject", "==", "nil", "{", "err", ":=", "t", ".", "setSessionObject", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "req2", ":=", "cloneRequest", "(", "req", ")", "// per RoundTripper contract", "\n", "for", "_", ",", "cookie", ":=", "range", "t", ".", "SessionObject", "{", "// Don't add an empty value cookie to the request", "if", "cookie", ".", "Value", "!=", "\"", "\"", "{", "req2", ".", "AddCookie", "(", "cookie", ")", "\n", "}", "\n", "}", "\n\n", "return", "t", ".", "transport", "(", ")", ".", "RoundTrip", "(", "req2", ")", "\n", "}" ]
// 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 != nil { return nil, err } req.Header.Set("Content-Type", "application/json") return req, nil }
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 != nil { return nil, err } req.Header.Set("Content-Type", "application/json") return req, nil }
[ "func", "(", "t", "*", "CookieAuthTransport", ")", "buildAuthRequest", "(", ")", "(", "*", "http", ".", "Request", ",", "error", ")", "{", "body", ":=", "struct", "{", "Username", "string", "`json:\"username\"`", "\n", "Password", "string", "`json:\"password\"`", "\n", "}", "{", "t", ".", "Username", ",", "t", ".", "Password", ",", "}", "\n\n", "b", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "json", ".", "NewEncoder", "(", "b", ")", ".", "Encode", "(", "body", ")", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "t", ".", "AuthURL", ",", "b", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "return", "req", ",", "nil", "\n", "}" ]
// 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 recoganize symbolic link, // which will lead "no such file or directory" error. return os.Symlink(target, dest) } sr, err := os.Open(src) if err != nil { return err } defer sr.Close() dw, err := os.Create(dest) if err != nil { return err } defer dw.Close() if _, err = io.Copy(dw, sr); err != nil { return err } // Set back file information. if err = os.Chtimes(dest, si.ModTime(), si.ModTime()); err != nil { return err } return os.Chmod(dest, si.Mode()) }
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 recoganize symbolic link, // which will lead "no such file or directory" error. return os.Symlink(target, dest) } sr, err := os.Open(src) if err != nil { return err } defer sr.Close() dw, err := os.Create(dest) if err != nil { return err } defer dw.Close() if _, err = io.Copy(dw, sr); err != nil { return err } // Set back file information. if err = os.Chtimes(dest, si.ModTime(), si.ModTime()); err != nil { return err } return os.Chmod(dest, si.Mode()) }
[ "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", "// Handle symbolic link.", "if", "si", ".", "Mode", "(", ")", "&", "os", ".", "ModeSymlink", "!=", "0", "{", "target", ",", "err", ":=", "os", ".", "Readlink", "(", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// NOTE: os.Chmod and os.Chtimes don't recoganize symbolic link,", "// which will lead \"no such file or directory\" error.", "return", "os", ".", "Symlink", "(", "target", ",", "dest", ")", "\n", "}", "\n\n", "sr", ",", "err", ":=", "os", ".", "Open", "(", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "sr", ".", "Close", "(", ")", "\n\n", "dw", ",", "err", ":=", "os", ".", "Create", "(", "dest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "dw", ".", "Close", "(", ")", "\n\n", "if", "_", ",", "err", "=", "io", ".", "Copy", "(", "dw", ",", "sr", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Set back file information.", "if", "err", "=", "os", ".", "Chtimes", "(", "dest", ",", "si", ".", "ModTime", "(", ")", ",", "si", ".", "ModTime", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "os", ".", "Chmod", "(", "dest", ",", "si", ".", "Mode", "(", ")", ")", "\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 info. infos, err := StatDir(srcPath, true) if err != nil { return err } var filter func(filePath string) bool if len(filters) > 0 { filter = filters[0] } for _, info := range infos { if filter != nil && filter(info) { continue } curPath := path.Join(destPath, info) if strings.HasSuffix(info, "/") { err = os.MkdirAll(curPath, os.ModePerm) } else { err = Copy(path.Join(srcPath, info), curPath) } if err != nil { return err } } return nil }
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 info. infos, err := StatDir(srcPath, true) if err != nil { return err } var filter func(filePath string) bool if len(filters) > 0 { filter = filters[0] } for _, info := range infos { if filter != nil && filter(info) { continue } curPath := path.Join(destPath, info) if strings.HasSuffix(info, "/") { err = os.MkdirAll(curPath, os.ModePerm) } else { err = Copy(path.Join(srcPath, info), curPath) } if err != nil { return err } } return nil }
[ "func", "CopyDir", "(", "srcPath", ",", "destPath", "string", ",", "filters", "...", "func", "(", "filePath", "string", ")", "bool", ")", "error", "{", "// Check if target directory exists.", "if", "IsExist", "(", "destPath", ")", "{", "return", "errors", ".", "New", "(", "\"", "\"", "+", "destPath", ")", "\n", "}", "\n\n", "err", ":=", "os", ".", "MkdirAll", "(", "destPath", ",", "os", ".", "ModePerm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Gather directory info.", "infos", ",", "err", ":=", "StatDir", "(", "srcPath", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "var", "filter", "func", "(", "filePath", "string", ")", "bool", "\n", "if", "len", "(", "filters", ")", ">", "0", "{", "filter", "=", "filters", "[", "0", "]", "\n", "}", "\n\n", "for", "_", ",", "info", ":=", "range", "infos", "{", "if", "filter", "!=", "nil", "&&", "filter", "(", "info", ")", "{", "continue", "\n", "}", "\n\n", "curPath", ":=", "path", ".", "Join", "(", "destPath", ",", "info", ")", "\n", "if", "strings", ".", "HasSuffix", "(", "info", ",", "\"", "\"", ")", "{", "err", "=", "os", ".", "MkdirAll", "(", "curPath", ",", "os", ".", "ModePerm", ")", "\n", "}", "else", "{", "err", "=", "Copy", "(", "path", ".", "Join", "(", "srcPath", ",", "info", ")", ",", "curPath", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", ".", "It", "returns", "error", "when", "error", "occurs", "in", "underlying", "functions", "." ]
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", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n\n", "cmd", ":=", "exec", ".", "Command", "(", "cmdName", ",", "args", "...", ")", "\n", "cmd", ".", "Dir", "=", "dir", "\n", "cmd", ".", "Stdout", "=", "bufOut", "\n", "cmd", ".", "Stderr", "=", "bufErr", "\n\n", "err", ":=", "cmd", ".", "Run", "(", ")", "\n", "return", "bufOut", ".", "Bytes", "(", ")", ",", "bufErr", ".", "Bytes", "(", ")", ",", "err", "\n", "}" ]
// 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", "...", ")", "\n", "return", "string", "(", "bufOut", ")", ",", "string", "(", "bufErr", ")", ",", "err", "\n", "}" ]
// 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", "(", "s", ")", "==", "str", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// 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).Get(1, 64)) case int: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int8: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int16: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int32: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int64: s = strconv.FormatInt(v, argInt(args).Get(0, 10)) case uint: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint8: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint16: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint32: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint64: s = strconv.FormatUint(v, argInt(args).Get(0, 10)) case string: s = v case []byte: s = string(v) default: s = fmt.Sprintf("%v", v) } return s }
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).Get(1, 64)) case int: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int8: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int16: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int32: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int64: s = strconv.FormatInt(v, argInt(args).Get(0, 10)) case uint: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint8: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint16: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint32: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint64: s = strconv.FormatUint(v, argInt(args).Get(0, 10)) case string: s = v case []byte: s = string(v) default: s = fmt.Sprintf("%v", v) } return s }
[ "func", "ToStr", "(", "value", "interface", "{", "}", ",", "args", "...", "int", ")", "(", "s", "string", ")", "{", "switch", "v", ":=", "value", ".", "(", "type", ")", "{", "case", "bool", ":", "s", "=", "strconv", ".", "FormatBool", "(", "v", ")", "\n", "case", "float32", ":", "s", "=", "strconv", ".", "FormatFloat", "(", "float64", "(", "v", ")", ",", "'f'", ",", "argInt", "(", "args", ")", ".", "Get", "(", "0", ",", "-", "1", ")", ",", "argInt", "(", "args", ")", ".", "Get", "(", "1", ",", "32", ")", ")", "\n", "case", "float64", ":", "s", "=", "strconv", ".", "FormatFloat", "(", "v", ",", "'f'", ",", "argInt", "(", "args", ")", ".", "Get", "(", "0", ",", "-", "1", ")", ",", "argInt", "(", "args", ")", ".", "Get", "(", "1", ",", "64", ")", ")", "\n", "case", "int", ":", "s", "=", "strconv", ".", "FormatInt", "(", "int64", "(", "v", ")", ",", "argInt", "(", "args", ")", ".", "Get", "(", "0", ",", "10", ")", ")", "\n", "case", "int8", ":", "s", "=", "strconv", ".", "FormatInt", "(", "int64", "(", "v", ")", ",", "argInt", "(", "args", ")", ".", "Get", "(", "0", ",", "10", ")", ")", "\n", "case", "int16", ":", "s", "=", "strconv", ".", "FormatInt", "(", "int64", "(", "v", ")", ",", "argInt", "(", "args", ")", ".", "Get", "(", "0", ",", "10", ")", ")", "\n", "case", "int32", ":", "s", "=", "strconv", ".", "FormatInt", "(", "int64", "(", "v", ")", ",", "argInt", "(", "args", ")", ".", "Get", "(", "0", ",", "10", ")", ")", "\n", "case", "int64", ":", "s", "=", "strconv", ".", "FormatInt", "(", "v", ",", "argInt", "(", "args", ")", ".", "Get", "(", "0", ",", "10", ")", ")", "\n", "case", "uint", ":", "s", "=", "strconv", ".", "FormatUint", "(", "uint64", "(", "v", ")", ",", "argInt", "(", "args", ")", ".", "Get", "(", "0", ",", "10", ")", ")", "\n", "case", "uint8", ":", "s", "=", "strconv", ".", "FormatUint", "(", "uint64", "(", "v", ")", ",", "argInt", "(", "args", ")", ".", "Get", "(", "0", ",", "10", ")", ")", "\n", "case", "uint16", ":", "s", "=", "strconv", ".", "FormatUint", "(", "uint64", "(", "v", ")", ",", "argInt", "(", "args", ")", ".", "Get", "(", "0", ",", "10", ")", ")", "\n", "case", "uint32", ":", "s", "=", "strconv", ".", "FormatUint", "(", "uint64", "(", "v", ")", ",", "argInt", "(", "args", ")", ".", "Get", "(", "0", ",", "10", ")", ")", "\n", "case", "uint64", ":", "s", "=", "strconv", ".", "FormatUint", "(", "v", ",", "argInt", "(", "args", ")", ".", "Get", "(", "0", ",", "10", ")", ")", "\n", "case", "string", ":", "s", "=", "v", "\n", "case", "[", "]", "byte", ":", "s", "=", "string", "(", "v", ")", "\n", "default", ":", "s", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "v", ")", "\n", "}", "\n", "return", "s", "\n", "}" ]
// 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", ",", "header", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "rc", ".", "Close", "(", ")", "\n", "return", "ioutil", ".", "ReadAll", "(", "rc", ")", "\n", "}" ]
// 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", "]", "map", "[", "string", "]", "string", ")", "\n", "c", ".", "keyList", "=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "c", ".", "sectionComments", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "c", ".", "keyComments", "=", "make", "(", "map", "[", "string", "]", "map", "[", "string", "]", "string", ")", "\n", "c", ".", "BlockMode", "=", "true", "\n", "return", "c", "\n", "}" ]
// 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 { delete(c.data[section], key) // Remove comments of key. c.SetKeyComments(section, key, "") // Get index of key. i := 0 for _, keyName := range c.keyList[section] { if keyName == key { break } i++ } // Remove from key list. c.keyList[section] = append(c.keyList[section][:i], c.keyList[section][i+1:]...) return true } return false }
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 { delete(c.data[section], key) // Remove comments of key. c.SetKeyComments(section, key, "") // Get index of key. i := 0 for _, keyName := range c.keyList[section] { if keyName == key { break } i++ } // Remove from key list. c.keyList[section] = append(c.keyList[section][:i], c.keyList[section][i+1:]...) return true } return false }
[ "func", "(", "c", "*", "ConfigFile", ")", "DeleteKey", "(", "section", ",", "key", "string", ")", "bool", "{", "// Blank section name represents DEFAULT section.", "if", "len", "(", "section", ")", "==", "0", "{", "section", "=", "DEFAULT_SECTION", "\n", "}", "\n\n", "// Check if section exists.", "if", "_", ",", "ok", ":=", "c", ".", "data", "[", "section", "]", ";", "!", "ok", "{", "return", "false", "\n", "}", "\n\n", "// Check if key exists.", "if", "_", ",", "ok", ":=", "c", ".", "data", "[", "section", "]", "[", "key", "]", ";", "ok", "{", "delete", "(", "c", ".", "data", "[", "section", "]", ",", "key", ")", "\n", "// Remove comments of key.", "c", ".", "SetKeyComments", "(", "section", ",", "key", ",", "\"", "\"", ")", "\n", "// Get index of key.", "i", ":=", "0", "\n", "for", "_", ",", "keyName", ":=", "range", "c", ".", "keyList", "[", "section", "]", "{", "if", "keyName", "==", "key", "{", "break", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "// Remove from key list.", "c", ".", "keyList", "[", "section", "]", "=", "append", "(", "c", ".", "keyList", "[", "section", "]", "[", ":", "i", "]", ",", "c", ".", "keyList", "[", "section", "]", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\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