id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
151,900 | rockneurotiko/go-tgbot | tgbot-apicalls.go | SendVideo | func (bot TgBot) SendVideo(cid int, photo string, caption *string, duration *int, rmi *int, rm *ReplyMarkupInt) ResultWithMessage {
var payload interface{} = SendVideoIDQuery{cid, photo, duration, caption, rmi, rm}
if looksLikePath(photo) {
payload = SendVideoPathQuery{cid, photo, duration, caption, rmi, rm}
}
return bot.SendVideoQuery(payload)
} | go | func (bot TgBot) SendVideo(cid int, photo string, caption *string, duration *int, rmi *int, rm *ReplyMarkupInt) ResultWithMessage {
var payload interface{} = SendVideoIDQuery{cid, photo, duration, caption, rmi, rm}
if looksLikePath(photo) {
payload = SendVideoPathQuery{cid, photo, duration, caption, rmi, rm}
}
return bot.SendVideoQuery(payload)
} | [
"func",
"(",
"bot",
"TgBot",
")",
"SendVideo",
"(",
"cid",
"int",
",",
"photo",
"string",
",",
"caption",
"*",
"string",
",",
"duration",
"*",
"int",
",",
"rmi",
"*",
"int",
",",
"rm",
"*",
"ReplyMarkupInt",
")",
"ResultWithMessage",
"{",
"var",
"paylo... | // SendVideo full function to send a video. | [
"SendVideo",
"full",
"function",
"to",
"send",
"a",
"video",
"."
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot-apicalls.go#L568-L574 |
151,901 | rockneurotiko/go-tgbot | tgbot-apicalls.go | SimpleSendLocation | func (bot TgBot) SimpleSendLocation(msg Message, latitude float64, longitude float64) (res Message, err error) {
ressm := bot.SendLocation(msg.Chat.ID, latitude, longitude, nil, nil)
return splitResultInMessageError(ressm)
} | go | func (bot TgBot) SimpleSendLocation(msg Message, latitude float64, longitude float64) (res Message, err error) {
ressm := bot.SendLocation(msg.Chat.ID, latitude, longitude, nil, nil)
return splitResultInMessageError(ressm)
} | [
"func",
"(",
"bot",
"TgBot",
")",
"SimpleSendLocation",
"(",
"msg",
"Message",
",",
"latitude",
"float64",
",",
"longitude",
"float64",
")",
"(",
"res",
"Message",
",",
"err",
"error",
")",
"{",
"ressm",
":=",
"bot",
".",
"SendLocation",
"(",
"msg",
".",... | // send Location!!!
// SimpleSendLocation just send a location. | [
"send",
"Location!!!",
"SimpleSendLocation",
"just",
"send",
"a",
"location",
"."
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot-apicalls.go#L584-L587 |
151,902 | rockneurotiko/go-tgbot | tgbot-apicalls.go | SendLocationWithKeyboard | func (bot TgBot) SendLocationWithKeyboard(cid int, latitude float64, longitude float64, rtmid *int, rm ReplyKeyboardMarkup) ResultWithMessage {
var rkm ReplyMarkupInt = rm
return bot.SendLocation(cid, latitude, longitude, rtmid, &rkm)
} | go | func (bot TgBot) SendLocationWithKeyboard(cid int, latitude float64, longitude float64, rtmid *int, rm ReplyKeyboardMarkup) ResultWithMessage {
var rkm ReplyMarkupInt = rm
return bot.SendLocation(cid, latitude, longitude, rtmid, &rkm)
} | [
"func",
"(",
"bot",
"TgBot",
")",
"SendLocationWithKeyboard",
"(",
"cid",
"int",
",",
"latitude",
"float64",
",",
"longitude",
"float64",
",",
"rtmid",
"*",
"int",
",",
"rm",
"ReplyKeyboardMarkup",
")",
"ResultWithMessage",
"{",
"var",
"rkm",
"ReplyMarkupInt",
... | // SendLocationWithKeyboard send a location with explicit keyboard. | [
"SendLocationWithKeyboard",
"send",
"a",
"location",
"with",
"explicit",
"keyboard",
"."
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot-apicalls.go#L590-L593 |
151,903 | rockneurotiko/go-tgbot | tgbot-apicalls.go | SendLocationWithForceReply | func (bot TgBot) SendLocationWithForceReply(cid int, latitude float64, longitude float64, rtmid *int, rm ForceReply) ResultWithMessage {
var rkm ReplyMarkupInt = rm
return bot.SendLocation(cid, latitude, longitude, rtmid, &rkm)
} | go | func (bot TgBot) SendLocationWithForceReply(cid int, latitude float64, longitude float64, rtmid *int, rm ForceReply) ResultWithMessage {
var rkm ReplyMarkupInt = rm
return bot.SendLocation(cid, latitude, longitude, rtmid, &rkm)
} | [
"func",
"(",
"bot",
"TgBot",
")",
"SendLocationWithForceReply",
"(",
"cid",
"int",
",",
"latitude",
"float64",
",",
"longitude",
"float64",
",",
"rtmid",
"*",
"int",
",",
"rm",
"ForceReply",
")",
"ResultWithMessage",
"{",
"var",
"rkm",
"ReplyMarkupInt",
"=",
... | // SendLocationWithForceReply send a location with explicit force reply. | [
"SendLocationWithForceReply",
"send",
"a",
"location",
"with",
"explicit",
"force",
"reply",
"."
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot-apicalls.go#L596-L599 |
151,904 | rockneurotiko/go-tgbot | tgbot-apicalls.go | SendLocationWithKeyboardHide | func (bot TgBot) SendLocationWithKeyboardHide(cid int, latitude float64, longitude float64, rtmid *int, rm ReplyKeyboardHide) ResultWithMessage {
var rkm ReplyMarkupInt = rm
return bot.SendLocation(cid, latitude, longitude, rtmid, &rkm)
} | go | func (bot TgBot) SendLocationWithKeyboardHide(cid int, latitude float64, longitude float64, rtmid *int, rm ReplyKeyboardHide) ResultWithMessage {
var rkm ReplyMarkupInt = rm
return bot.SendLocation(cid, latitude, longitude, rtmid, &rkm)
} | [
"func",
"(",
"bot",
"TgBot",
")",
"SendLocationWithKeyboardHide",
"(",
"cid",
"int",
",",
"latitude",
"float64",
",",
"longitude",
"float64",
",",
"rtmid",
"*",
"int",
",",
"rm",
"ReplyKeyboardHide",
")",
"ResultWithMessage",
"{",
"var",
"rkm",
"ReplyMarkupInt",... | // SendLocationWithKeyboardHide send a location with explicit keyboard hide. | [
"SendLocationWithKeyboardHide",
"send",
"a",
"location",
"with",
"explicit",
"keyboard",
"hide",
"."
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot-apicalls.go#L602-L605 |
151,905 | rockneurotiko/go-tgbot | tgbot-apicalls.go | SendLocation | func (bot TgBot) SendLocation(cid int, latitude float64, longitude float64, rtmid *int, rm *ReplyMarkupInt) ResultWithMessage {
payload := SendLocationQuery{cid, latitude, longitude, rtmid, rm}
return bot.SendLocationQuery(payload)
} | go | func (bot TgBot) SendLocation(cid int, latitude float64, longitude float64, rtmid *int, rm *ReplyMarkupInt) ResultWithMessage {
payload := SendLocationQuery{cid, latitude, longitude, rtmid, rm}
return bot.SendLocationQuery(payload)
} | [
"func",
"(",
"bot",
"TgBot",
")",
"SendLocation",
"(",
"cid",
"int",
",",
"latitude",
"float64",
",",
"longitude",
"float64",
",",
"rtmid",
"*",
"int",
",",
"rm",
"*",
"ReplyMarkupInt",
")",
"ResultWithMessage",
"{",
"payload",
":=",
"SendLocationQuery",
"{"... | // SendLocation full function wrapper for sendLocation | [
"SendLocation",
"full",
"function",
"wrapper",
"for",
"sendLocation"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot-apicalls.go#L608-L611 |
151,906 | rockneurotiko/go-tgbot | tgbot-apicalls.go | SimpleSendChatAction | func (bot TgBot) SimpleSendChatAction(msg Message, ca ChatAction) {
bot.SendChatAction(msg.Chat.ID, ca)
} | go | func (bot TgBot) SimpleSendChatAction(msg Message, ca ChatAction) {
bot.SendChatAction(msg.Chat.ID, ca)
} | [
"func",
"(",
"bot",
"TgBot",
")",
"SimpleSendChatAction",
"(",
"msg",
"Message",
",",
"ca",
"ChatAction",
")",
"{",
"bot",
".",
"SendChatAction",
"(",
"msg",
".",
"Chat",
".",
"ID",
",",
"ca",
")",
"\n",
"}"
] | // Send chat action!!!
// SimpleSendChatAction just send an action answering a message. | [
"Send",
"chat",
"action!!!",
"SimpleSendChatAction",
"just",
"send",
"an",
"action",
"answering",
"a",
"message",
"."
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot-apicalls.go#L623-L625 |
151,907 | rockneurotiko/go-tgbot | tgbot-apicalls.go | SendChatAction | func (bot TgBot) SendChatAction(cid int, ca ChatAction) {
bot.SendChatActionQuery(SendChatActionQuery{cid, ca.String()})
} | go | func (bot TgBot) SendChatAction(cid int, ca ChatAction) {
bot.SendChatActionQuery(SendChatActionQuery{cid, ca.String()})
} | [
"func",
"(",
"bot",
"TgBot",
")",
"SendChatAction",
"(",
"cid",
"int",
",",
"ca",
"ChatAction",
")",
"{",
"bot",
".",
"SendChatActionQuery",
"(",
"SendChatActionQuery",
"{",
"cid",
",",
"ca",
".",
"String",
"(",
")",
"}",
")",
"\n",
"}"
] | // SendChatAction send an action to an id. | [
"SendChatAction",
"send",
"an",
"action",
"to",
"an",
"id",
"."
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot-apicalls.go#L628-L630 |
151,908 | rockneurotiko/go-tgbot | tgbot-apicalls.go | SendChatActionQuery | func (bot TgBot) SendChatActionQuery(payload SendChatActionQuery) {
url := bot.buildPath("sendChatAction")
hookPayload(&payload, bot.DefaultOptions)
bot.genericSendPostData(url, payload)
} | go | func (bot TgBot) SendChatActionQuery(payload SendChatActionQuery) {
url := bot.buildPath("sendChatAction")
hookPayload(&payload, bot.DefaultOptions)
bot.genericSendPostData(url, payload)
} | [
"func",
"(",
"bot",
"TgBot",
")",
"SendChatActionQuery",
"(",
"payload",
"SendChatActionQuery",
")",
"{",
"url",
":=",
"bot",
".",
"buildPath",
"(",
"\"",
"\"",
")",
"\n",
"hookPayload",
"(",
"&",
"payload",
",",
"bot",
".",
"DefaultOptions",
")",
"\n",
... | // SendChatActionQuery send an action query. | [
"SendChatActionQuery",
"send",
"an",
"action",
"query",
"."
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot-apicalls.go#L633-L637 |
151,909 | rockneurotiko/go-tgbot | tgbot-apicalls.go | GetUserProfilePhotosQuery | func (bot TgBot) GetUserProfilePhotosQuery(quer GetUserProfilePhotosQuery) ResultWithUserProfilePhotos {
url := bot.buildPath("getUserProfilePhotos")
body, error := postPetition(url, quer, nil)
if error != nil {
errc := 500
err := "Some error happened while sending the message"
return ResultWithUserProfilePhotos{ResultBase{false, &errc, &err}, nil}
}
var result ResultWithUserProfilePhotos
json.Unmarshal([]byte(body), &result)
return result
} | go | func (bot TgBot) GetUserProfilePhotosQuery(quer GetUserProfilePhotosQuery) ResultWithUserProfilePhotos {
url := bot.buildPath("getUserProfilePhotos")
body, error := postPetition(url, quer, nil)
if error != nil {
errc := 500
err := "Some error happened while sending the message"
return ResultWithUserProfilePhotos{ResultBase{false, &errc, &err}, nil}
}
var result ResultWithUserProfilePhotos
json.Unmarshal([]byte(body), &result)
return result
} | [
"func",
"(",
"bot",
"TgBot",
")",
"GetUserProfilePhotosQuery",
"(",
"quer",
"GetUserProfilePhotosQuery",
")",
"ResultWithUserProfilePhotos",
"{",
"url",
":=",
"bot",
".",
"buildPath",
"(",
"\"",
"\"",
")",
"\n",
"body",
",",
"error",
":=",
"postPetition",
"(",
... | // GetUserProfilePhotosQuery raw method that uses the struct to send the petition. | [
"GetUserProfilePhotosQuery",
"raw",
"method",
"that",
"uses",
"the",
"struct",
"to",
"send",
"the",
"petition",
"."
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot-apicalls.go#L640-L652 |
151,910 | rockneurotiko/go-tgbot | tgbot.go | NewTgBot | func NewTgBot(token string) *TgBot {
bot, err := NewWithError(token)
if err != nil {
panic(err)
}
return bot
} | go | func NewTgBot(token string) *TgBot {
bot, err := NewWithError(token)
if err != nil {
panic(err)
}
return bot
} | [
"func",
"NewTgBot",
"(",
"token",
"string",
")",
"*",
"TgBot",
"{",
"bot",
",",
"err",
":=",
"NewWithError",
"(",
"token",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"bot",
"\n",
"}"
] | // NewTgBot creates an instance of a new bot with the token supplied, if it's invalid this method fail with a panic. | [
"NewTgBot",
"creates",
"an",
"instance",
"of",
"a",
"new",
"bot",
"with",
"the",
"token",
"supplied",
"if",
"it",
"s",
"invalid",
"this",
"method",
"fail",
"with",
"a",
"panic",
"."
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot.go#L29-L35 |
151,911 | rockneurotiko/go-tgbot | tgbot.go | NewWithError | func NewWithError(token string) (*TgBot, error) {
url := fmt.Sprintf(baseURL, token, "%s")
furl := fmt.Sprintf(fileURL, token, "%s")
tgbot := &TgBot{
Token: token,
BaseRequestURL: url,
BaseFileRequestURL: furl,
MainListener: nil,
RelicCfg: nil,
BotanIO: nil,
TestConditionalFuncs: make([]ConditionCallStructure, 0),
NoMessageFuncs: make([]NoMessageCall, 0),
ChainConditionals: make([]*ChainStructure, 0),
BuildingChain: false,
DefaultOptions: DefaultOptionsBot{
CleanInitialUsername: true,
AllowWithoutSlashInMention: true,
},
}
user, err := tgbot.GetMe()
if err != nil {
return nil, err
// panic(err)
} else {
tgbot.FirstName = user.FirstName
tgbot.ID = user.ID
tgbot.Username = *user.Username
}
return tgbot, nil
} | go | func NewWithError(token string) (*TgBot, error) {
url := fmt.Sprintf(baseURL, token, "%s")
furl := fmt.Sprintf(fileURL, token, "%s")
tgbot := &TgBot{
Token: token,
BaseRequestURL: url,
BaseFileRequestURL: furl,
MainListener: nil,
RelicCfg: nil,
BotanIO: nil,
TestConditionalFuncs: make([]ConditionCallStructure, 0),
NoMessageFuncs: make([]NoMessageCall, 0),
ChainConditionals: make([]*ChainStructure, 0),
BuildingChain: false,
DefaultOptions: DefaultOptionsBot{
CleanInitialUsername: true,
AllowWithoutSlashInMention: true,
},
}
user, err := tgbot.GetMe()
if err != nil {
return nil, err
// panic(err)
} else {
tgbot.FirstName = user.FirstName
tgbot.ID = user.ID
tgbot.Username = *user.Username
}
return tgbot, nil
} | [
"func",
"NewWithError",
"(",
"token",
"string",
")",
"(",
"*",
"TgBot",
",",
"error",
")",
"{",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"baseURL",
",",
"token",
",",
"\"",
"\"",
")",
"\n",
"furl",
":=",
"fmt",
".",
"Sprintf",
"(",
"fileURL",
",",
... | // NewWithError creates an instance and return possible error | [
"NewWithError",
"creates",
"an",
"instance",
"and",
"return",
"possible",
"error"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot.go#L38-L67 |
151,912 | rockneurotiko/go-tgbot | tgbot.go | ProcessAllMsg | func (bot TgBot) ProcessAllMsg(msg Message) {
msg = bot.cleanMessage(msg)
// Let's try with and without goroutines here
for _, c := range bot.ChainConditionals {
if c.canCall(bot, msg) {
// c.call(bot, msg)
go c.call(bot, msg)
return
}
if c.UserInChain(msg) {
return
}
}
// execlater := make([]ConditionCallStructure, 0)
executed := false
for _, v := range bot.TestConditionalFuncs {
// if nm, ok := v.(NoMessageCall); ok {
// execlater = append(execlater, nm)
// }
if v.canCall(bot, msg) {
executed = true
v.call(bot, msg)
// go v.call(bot, msg)
}
}
if !executed {
for _, f := range bot.NoMessageFuncs {
f.call(bot, msg)
}
}
} | go | func (bot TgBot) ProcessAllMsg(msg Message) {
msg = bot.cleanMessage(msg)
// Let's try with and without goroutines here
for _, c := range bot.ChainConditionals {
if c.canCall(bot, msg) {
// c.call(bot, msg)
go c.call(bot, msg)
return
}
if c.UserInChain(msg) {
return
}
}
// execlater := make([]ConditionCallStructure, 0)
executed := false
for _, v := range bot.TestConditionalFuncs {
// if nm, ok := v.(NoMessageCall); ok {
// execlater = append(execlater, nm)
// }
if v.canCall(bot, msg) {
executed = true
v.call(bot, msg)
// go v.call(bot, msg)
}
}
if !executed {
for _, f := range bot.NoMessageFuncs {
f.call(bot, msg)
}
}
} | [
"func",
"(",
"bot",
"TgBot",
")",
"ProcessAllMsg",
"(",
"msg",
"Message",
")",
"{",
"msg",
"=",
"bot",
".",
"cleanMessage",
"(",
"msg",
")",
"\n",
"// Let's try with and without goroutines here",
"for",
"_",
",",
"c",
":=",
"range",
"bot",
".",
"ChainConditi... | // ProcessAllMsg default message handler that take care of clean the messages, the chains and the action functions. | [
"ProcessAllMsg",
"default",
"message",
"handler",
"that",
"take",
"care",
"of",
"clean",
"the",
"messages",
"the",
"chains",
"and",
"the",
"action",
"functions",
"."
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot.go#L94-L126 |
151,913 | rockneurotiko/go-tgbot | tgbot.go | MessagesHandler | func (bot TgBot) MessagesHandler(Incoming <-chan MessageWithUpdateID) {
for {
input := <-Incoming
go bot.ProcessAllMsg(input.Msg) // go this or not?
}
} | go | func (bot TgBot) MessagesHandler(Incoming <-chan MessageWithUpdateID) {
for {
input := <-Incoming
go bot.ProcessAllMsg(input.Msg) // go this or not?
}
} | [
"func",
"(",
"bot",
"TgBot",
")",
"MessagesHandler",
"(",
"Incoming",
"<-",
"chan",
"MessageWithUpdateID",
")",
"{",
"for",
"{",
"input",
":=",
"<-",
"Incoming",
"\n",
"go",
"bot",
".",
"ProcessAllMsg",
"(",
"input",
".",
"Msg",
")",
"// go this or not?",
... | // MessagesHandler is the default listener, just listen for a channel and call the default message processor | [
"MessagesHandler",
"is",
"the",
"default",
"listener",
"just",
"listen",
"for",
"a",
"channel",
"and",
"call",
"the",
"default",
"message",
"processor"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot.go#L129-L134 |
151,914 | rockneurotiko/go-tgbot | tgbot.go | ProcessMessages | func (bot *TgBot) ProcessMessages(messages []MessageWithUpdateID) {
for _, msg := range messages {
// if int64(msg.UpdateID) > bot.LastUpdateID {
// // Add lock
// bot.LastUpdateID = int64(msg.UpdateID)
// }
atomic.CompareAndSwapInt64(&bot.LastUpdateID, bot.LastUpdateID, int64(msg.UpdateID))
if bot.MainListener != nil {
bot.MainListener <- msg
}
}
} | go | func (bot *TgBot) ProcessMessages(messages []MessageWithUpdateID) {
for _, msg := range messages {
// if int64(msg.UpdateID) > bot.LastUpdateID {
// // Add lock
// bot.LastUpdateID = int64(msg.UpdateID)
// }
atomic.CompareAndSwapInt64(&bot.LastUpdateID, bot.LastUpdateID, int64(msg.UpdateID))
if bot.MainListener != nil {
bot.MainListener <- msg
}
}
} | [
"func",
"(",
"bot",
"*",
"TgBot",
")",
"ProcessMessages",
"(",
"messages",
"[",
"]",
"MessageWithUpdateID",
")",
"{",
"for",
"_",
",",
"msg",
":=",
"range",
"messages",
"{",
"// if int64(msg.UpdateID) > bot.LastUpdateID {",
"// \t// Add lock",
"// \tbot.LastUpdateID =... | // ProcessMessages will take care about the highest message ID to get updates in the right way. This will call the MainListener channel with a MessageWithUpdateID | [
"ProcessMessages",
"will",
"take",
"care",
"about",
"the",
"highest",
"message",
"ID",
"to",
"get",
"updates",
"in",
"the",
"right",
"way",
".",
"This",
"will",
"call",
"the",
"MainListener",
"channel",
"with",
"a",
"MessageWithUpdateID"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/tgbot.go#L137-L148 |
151,915 | rockneurotiko/go-tgbot | example/manualexample/main.go | MessageHandler | func MessageHandler(Incoming <-chan tgbot.MessageWithUpdateID, bot *tgbot.TgBot) {
for {
input := <-Incoming
if input.Msg.Text != nil {
text := handleMessageText(*input.Msg.Text, input.Msg)
if text != "" {
nmsg, err := bot.SimpleSendMessage(input.Msg, text)
if err != nil {
fmt.Println(err)
continue
}
fmt.Println(nmsg.String())
}
}
}
} | go | func MessageHandler(Incoming <-chan tgbot.MessageWithUpdateID, bot *tgbot.TgBot) {
for {
input := <-Incoming
if input.Msg.Text != nil {
text := handleMessageText(*input.Msg.Text, input.Msg)
if text != "" {
nmsg, err := bot.SimpleSendMessage(input.Msg, text)
if err != nil {
fmt.Println(err)
continue
}
fmt.Println(nmsg.String())
}
}
}
} | [
"func",
"MessageHandler",
"(",
"Incoming",
"<-",
"chan",
"tgbot",
".",
"MessageWithUpdateID",
",",
"bot",
"*",
"tgbot",
".",
"TgBot",
")",
"{",
"for",
"{",
"input",
":=",
"<-",
"Incoming",
"\n\n",
"if",
"input",
".",
"Msg",
".",
"Text",
"!=",
"nil",
"{... | // MessageHandler will be the custom handler | [
"MessageHandler",
"will",
"be",
"the",
"custom",
"handler"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/example/manualexample/main.go#L35-L51 |
151,916 | rockneurotiko/go-tgbot | callbacktypes.go | CallSimpleCommandFunc | func (scf SimpleCommandFuncStruct) CallSimpleCommandFunc(bot TgBot, msg Message, m []string, km map[string]string) *string {
res := ""
if msg.Text != nil {
res2 := scf.f(bot, msg, *msg.Text)
if res2 != nil {
res = *res2
}
}
return &res
} | go | func (scf SimpleCommandFuncStruct) CallSimpleCommandFunc(bot TgBot, msg Message, m []string, km map[string]string) *string {
res := ""
if msg.Text != nil {
res2 := scf.f(bot, msg, *msg.Text)
if res2 != nil {
res = *res2
}
}
return &res
} | [
"func",
"(",
"scf",
"SimpleCommandFuncStruct",
")",
"CallSimpleCommandFunc",
"(",
"bot",
"TgBot",
",",
"msg",
"Message",
",",
"m",
"[",
"]",
"string",
",",
"km",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"string",
"{",
"res",
":=",
"\"",
"\"",
"\n... | // CallSimpleCommandFunc wrapper for simple functions | [
"CallSimpleCommandFunc",
"wrapper",
"for",
"simple",
"functions"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/callbacktypes.go#L559-L568 |
151,917 | rockneurotiko/go-tgbot | sendtypes.go | Text | func (s *Send) Text(text string) *SendText {
return &SendText{s, text, nil, nil, nil, nil}
} | go | func (s *Send) Text(text string) *SendText {
return &SendText{s, text, nil, nil, nil, nil}
} | [
"func",
"(",
"s",
"*",
"Send",
")",
"Text",
"(",
"text",
"string",
")",
"*",
"SendText",
"{",
"return",
"&",
"SendText",
"{",
"s",
",",
"text",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
"}",
"\n",
"}"
] | // Text return a SendText instance to chain actions easy | [
"Text",
"return",
"a",
"SendText",
"instance",
"to",
"chain",
"actions",
"easy"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/sendtypes.go#L16-L18 |
151,918 | rockneurotiko/go-tgbot | sendtypes.go | Forward | func (s *Send) Forward(to int, msg int) *SendForward {
return &SendForward{s, to, msg}
} | go | func (s *Send) Forward(to int, msg int) *SendForward {
return &SendForward{s, to, msg}
} | [
"func",
"(",
"s",
"*",
"Send",
")",
"Forward",
"(",
"to",
"int",
",",
"msg",
"int",
")",
"*",
"SendForward",
"{",
"return",
"&",
"SendForward",
"{",
"s",
",",
"to",
",",
"msg",
"}",
"\n",
"}"
] | // Forward return a SendForward instance to chain actions easy | [
"Forward",
"return",
"a",
"SendForward",
"instance",
"to",
"chain",
"actions",
"easy"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/sendtypes.go#L21-L23 |
151,919 | rockneurotiko/go-tgbot | sendtypes.go | Photo | func (s *Send) Photo(photo interface{}) *SendPhoto {
// Check here that the interface works?
return &SendPhoto{s, photo, nil, nil, nil}
} | go | func (s *Send) Photo(photo interface{}) *SendPhoto {
// Check here that the interface works?
return &SendPhoto{s, photo, nil, nil, nil}
} | [
"func",
"(",
"s",
"*",
"Send",
")",
"Photo",
"(",
"photo",
"interface",
"{",
"}",
")",
"*",
"SendPhoto",
"{",
"// Check here that the interface works?",
"return",
"&",
"SendPhoto",
"{",
"s",
",",
"photo",
",",
"nil",
",",
"nil",
",",
"nil",
"}",
"\n",
... | // Photo return a SendPhoto instance to chain actions easy | [
"Photo",
"return",
"a",
"SendPhoto",
"instance",
"to",
"chain",
"actions",
"easy"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/sendtypes.go#L26-L29 |
151,920 | rockneurotiko/go-tgbot | sendtypes.go | Audio | func (s *Send) Audio(audio string) *SendAudio {
return &SendAudio{s, audio, nil, nil, nil, nil, nil}
} | go | func (s *Send) Audio(audio string) *SendAudio {
return &SendAudio{s, audio, nil, nil, nil, nil, nil}
} | [
"func",
"(",
"s",
"*",
"Send",
")",
"Audio",
"(",
"audio",
"string",
")",
"*",
"SendAudio",
"{",
"return",
"&",
"SendAudio",
"{",
"s",
",",
"audio",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
"}",
"\n",
"}"
] | // Audio return a SendAudio instance to chain actions easy | [
"Audio",
"return",
"a",
"SendAudio",
"instance",
"to",
"chain",
"actions",
"easy"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/sendtypes.go#L32-L34 |
151,921 | rockneurotiko/go-tgbot | sendtypes.go | Voice | func (s *Send) Voice(voice string) *SendVoice {
return &SendVoice{s, voice, nil, nil, nil}
} | go | func (s *Send) Voice(voice string) *SendVoice {
return &SendVoice{s, voice, nil, nil, nil}
} | [
"func",
"(",
"s",
"*",
"Send",
")",
"Voice",
"(",
"voice",
"string",
")",
"*",
"SendVoice",
"{",
"return",
"&",
"SendVoice",
"{",
"s",
",",
"voice",
",",
"nil",
",",
"nil",
",",
"nil",
"}",
"\n",
"}"
] | // Voice return a SendVoice instance to chain actions easy | [
"Voice",
"return",
"a",
"SendVoice",
"instance",
"to",
"chain",
"actions",
"easy"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/sendtypes.go#L37-L39 |
151,922 | rockneurotiko/go-tgbot | sendtypes.go | Document | func (s *Send) Document(doc interface{}) *SendDocument {
return &SendDocument{s, doc, nil, nil}
} | go | func (s *Send) Document(doc interface{}) *SendDocument {
return &SendDocument{s, doc, nil, nil}
} | [
"func",
"(",
"s",
"*",
"Send",
")",
"Document",
"(",
"doc",
"interface",
"{",
"}",
")",
"*",
"SendDocument",
"{",
"return",
"&",
"SendDocument",
"{",
"s",
",",
"doc",
",",
"nil",
",",
"nil",
"}",
"\n",
"}"
] | // Document return a SendDocument instance to chain actions easy | [
"Document",
"return",
"a",
"SendDocument",
"instance",
"to",
"chain",
"actions",
"easy"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/sendtypes.go#L42-L44 |
151,923 | rockneurotiko/go-tgbot | sendtypes.go | Sticker | func (s *Send) Sticker(stick interface{}) *SendSticker {
return &SendSticker{s, stick, nil, nil}
} | go | func (s *Send) Sticker(stick interface{}) *SendSticker {
return &SendSticker{s, stick, nil, nil}
} | [
"func",
"(",
"s",
"*",
"Send",
")",
"Sticker",
"(",
"stick",
"interface",
"{",
"}",
")",
"*",
"SendSticker",
"{",
"return",
"&",
"SendSticker",
"{",
"s",
",",
"stick",
",",
"nil",
",",
"nil",
"}",
"\n",
"}"
] | // Sticker return a SendSticker instance to chain actions easy | [
"Sticker",
"return",
"a",
"SendSticker",
"instance",
"to",
"chain",
"actions",
"easy"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/sendtypes.go#L47-L49 |
151,924 | rockneurotiko/go-tgbot | sendtypes.go | Video | func (s *Send) Video(vid string) *SendVideo {
return &SendVideo{s, vid, nil, nil, nil, nil}
} | go | func (s *Send) Video(vid string) *SendVideo {
return &SendVideo{s, vid, nil, nil, nil, nil}
} | [
"func",
"(",
"s",
"*",
"Send",
")",
"Video",
"(",
"vid",
"string",
")",
"*",
"SendVideo",
"{",
"return",
"&",
"SendVideo",
"{",
"s",
",",
"vid",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
"}",
"\n",
"}"
] | // Video return a SendVideo instance to chain actions easy | [
"Video",
"return",
"a",
"SendVideo",
"instance",
"to",
"chain",
"actions",
"easy"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/sendtypes.go#L52-L54 |
151,925 | rockneurotiko/go-tgbot | sendtypes.go | Location | func (s *Send) Location(latitude float64, long float64) *SendLocation {
return &SendLocation{s, latitude, long, nil, nil}
} | go | func (s *Send) Location(latitude float64, long float64) *SendLocation {
return &SendLocation{s, latitude, long, nil, nil}
} | [
"func",
"(",
"s",
"*",
"Send",
")",
"Location",
"(",
"latitude",
"float64",
",",
"long",
"float64",
")",
"*",
"SendLocation",
"{",
"return",
"&",
"SendLocation",
"{",
"s",
",",
"latitude",
",",
"long",
",",
"nil",
",",
"nil",
"}",
"\n",
"}"
] | // Location return a SendLocation instance to chain actions easy | [
"Location",
"return",
"a",
"SendLocation",
"instance",
"to",
"chain",
"actions",
"easy"
] | 50ec5924e3c134ff1c34efd5d8fe9057c67790b7 | https://github.com/rockneurotiko/go-tgbot/blob/50ec5924e3c134ff1c34efd5d8fe9057c67790b7/sendtypes.go#L57-L59 |
151,926 | soniah/evaler | evaler.go | prec | func prec(op string) (result int) {
if op == "-" || op == "+" {
result = 1
} else if op == "*" || op == "/" {
result = 2
} else if op == "^" || op == "%" || op == "**" {
result = 3
} else if op == "@" {
result = 4
} else if functions_rx.MatchString(op) {
result = 5
} else {
result = 0
}
return
} | go | func prec(op string) (result int) {
if op == "-" || op == "+" {
result = 1
} else if op == "*" || op == "/" {
result = 2
} else if op == "^" || op == "%" || op == "**" {
result = 3
} else if op == "@" {
result = 4
} else if functions_rx.MatchString(op) {
result = 5
} else {
result = 0
}
return
} | [
"func",
"prec",
"(",
"op",
"string",
")",
"(",
"result",
"int",
")",
"{",
"if",
"op",
"==",
"\"",
"\"",
"||",
"op",
"==",
"\"",
"\"",
"{",
"result",
"=",
"1",
"\n",
"}",
"else",
"if",
"op",
"==",
"\"",
"\"",
"||",
"op",
"==",
"\"",
"\"",
"{... | // prec returns the operator's precedence | [
"prec",
"returns",
"the",
"operator",
"s",
"precedence"
] | 227e5c8edc1d21fd08832664f38c4d31eceb7fa5 | https://github.com/soniah/evaler/blob/227e5c8edc1d21fd08832664f38c4d31eceb7fa5/evaler.go#L31-L46 |
151,927 | soniah/evaler | evaler.go | isOperator | func isOperator(token string) bool {
for _, v := range operators {
if v == token {
return true
}
}
return false
} | go | func isOperator(token string) bool {
for _, v := range operators {
if v == token {
return true
}
}
return false
} | [
"func",
"isOperator",
"(",
"token",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"operators",
"{",
"if",
"v",
"==",
"token",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // isOperator returns true if token is an operator | [
"isOperator",
"returns",
"true",
"if",
"token",
"is",
"an",
"operator"
] | 227e5c8edc1d21fd08832664f38c4d31eceb7fa5 | https://github.com/soniah/evaler/blob/227e5c8edc1d21fd08832664f38c4d31eceb7fa5/evaler.go#L58-L65 |
151,928 | soniah/evaler | evaler.go | convert2postfix | func convert2postfix(tokens []string) []string {
var stack stack.Stack
var result []string
for _, token := range tokens {
stackString := fmt.Sprint(stack) // HACK - debugging
stackString += "" // HACK - debugging
if isOperator(token) {
OPERATOR:
for {
top, err := stack.Top()
if err == nil && top != "(" {
if opGTE(top.(string), token) {
pop, _ := stack.Pop()
result = append(result, pop.(string))
continue
} else {
break OPERATOR
}
}
break OPERATOR
}
stack.Push(token)
} else if isFunction(token) {
FUNCTION:
for {
top, err := stack.Top()
if err == nil && top != "(" {
if opGTE(top.(string), token) {
pop, _ := stack.Pop()
result = append(result, pop.(string))
}
} else {
break FUNCTION
}
break FUNCTION
}
stack.Push(token)
} else if token == "(" {
stack.Push(token)
} else if token == ")" {
PAREN:
for {
top, err := stack.Top()
if err == nil && top != "(" {
pop, _ := stack.Pop()
result = append(result, pop.(string))
} else {
stack.Pop() // pop off "("
break PAREN
}
}
} else if isOperand(token) {
result = append(result, token)
} else if isSymbol(token) {
result = append(result, symbolTable[token])
} else {
result = append(result, token)
}
}
for !stack.IsEmpty() {
pop, _ := stack.Pop()
result = append(result, pop.(string))
}
return result
} | go | func convert2postfix(tokens []string) []string {
var stack stack.Stack
var result []string
for _, token := range tokens {
stackString := fmt.Sprint(stack) // HACK - debugging
stackString += "" // HACK - debugging
if isOperator(token) {
OPERATOR:
for {
top, err := stack.Top()
if err == nil && top != "(" {
if opGTE(top.(string), token) {
pop, _ := stack.Pop()
result = append(result, pop.(string))
continue
} else {
break OPERATOR
}
}
break OPERATOR
}
stack.Push(token)
} else if isFunction(token) {
FUNCTION:
for {
top, err := stack.Top()
if err == nil && top != "(" {
if opGTE(top.(string), token) {
pop, _ := stack.Pop()
result = append(result, pop.(string))
}
} else {
break FUNCTION
}
break FUNCTION
}
stack.Push(token)
} else if token == "(" {
stack.Push(token)
} else if token == ")" {
PAREN:
for {
top, err := stack.Top()
if err == nil && top != "(" {
pop, _ := stack.Pop()
result = append(result, pop.(string))
} else {
stack.Pop() // pop off "("
break PAREN
}
}
} else if isOperand(token) {
result = append(result, token)
} else if isSymbol(token) {
result = append(result, symbolTable[token])
} else {
result = append(result, token)
}
}
for !stack.IsEmpty() {
pop, _ := stack.Pop()
result = append(result, pop.(string))
}
return result
} | [
"func",
"convert2postfix",
"(",
"tokens",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"var",
"stack",
"stack",
".",
"Stack",
"\n",
"var",
"result",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"token",
":=",
"range",
"tokens",
"{",
"stackString",
... | // convert2postfix converts an infix expression to postfix | [
"convert2postfix",
"converts",
"an",
"infix",
"expression",
"to",
"postfix"
] | 227e5c8edc1d21fd08832664f38c4d31eceb7fa5 | https://github.com/soniah/evaler/blob/227e5c8edc1d21fd08832664f38c4d31eceb7fa5/evaler.go#L82-L157 |
151,929 | soniah/evaler | evaler.go | Tokenise | func Tokenise(expr string) []string {
spaced := unary_minus_rx.ReplaceAllString(expr, "$1 @")
spaced = fp_rx.ReplaceAllString(spaced, " ${1} ")
spaced = functions_rx.ReplaceAllString(spaced, " ${1} ")
if symbols_rx != nil {
spaced = symbols_rx.ReplaceAllString(spaced, " ${1} ")
}
symbols := []string{"(", ")"}
for _, symbol := range symbols {
spaced = strings.Replace(spaced, symbol, fmt.Sprintf(" %s ", symbol), -1)
}
stripped := whitespace_rx.ReplaceAllString(strings.TrimSpace(spaced), "|")
result := strings.Split(stripped, "|")
return result
} | go | func Tokenise(expr string) []string {
spaced := unary_minus_rx.ReplaceAllString(expr, "$1 @")
spaced = fp_rx.ReplaceAllString(spaced, " ${1} ")
spaced = functions_rx.ReplaceAllString(spaced, " ${1} ")
if symbols_rx != nil {
spaced = symbols_rx.ReplaceAllString(spaced, " ${1} ")
}
symbols := []string{"(", ")"}
for _, symbol := range symbols {
spaced = strings.Replace(spaced, symbol, fmt.Sprintf(" %s ", symbol), -1)
}
stripped := whitespace_rx.ReplaceAllString(strings.TrimSpace(spaced), "|")
result := strings.Split(stripped, "|")
return result
} | [
"func",
"Tokenise",
"(",
"expr",
"string",
")",
"[",
"]",
"string",
"{",
"spaced",
":=",
"unary_minus_rx",
".",
"ReplaceAllString",
"(",
"expr",
",",
"\"",
"\"",
")",
"\n",
"spaced",
"=",
"fp_rx",
".",
"ReplaceAllString",
"(",
"spaced",
",",
"\"",
"\"",
... | // Tokenise takes an expr string and converts it to a slice of tokens
//
// Tokenise puts spaces around all non-numbers, removes leading and
// trailing spaces, then splits on spaces
// | [
"Tokenise",
"takes",
"an",
"expr",
"string",
"and",
"converts",
"it",
"to",
"a",
"slice",
"of",
"tokens",
"Tokenise",
"puts",
"spaces",
"around",
"all",
"non",
"-",
"numbers",
"removes",
"leading",
"and",
"trailing",
"spaces",
"then",
"splits",
"on",
"spaces... | 227e5c8edc1d21fd08832664f38c4d31eceb7fa5 | https://github.com/soniah/evaler/blob/227e5c8edc1d21fd08832664f38c4d31eceb7fa5/evaler.go#L302-L320 |
151,930 | soniah/evaler | evaler.go | EvalWithVariables | func EvalWithVariables(expr string, variables map[string]string) (result *big.Rat, err error) {
symbolTable = variables
s := ""
for k := range symbolTable {
s += k
}
symbols_rx = regexp.MustCompile(fmt.Sprintf("(%s)", s))
return Eval(expr)
} | go | func EvalWithVariables(expr string, variables map[string]string) (result *big.Rat, err error) {
symbolTable = variables
s := ""
for k := range symbolTable {
s += k
}
symbols_rx = regexp.MustCompile(fmt.Sprintf("(%s)", s))
return Eval(expr)
} | [
"func",
"EvalWithVariables",
"(",
"expr",
"string",
",",
"variables",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"result",
"*",
"big",
".",
"Rat",
",",
"err",
"error",
")",
"{",
"symbolTable",
"=",
"variables",
"\n",
"s",
":=",
"\"",
"\"",
"\n",
... | // EvalWithVariables allows variables to be passed into expressions, for
// example evaluate "x + 1" where x=5 | [
"EvalWithVariables",
"allows",
"variables",
"to",
"be",
"passed",
"into",
"expressions",
"for",
"example",
"evaluate",
"x",
"+",
"1",
"where",
"x",
"=",
"5"
] | 227e5c8edc1d21fd08832664f38c4d31eceb7fa5 | https://github.com/soniah/evaler/blob/227e5c8edc1d21fd08832664f38c4d31eceb7fa5/evaler.go#L343-L351 |
151,931 | soniah/evaler | stack/stack.go | String | func (s Stack) String() string {
var result string
for _, value := range s {
result += fmt.Sprintf("%s | ", value)
}
return result
} | go | func (s Stack) String() string {
var result string
for _, value := range s {
result += fmt.Sprintf("%s | ", value)
}
return result
} | [
"func",
"(",
"s",
"Stack",
")",
"String",
"(",
")",
"string",
"{",
"var",
"result",
"string",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"s",
"{",
"result",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"value",
")",
"\n",
"}",
"\n",
"... | // Stringer is useful for debugging | [
"Stringer",
"is",
"useful",
"for",
"debugging"
] | 227e5c8edc1d21fd08832664f38c4d31eceb7fa5 | https://github.com/soniah/evaler/blob/227e5c8edc1d21fd08832664f38c4d31eceb7fa5/stack/stack.go#L26-L32 |
151,932 | BeepBoopHQ/go-slackbot | router.go | Match | func (r *SimpleRouter) Match(ctx context.Context, match *RouteMatch) (bool, context.Context) {
for _, route := range r.routes {
var matched bool
if matched, ctx = route.Match(ctx, match); matched {
return true, ctx
}
}
return false, ctx
} | go | func (r *SimpleRouter) Match(ctx context.Context, match *RouteMatch) (bool, context.Context) {
for _, route := range r.routes {
var matched bool
if matched, ctx = route.Match(ctx, match); matched {
return true, ctx
}
}
return false, ctx
} | [
"func",
"(",
"r",
"*",
"SimpleRouter",
")",
"Match",
"(",
"ctx",
"context",
".",
"Context",
",",
"match",
"*",
"RouteMatch",
")",
"(",
"bool",
",",
"context",
".",
"Context",
")",
"{",
"for",
"_",
",",
"route",
":=",
"range",
"r",
".",
"routes",
"{... | // Match matches registered routes against the request. | [
"Match",
"matches",
"registered",
"routes",
"against",
"the",
"request",
"."
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/router.go#L24-L33 |
151,933 | BeepBoopHQ/go-slackbot | router.go | NewRoute | func (r *SimpleRouter) NewRoute() *Route {
route := &Route{}
r.routes = append(r.routes, route)
return route
} | go | func (r *SimpleRouter) NewRoute() *Route {
route := &Route{}
r.routes = append(r.routes, route)
return route
} | [
"func",
"(",
"r",
"*",
"SimpleRouter",
")",
"NewRoute",
"(",
")",
"*",
"Route",
"{",
"route",
":=",
"&",
"Route",
"{",
"}",
"\n",
"r",
".",
"routes",
"=",
"append",
"(",
"r",
".",
"routes",
",",
"route",
")",
"\n",
"return",
"route",
"\n",
"}"
] | // NewRoute registers an empty route. | [
"NewRoute",
"registers",
"an",
"empty",
"route",
"."
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/router.go#L36-L40 |
151,934 | BeepBoopHQ/go-slackbot | bot.go | New | func New(slackToken string) *Bot {
b := &Bot{Client: slack.New(slackToken)}
return b
} | go | func New(slackToken string) *Bot {
b := &Bot{Client: slack.New(slackToken)}
return b
} | [
"func",
"New",
"(",
"slackToken",
"string",
")",
"*",
"Bot",
"{",
"b",
":=",
"&",
"Bot",
"{",
"Client",
":",
"slack",
".",
"New",
"(",
"slackToken",
")",
"}",
"\n",
"return",
"b",
"\n",
"}"
] | // New constructs a new Bot using the slackToken to authorize against the Slack service. | [
"New",
"constructs",
"a",
"new",
"Bot",
"using",
"the",
"slackToken",
"to",
"authorize",
"against",
"the",
"Slack",
"service",
"."
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/bot.go#L55-L58 |
151,935 | BeepBoopHQ/go-slackbot | bot.go | Run | func (b *Bot) Run() {
b.RTM = b.Client.NewRTM()
go b.RTM.ManageConnection()
for {
select {
case msg := <-b.RTM.IncomingEvents:
ctx := context.Background()
ctx = AddBotToContext(ctx, b)
switch ev := msg.Data.(type) {
case *slack.ConnectedEvent:
fmt.Printf("Connected: %#v\n", ev.Info.User)
b.setBotID(ev.Info.User.ID)
case *slack.MessageEvent:
// ignore messages from the current user, the bot user
if b.botUserID == ev.User {
continue
}
ctx = AddMessageToContext(ctx, ev)
var match RouteMatch
if matched, ctx := b.Match(ctx, &match); matched {
match.Handler(ctx)
}
case *slack.RTMError:
fmt.Printf("Error: %s\n", ev.Error())
case *slack.InvalidAuthEvent:
fmt.Printf("Invalid credentials")
break
default:
// Ignore other events..
// fmt.Printf("Unexpected: %v\n", msg.Data)
}
}
}
} | go | func (b *Bot) Run() {
b.RTM = b.Client.NewRTM()
go b.RTM.ManageConnection()
for {
select {
case msg := <-b.RTM.IncomingEvents:
ctx := context.Background()
ctx = AddBotToContext(ctx, b)
switch ev := msg.Data.(type) {
case *slack.ConnectedEvent:
fmt.Printf("Connected: %#v\n", ev.Info.User)
b.setBotID(ev.Info.User.ID)
case *slack.MessageEvent:
// ignore messages from the current user, the bot user
if b.botUserID == ev.User {
continue
}
ctx = AddMessageToContext(ctx, ev)
var match RouteMatch
if matched, ctx := b.Match(ctx, &match); matched {
match.Handler(ctx)
}
case *slack.RTMError:
fmt.Printf("Error: %s\n", ev.Error())
case *slack.InvalidAuthEvent:
fmt.Printf("Invalid credentials")
break
default:
// Ignore other events..
// fmt.Printf("Unexpected: %v\n", msg.Data)
}
}
}
} | [
"func",
"(",
"b",
"*",
"Bot",
")",
"Run",
"(",
")",
"{",
"b",
".",
"RTM",
"=",
"b",
".",
"Client",
".",
"NewRTM",
"(",
")",
"\n",
"go",
"b",
".",
"RTM",
".",
"ManageConnection",
"(",
")",
"\n",
"for",
"{",
"select",
"{",
"case",
"msg",
":=",
... | // Run listens for incoming slack RTM events, matching them to an appropriate handler. | [
"Run",
"listens",
"for",
"incoming",
"slack",
"RTM",
"events",
"matching",
"them",
"to",
"an",
"appropriate",
"handler",
"."
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/bot.go#L72-L109 |
151,936 | BeepBoopHQ/go-slackbot | bot.go | Reply | func (b *Bot) Reply(evt *slack.MessageEvent, msg string, typing bool) {
if typing {
b.Type(evt, msg)
}
b.RTM.SendMessage(b.RTM.NewOutgoingMessage(msg, evt.Channel))
} | go | func (b *Bot) Reply(evt *slack.MessageEvent, msg string, typing bool) {
if typing {
b.Type(evt, msg)
}
b.RTM.SendMessage(b.RTM.NewOutgoingMessage(msg, evt.Channel))
} | [
"func",
"(",
"b",
"*",
"Bot",
")",
"Reply",
"(",
"evt",
"*",
"slack",
".",
"MessageEvent",
",",
"msg",
"string",
",",
"typing",
"bool",
")",
"{",
"if",
"typing",
"{",
"b",
".",
"Type",
"(",
"evt",
",",
"msg",
")",
"\n",
"}",
"\n",
"b",
".",
"... | // Reply replies to a message event with a simple message. | [
"Reply",
"replies",
"to",
"a",
"message",
"event",
"with",
"a",
"simple",
"message",
"."
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/bot.go#L112-L117 |
151,937 | BeepBoopHQ/go-slackbot | bot.go | ReplyWithAttachments | func (b *Bot) ReplyWithAttachments(evt *slack.MessageEvent, attachments []slack.Attachment, typing bool) {
params := slack.PostMessageParameters{AsUser: true}
params.Attachments = attachments
b.Client.PostMessage(evt.Msg.Channel, "", params)
} | go | func (b *Bot) ReplyWithAttachments(evt *slack.MessageEvent, attachments []slack.Attachment, typing bool) {
params := slack.PostMessageParameters{AsUser: true}
params.Attachments = attachments
b.Client.PostMessage(evt.Msg.Channel, "", params)
} | [
"func",
"(",
"b",
"*",
"Bot",
")",
"ReplyWithAttachments",
"(",
"evt",
"*",
"slack",
".",
"MessageEvent",
",",
"attachments",
"[",
"]",
"slack",
".",
"Attachment",
",",
"typing",
"bool",
")",
"{",
"params",
":=",
"slack",
".",
"PostMessageParameters",
"{",... | // ReplyWithAttachments replys to a message event with a Slack Attachments message. | [
"ReplyWithAttachments",
"replys",
"to",
"a",
"message",
"event",
"with",
"a",
"Slack",
"Attachments",
"message",
"."
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/bot.go#L120-L125 |
151,938 | BeepBoopHQ/go-slackbot | bot.go | msgLen | func msgLen(msg interface{}) (msgLen int) {
switch m := msg.(type) {
case string:
msgLen = len(m)
case []slack.Attachment:
msgLen = len(fmt.Sprintf("%#v", m))
}
return
} | go | func msgLen(msg interface{}) (msgLen int) {
switch m := msg.(type) {
case string:
msgLen = len(m)
case []slack.Attachment:
msgLen = len(fmt.Sprintf("%#v", m))
}
return
} | [
"func",
"msgLen",
"(",
"msg",
"interface",
"{",
"}",
")",
"(",
"msgLen",
"int",
")",
"{",
"switch",
"m",
":=",
"msg",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"msgLen",
"=",
"len",
"(",
"m",
")",
"\n",
"case",
"[",
"]",
"slack",
".",
... | // msgLen gets lenght of message and attachment messages. Unsupported types return 0. | [
"msgLen",
"gets",
"lenght",
"of",
"message",
"and",
"attachment",
"messages",
".",
"Unsupported",
"types",
"return",
"0",
"."
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/bot.go#L150-L158 |
151,939 | evmar/gocairo | gen.go | generateHeader | func generateHeader(outHeaderPath string, features []string) error {
inHeaderPath := "cairo.h"
if err := generateInputHeader(inHeaderPath, features); err != nil {
return err
}
inf, err := os.Open(inHeaderPath)
if err != nil {
return fmt.Errorf("open %q: %s", inHeaderPath, err)
}
defer inf.Close()
outf, err := os.Create(outHeaderPath)
if err != nil {
return fmt.Errorf("create %q: %s", outHeaderPath, err)
}
defer outf.Close()
// Gather cflags from pkg-config --cflags.
cmd := exec.Command("pkg-config", "--cflags", "cairo")
for _, feature := range features {
cmd.Args = append(cmd.Args, feature)
}
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
return err
}
cflags := strings.Split(strings.TrimSpace(string(out)), " ")
// Preprocess the cairo header.
cmd = exec.Command("gcc", "-E")
cmd.Args = append(cmd.Args, cflags...)
cmd.Args = append(cmd.Args, "-")
cmd.Stdin = inf
cmd.Stdout = outf
return cmd.Run()
} | go | func generateHeader(outHeaderPath string, features []string) error {
inHeaderPath := "cairo.h"
if err := generateInputHeader(inHeaderPath, features); err != nil {
return err
}
inf, err := os.Open(inHeaderPath)
if err != nil {
return fmt.Errorf("open %q: %s", inHeaderPath, err)
}
defer inf.Close()
outf, err := os.Create(outHeaderPath)
if err != nil {
return fmt.Errorf("create %q: %s", outHeaderPath, err)
}
defer outf.Close()
// Gather cflags from pkg-config --cflags.
cmd := exec.Command("pkg-config", "--cflags", "cairo")
for _, feature := range features {
cmd.Args = append(cmd.Args, feature)
}
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
return err
}
cflags := strings.Split(strings.TrimSpace(string(out)), " ")
// Preprocess the cairo header.
cmd = exec.Command("gcc", "-E")
cmd.Args = append(cmd.Args, cflags...)
cmd.Args = append(cmd.Args, "-")
cmd.Stdin = inf
cmd.Stdout = outf
return cmd.Run()
} | [
"func",
"generateHeader",
"(",
"outHeaderPath",
"string",
",",
"features",
"[",
"]",
"string",
")",
"error",
"{",
"inHeaderPath",
":=",
"\"",
"\"",
"\n",
"if",
"err",
":=",
"generateInputHeader",
"(",
"inHeaderPath",
",",
"features",
")",
";",
"err",
"!=",
... | // generateHeader generates the header that we parse, by expanding the
// helper header using the C preprocessor. | [
"generateHeader",
"generates",
"the",
"header",
"that",
"we",
"parse",
"by",
"expanding",
"the",
"helper",
"header",
"using",
"the",
"C",
"preprocessor",
"."
] | ddd30f837497f6fcfe5e3c3665b97d7c17d381fe | https://github.com/evmar/gocairo/blob/ddd30f837497f6fcfe5e3c3665b97d7c17d381fe/gen.go#L931-L967 |
151,940 | BeepBoopHQ/go-slackbot | examples/wit/wit.go | AddWitToContext | func AddWitToContext(ctx context.Context, witMessage *wit.Message) context.Context {
return context.WithValue(ctx, "__WIT__", witMessage)
} | go | func AddWitToContext(ctx context.Context, witMessage *wit.Message) context.Context {
return context.WithValue(ctx, "__WIT__", witMessage)
} | [
"func",
"AddWitToContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"witMessage",
"*",
"wit",
".",
"Message",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"\"",
"\"",
",",
"witMessage",
")",
"\n",
"}"
] | // AddLoggerToContext sets the logger and returns the newly derived context | [
"AddLoggerToContext",
"sets",
"the",
"logger",
"and",
"returns",
"the",
"newly",
"derived",
"context"
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/examples/wit/wit.go#L80-L82 |
151,941 | dogenzaka/tsv | parser.go | NewParser | func NewParser(reader io.Reader, data interface{}) (*Parser, error) {
r := csv.NewReader(reader)
r.Comma = '\t'
// first line should be fields
headers, err := r.Read()
if err != nil {
return nil, err
}
for i, header := range headers {
headers[i] = header
}
p := &Parser{
Reader: r,
Headers: headers,
Data: data,
ref: reflect.ValueOf(data).Elem(),
indices: make([]int, len(headers)),
structMode: false,
normalize: -1,
}
// get type information
t := p.ref.Type()
for i := 0; i < t.NumField(); i++ {
// get TSV tag
tsvtag := t.Field(i).Tag.Get("tsv")
if tsvtag != "" {
// find tsv position by header
for j := 0; j < len(headers); j++ {
if headers[j] == tsvtag {
// indices are 1 start
p.indices[j] = i + 1
p.structMode = true
}
}
}
}
if !p.structMode {
for i := 0; i < len(headers); i++ {
p.indices[i] = i + 1
}
}
return p, nil
} | go | func NewParser(reader io.Reader, data interface{}) (*Parser, error) {
r := csv.NewReader(reader)
r.Comma = '\t'
// first line should be fields
headers, err := r.Read()
if err != nil {
return nil, err
}
for i, header := range headers {
headers[i] = header
}
p := &Parser{
Reader: r,
Headers: headers,
Data: data,
ref: reflect.ValueOf(data).Elem(),
indices: make([]int, len(headers)),
structMode: false,
normalize: -1,
}
// get type information
t := p.ref.Type()
for i := 0; i < t.NumField(); i++ {
// get TSV tag
tsvtag := t.Field(i).Tag.Get("tsv")
if tsvtag != "" {
// find tsv position by header
for j := 0; j < len(headers); j++ {
if headers[j] == tsvtag {
// indices are 1 start
p.indices[j] = i + 1
p.structMode = true
}
}
}
}
if !p.structMode {
for i := 0; i < len(headers); i++ {
p.indices[i] = i + 1
}
}
return p, nil
} | [
"func",
"NewParser",
"(",
"reader",
"io",
".",
"Reader",
",",
"data",
"interface",
"{",
"}",
")",
"(",
"*",
"Parser",
",",
"error",
")",
"{",
"r",
":=",
"csv",
".",
"NewReader",
"(",
"reader",
")",
"\n",
"r",
".",
"Comma",
"=",
"'\\t'",
"\n\n",
"... | // NewStructModeParser creates new TSV parser with given io.Reader as struct mode | [
"NewStructModeParser",
"creates",
"new",
"TSV",
"parser",
"with",
"given",
"io",
".",
"Reader",
"as",
"struct",
"mode"
] | 8e02e611b1fb06f657b075f37e8770db156a101a | https://github.com/dogenzaka/tsv/blob/8e02e611b1fb06f657b075f37e8770db156a101a/parser.go#L24-L74 |
151,942 | dogenzaka/tsv | parser.go | NewParserWithoutHeader | func NewParserWithoutHeader(reader io.Reader, data interface{}) *Parser {
r := csv.NewReader(reader)
r.Comma = '\t'
p := &Parser{
Reader: r,
Data: data,
ref: reflect.ValueOf(data).Elem(),
normalize: -1,
}
return p
} | go | func NewParserWithoutHeader(reader io.Reader, data interface{}) *Parser {
r := csv.NewReader(reader)
r.Comma = '\t'
p := &Parser{
Reader: r,
Data: data,
ref: reflect.ValueOf(data).Elem(),
normalize: -1,
}
return p
} | [
"func",
"NewParserWithoutHeader",
"(",
"reader",
"io",
".",
"Reader",
",",
"data",
"interface",
"{",
"}",
")",
"*",
"Parser",
"{",
"r",
":=",
"csv",
".",
"NewReader",
"(",
"reader",
")",
"\n",
"r",
".",
"Comma",
"=",
"'\\t'",
"\n\n",
"p",
":=",
"&",
... | // NewParserWithoutHeader creates new TSV parser with given io.Reader | [
"NewParserWithoutHeader",
"creates",
"new",
"TSV",
"parser",
"with",
"given",
"io",
".",
"Reader"
] | 8e02e611b1fb06f657b075f37e8770db156a101a | https://github.com/dogenzaka/tsv/blob/8e02e611b1fb06f657b075f37e8770db156a101a/parser.go#L77-L89 |
151,943 | dogenzaka/tsv | parser.go | Next | func (p *Parser) Next() (eof bool, err error) {
// Get next record
var records []string
for {
// read until valid record
records, err = p.Reader.Read()
if err != nil {
if err.Error() == "EOF" {
return true, nil
}
return false, err
}
if len(records) > 0 {
break
}
}
if len(p.indices) == 0 {
p.indices = make([]int, len(records))
// mapping simple index
for i := 0; i < len(records); i++ {
p.indices[i] = i + 1
}
}
// record should be a pointer
for i, record := range records {
idx := p.indices[i]
if idx == 0 {
// skip empty index
continue
}
// get target field
field := p.ref.Field(idx - 1)
switch field.Kind() {
case reflect.String:
// Normalize text
if p.normalize >= 0 {
record = p.normalize.String(record)
}
field.SetString(record)
case reflect.Bool:
if record == "" {
field.SetBool(false)
} else {
col, err := strconv.ParseBool(record)
if err != nil {
return false, err
}
field.SetBool(col)
}
case reflect.Int:
if record == "" {
field.SetInt(0)
} else {
col, err := strconv.ParseInt(record, 10, 0)
if err != nil {
return false, err
}
field.SetInt(col)
}
default:
return false, errors.New("Unsupported field type")
}
}
return false, nil
} | go | func (p *Parser) Next() (eof bool, err error) {
// Get next record
var records []string
for {
// read until valid record
records, err = p.Reader.Read()
if err != nil {
if err.Error() == "EOF" {
return true, nil
}
return false, err
}
if len(records) > 0 {
break
}
}
if len(p.indices) == 0 {
p.indices = make([]int, len(records))
// mapping simple index
for i := 0; i < len(records); i++ {
p.indices[i] = i + 1
}
}
// record should be a pointer
for i, record := range records {
idx := p.indices[i]
if idx == 0 {
// skip empty index
continue
}
// get target field
field := p.ref.Field(idx - 1)
switch field.Kind() {
case reflect.String:
// Normalize text
if p.normalize >= 0 {
record = p.normalize.String(record)
}
field.SetString(record)
case reflect.Bool:
if record == "" {
field.SetBool(false)
} else {
col, err := strconv.ParseBool(record)
if err != nil {
return false, err
}
field.SetBool(col)
}
case reflect.Int:
if record == "" {
field.SetInt(0)
} else {
col, err := strconv.ParseInt(record, 10, 0)
if err != nil {
return false, err
}
field.SetInt(col)
}
default:
return false, errors.New("Unsupported field type")
}
}
return false, nil
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"Next",
"(",
")",
"(",
"eof",
"bool",
",",
"err",
"error",
")",
"{",
"// Get next record",
"var",
"records",
"[",
"]",
"string",
"\n\n",
"for",
"{",
"// read until valid record",
"records",
",",
"err",
"=",
"p",
".... | // Next puts reader forward by a line | [
"Next",
"puts",
"reader",
"forward",
"by",
"a",
"line"
] | 8e02e611b1fb06f657b075f37e8770db156a101a | https://github.com/dogenzaka/tsv/blob/8e02e611b1fb06f657b075f37e8770db156a101a/parser.go#L92-L161 |
151,944 | evmar/gocairo | cairo/cairo.go | WriteToPNG | func (surface *Surface) WriteToPNG(w io.Writer) error {
data := writeClosure{w: w}
key := goPointers.put(data)
status := C.cairo_surface_write_to_png_stream((*C.cairo_surface_t)(surface.Ptr),
(C.cairo_write_func_t)(unsafe.Pointer(C.gocairo_write_func)),
unsafe.Pointer(&key))
goPointers.clear(key)
// TODO: which should we prefer between writeClosure.err and status?
// Perhaps test against CAIRO_STATUS_WRITE_ERROR? Needs a test case.
return Status(status).toError()
} | go | func (surface *Surface) WriteToPNG(w io.Writer) error {
data := writeClosure{w: w}
key := goPointers.put(data)
status := C.cairo_surface_write_to_png_stream((*C.cairo_surface_t)(surface.Ptr),
(C.cairo_write_func_t)(unsafe.Pointer(C.gocairo_write_func)),
unsafe.Pointer(&key))
goPointers.clear(key)
// TODO: which should we prefer between writeClosure.err and status?
// Perhaps test against CAIRO_STATUS_WRITE_ERROR? Needs a test case.
return Status(status).toError()
} | [
"func",
"(",
"surface",
"*",
"Surface",
")",
"WriteToPNG",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"data",
":=",
"writeClosure",
"{",
"w",
":",
"w",
"}",
"\n",
"key",
":=",
"goPointers",
".",
"put",
"(",
"data",
")",
"\n",
"status",
":=",... | // WriteToPNG encodes a Surface to an io.Writer as a PNG file. | [
"WriteToPNG",
"encodes",
"a",
"Surface",
"to",
"an",
"io",
".",
"Writer",
"as",
"a",
"PNG",
"file",
"."
] | ddd30f837497f6fcfe5e3c3665b97d7c17d381fe | https://github.com/evmar/gocairo/blob/ddd30f837497f6fcfe5e3c3665b97d7c17d381fe/cairo/cairo.go#L66-L76 |
151,945 | evmar/gocairo | cairo/cairo.go | ImageSurfaceCreateFromPNGStream | func ImageSurfaceCreateFromPNGStream(r io.Reader) (*ImageSurface, error) {
data := readClosure{r: r}
key := goPointers.put(data)
surf := &ImageSurface{wrapSurface(C.cairo_image_surface_create_from_png_stream(
(C.cairo_read_func_t)(unsafe.Pointer(C.gocairo_read_func)),
unsafe.Pointer(&key)))}
goPointers.clear(key)
// TODO: which should we prefer between readClosure.err and status?
// Perhaps test against CAIRO_STATUS_WRITE_ERROR? Needs a test case.
return surf, surf.status()
} | go | func ImageSurfaceCreateFromPNGStream(r io.Reader) (*ImageSurface, error) {
data := readClosure{r: r}
key := goPointers.put(data)
surf := &ImageSurface{wrapSurface(C.cairo_image_surface_create_from_png_stream(
(C.cairo_read_func_t)(unsafe.Pointer(C.gocairo_read_func)),
unsafe.Pointer(&key)))}
goPointers.clear(key)
// TODO: which should we prefer between readClosure.err and status?
// Perhaps test against CAIRO_STATUS_WRITE_ERROR? Needs a test case.
return surf, surf.status()
} | [
"func",
"ImageSurfaceCreateFromPNGStream",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"ImageSurface",
",",
"error",
")",
"{",
"data",
":=",
"readClosure",
"{",
"r",
":",
"r",
"}",
"\n",
"key",
":=",
"goPointers",
".",
"put",
"(",
"data",
")",
"\n",
... | // ImageSurfaceCreateFromPNGStream creates an ImageSurface from a stream of
// PNG data. | [
"ImageSurfaceCreateFromPNGStream",
"creates",
"an",
"ImageSurface",
"from",
"a",
"stream",
"of",
"PNG",
"data",
"."
] | ddd30f837497f6fcfe5e3c3665b97d7c17d381fe | https://github.com/evmar/gocairo/blob/ddd30f837497f6fcfe5e3c3665b97d7c17d381fe/cairo/cairo.go#L80-L90 |
151,946 | evmar/gocairo | cairo/cairo.go | Next | func (pi *PathIter) Next() *PathSegment {
if pi.i >= pi.path.Ptr.num_data {
return nil
}
// path.data is an array of cairo_path_data_t, but the union makes
// things complicated.
dataArray := (*[1 << 30]C.cairo_path_data_t)(unsafe.Pointer(pi.path.Ptr.data))
seg, ofs := decodePathSegment(unsafe.Pointer(&dataArray[pi.i]))
pi.i += C.int(ofs)
return seg
} | go | func (pi *PathIter) Next() *PathSegment {
if pi.i >= pi.path.Ptr.num_data {
return nil
}
// path.data is an array of cairo_path_data_t, but the union makes
// things complicated.
dataArray := (*[1 << 30]C.cairo_path_data_t)(unsafe.Pointer(pi.path.Ptr.data))
seg, ofs := decodePathSegment(unsafe.Pointer(&dataArray[pi.i]))
pi.i += C.int(ofs)
return seg
} | [
"func",
"(",
"pi",
"*",
"PathIter",
")",
"Next",
"(",
")",
"*",
"PathSegment",
"{",
"if",
"pi",
".",
"i",
">=",
"pi",
".",
"path",
".",
"Ptr",
".",
"num_data",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"// path.data is an array of cairo_path_data_t, but the u... | // Next returns the next PathSegment, or returns nil at the end of the path. | [
"Next",
"returns",
"the",
"next",
"PathSegment",
"or",
"returns",
"nil",
"at",
"the",
"end",
"of",
"the",
"path",
"."
] | ddd30f837497f6fcfe5e3c3665b97d7c17d381fe | https://github.com/evmar/gocairo/blob/ddd30f837497f6fcfe5e3c3665b97d7c17d381fe/cairo/cairo.go#L104-L114 |
151,947 | creack/termios | raw/raw.go | TcSetAttr | func TcSetAttr(fd uintptr, termios *Termios) error {
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(termios))); err != 0 {
return err
}
return nil
} | go | func TcSetAttr(fd uintptr, termios *Termios) error {
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(termios))); err != 0 {
return err
}
return nil
} | [
"func",
"TcSetAttr",
"(",
"fd",
"uintptr",
",",
"termios",
"*",
"Termios",
")",
"error",
"{",
"if",
"_",
",",
"_",
",",
"err",
":=",
"syscall",
".",
"Syscall",
"(",
"syscall",
".",
"SYS_IOCTL",
",",
"fd",
",",
"uintptr",
"(",
"setTermios",
")",
",",
... | // TcSetAttr restores the terminal connected to the given file descriptor to a
// previous state. | [
"TcSetAttr",
"restores",
"the",
"terminal",
"connected",
"to",
"the",
"given",
"file",
"descriptor",
"to",
"a",
"previous",
"state",
"."
] | 88d0029e36a108c959d6f8fc63c393f591b0302b | https://github.com/creack/termios/blob/88d0029e36a108c959d6f8fc63c393f591b0302b/raw/raw.go#L10-L15 |
151,948 | creack/termios | raw/raw.go | TcGetAttr | func TcGetAttr(fd uintptr) (*Termios, error) {
var termios = &Termios{}
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(termios))); err != 0 {
return nil, err
}
return termios, nil
} | go | func TcGetAttr(fd uintptr) (*Termios, error) {
var termios = &Termios{}
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(termios))); err != 0 {
return nil, err
}
return termios, nil
} | [
"func",
"TcGetAttr",
"(",
"fd",
"uintptr",
")",
"(",
"*",
"Termios",
",",
"error",
")",
"{",
"var",
"termios",
"=",
"&",
"Termios",
"{",
"}",
"\n",
"if",
"_",
",",
"_",
",",
"err",
":=",
"syscall",
".",
"Syscall",
"(",
"syscall",
".",
"SYS_IOCTL",
... | // TcGetAttr retrieves the current terminal settings and returns it. | [
"TcGetAttr",
"retrieves",
"the",
"current",
"terminal",
"settings",
"and",
"returns",
"it",
"."
] | 88d0029e36a108c959d6f8fc63c393f591b0302b | https://github.com/creack/termios/blob/88d0029e36a108c959d6f8fc63c393f591b0302b/raw/raw.go#L18-L24 |
151,949 | evmar/gocairo | cairo/util.go | sliceBytes | func sliceBytes(p unsafe.Pointer) unsafe.Pointer {
hdr := (*reflect.SliceHeader)(p)
return unsafe.Pointer(hdr.Data)
} | go | func sliceBytes(p unsafe.Pointer) unsafe.Pointer {
hdr := (*reflect.SliceHeader)(p)
return unsafe.Pointer(hdr.Data)
} | [
"func",
"sliceBytes",
"(",
"p",
"unsafe",
".",
"Pointer",
")",
"unsafe",
".",
"Pointer",
"{",
"hdr",
":=",
"(",
"*",
"reflect",
".",
"SliceHeader",
")",
"(",
"p",
")",
"\n",
"return",
"unsafe",
".",
"Pointer",
"(",
"hdr",
".",
"Data",
")",
"\n",
"}... | // sliceBytes returns a pointer to the bytes of the data in a slice. | [
"sliceBytes",
"returns",
"a",
"pointer",
"to",
"the",
"bytes",
"of",
"the",
"data",
"in",
"a",
"slice",
"."
] | ddd30f837497f6fcfe5e3c3665b97d7c17d381fe | https://github.com/evmar/gocairo/blob/ddd30f837497f6fcfe5e3c3665b97d7c17d381fe/cairo/util.go#L27-L30 |
151,950 | evmar/gocairo | cairo/path.go | decodePathSegment | func decodePathSegment(pathData unsafe.Pointer) (*PathSegment, int) {
header := (*pathDataHeader)(pathData)
seg := PathSegment{
Type: PathDataType(header.dataType),
Points: make([]PathPoint, header.length-1),
}
parts := (*[1 << 30]PathPoint)(pathData)
copy(seg.Points, parts[1:])
return &seg, int(header.length)
} | go | func decodePathSegment(pathData unsafe.Pointer) (*PathSegment, int) {
header := (*pathDataHeader)(pathData)
seg := PathSegment{
Type: PathDataType(header.dataType),
Points: make([]PathPoint, header.length-1),
}
parts := (*[1 << 30]PathPoint)(pathData)
copy(seg.Points, parts[1:])
return &seg, int(header.length)
} | [
"func",
"decodePathSegment",
"(",
"pathData",
"unsafe",
".",
"Pointer",
")",
"(",
"*",
"PathSegment",
",",
"int",
")",
"{",
"header",
":=",
"(",
"*",
"pathDataHeader",
")",
"(",
"pathData",
")",
"\n",
"seg",
":=",
"PathSegment",
"{",
"Type",
":",
"PathDa... | // decodePathSegment extracts a series of points out of a cairo_path_data_t array. | [
"decodePathSegment",
"extracts",
"a",
"series",
"of",
"points",
"out",
"of",
"a",
"cairo_path_data_t",
"array",
"."
] | ddd30f837497f6fcfe5e3c3665b97d7c17d381fe | https://github.com/evmar/gocairo/blob/ddd30f837497f6fcfe5e3c3665b97d7c17d381fe/cairo/path.go#L37-L46 |
151,951 | BeepBoopHQ/go-slackbot | utils.go | IsDirectMessage | func IsDirectMessage(evt *slack.MessageEvent) bool {
return regexp.MustCompile("^D.*").MatchString(evt.Channel)
} | go | func IsDirectMessage(evt *slack.MessageEvent) bool {
return regexp.MustCompile("^D.*").MatchString(evt.Channel)
} | [
"func",
"IsDirectMessage",
"(",
"evt",
"*",
"slack",
".",
"MessageEvent",
")",
"bool",
"{",
"return",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
")",
".",
"MatchString",
"(",
"evt",
".",
"Channel",
")",
"\n",
"}"
] | // IsDirectMessage returns true if this message is in a direct message conversation | [
"IsDirectMessage",
"returns",
"true",
"if",
"this",
"message",
"is",
"in",
"a",
"direct",
"message",
"conversation"
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/utils.go#L15-L17 |
151,952 | BeepBoopHQ/go-slackbot | utils.go | IsDirectMention | func IsDirectMention(evt *slack.MessageEvent, userID string) bool {
return regexp.MustCompile("^<@" + userID + ">.*").MatchString(evt.Text)
} | go | func IsDirectMention(evt *slack.MessageEvent, userID string) bool {
return regexp.MustCompile("^<@" + userID + ">.*").MatchString(evt.Text)
} | [
"func",
"IsDirectMention",
"(",
"evt",
"*",
"slack",
".",
"MessageEvent",
",",
"userID",
"string",
")",
"bool",
"{",
"return",
"regexp",
".",
"MustCompile",
"(",
"\"",
"\"",
"+",
"userID",
"+",
"\"",
"\"",
")",
".",
"MatchString",
"(",
"evt",
".",
"Tex... | // IsDirectMention returns true is message is a Direct Mention that mentions a specific user. A
// direct mention is a mention at the very beginning of the message | [
"IsDirectMention",
"returns",
"true",
"is",
"message",
"is",
"a",
"Direct",
"Mention",
"that",
"mentions",
"a",
"specific",
"user",
".",
"A",
"direct",
"mention",
"is",
"a",
"mention",
"at",
"the",
"very",
"beginning",
"of",
"the",
"message"
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/utils.go#L21-L23 |
151,953 | BeepBoopHQ/go-slackbot | utils.go | IsMentioned | func IsMentioned(evt *slack.MessageEvent, userID string) bool {
userIDs := WhoMentioned(evt)
for _, u := range userIDs {
if u == userID {
return true
}
}
return false
} | go | func IsMentioned(evt *slack.MessageEvent, userID string) bool {
userIDs := WhoMentioned(evt)
for _, u := range userIDs {
if u == userID {
return true
}
}
return false
} | [
"func",
"IsMentioned",
"(",
"evt",
"*",
"slack",
".",
"MessageEvent",
",",
"userID",
"string",
")",
"bool",
"{",
"userIDs",
":=",
"WhoMentioned",
"(",
"evt",
")",
"\n",
"for",
"_",
",",
"u",
":=",
"range",
"userIDs",
"{",
"if",
"u",
"==",
"userID",
"... | // IsMentioned returns true if this message contains a mention of a specific user | [
"IsMentioned",
"returns",
"true",
"if",
"this",
"message",
"contains",
"a",
"mention",
"of",
"a",
"specific",
"user"
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/utils.go#L26-L34 |
151,954 | BeepBoopHQ/go-slackbot | utils.go | IsMention | func IsMention(evt *slack.MessageEvent) bool {
results := regexp.MustCompile(`<@([a-zA-z0-9]+)?>`).FindAllStringSubmatch(evt.Text, -1)
return len(results) > 0
} | go | func IsMention(evt *slack.MessageEvent) bool {
results := regexp.MustCompile(`<@([a-zA-z0-9]+)?>`).FindAllStringSubmatch(evt.Text, -1)
return len(results) > 0
} | [
"func",
"IsMention",
"(",
"evt",
"*",
"slack",
".",
"MessageEvent",
")",
"bool",
"{",
"results",
":=",
"regexp",
".",
"MustCompile",
"(",
"`<@([a-zA-z0-9]+)?>`",
")",
".",
"FindAllStringSubmatch",
"(",
"evt",
".",
"Text",
",",
"-",
"1",
")",
"\n",
"return"... | // IsMention returns true the message contains a mention | [
"IsMention",
"returns",
"true",
"the",
"message",
"contains",
"a",
"mention"
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/utils.go#L37-L40 |
151,955 | BeepBoopHQ/go-slackbot | utils.go | WhoMentioned | func WhoMentioned(evt *slack.MessageEvent) []string {
results := regexp.MustCompile(`<@([a-zA-z0-9]+)>`).FindAllStringSubmatch(evt.Text, -1)
matches := make([]string, len(results))
for i, r := range results {
matches[i] = r[1]
}
return matches
} | go | func WhoMentioned(evt *slack.MessageEvent) []string {
results := regexp.MustCompile(`<@([a-zA-z0-9]+)>`).FindAllStringSubmatch(evt.Text, -1)
matches := make([]string, len(results))
for i, r := range results {
matches[i] = r[1]
}
return matches
} | [
"func",
"WhoMentioned",
"(",
"evt",
"*",
"slack",
".",
"MessageEvent",
")",
"[",
"]",
"string",
"{",
"results",
":=",
"regexp",
".",
"MustCompile",
"(",
"`<@([a-zA-z0-9]+)>`",
")",
".",
"FindAllStringSubmatch",
"(",
"evt",
".",
"Text",
",",
"-",
"1",
")",
... | // WhoMentioned returns a list of userIDs mentioned in the message | [
"WhoMentioned",
"returns",
"a",
"list",
"of",
"userIDs",
"mentioned",
"in",
"the",
"message"
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/utils.go#L43-L50 |
151,956 | BeepBoopHQ/go-slackbot | context.go | AddBotToContext | func AddBotToContext(ctx context.Context, bot *Bot) context.Context {
return context.WithValue(ctx, BOT_CONTEXT, bot)
} | go | func AddBotToContext(ctx context.Context, bot *Bot) context.Context {
return context.WithValue(ctx, BOT_CONTEXT, bot)
} | [
"func",
"AddBotToContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"bot",
"*",
"Bot",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"BOT_CONTEXT",
",",
"bot",
")",
"\n",
"}"
] | // AddBotToContext sets the bot reference in context and returns the newly derived context | [
"AddBotToContext",
"sets",
"the",
"bot",
"reference",
"in",
"context",
"and",
"returns",
"the",
"newly",
"derived",
"context"
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/context.go#L21-L23 |
151,957 | BeepBoopHQ/go-slackbot | context.go | AddMessageToContext | func AddMessageToContext(ctx context.Context, msg *slack.MessageEvent) context.Context {
return context.WithValue(ctx, MESSAGE_CONTEXT, msg)
} | go | func AddMessageToContext(ctx context.Context, msg *slack.MessageEvent) context.Context {
return context.WithValue(ctx, MESSAGE_CONTEXT, msg)
} | [
"func",
"AddMessageToContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"msg",
"*",
"slack",
".",
"MessageEvent",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"MESSAGE_CONTEXT",
",",
"msg",
")",
"\n",
"}"
... | // AddMessageToContext sets the Slack message event reference in context and returns the newly derived context | [
"AddMessageToContext",
"sets",
"the",
"Slack",
"message",
"event",
"reference",
"in",
"context",
"and",
"returns",
"the",
"newly",
"derived",
"context"
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/context.go#L33-L35 |
151,958 | BeepBoopHQ/go-slackbot | route.go | Hear | func (r *Route) Hear(regex string) *Route {
r.err = r.addRegexpMatcher(regex)
return r
} | go | func (r *Route) Hear(regex string) *Route {
r.err = r.addRegexpMatcher(regex)
return r
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"Hear",
"(",
"regex",
"string",
")",
"*",
"Route",
"{",
"r",
".",
"err",
"=",
"r",
".",
"addRegexpMatcher",
"(",
"regex",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // Hear adds a matcher for the message text | [
"Hear",
"adds",
"a",
"matcher",
"for",
"the",
"message",
"text"
] | 58027c0d5238a0604305652ea526b3c18a7cead1 | https://github.com/BeepBoopHQ/go-slackbot/blob/58027c0d5238a0604305652ea526b3c18a7cead1/route.go#L54-L57 |
151,959 | moonrhythm/session | manager.go | New | func New(config Config) *Manager {
if config.Store == nil {
panic("session: nil store")
}
m := Manager{}
m.config = config
if m.config.GenerateID == nil {
m.config.GenerateID = func() string {
b := make([]byte, 32)
if _, err := rand.Read(b); err != nil {
// this should never happened
// or something wrong with OS's crypto pseudorandom generator
panic(err)
}
return base64.RawURLEncoding.EncodeToString(b)
}
}
if m.config.DisableHashID {
m.hashID = func(id string) string {
return id
}
} else {
m.hashID = func(id string) string {
h := sha256.New()
h.Write([]byte(id))
h.Write(config.Secret)
return base64.RawURLEncoding.EncodeToString(h.Sum(nil))
}
}
if m.config.IdleTimeout <= 0 {
m.config.IdleTimeout = m.config.MaxAge
}
return &m
} | go | func New(config Config) *Manager {
if config.Store == nil {
panic("session: nil store")
}
m := Manager{}
m.config = config
if m.config.GenerateID == nil {
m.config.GenerateID = func() string {
b := make([]byte, 32)
if _, err := rand.Read(b); err != nil {
// this should never happened
// or something wrong with OS's crypto pseudorandom generator
panic(err)
}
return base64.RawURLEncoding.EncodeToString(b)
}
}
if m.config.DisableHashID {
m.hashID = func(id string) string {
return id
}
} else {
m.hashID = func(id string) string {
h := sha256.New()
h.Write([]byte(id))
h.Write(config.Secret)
return base64.RawURLEncoding.EncodeToString(h.Sum(nil))
}
}
if m.config.IdleTimeout <= 0 {
m.config.IdleTimeout = m.config.MaxAge
}
return &m
} | [
"func",
"New",
"(",
"config",
"Config",
")",
"*",
"Manager",
"{",
"if",
"config",
".",
"Store",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"m",
":=",
"Manager",
"{",
"}",
"\n",
"m",
".",
"config",
"=",
"config",
"\n\n",
... | // New creates new session manager | [
"New",
"creates",
"new",
"session",
"manager"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/manager.go#L19-L57 |
151,960 | moonrhythm/session | manager.go | Get | func (m *Manager) Get(r *http.Request, name string) (*Session, error) {
s := Session{
Name: name,
Domain: m.config.Domain,
Path: m.config.Path,
HTTPOnly: m.config.HTTPOnly,
MaxAge: m.config.MaxAge,
Secure: m.isSecure(r),
SameSite: m.config.SameSite,
Rolling: m.config.Rolling,
}
// get session id from cookie
cookie, err := r.Cookie(name)
if err == nil && len(cookie.Value) > 0 {
var rawID string
// verify signature
if len(m.config.Keys) > 0 {
parts := strings.Split(cookie.Value, ".")
rawID = parts[0]
if len(parts) != 2 || !verify(rawID, parts[1], m.config.Keys) {
goto invalidSignature
}
} else {
rawID = cookie.Value
}
hashedID := m.hashID(rawID)
// get session data from store
s.data, err = m.config.Store.Get(hashedID, makeStoreOption(m, &s))
if err == nil {
s.rawID = rawID
s.id = hashedID
} else if err != ErrNotFound {
return nil, err
}
// DO NOT set session id to cookie value if not found in store
// to prevent session fixation attack
}
invalidSignature:
if len(s.id) == 0 {
s.rawID = m.config.GenerateID()
s.id = m.hashID(s.rawID)
s.isNew = true
}
return &s, nil
} | go | func (m *Manager) Get(r *http.Request, name string) (*Session, error) {
s := Session{
Name: name,
Domain: m.config.Domain,
Path: m.config.Path,
HTTPOnly: m.config.HTTPOnly,
MaxAge: m.config.MaxAge,
Secure: m.isSecure(r),
SameSite: m.config.SameSite,
Rolling: m.config.Rolling,
}
// get session id from cookie
cookie, err := r.Cookie(name)
if err == nil && len(cookie.Value) > 0 {
var rawID string
// verify signature
if len(m.config.Keys) > 0 {
parts := strings.Split(cookie.Value, ".")
rawID = parts[0]
if len(parts) != 2 || !verify(rawID, parts[1], m.config.Keys) {
goto invalidSignature
}
} else {
rawID = cookie.Value
}
hashedID := m.hashID(rawID)
// get session data from store
s.data, err = m.config.Store.Get(hashedID, makeStoreOption(m, &s))
if err == nil {
s.rawID = rawID
s.id = hashedID
} else if err != ErrNotFound {
return nil, err
}
// DO NOT set session id to cookie value if not found in store
// to prevent session fixation attack
}
invalidSignature:
if len(s.id) == 0 {
s.rawID = m.config.GenerateID()
s.id = m.hashID(s.rawID)
s.isNew = true
}
return &s, nil
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"Get",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"name",
"string",
")",
"(",
"*",
"Session",
",",
"error",
")",
"{",
"s",
":=",
"Session",
"{",
"Name",
":",
"name",
",",
"Domain",
":",
"m",
".",
"config"... | // Get retrieves session from request | [
"Get",
"retrieves",
"session",
"from",
"request"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/manager.go#L60-L112 |
151,961 | moonrhythm/session | manager.go | Save | func (m *Manager) Save(w http.ResponseWriter, s *Session) error {
m.setCookie(w, s)
opt := makeStoreOption(m, s)
// detect is flash changed and encode new flash data
if s.flash != nil && s.flash.Changed() {
b, _ := s.flash.encode()
s.Set(flashKey, b)
}
// if session not modified, don't save to store to prevent store overflow
if !m.config.Resave && !s.Changed() {
return nil
}
// save sesion data to store
s.Set(timestampKey, time.Now().Unix())
return m.config.Store.Set(s.id, s.data, opt)
} | go | func (m *Manager) Save(w http.ResponseWriter, s *Session) error {
m.setCookie(w, s)
opt := makeStoreOption(m, s)
// detect is flash changed and encode new flash data
if s.flash != nil && s.flash.Changed() {
b, _ := s.flash.encode()
s.Set(flashKey, b)
}
// if session not modified, don't save to store to prevent store overflow
if !m.config.Resave && !s.Changed() {
return nil
}
// save sesion data to store
s.Set(timestampKey, time.Now().Unix())
return m.config.Store.Set(s.id, s.data, opt)
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"Save",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"s",
"*",
"Session",
")",
"error",
"{",
"m",
".",
"setCookie",
"(",
"w",
",",
"s",
")",
"\n\n",
"opt",
":=",
"makeStoreOption",
"(",
"m",
",",
"s",
")",
... | // Save saves session to store and set cookie to response
//
// Save must be called before response header was written | [
"Save",
"saves",
"session",
"to",
"store",
"and",
"set",
"cookie",
"to",
"response",
"Save",
"must",
"be",
"called",
"before",
"response",
"header",
"was",
"written"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/manager.go#L117-L136 |
151,962 | moonrhythm/session | manager.go | Destroy | func (m *Manager) Destroy(s *Session) error {
return m.config.Store.Del(s.id, makeStoreOption(m, s))
} | go | func (m *Manager) Destroy(s *Session) error {
return m.config.Store.Del(s.id, makeStoreOption(m, s))
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"Destroy",
"(",
"s",
"*",
"Session",
")",
"error",
"{",
"return",
"m",
".",
"config",
".",
"Store",
".",
"Del",
"(",
"s",
".",
"id",
",",
"makeStoreOption",
"(",
"m",
",",
"s",
")",
")",
"\n",
"}"
] | // Destroy deletes session from store | [
"Destroy",
"deletes",
"session",
"from",
"store"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/manager.go#L139-L141 |
151,963 | moonrhythm/session | manager.go | Regenerate | func (m *Manager) Regenerate(w http.ResponseWriter, s *Session) error {
opt := makeStoreOption(m, s)
id := s.id
s.rawID = m.config.GenerateID()
s.isNew = true
s.id = m.hashID(s.rawID)
s.changed = true
if m.config.DeleteOldSession {
return m.config.Store.Del(id, opt)
}
data := s.data.Clone()
data[timestampKey] = int64(0)
data[destroyedKey] = time.Now().UnixNano()
return m.config.Store.Set(id, data, opt)
} | go | func (m *Manager) Regenerate(w http.ResponseWriter, s *Session) error {
opt := makeStoreOption(m, s)
id := s.id
s.rawID = m.config.GenerateID()
s.isNew = true
s.id = m.hashID(s.rawID)
s.changed = true
if m.config.DeleteOldSession {
return m.config.Store.Del(id, opt)
}
data := s.data.Clone()
data[timestampKey] = int64(0)
data[destroyedKey] = time.Now().UnixNano()
return m.config.Store.Set(id, data, opt)
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"Regenerate",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"s",
"*",
"Session",
")",
"error",
"{",
"opt",
":=",
"makeStoreOption",
"(",
"m",
",",
"s",
")",
"\n\n",
"id",
":=",
"s",
".",
"id",
"\n\n",
"s",
"... | // Regenerate regenerates session id
// use when change user access level to prevent session fixation | [
"Regenerate",
"regenerates",
"session",
"id",
"use",
"when",
"change",
"user",
"access",
"level",
"to",
"prevent",
"session",
"fixation"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/manager.go#L145-L163 |
151,964 | moonrhythm/session | manager.go | Renew | func (m *Manager) Renew(w http.ResponseWriter, s *Session) error {
s.data = make(Data)
return m.Regenerate(w, s)
} | go | func (m *Manager) Renew(w http.ResponseWriter, s *Session) error {
s.data = make(Data)
return m.Regenerate(w, s)
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"Renew",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"s",
"*",
"Session",
")",
"error",
"{",
"s",
".",
"data",
"=",
"make",
"(",
"Data",
")",
"\n",
"return",
"m",
".",
"Regenerate",
"(",
"w",
",",
"s",
"... | // Renew clears session data and regenerate new session id | [
"Renew",
"clears",
"session",
"data",
"and",
"regenerate",
"new",
"session",
"id"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/manager.go#L166-L169 |
151,965 | moonrhythm/session | middleware.go | Middleware | func (m *Manager) Middleware() func(http.Handler) http.Handler {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rm := &scopedManager{
Manager: m,
ResponseWriter: w,
r: r,
storage: make(map[string]*Session),
}
ctx := context.WithValue(r.Context(), scopedManagerKey{}, rm)
h.ServeHTTP(rm, r.WithContext(ctx))
rm.MustSaveAll()
})
}
} | go | func (m *Manager) Middleware() func(http.Handler) http.Handler {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rm := &scopedManager{
Manager: m,
ResponseWriter: w,
r: r,
storage: make(map[string]*Session),
}
ctx := context.WithValue(r.Context(), scopedManagerKey{}, rm)
h.ServeHTTP(rm, r.WithContext(ctx))
rm.MustSaveAll()
})
}
} | [
"func",
"(",
"m",
"*",
"Manager",
")",
"Middleware",
"(",
")",
"func",
"(",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"func",
"(",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"Hand... | // Middleware injects session manager into request's context.
//
// All data changed before write response writer's header will be save. | [
"Middleware",
"injects",
"session",
"manager",
"into",
"request",
"s",
"context",
".",
"All",
"data",
"changed",
"before",
"write",
"response",
"writer",
"s",
"header",
"will",
"be",
"save",
"."
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/middleware.go#L26-L42 |
151,966 | moonrhythm/session | middleware.go | Get | func Get(ctx context.Context, name string) (*Session, error) {
m, _ := ctx.Value(scopedManagerKey{}).(*scopedManager)
if m == nil {
return nil, ErrNotPassMiddleware
}
// try get session from storage first
// to preserve session data from difference handler
if s, ok := m.storage[name]; ok {
return s, nil
}
// get session from manager
s, err := m.Get(name)
if err != nil {
return nil, err
}
s.m = m
// save session to storage for later get
m.storage[name] = s
return s, nil
} | go | func Get(ctx context.Context, name string) (*Session, error) {
m, _ := ctx.Value(scopedManagerKey{}).(*scopedManager)
if m == nil {
return nil, ErrNotPassMiddleware
}
// try get session from storage first
// to preserve session data from difference handler
if s, ok := m.storage[name]; ok {
return s, nil
}
// get session from manager
s, err := m.Get(name)
if err != nil {
return nil, err
}
s.m = m
// save session to storage for later get
m.storage[name] = s
return s, nil
} | [
"func",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"(",
"*",
"Session",
",",
"error",
")",
"{",
"m",
",",
"_",
":=",
"ctx",
".",
"Value",
"(",
"scopedManagerKey",
"{",
"}",
")",
".",
"(",
"*",
"scopedManager",
")",
... | // Get gets session from context | [
"Get",
"gets",
"session",
"from",
"context"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/middleware.go#L45-L67 |
151,967 | moonrhythm/session | middleware.go | Write | func (m *scopedManager) Write(b []byte) (int, error) {
if !m.wroteHeader {
m.WriteHeader(http.StatusOK)
}
return m.ResponseWriter.Write(b)
} | go | func (m *scopedManager) Write(b []byte) (int, error) {
if !m.wroteHeader {
m.WriteHeader(http.StatusOK)
}
return m.ResponseWriter.Write(b)
} | [
"func",
"(",
"m",
"*",
"scopedManager",
")",
"Write",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"!",
"m",
".",
"wroteHeader",
"{",
"m",
".",
"WriteHeader",
"(",
"http",
".",
"StatusOK",
")",
"\n",
"}",
"\n",
"re... | // Write implements http.ResponseWriter | [
"Write",
"implements",
"http",
".",
"ResponseWriter"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/middleware.go#L110-L115 |
151,968 | moonrhythm/session | middleware.go | WriteHeader | func (m *scopedManager) WriteHeader(code int) {
if m.wroteHeader {
return
}
m.MustSaveAll()
m.wroteHeader = true
m.ResponseWriter.WriteHeader(code)
} | go | func (m *scopedManager) WriteHeader(code int) {
if m.wroteHeader {
return
}
m.MustSaveAll()
m.wroteHeader = true
m.ResponseWriter.WriteHeader(code)
} | [
"func",
"(",
"m",
"*",
"scopedManager",
")",
"WriteHeader",
"(",
"code",
"int",
")",
"{",
"if",
"m",
".",
"wroteHeader",
"{",
"return",
"\n",
"}",
"\n",
"m",
".",
"MustSaveAll",
"(",
")",
"\n",
"m",
".",
"wroteHeader",
"=",
"true",
"\n",
"m",
".",
... | // WriteHeader implements http.ResponseWriter | [
"WriteHeader",
"implements",
"http",
".",
"ResponseWriter"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/middleware.go#L118-L125 |
151,969 | moonrhythm/session | flash.go | encode | func (f *Flash) encode() ([]byte, error) {
// empty flash encode to empty bytes
if len(f.v) == 0 {
return []byte{}, nil
}
buf := &bytes.Buffer{}
err := gob.NewEncoder(buf).Encode(f.v)
if err != nil {
return []byte{}, err
}
return buf.Bytes(), nil
} | go | func (f *Flash) encode() ([]byte, error) {
// empty flash encode to empty bytes
if len(f.v) == 0 {
return []byte{}, nil
}
buf := &bytes.Buffer{}
err := gob.NewEncoder(buf).Encode(f.v)
if err != nil {
return []byte{}, err
}
return buf.Bytes(), nil
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"encode",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// empty flash encode to empty bytes",
"if",
"len",
"(",
"f",
".",
"v",
")",
"==",
"0",
"{",
"return",
"[",
"]",
"byte",
"{",
"}",
",",
"nil"... | // Encode encodes flash | [
"Encode",
"encodes",
"flash"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L25-L37 |
151,970 | moonrhythm/session | flash.go | Values | func (f *Flash) Values(key string) []interface{} {
if !f.Has(key) {
return []interface{}{}
}
f.changed = true
r := f.v[key]
delete(f.v, key)
return r
} | go | func (f *Flash) Values(key string) []interface{} {
if !f.Has(key) {
return []interface{}{}
}
f.changed = true
r := f.v[key]
delete(f.v, key)
return r
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"Values",
"(",
"key",
"string",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"if",
"!",
"f",
".",
"Has",
"(",
"key",
")",
"{",
"return",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n\n",
"f",
"... | // Values returns slice of given key | [
"Values",
"returns",
"slice",
"of",
"given",
"key"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L40-L49 |
151,971 | moonrhythm/session | flash.go | Set | func (f *Flash) Set(key string, value interface{}) {
if !f.changed {
f.changed = true
}
if f.v == nil {
f.v = make(flashData)
}
f.v[key] = []interface{}{value}
} | go | func (f *Flash) Set(key string, value interface{}) {
if !f.changed {
f.changed = true
}
if f.v == nil {
f.v = make(flashData)
}
f.v[key] = []interface{}{value}
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"Set",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"if",
"!",
"f",
".",
"changed",
"{",
"f",
".",
"changed",
"=",
"true",
"\n",
"}",
"\n",
"if",
"f",
".",
"v",
"==",
"nil",
"{",
... | // Set sets value to flash | [
"Set",
"sets",
"value",
"to",
"flash"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L52-L60 |
151,972 | moonrhythm/session | flash.go | Get | func (f *Flash) Get(key string) interface{} {
if !f.Has(key) {
return nil
}
f.changed = true
r := f.v[key][0]
delete(f.v, key)
return r
} | go | func (f *Flash) Get(key string) interface{} {
if !f.Has(key) {
return nil
}
f.changed = true
r := f.v[key][0]
delete(f.v, key)
return r
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"Get",
"(",
"key",
"string",
")",
"interface",
"{",
"}",
"{",
"if",
"!",
"f",
".",
"Has",
"(",
"key",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"f",
".",
"changed",
"=",
"true",
"\n",
"r",
":=",
"f",
... | // Get gets value from flash | [
"Get",
"gets",
"value",
"from",
"flash"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L74-L83 |
151,973 | moonrhythm/session | flash.go | GetString | func (f *Flash) GetString(key string) string {
r, _ := f.Get(key).(string)
return r
} | go | func (f *Flash) GetString(key string) string {
r, _ := f.Get(key).(string)
return r
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"GetString",
"(",
"key",
"string",
")",
"string",
"{",
"r",
",",
"_",
":=",
"f",
".",
"Get",
"(",
"key",
")",
".",
"(",
"string",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetString gets string from flash | [
"GetString",
"gets",
"string",
"from",
"flash"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L86-L89 |
151,974 | moonrhythm/session | flash.go | GetInt | func (f *Flash) GetInt(key string) int {
r, _ := f.Get(key).(int)
return r
} | go | func (f *Flash) GetInt(key string) int {
r, _ := f.Get(key).(int)
return r
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"GetInt",
"(",
"key",
"string",
")",
"int",
"{",
"r",
",",
"_",
":=",
"f",
".",
"Get",
"(",
"key",
")",
".",
"(",
"int",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetInt gets int from flash | [
"GetInt",
"gets",
"int",
"from",
"flash"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L92-L95 |
151,975 | moonrhythm/session | flash.go | GetInt64 | func (f *Flash) GetInt64(key string) int64 {
r, _ := f.Get(key).(int64)
return r
} | go | func (f *Flash) GetInt64(key string) int64 {
r, _ := f.Get(key).(int64)
return r
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"GetInt64",
"(",
"key",
"string",
")",
"int64",
"{",
"r",
",",
"_",
":=",
"f",
".",
"Get",
"(",
"key",
")",
".",
"(",
"int64",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetInt64 gets int64 from flash | [
"GetInt64",
"gets",
"int64",
"from",
"flash"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L98-L101 |
151,976 | moonrhythm/session | flash.go | GetFloat32 | func (f *Flash) GetFloat32(key string) float32 {
r, _ := f.Get(key).(float32)
return r
} | go | func (f *Flash) GetFloat32(key string) float32 {
r, _ := f.Get(key).(float32)
return r
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"GetFloat32",
"(",
"key",
"string",
")",
"float32",
"{",
"r",
",",
"_",
":=",
"f",
".",
"Get",
"(",
"key",
")",
".",
"(",
"float32",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetFloat32 gets float32 from flash | [
"GetFloat32",
"gets",
"float32",
"from",
"flash"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L104-L107 |
151,977 | moonrhythm/session | flash.go | GetFloat64 | func (f *Flash) GetFloat64(key string) float64 {
r, _ := f.Get(key).(float64)
return r
} | go | func (f *Flash) GetFloat64(key string) float64 {
r, _ := f.Get(key).(float64)
return r
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"GetFloat64",
"(",
"key",
"string",
")",
"float64",
"{",
"r",
",",
"_",
":=",
"f",
".",
"Get",
"(",
"key",
")",
".",
"(",
"float64",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetFloat64 gets float64 from flash | [
"GetFloat64",
"gets",
"float64",
"from",
"flash"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L110-L113 |
151,978 | moonrhythm/session | flash.go | GetBool | func (f *Flash) GetBool(key string) bool {
r, _ := f.Get(key).(bool)
return r
} | go | func (f *Flash) GetBool(key string) bool {
r, _ := f.Get(key).(bool)
return r
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"GetBool",
"(",
"key",
"string",
")",
"bool",
"{",
"r",
",",
"_",
":=",
"f",
".",
"Get",
"(",
"key",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetBool gets bool from flash | [
"GetBool",
"gets",
"bool",
"from",
"flash"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L116-L119 |
151,979 | moonrhythm/session | flash.go | Del | func (f *Flash) Del(key string) {
if f.Has(key) {
f.changed = true
}
delete(f.v, key)
} | go | func (f *Flash) Del(key string) {
if f.Has(key) {
f.changed = true
}
delete(f.v, key)
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"Del",
"(",
"key",
"string",
")",
"{",
"if",
"f",
".",
"Has",
"(",
"key",
")",
"{",
"f",
".",
"changed",
"=",
"true",
"\n",
"}",
"\n",
"delete",
"(",
"f",
".",
"v",
",",
"key",
")",
"\n",
"}"
] | // Del deletes key from flash | [
"Del",
"deletes",
"key",
"from",
"flash"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L122-L127 |
151,980 | moonrhythm/session | flash.go | Has | func (f *Flash) Has(key string) bool {
if f.v == nil {
return false
}
return len(f.v[key]) > 0
} | go | func (f *Flash) Has(key string) bool {
if f.v == nil {
return false
}
return len(f.v[key]) > 0
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"Has",
"(",
"key",
"string",
")",
"bool",
"{",
"if",
"f",
".",
"v",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"len",
"(",
"f",
".",
"v",
"[",
"key",
"]",
")",
">",
"0",
"\n",
"}"
] | // Has checks is flash has a given key | [
"Has",
"checks",
"is",
"flash",
"has",
"a",
"given",
"key"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L130-L135 |
151,981 | moonrhythm/session | flash.go | Clear | func (f *Flash) Clear() {
if f.Count() > 0 {
f.changed = true
}
f.v = nil
} | go | func (f *Flash) Clear() {
if f.Count() > 0 {
f.changed = true
}
f.v = nil
} | [
"func",
"(",
"f",
"*",
"Flash",
")",
"Clear",
"(",
")",
"{",
"if",
"f",
".",
"Count",
"(",
")",
">",
"0",
"{",
"f",
".",
"changed",
"=",
"true",
"\n",
"}",
"\n",
"f",
".",
"v",
"=",
"nil",
"\n",
"}"
] | // Clear deletes all data | [
"Clear",
"deletes",
"all",
"data"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/flash.go#L138-L143 |
151,982 | moonrhythm/session | session.go | Clone | func (data Data) Clone() Data {
r := make(Data)
for k, v := range data {
r[k] = v
}
return r
} | go | func (data Data) Clone() Data {
r := make(Data)
for k, v := range data {
r[k] = v
}
return r
} | [
"func",
"(",
"data",
"Data",
")",
"Clone",
"(",
")",
"Data",
"{",
"r",
":=",
"make",
"(",
"Data",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"data",
"{",
"r",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] | // Clone clones session data | [
"Clone",
"clones",
"session",
"data"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L34-L40 |
151,983 | moonrhythm/session | session.go | Changed | func (s *Session) Changed() bool {
if s.changed {
return true
}
if s.flash != nil && s.flash.Changed() {
s.changed = true
return true
}
return false
} | go | func (s *Session) Changed() bool {
if s.changed {
return true
}
if s.flash != nil && s.flash.Changed() {
s.changed = true
return true
}
return false
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Changed",
"(",
")",
"bool",
"{",
"if",
"s",
".",
"changed",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"s",
".",
"flash",
"!=",
"nil",
"&&",
"s",
".",
"flash",
".",
"Changed",
"(",
")",
"{",
"s",
"."... | // Changed returns is session data changed | [
"Changed",
"returns",
"is",
"session",
"data",
"changed"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L48-L57 |
151,984 | moonrhythm/session | session.go | Get | func (s *Session) Get(key string) interface{} {
if s.data == nil {
return nil
}
return s.data[key]
} | go | func (s *Session) Get(key string) interface{} {
if s.data == nil {
return nil
}
return s.data[key]
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Get",
"(",
"key",
"string",
")",
"interface",
"{",
"}",
"{",
"if",
"s",
".",
"data",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"s",
".",
"data",
"[",
"key",
"]",
"\n",
"}"
] | // Get gets data from session | [
"Get",
"gets",
"data",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L60-L65 |
151,985 | moonrhythm/session | session.go | GetString | func (s *Session) GetString(key string) string {
r, _ := s.Get(key).(string)
return r
} | go | func (s *Session) GetString(key string) string {
r, _ := s.Get(key).(string)
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"GetString",
"(",
"key",
"string",
")",
"string",
"{",
"r",
",",
"_",
":=",
"s",
".",
"Get",
"(",
"key",
")",
".",
"(",
"string",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetString gets string from session | [
"GetString",
"gets",
"string",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L68-L71 |
151,986 | moonrhythm/session | session.go | GetInt | func (s *Session) GetInt(key string) int {
r, _ := s.Get(key).(int)
return r
} | go | func (s *Session) GetInt(key string) int {
r, _ := s.Get(key).(int)
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"GetInt",
"(",
"key",
"string",
")",
"int",
"{",
"r",
",",
"_",
":=",
"s",
".",
"Get",
"(",
"key",
")",
".",
"(",
"int",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetInt gets int from session | [
"GetInt",
"gets",
"int",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L74-L77 |
151,987 | moonrhythm/session | session.go | GetInt64 | func (s *Session) GetInt64(key string) int64 {
r, _ := s.Get(key).(int64)
return r
} | go | func (s *Session) GetInt64(key string) int64 {
r, _ := s.Get(key).(int64)
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"GetInt64",
"(",
"key",
"string",
")",
"int64",
"{",
"r",
",",
"_",
":=",
"s",
".",
"Get",
"(",
"key",
")",
".",
"(",
"int64",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetInt64 gets int64 from session | [
"GetInt64",
"gets",
"int64",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L80-L83 |
151,988 | moonrhythm/session | session.go | GetFloat32 | func (s *Session) GetFloat32(key string) float32 {
r, _ := s.Get(key).(float32)
return r
} | go | func (s *Session) GetFloat32(key string) float32 {
r, _ := s.Get(key).(float32)
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"GetFloat32",
"(",
"key",
"string",
")",
"float32",
"{",
"r",
",",
"_",
":=",
"s",
".",
"Get",
"(",
"key",
")",
".",
"(",
"float32",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetFloat32 gets float32 from session | [
"GetFloat32",
"gets",
"float32",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L86-L89 |
151,989 | moonrhythm/session | session.go | GetFloat64 | func (s *Session) GetFloat64(key string) float64 {
r, _ := s.Get(key).(float64)
return r
} | go | func (s *Session) GetFloat64(key string) float64 {
r, _ := s.Get(key).(float64)
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"GetFloat64",
"(",
"key",
"string",
")",
"float64",
"{",
"r",
",",
"_",
":=",
"s",
".",
"Get",
"(",
"key",
")",
".",
"(",
"float64",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetFloat64 gets float64 from session | [
"GetFloat64",
"gets",
"float64",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L92-L95 |
151,990 | moonrhythm/session | session.go | GetBool | func (s *Session) GetBool(key string) bool {
r, _ := s.Get(key).(bool)
return r
} | go | func (s *Session) GetBool(key string) bool {
r, _ := s.Get(key).(bool)
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"GetBool",
"(",
"key",
"string",
")",
"bool",
"{",
"r",
",",
"_",
":=",
"s",
".",
"Get",
"(",
"key",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // GetBool gets bool from session | [
"GetBool",
"gets",
"bool",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L98-L101 |
151,991 | moonrhythm/session | session.go | Set | func (s *Session) Set(key string, value interface{}) {
if s.data == nil {
s.data = make(Data)
}
s.changed = true
s.data[key] = value
} | go | func (s *Session) Set(key string, value interface{}) {
if s.data == nil {
s.data = make(Data)
}
s.changed = true
s.data[key] = value
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Set",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"if",
"s",
".",
"data",
"==",
"nil",
"{",
"s",
".",
"data",
"=",
"make",
"(",
"Data",
")",
"\n",
"}",
"\n",
"s",
".",
"changed"... | // Set sets data to session | [
"Set",
"sets",
"data",
"to",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L104-L110 |
151,992 | moonrhythm/session | session.go | Del | func (s *Session) Del(key string) {
if s.data == nil {
return
}
if _, ok := s.data[key]; ok {
s.changed = true
delete(s.data, key)
}
} | go | func (s *Session) Del(key string) {
if s.data == nil {
return
}
if _, ok := s.data[key]; ok {
s.changed = true
delete(s.data, key)
}
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Del",
"(",
"key",
"string",
")",
"{",
"if",
"s",
".",
"data",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"s",
".",
"data",
"[",
"key",
"]",
";",
"ok",
"{",
"s",
".",
"c... | // Del deletes data from session | [
"Del",
"deletes",
"data",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L113-L121 |
151,993 | moonrhythm/session | session.go | Pop | func (s *Session) Pop(key string) interface{} {
if s.data == nil {
return nil
}
r, ok := s.data[key]
if ok {
s.changed = true
delete(s.data, key)
}
return r
} | go | func (s *Session) Pop(key string) interface{} {
if s.data == nil {
return nil
}
r, ok := s.data[key]
if ok {
s.changed = true
delete(s.data, key)
}
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Pop",
"(",
"key",
"string",
")",
"interface",
"{",
"}",
"{",
"if",
"s",
".",
"data",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"r",
",",
"ok",
":=",
"s",
".",
"data",
"[",
"key",
"]",
"\n",
... | // Pop gets data from session then delete it | [
"Pop",
"gets",
"data",
"from",
"session",
"then",
"delete",
"it"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L124-L135 |
151,994 | moonrhythm/session | session.go | PopString | func (s *Session) PopString(key string) string {
r, _ := s.Pop(key).(string)
return r
} | go | func (s *Session) PopString(key string) string {
r, _ := s.Pop(key).(string)
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"PopString",
"(",
"key",
"string",
")",
"string",
"{",
"r",
",",
"_",
":=",
"s",
".",
"Pop",
"(",
"key",
")",
".",
"(",
"string",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // PopString pops string from session | [
"PopString",
"pops",
"string",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L138-L141 |
151,995 | moonrhythm/session | session.go | PopInt | func (s *Session) PopInt(key string) int {
r, _ := s.Pop(key).(int)
return r
} | go | func (s *Session) PopInt(key string) int {
r, _ := s.Pop(key).(int)
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"PopInt",
"(",
"key",
"string",
")",
"int",
"{",
"r",
",",
"_",
":=",
"s",
".",
"Pop",
"(",
"key",
")",
".",
"(",
"int",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // PopInt pops int from session | [
"PopInt",
"pops",
"int",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L144-L147 |
151,996 | moonrhythm/session | session.go | PopInt64 | func (s *Session) PopInt64(key string) int64 {
r, _ := s.Pop(key).(int64)
return r
} | go | func (s *Session) PopInt64(key string) int64 {
r, _ := s.Pop(key).(int64)
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"PopInt64",
"(",
"key",
"string",
")",
"int64",
"{",
"r",
",",
"_",
":=",
"s",
".",
"Pop",
"(",
"key",
")",
".",
"(",
"int64",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // PopInt64 pops int64 from session | [
"PopInt64",
"pops",
"int64",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L150-L153 |
151,997 | moonrhythm/session | session.go | PopFloat32 | func (s *Session) PopFloat32(key string) float32 {
r, _ := s.Pop(key).(float32)
return r
} | go | func (s *Session) PopFloat32(key string) float32 {
r, _ := s.Pop(key).(float32)
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"PopFloat32",
"(",
"key",
"string",
")",
"float32",
"{",
"r",
",",
"_",
":=",
"s",
".",
"Pop",
"(",
"key",
")",
".",
"(",
"float32",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // PopFloat32 pops float32 from session | [
"PopFloat32",
"pops",
"float32",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L156-L159 |
151,998 | moonrhythm/session | session.go | PopFloat64 | func (s *Session) PopFloat64(key string) float64 {
r, _ := s.Pop(key).(float64)
return r
} | go | func (s *Session) PopFloat64(key string) float64 {
r, _ := s.Pop(key).(float64)
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"PopFloat64",
"(",
"key",
"string",
")",
"float64",
"{",
"r",
",",
"_",
":=",
"s",
".",
"Pop",
"(",
"key",
")",
".",
"(",
"float64",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // PopFloat64 pops float64 from session | [
"PopFloat64",
"pops",
"float64",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L162-L165 |
151,999 | moonrhythm/session | session.go | PopBool | func (s *Session) PopBool(key string) bool {
r, _ := s.Pop(key).(bool)
return r
} | go | func (s *Session) PopBool(key string) bool {
r, _ := s.Pop(key).(bool)
return r
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"PopBool",
"(",
"key",
"string",
")",
"bool",
"{",
"r",
",",
"_",
":=",
"s",
".",
"Pop",
"(",
"key",
")",
".",
"(",
"bool",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // PopBool pops bool from session | [
"PopBool",
"pops",
"bool",
"from",
"session"
] | d2c990e98d2125bc454b7903d1f9299e1be6c84d | https://github.com/moonrhythm/session/blob/d2c990e98d2125bc454b7903d1f9299e1be6c84d/session.go#L168-L171 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.