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 listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
140,000 | paked/messenger | messenger.go | handle | func (m *Messenger) handle(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
m.verifyHandler(w, r)
return
}
var rec Receive
// consume a *copy* of the request body
body, _ := ioutil.ReadAll(r.Body)
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
err := json.Unmarshal(body, &rec)
if err !=... | go | func (m *Messenger) handle(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
m.verifyHandler(w, r)
return
}
var rec Receive
// consume a *copy* of the request body
body, _ := ioutil.ReadAll(r.Body)
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
err := json.Unmarshal(body, &rec)
if err !=... | [
"func",
"(",
"m",
"*",
"Messenger",
")",
"handle",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"r",
".",
"Method",
"==",
"\"",
"\"",
"{",
"m",
".",
"verifyHandler",
"(",
"w",
",",
"r",
")",
"\... | // handle is the internal HTTP handler for the webhooks. | [
"handle",
"is",
"the",
"internal",
"HTTP",
"handler",
"for",
"the",
"webhooks",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/messenger.go#L268-L302 |
140,001 | paked/messenger | messenger.go | checkIntegrity | func (m *Messenger) checkIntegrity(r *http.Request) error {
if m.appSecret == "" {
return fmt.Errorf("missing app secret")
}
sigHeader := "X-Hub-Signature"
sig := strings.SplitN(r.Header.Get(sigHeader), "=", 2)
if len(sig) == 1 {
if sig[0] == "" {
return fmt.Errorf("missing %s header", sigHeader)
}
ret... | go | func (m *Messenger) checkIntegrity(r *http.Request) error {
if m.appSecret == "" {
return fmt.Errorf("missing app secret")
}
sigHeader := "X-Hub-Signature"
sig := strings.SplitN(r.Header.Get(sigHeader), "=", 2)
if len(sig) == 1 {
if sig[0] == "" {
return fmt.Errorf("missing %s header", sigHeader)
}
ret... | [
"func",
"(",
"m",
"*",
"Messenger",
")",
"checkIntegrity",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"if",
"m",
".",
"appSecret",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"sig... | // checkIntegrity checks the integrity of the requests received | [
"checkIntegrity",
"checks",
"the",
"integrity",
"of",
"the",
"requests",
"received"
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/messenger.go#L305-L338 |
140,002 | paked/messenger | messenger.go | dispatch | func (m *Messenger) dispatch(r Receive) {
for _, entry := range r.Entry {
for _, info := range entry.Messaging {
a := m.classify(info, entry)
if a == UnknownAction {
fmt.Println("Unknown action:", info)
continue
}
resp := &Response{
to: Recipient{info.Sender.ID},
token: m.token,
}
... | go | func (m *Messenger) dispatch(r Receive) {
for _, entry := range r.Entry {
for _, info := range entry.Messaging {
a := m.classify(info, entry)
if a == UnknownAction {
fmt.Println("Unknown action:", info)
continue
}
resp := &Response{
to: Recipient{info.Sender.ID},
token: m.token,
}
... | [
"func",
"(",
"m",
"*",
"Messenger",
")",
"dispatch",
"(",
"r",
"Receive",
")",
"{",
"for",
"_",
",",
"entry",
":=",
"range",
"r",
".",
"Entry",
"{",
"for",
"_",
",",
"info",
":=",
"range",
"entry",
".",
"Messaging",
"{",
"a",
":=",
"m",
".",
"c... | // dispatch triggers all of the relevant handlers when a webhook event is received. | [
"dispatch",
"triggers",
"all",
"of",
"the",
"relevant",
"handlers",
"when",
"a",
"webhook",
"event",
"is",
"received",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/messenger.go#L341-L407 |
140,003 | paked/messenger | messenger.go | Response | func (m *Messenger) Response(to int64) *Response {
return &Response{
to: Recipient{to},
token: m.token,
}
} | go | func (m *Messenger) Response(to int64) *Response {
return &Response{
to: Recipient{to},
token: m.token,
}
} | [
"func",
"(",
"m",
"*",
"Messenger",
")",
"Response",
"(",
"to",
"int64",
")",
"*",
"Response",
"{",
"return",
"&",
"Response",
"{",
"to",
":",
"Recipient",
"{",
"to",
"}",
",",
"token",
":",
"m",
".",
"token",
",",
"}",
"\n",
"}"
] | // Response returns new Response object | [
"Response",
"returns",
"new",
"Response",
"object"
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/messenger.go#L410-L415 |
140,004 | paked/messenger | messenger.go | Send | func (m *Messenger) Send(to Recipient, message string, messagingType MessagingType, tags ...string) error {
return m.SendWithReplies(to, message, nil, messagingType, tags...)
} | go | func (m *Messenger) Send(to Recipient, message string, messagingType MessagingType, tags ...string) error {
return m.SendWithReplies(to, message, nil, messagingType, tags...)
} | [
"func",
"(",
"m",
"*",
"Messenger",
")",
"Send",
"(",
"to",
"Recipient",
",",
"message",
"string",
",",
"messagingType",
"MessagingType",
",",
"tags",
"...",
"string",
")",
"error",
"{",
"return",
"m",
".",
"SendWithReplies",
"(",
"to",
",",
"message",
"... | // Send will send a textual message to a user. This user must have previously initiated a conversation with the bot. | [
"Send",
"will",
"send",
"a",
"textual",
"message",
"to",
"a",
"user",
".",
"This",
"user",
"must",
"have",
"previously",
"initiated",
"a",
"conversation",
"with",
"the",
"bot",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/messenger.go#L418-L420 |
140,005 | paked/messenger | messenger.go | SendGeneralMessage | func (m *Messenger) SendGeneralMessage(to Recipient, elements *[]StructuredMessageElement, messagingType MessagingType, tags ...string) error {
r := &Response{
token: m.token,
to: to,
}
return r.GenericTemplate(elements, messagingType, tags...)
} | go | func (m *Messenger) SendGeneralMessage(to Recipient, elements *[]StructuredMessageElement, messagingType MessagingType, tags ...string) error {
r := &Response{
token: m.token,
to: to,
}
return r.GenericTemplate(elements, messagingType, tags...)
} | [
"func",
"(",
"m",
"*",
"Messenger",
")",
"SendGeneralMessage",
"(",
"to",
"Recipient",
",",
"elements",
"*",
"[",
"]",
"StructuredMessageElement",
",",
"messagingType",
"MessagingType",
",",
"tags",
"...",
"string",
")",
"error",
"{",
"r",
":=",
"&",
"Respon... | // SendGeneralMessage will send the GenericTemplate message | [
"SendGeneralMessage",
"will",
"send",
"the",
"GenericTemplate",
"message"
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/messenger.go#L423-L429 |
140,006 | paked/messenger | messenger.go | SendWithReplies | func (m *Messenger) SendWithReplies(to Recipient, message string, replies []QuickReply, messagingType MessagingType, tags ...string) error {
response := &Response{
token: m.token,
to: to,
}
return response.TextWithReplies(message, replies, messagingType, tags...)
} | go | func (m *Messenger) SendWithReplies(to Recipient, message string, replies []QuickReply, messagingType MessagingType, tags ...string) error {
response := &Response{
token: m.token,
to: to,
}
return response.TextWithReplies(message, replies, messagingType, tags...)
} | [
"func",
"(",
"m",
"*",
"Messenger",
")",
"SendWithReplies",
"(",
"to",
"Recipient",
",",
"message",
"string",
",",
"replies",
"[",
"]",
"QuickReply",
",",
"messagingType",
"MessagingType",
",",
"tags",
"...",
"string",
")",
"error",
"{",
"response",
":=",
... | // SendWithReplies sends a textual message to a user, but gives them the option of numerous quick response options. | [
"SendWithReplies",
"sends",
"a",
"textual",
"message",
"to",
"a",
"user",
"but",
"gives",
"them",
"the",
"option",
"of",
"numerous",
"quick",
"response",
"options",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/messenger.go#L432-L439 |
140,007 | paked/messenger | messenger.go | Attachment | func (m *Messenger) Attachment(to Recipient, dataType AttachmentType, url string, messagingType MessagingType, tags ...string) error {
response := &Response{
token: m.token,
to: to,
}
return response.Attachment(dataType, url, messagingType, tags...)
} | go | func (m *Messenger) Attachment(to Recipient, dataType AttachmentType, url string, messagingType MessagingType, tags ...string) error {
response := &Response{
token: m.token,
to: to,
}
return response.Attachment(dataType, url, messagingType, tags...)
} | [
"func",
"(",
"m",
"*",
"Messenger",
")",
"Attachment",
"(",
"to",
"Recipient",
",",
"dataType",
"AttachmentType",
",",
"url",
"string",
",",
"messagingType",
"MessagingType",
",",
"tags",
"...",
"string",
")",
"error",
"{",
"response",
":=",
"&",
"Response",... | // Attachment sends an image, sound, video or a regular file to a given recipient. | [
"Attachment",
"sends",
"an",
"image",
"sound",
"video",
"or",
"a",
"regular",
"file",
"to",
"a",
"given",
"recipient",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/messenger.go#L442-L449 |
140,008 | paked/messenger | messenger.go | EnableChatExtension | func (m *Messenger) EnableChatExtension(homeURL HomeURL) error {
wrap := map[string]interface{}{
"home_url": homeURL,
}
data, err := json.Marshal(wrap)
if err != nil {
return err
}
req, err := http.NewRequest("POST", MessengerProfileURL, bytes.NewBuffer(data))
if err != nil {
return err
}
req.Header.Se... | go | func (m *Messenger) EnableChatExtension(homeURL HomeURL) error {
wrap := map[string]interface{}{
"home_url": homeURL,
}
data, err := json.Marshal(wrap)
if err != nil {
return err
}
req, err := http.NewRequest("POST", MessengerProfileURL, bytes.NewBuffer(data))
if err != nil {
return err
}
req.Header.Se... | [
"func",
"(",
"m",
"*",
"Messenger",
")",
"EnableChatExtension",
"(",
"homeURL",
"HomeURL",
")",
"error",
"{",
"wrap",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"homeURL",
",",
"}",
"\n",
"data",
",",
"err",
":=",
... | // EnableChatExtension set the homepage url required for a chat extension. | [
"EnableChatExtension",
"set",
"the",
"homepage",
"url",
"required",
"for",
"a",
"chat",
"extension",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/messenger.go#L452-L478 |
140,009 | paked/messenger | messenger.go | classify | func (m *Messenger) classify(info MessageInfo, e Entry) Action {
if info.Message != nil {
return TextAction
} else if info.Delivery != nil {
return DeliveryAction
} else if info.Read != nil {
return ReadAction
} else if info.PostBack != nil {
return PostBackAction
} else if info.OptIn != nil {
return Opt... | go | func (m *Messenger) classify(info MessageInfo, e Entry) Action {
if info.Message != nil {
return TextAction
} else if info.Delivery != nil {
return DeliveryAction
} else if info.Read != nil {
return ReadAction
} else if info.PostBack != nil {
return PostBackAction
} else if info.OptIn != nil {
return Opt... | [
"func",
"(",
"m",
"*",
"Messenger",
")",
"classify",
"(",
"info",
"MessageInfo",
",",
"e",
"Entry",
")",
"Action",
"{",
"if",
"info",
".",
"Message",
"!=",
"nil",
"{",
"return",
"TextAction",
"\n",
"}",
"else",
"if",
"info",
".",
"Delivery",
"!=",
"n... | // classify determines what type of message a webhook event is. | [
"classify",
"determines",
"what",
"type",
"of",
"message",
"a",
"webhook",
"event",
"is",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/messenger.go#L481-L498 |
140,010 | paked/messenger | messenger.go | newVerifyHandler | func newVerifyHandler(token string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if r.FormValue("hub.verify_token") == token {
fmt.Fprintln(w, r.FormValue("hub.challenge"))
return
}
fmt.Fprintln(w, "Incorrect verify token.")
}
} | go | func newVerifyHandler(token string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if r.FormValue("hub.verify_token") == token {
fmt.Fprintln(w, r.FormValue("hub.challenge"))
return
}
fmt.Fprintln(w, "Incorrect verify token.")
}
} | [
"func",
"newVerifyHandler",
"(",
"token",
"string",
")",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",... | // newVerifyHandler returns a function which can be used to handle webhook verification | [
"newVerifyHandler",
"returns",
"a",
"function",
"which",
"can",
"be",
"used",
"to",
"handle",
"webhook",
"verification"
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/messenger.go#L501-L509 |
140,011 | paked/messenger | examples/linked-account/main.go | loginButton | func loginButton(r *messenger.Response) error {
buttons := &[]messenger.StructuredMessageButton{
{
Type: "account_link",
URL: "https://" + path.Join(*publicHost, loginPath),
},
}
return r.ButtonTemplate("Link your account.", buttons, messenger.ResponseType)
} | go | func loginButton(r *messenger.Response) error {
buttons := &[]messenger.StructuredMessageButton{
{
Type: "account_link",
URL: "https://" + path.Join(*publicHost, loginPath),
},
}
return r.ButtonTemplate("Link your account.", buttons, messenger.ResponseType)
} | [
"func",
"loginButton",
"(",
"r",
"*",
"messenger",
".",
"Response",
")",
"error",
"{",
"buttons",
":=",
"&",
"[",
"]",
"messenger",
".",
"StructuredMessageButton",
"{",
"{",
"Type",
":",
"\"",
"\"",
",",
"URL",
":",
"\"",
"\"",
"+",
"path",
".",
"Joi... | // loginButton will present to the user a button that can be used to
// start the account linking process. | [
"loginButton",
"will",
"present",
"to",
"the",
"user",
"a",
"button",
"that",
"can",
"be",
"used",
"to",
"start",
"the",
"account",
"linking",
"process",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/examples/linked-account/main.go#L113-L121 |
140,012 | paked/messenger | examples/linked-account/main.go | logoutButton | func logoutButton(r *messenger.Response) error {
buttons := &[]messenger.StructuredMessageButton{
{
Type: "account_unlink",
},
}
return r.ButtonTemplate("Unlink your account.", buttons, messenger.ResponseType)
} | go | func logoutButton(r *messenger.Response) error {
buttons := &[]messenger.StructuredMessageButton{
{
Type: "account_unlink",
},
}
return r.ButtonTemplate("Unlink your account.", buttons, messenger.ResponseType)
} | [
"func",
"logoutButton",
"(",
"r",
"*",
"messenger",
".",
"Response",
")",
"error",
"{",
"buttons",
":=",
"&",
"[",
"]",
"messenger",
".",
"StructuredMessageButton",
"{",
"{",
"Type",
":",
"\"",
"\"",
",",
"}",
",",
"}",
"\n",
"return",
"r",
".",
"But... | // logoutButton show to the user a button that can be used to start
// the process of unlinking an account. | [
"logoutButton",
"show",
"to",
"the",
"user",
"a",
"button",
"that",
"can",
"be",
"used",
"to",
"start",
"the",
"process",
"of",
"unlinking",
"an",
"account",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/examples/linked-account/main.go#L125-L132 |
140,013 | paked/messenger | examples/linked-account/main.go | greeting | func greeting(p messenger.Profile, r *messenger.Response) error {
return r.Text(fmt.Sprintf("Hello, %v!", p.FirstName), messenger.ResponseType)
} | go | func greeting(p messenger.Profile, r *messenger.Response) error {
return r.Text(fmt.Sprintf("Hello, %v!", p.FirstName), messenger.ResponseType)
} | [
"func",
"greeting",
"(",
"p",
"messenger",
".",
"Profile",
",",
"r",
"*",
"messenger",
".",
"Response",
")",
"error",
"{",
"return",
"r",
".",
"Text",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"FirstName",
")",
",",
"messenger",
"... | // greeting salutes the user. | [
"greeting",
"salutes",
"the",
"user",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/examples/linked-account/main.go#L135-L137 |
140,014 | paked/messenger | examples/linked-account/main.go | help | func help(p messenger.Profile, r *messenger.Response) error {
text := fmt.Sprintf(
"%s, looking for actions to do? Here is what I understand.",
p.FirstName,
)
replies := []messenger.QuickReply{
{
ContentType: "text",
Title: "Login",
},
{
ContentType: "text",
Title: "Logout",
},
... | go | func help(p messenger.Profile, r *messenger.Response) error {
text := fmt.Sprintf(
"%s, looking for actions to do? Here is what I understand.",
p.FirstName,
)
replies := []messenger.QuickReply{
{
ContentType: "text",
Title: "Login",
},
{
ContentType: "text",
Title: "Logout",
},
... | [
"func",
"help",
"(",
"p",
"messenger",
".",
"Profile",
",",
"r",
"*",
"messenger",
".",
"Response",
")",
"error",
"{",
"text",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"FirstName",
",",
")",
"\n\n",
"replies",
":=",
"[",
"]",
... | // help displays possibles actions to the user. | [
"help",
"displays",
"possibles",
"actions",
"to",
"the",
"user",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/examples/linked-account/main.go#L140-L158 |
140,015 | paked/messenger | examples/linked-account/main.go | loginForm | func loginForm(w http.ResponseWriter, r *http.Request) {
values := r.URL.Query()
linkingToken := values.Get("account_linking_token")
redirectURI := values.Get("redirect_uri")
fmt.Fprint(w, templateLogin(loginPath, linkingToken, redirectURI, false))
} | go | func loginForm(w http.ResponseWriter, r *http.Request) {
values := r.URL.Query()
linkingToken := values.Get("account_linking_token")
redirectURI := values.Get("redirect_uri")
fmt.Fprint(w, templateLogin(loginPath, linkingToken, redirectURI, false))
} | [
"func",
"loginForm",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"values",
":=",
"r",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"linkingToken",
":=",
"values",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
... | // loginForm is the endpoint responsible to displays a login
// form. During the account linking process, after clicking on the
// login button, users are directed to this form where they are
// supposed to sign into their account. When the form is submitted,
// credentials are sent to the login endpoint. | [
"loginForm",
"is",
"the",
"endpoint",
"responsible",
"to",
"displays",
"a",
"login",
"form",
".",
"During",
"the",
"account",
"linking",
"process",
"after",
"clicking",
"on",
"the",
"login",
"button",
"users",
"are",
"directed",
"to",
"this",
"form",
"where",
... | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/examples/linked-account/main.go#L165-L170 |
140,016 | paked/messenger | examples/linked-account/main.go | login | func login(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
username := r.FormValue("username")
password := r.FormValue("password")
linkingToken := r.FormValue("account_linking_token")
rawRedirect := r.FormValue("redirect_uri")
if !checkCredentials(username, password) {
fmt.Fprint(w, templateLogin(logi... | go | func login(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
username := r.FormValue("username")
password := r.FormValue("password")
linkingToken := r.FormValue("account_linking_token")
rawRedirect := r.FormValue("redirect_uri")
if !checkCredentials(username, password) {
fmt.Fprint(w, templateLogin(logi... | [
"func",
"login",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"r",
".",
"ParseForm",
"(",
")",
"\n\n",
"username",
":=",
"r",
".",
"FormValue",
"(",
"\"",
"\"",
")",
"\n",
"password",
":=",
"r",
".",
"... | // login is the endpoint that handles the actual signing in, by
// checking the credentials, then redirecting to Facebook Messenger if
// they are valid. | [
"login",
"is",
"the",
"endpoint",
"that",
"handles",
"the",
"actual",
"signing",
"in",
"by",
"checking",
"the",
"credentials",
"then",
"redirecting",
"to",
"Facebook",
"Messenger",
"if",
"they",
"are",
"valid",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/examples/linked-account/main.go#L175-L200 |
140,017 | paked/messenger | examples/linked-account/main.go | templateLogin | func templateLogin(loginPath, linkingToken, redirectURI string, failed bool) string {
failedInfo := ""
if failed {
failedInfo = `<p class="alert alert-danger">Incorrect credentials</p>`
}
template := `
<html>
<head>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/... | go | func templateLogin(loginPath, linkingToken, redirectURI string, failed bool) string {
failedInfo := ""
if failed {
failedInfo = `<p class="alert alert-danger">Incorrect credentials</p>`
}
template := `
<html>
<head>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/... | [
"func",
"templateLogin",
"(",
"loginPath",
",",
"linkingToken",
",",
"redirectURI",
"string",
",",
"failed",
"bool",
")",
"string",
"{",
"failedInfo",
":=",
"\"",
"\"",
"\n",
"if",
"failed",
"{",
"failedInfo",
"=",
"`<p class=\"alert alert-danger\">Incorrect credent... | // templateLogin constructs the signin form. | [
"templateLogin",
"constructs",
"the",
"signin",
"form",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/examples/linked-account/main.go#L207-L246 |
140,018 | paked/messenger | response.go | Text | func (r *Response) Text(message string, messagingType MessagingType, tags ...string) error {
return r.TextWithReplies(message, nil, messagingType, tags...)
} | go | func (r *Response) Text(message string, messagingType MessagingType, tags ...string) error {
return r.TextWithReplies(message, nil, messagingType, tags...)
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"Text",
"(",
"message",
"string",
",",
"messagingType",
"MessagingType",
",",
"tags",
"...",
"string",
")",
"error",
"{",
"return",
"r",
".",
"TextWithReplies",
"(",
"message",
",",
"nil",
",",
"messagingType",
",",
... | // Text sends a textual message. | [
"Text",
"sends",
"a",
"textual",
"message",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/response.go#L100-L102 |
140,019 | paked/messenger | response.go | AttachmentWithReplies | func (r *Response) AttachmentWithReplies(attachment *StructuredMessageAttachment, replies []QuickReply, messagingType MessagingType, tags ...string) error {
var tag string
if len(tags) > 0 {
tag = tags[0]
}
m := SendMessage{
MessagingType: messagingType,
Recipient: r.to,
Message: MessageData{
Attach... | go | func (r *Response) AttachmentWithReplies(attachment *StructuredMessageAttachment, replies []QuickReply, messagingType MessagingType, tags ...string) error {
var tag string
if len(tags) > 0 {
tag = tags[0]
}
m := SendMessage{
MessagingType: messagingType,
Recipient: r.to,
Message: MessageData{
Attach... | [
"func",
"(",
"r",
"*",
"Response",
")",
"AttachmentWithReplies",
"(",
"attachment",
"*",
"StructuredMessageAttachment",
",",
"replies",
"[",
"]",
"QuickReply",
",",
"messagingType",
"MessagingType",
",",
"tags",
"...",
"string",
")",
"error",
"{",
"var",
"tag",
... | // AttachmentWithReplies sends a attachment message with some replies | [
"AttachmentWithReplies",
"sends",
"a",
"attachment",
"message",
"with",
"some",
"replies"
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/response.go#L127-L143 |
140,020 | paked/messenger | response.go | Image | func (r *Response) Image(im image.Image) error {
imageBytes := new(bytes.Buffer)
err := jpeg.Encode(imageBytes, im, nil)
if err != nil {
return err
}
return r.AttachmentData(ImageAttachment, "meme.jpg", imageBytes)
} | go | func (r *Response) Image(im image.Image) error {
imageBytes := new(bytes.Buffer)
err := jpeg.Encode(imageBytes, im, nil)
if err != nil {
return err
}
return r.AttachmentData(ImageAttachment, "meme.jpg", imageBytes)
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"Image",
"(",
"im",
"image",
".",
"Image",
")",
"error",
"{",
"imageBytes",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"err",
":=",
"jpeg",
".",
"Encode",
"(",
"imageBytes",
",",
"im",
",",
"nil",
... | // Image sends an image. | [
"Image",
"sends",
"an",
"image",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/response.go#L146-L154 |
140,021 | paked/messenger | response.go | Attachment | func (r *Response) Attachment(dataType AttachmentType, url string, messagingType MessagingType, tags ...string) error {
var tag string
if len(tags) > 0 {
tag = tags[0]
}
m := SendStructuredMessage{
MessagingType: messagingType,
Recipient: r.to,
Message: StructuredMessageData{
Attachment: StructuredM... | go | func (r *Response) Attachment(dataType AttachmentType, url string, messagingType MessagingType, tags ...string) error {
var tag string
if len(tags) > 0 {
tag = tags[0]
}
m := SendStructuredMessage{
MessagingType: messagingType,
Recipient: r.to,
Message: StructuredMessageData{
Attachment: StructuredM... | [
"func",
"(",
"r",
"*",
"Response",
")",
"Attachment",
"(",
"dataType",
"AttachmentType",
",",
"url",
"string",
",",
"messagingType",
"MessagingType",
",",
"tags",
"...",
"string",
")",
"error",
"{",
"var",
"tag",
"string",
"\n",
"if",
"len",
"(",
"tags",
... | // Attachment sends an image, sound, video or a regular file to a chat. | [
"Attachment",
"sends",
"an",
"image",
"sound",
"video",
"or",
"a",
"regular",
"file",
"to",
"a",
"chat",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/response.go#L157-L177 |
140,022 | paked/messenger | response.go | createFormFile | func createFormFile(filename string, w *multipart.Writer, contentType string) (io.Writer, error) {
h := make(textproto.MIMEHeader)
h.Set("Content-Disposition",
fmt.Sprintf(`form-data; name="filedata"; filename="%s"`,
escapeQuotes(filename)))
h.Set("Content-Type", contentType)
return w.CreatePart(h)
} | go | func createFormFile(filename string, w *multipart.Writer, contentType string) (io.Writer, error) {
h := make(textproto.MIMEHeader)
h.Set("Content-Disposition",
fmt.Sprintf(`form-data; name="filedata"; filename="%s"`,
escapeQuotes(filename)))
h.Set("Content-Type", contentType)
return w.CreatePart(h)
} | [
"func",
"createFormFile",
"(",
"filename",
"string",
",",
"w",
"*",
"multipart",
".",
"Writer",
",",
"contentType",
"string",
")",
"(",
"io",
".",
"Writer",
",",
"error",
")",
"{",
"h",
":=",
"make",
"(",
"textproto",
".",
"MIMEHeader",
")",
"\n",
"h",... | // copied from multipart package with slight changes due to fixed content-type there | [
"copied",
"from",
"multipart",
"package",
"with",
"slight",
"changes",
"due",
"to",
"fixed",
"content",
"-",
"type",
"there"
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/response.go#L188-L195 |
140,023 | paked/messenger | response.go | AttachmentData | func (r *Response) AttachmentData(dataType AttachmentType, filename string, filedata io.Reader) error {
filedataBytes, err := ioutil.ReadAll(filedata)
if err != nil {
return err
}
contentType := http.DetectContentType(filedataBytes[:512])
fmt.Println("Content-type detected:", contentType)
var body bytes.Buffe... | go | func (r *Response) AttachmentData(dataType AttachmentType, filename string, filedata io.Reader) error {
filedataBytes, err := ioutil.ReadAll(filedata)
if err != nil {
return err
}
contentType := http.DetectContentType(filedataBytes[:512])
fmt.Println("Content-type detected:", contentType)
var body bytes.Buffe... | [
"func",
"(",
"r",
"*",
"Response",
")",
"AttachmentData",
"(",
"dataType",
"AttachmentType",
",",
"filename",
"string",
",",
"filedata",
"io",
".",
"Reader",
")",
"error",
"{",
"filedataBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"filedata",
"... | // AttachmentData sends an image, sound, video or a regular file to a chat via an io.Reader. | [
"AttachmentData",
"sends",
"an",
"image",
"sound",
"video",
"or",
"a",
"regular",
"file",
"to",
"a",
"chat",
"via",
"an",
"io",
".",
"Reader",
"."
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/response.go#L198-L238 |
140,024 | paked/messenger | response.go | ButtonTemplate | func (r *Response) ButtonTemplate(text string, buttons *[]StructuredMessageButton, messagingType MessagingType, tags ...string) error {
var tag string
if len(tags) > 0 {
tag = tags[0]
}
m := SendStructuredMessage{
MessagingType: messagingType,
Recipient: r.to,
Message: StructuredMessageData{
Attachm... | go | func (r *Response) ButtonTemplate(text string, buttons *[]StructuredMessageButton, messagingType MessagingType, tags ...string) error {
var tag string
if len(tags) > 0 {
tag = tags[0]
}
m := SendStructuredMessage{
MessagingType: messagingType,
Recipient: r.to,
Message: StructuredMessageData{
Attachm... | [
"func",
"(",
"r",
"*",
"Response",
")",
"ButtonTemplate",
"(",
"text",
"string",
",",
"buttons",
"*",
"[",
"]",
"StructuredMessageButton",
",",
"messagingType",
"MessagingType",
",",
"tags",
"...",
"string",
")",
"error",
"{",
"var",
"tag",
"string",
"\n",
... | // ButtonTemplate sends a message with the main contents being button elements | [
"ButtonTemplate",
"sends",
"a",
"message",
"with",
"the",
"main",
"contents",
"being",
"button",
"elements"
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/response.go#L241-L265 |
140,025 | paked/messenger | response.go | GenericTemplate | func (r *Response) GenericTemplate(elements *[]StructuredMessageElement, messagingType MessagingType, tags ...string) error {
var tag string
if len(tags) > 0 {
tag = tags[0]
}
m := SendStructuredMessage{
MessagingType: messagingType,
Recipient: r.to,
Message: StructuredMessageData{
Attachment: Struc... | go | func (r *Response) GenericTemplate(elements *[]StructuredMessageElement, messagingType MessagingType, tags ...string) error {
var tag string
if len(tags) > 0 {
tag = tags[0]
}
m := SendStructuredMessage{
MessagingType: messagingType,
Recipient: r.to,
Message: StructuredMessageData{
Attachment: Struc... | [
"func",
"(",
"r",
"*",
"Response",
")",
"GenericTemplate",
"(",
"elements",
"*",
"[",
"]",
"StructuredMessageElement",
",",
"messagingType",
"MessagingType",
",",
"tags",
"...",
"string",
")",
"error",
"{",
"var",
"tag",
"string",
"\n",
"if",
"len",
"(",
"... | // GenericTemplate is a message which allows for structural elements to be sent | [
"GenericTemplate",
"is",
"a",
"message",
"which",
"allows",
"for",
"structural",
"elements",
"to",
"be",
"sent"
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/response.go#L268-L290 |
140,026 | paked/messenger | response.go | SenderAction | func (r *Response) SenderAction(action string) error {
m := SendSenderAction{
Recipient: r.to,
SenderAction: action,
}
return r.DispatchMessage(&m)
} | go | func (r *Response) SenderAction(action string) error {
m := SendSenderAction{
Recipient: r.to,
SenderAction: action,
}
return r.DispatchMessage(&m)
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"SenderAction",
"(",
"action",
"string",
")",
"error",
"{",
"m",
":=",
"SendSenderAction",
"{",
"Recipient",
":",
"r",
".",
"to",
",",
"SenderAction",
":",
"action",
",",
"}",
"\n",
"return",
"r",
".",
"DispatchM... | // SenderAction sends a info about sender action | [
"SenderAction",
"sends",
"a",
"info",
"about",
"sender",
"action"
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/response.go#L319-L325 |
140,027 | paked/messenger | response.go | DispatchMessage | func (r *Response) DispatchMessage(m interface{}) error {
data, err := json.Marshal(m)
if err != nil {
return err
}
req, err := http.NewRequest("POST", SendMessageURL, bytes.NewBuffer(data))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
req.URL.RawQuery = "access_token=" ... | go | func (r *Response) DispatchMessage(m interface{}) error {
data, err := json.Marshal(m)
if err != nil {
return err
}
req, err := http.NewRequest("POST", SendMessageURL, bytes.NewBuffer(data))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
req.URL.RawQuery = "access_token=" ... | [
"func",
"(",
"r",
"*",
"Response",
")",
"DispatchMessage",
"(",
"m",
"interface",
"{",
"}",
")",
"error",
"{",
"data",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n... | // DispatchMessage posts the message to messenger, return the error if there's any | [
"DispatchMessage",
"posts",
"the",
"message",
"to",
"messenger",
"return",
"the",
"error",
"if",
"there",
"s",
"any"
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/response.go#L328-L351 |
140,028 | paked/messenger | message.go | GetNLP | func (m *Message) GetNLP(i interface{}) error {
return json.Unmarshal(m.NLP, &i)
} | go | func (m *Message) GetNLP(i interface{}) error {
return json.Unmarshal(m.NLP, &i)
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"GetNLP",
"(",
"i",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"json",
".",
"Unmarshal",
"(",
"m",
".",
"NLP",
",",
"&",
"i",
")",
"\n",
"}"
] | // GetNLP simply unmarshals the NLP entities to the given struct and returns
// an error if it's not possible | [
"GetNLP",
"simply",
"unmarshals",
"the",
"NLP",
"entities",
"to",
"the",
"given",
"struct",
"and",
"returns",
"an",
"error",
"if",
"it",
"s",
"not",
"possible"
] | 841714601c8a2d693f15fc70e74aa72af4a117a2 | https://github.com/paked/messenger/blob/841714601c8a2d693f15fc70e74aa72af4a117a2/message.go#L96-L98 |
140,029 | danhper/structomap | structomap.go | ConvertKeys | func (b *Base) ConvertKeys(keyConverter KeyConverter) Serializer {
b.keyConverter = keyConverter
return b
} | go | func (b *Base) ConvertKeys(keyConverter KeyConverter) Serializer {
b.keyConverter = keyConverter
return b
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"ConvertKeys",
"(",
"keyConverter",
"KeyConverter",
")",
"Serializer",
"{",
"b",
".",
"keyConverter",
"=",
"keyConverter",
"\n",
"return",
"b",
"\n",
"}"
] | // ConvertKeys converts all the keys using the given converter | [
"ConvertKeys",
"converts",
"all",
"the",
"keys",
"using",
"the",
"given",
"converter"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L162-L165 |
140,030 | danhper/structomap | structomap.go | UsePascalCase | func (b *Base) UsePascalCase() Serializer {
return b.ConvertKeys(func(k string) string {
return xstrings.ToCamelCase(k)
})
} | go | func (b *Base) UsePascalCase() Serializer {
return b.ConvertKeys(func(k string) string {
return xstrings.ToCamelCase(k)
})
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"UsePascalCase",
"(",
")",
"Serializer",
"{",
"return",
"b",
".",
"ConvertKeys",
"(",
"func",
"(",
"k",
"string",
")",
"string",
"{",
"return",
"xstrings",
".",
"ToCamelCase",
"(",
"k",
")",
"\n",
"}",
")",
"\n",
... | // UsePascalCase uses PascalCase keys for the serializer | [
"UsePascalCase",
"uses",
"PascalCase",
"keys",
"for",
"the",
"serializer"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L168-L172 |
140,031 | danhper/structomap | structomap.go | UseCamelCase | func (b *Base) UseCamelCase() Serializer {
return b.ConvertKeys(func(k string) string {
return xstrings.FirstRuneToLower(xstrings.ToCamelCase(xstrings.ToSnakeCase(k)))
})
} | go | func (b *Base) UseCamelCase() Serializer {
return b.ConvertKeys(func(k string) string {
return xstrings.FirstRuneToLower(xstrings.ToCamelCase(xstrings.ToSnakeCase(k)))
})
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"UseCamelCase",
"(",
")",
"Serializer",
"{",
"return",
"b",
".",
"ConvertKeys",
"(",
"func",
"(",
"k",
"string",
")",
"string",
"{",
"return",
"xstrings",
".",
"FirstRuneToLower",
"(",
"xstrings",
".",
"ToCamelCase",
"... | // UseCamelCase uses camelCase keys for the serializer | [
"UseCamelCase",
"uses",
"camelCase",
"keys",
"for",
"the",
"serializer"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L175-L179 |
140,032 | danhper/structomap | structomap.go | PickAll | func (b *Base) PickAll() Serializer {
b.modifiers = append(b.modifiers, func(m jsonMap) jsonMap {
return structs.Map(b.raw)
})
return b
} | go | func (b *Base) PickAll() Serializer {
b.modifiers = append(b.modifiers, func(m jsonMap) jsonMap {
return structs.Map(b.raw)
})
return b
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"PickAll",
"(",
")",
"Serializer",
"{",
"b",
".",
"modifiers",
"=",
"append",
"(",
"b",
".",
"modifiers",
",",
"func",
"(",
"m",
"jsonMap",
")",
"jsonMap",
"{",
"return",
"structs",
".",
"Map",
"(",
"b",
".",
"... | // PickAll adds all the exported fields to the result | [
"PickAll",
"adds",
"all",
"the",
"exported",
"fields",
"to",
"the",
"result"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L187-L192 |
140,033 | danhper/structomap | structomap.go | Pick | func (b *Base) Pick(keys ...string) Serializer {
return b.PickFunc(identity, keys...)
} | go | func (b *Base) Pick(keys ...string) Serializer {
return b.PickFunc(identity, keys...)
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"Pick",
"(",
"keys",
"...",
"string",
")",
"Serializer",
"{",
"return",
"b",
".",
"PickFunc",
"(",
"identity",
",",
"keys",
"...",
")",
"\n",
"}"
] | // Pick adds the given fields to the result | [
"Pick",
"adds",
"the",
"given",
"fields",
"to",
"the",
"result"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L195-L197 |
140,034 | danhper/structomap | structomap.go | PickIf | func (b *Base) PickIf(p Predicate, keys ...string) Serializer {
return b.PickFuncIf(p, identity, keys...)
} | go | func (b *Base) PickIf(p Predicate, keys ...string) Serializer {
return b.PickFuncIf(p, identity, keys...)
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"PickIf",
"(",
"p",
"Predicate",
",",
"keys",
"...",
"string",
")",
"Serializer",
"{",
"return",
"b",
".",
"PickFuncIf",
"(",
"p",
",",
"identity",
",",
"keys",
"...",
")",
"\n",
"}"
] | // PickIf adds the given fields to the result if the Predicate returns true | [
"PickIf",
"adds",
"the",
"given",
"fields",
"to",
"the",
"result",
"if",
"the",
"Predicate",
"returns",
"true"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L200-L202 |
140,035 | danhper/structomap | structomap.go | PickFunc | func (b *Base) PickFunc(converter ValueConverter, keys ...string) Serializer {
return b.PickFuncIf(alwaysTrue, converter, keys...)
} | go | func (b *Base) PickFunc(converter ValueConverter, keys ...string) Serializer {
return b.PickFuncIf(alwaysTrue, converter, keys...)
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"PickFunc",
"(",
"converter",
"ValueConverter",
",",
"keys",
"...",
"string",
")",
"Serializer",
"{",
"return",
"b",
".",
"PickFuncIf",
"(",
"alwaysTrue",
",",
"converter",
",",
"keys",
"...",
")",
"\n",
"}"
] | // PickFunc adds the given fields to the result after applying the converter | [
"PickFunc",
"adds",
"the",
"given",
"fields",
"to",
"the",
"result",
"after",
"applying",
"the",
"converter"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L205-L207 |
140,036 | danhper/structomap | structomap.go | PickFuncIf | func (b *Base) PickFuncIf(p Predicate, converter ValueConverter, keys ...string) Serializer {
b.modifiers = append(b.modifiers, func(m jsonMap) jsonMap {
if p(b.raw) {
for _, key := range keys {
m[key] = converter(b.reflected.FieldByName(key).Interface())
}
}
return m
})
return b
} | go | func (b *Base) PickFuncIf(p Predicate, converter ValueConverter, keys ...string) Serializer {
b.modifiers = append(b.modifiers, func(m jsonMap) jsonMap {
if p(b.raw) {
for _, key := range keys {
m[key] = converter(b.reflected.FieldByName(key).Interface())
}
}
return m
})
return b
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"PickFuncIf",
"(",
"p",
"Predicate",
",",
"converter",
"ValueConverter",
",",
"keys",
"...",
"string",
")",
"Serializer",
"{",
"b",
".",
"modifiers",
"=",
"append",
"(",
"b",
".",
"modifiers",
",",
"func",
"(",
"m",
... | // PickFuncIf adds the given fields to the result after applying the converter if the predicate returns true | [
"PickFuncIf",
"adds",
"the",
"given",
"fields",
"to",
"the",
"result",
"after",
"applying",
"the",
"converter",
"if",
"the",
"predicate",
"returns",
"true"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L210-L220 |
140,037 | danhper/structomap | structomap.go | Omit | func (b *Base) Omit(keys ...string) Serializer {
return b.OmitIf(alwaysTrue, keys...)
} | go | func (b *Base) Omit(keys ...string) Serializer {
return b.OmitIf(alwaysTrue, keys...)
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"Omit",
"(",
"keys",
"...",
"string",
")",
"Serializer",
"{",
"return",
"b",
".",
"OmitIf",
"(",
"alwaysTrue",
",",
"keys",
"...",
")",
"\n",
"}"
] | // Omit omits the given fields from the result | [
"Omit",
"omits",
"the",
"given",
"fields",
"from",
"the",
"result"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L223-L225 |
140,038 | danhper/structomap | structomap.go | OmitIf | func (b *Base) OmitIf(p Predicate, keys ...string) Serializer {
b.modifiers = append(b.modifiers, func(m jsonMap) jsonMap {
if p(b.raw) {
for _, key := range keys {
delete(m, key)
}
}
return m
})
return b
} | go | func (b *Base) OmitIf(p Predicate, keys ...string) Serializer {
b.modifiers = append(b.modifiers, func(m jsonMap) jsonMap {
if p(b.raw) {
for _, key := range keys {
delete(m, key)
}
}
return m
})
return b
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"OmitIf",
"(",
"p",
"Predicate",
",",
"keys",
"...",
"string",
")",
"Serializer",
"{",
"b",
".",
"modifiers",
"=",
"append",
"(",
"b",
".",
"modifiers",
",",
"func",
"(",
"m",
"jsonMap",
")",
"jsonMap",
"{",
"if"... | // OmitIf omits the given fields from the result if the Predicate returns true | [
"OmitIf",
"omits",
"the",
"given",
"fields",
"from",
"the",
"result",
"if",
"the",
"Predicate",
"returns",
"true"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L228-L238 |
140,039 | danhper/structomap | structomap.go | Add | func (b *Base) Add(key string, value interface{}) Serializer {
return b.AddIf(alwaysTrue, key, value)
} | go | func (b *Base) Add(key string, value interface{}) Serializer {
return b.AddIf(alwaysTrue, key, value)
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"Add",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"Serializer",
"{",
"return",
"b",
".",
"AddIf",
"(",
"alwaysTrue",
",",
"key",
",",
"value",
")",
"\n",
"}"
] | // Add adds a custom field to the result | [
"Add",
"adds",
"a",
"custom",
"field",
"to",
"the",
"result"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L241-L243 |
140,040 | danhper/structomap | structomap.go | AddIf | func (b *Base) AddIf(p Predicate, key string, value interface{}) Serializer {
return b.AddFuncIf(p, key, func(m interface{}) interface{} { return value })
} | go | func (b *Base) AddIf(p Predicate, key string, value interface{}) Serializer {
return b.AddFuncIf(p, key, func(m interface{}) interface{} { return value })
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"AddIf",
"(",
"p",
"Predicate",
",",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"Serializer",
"{",
"return",
"b",
".",
"AddFuncIf",
"(",
"p",
",",
"key",
",",
"func",
"(",
"m",
"interface",
"{",
... | // AddIf adds a custom field to the result if the Predicate returns true | [
"AddIf",
"adds",
"a",
"custom",
"field",
"to",
"the",
"result",
"if",
"the",
"Predicate",
"returns",
"true"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L246-L248 |
140,041 | danhper/structomap | structomap.go | AddFunc | func (b *Base) AddFunc(key string, f ValueConverter) Serializer {
return b.AddFuncIf(alwaysTrue, key, f)
} | go | func (b *Base) AddFunc(key string, f ValueConverter) Serializer {
return b.AddFuncIf(alwaysTrue, key, f)
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"AddFunc",
"(",
"key",
"string",
",",
"f",
"ValueConverter",
")",
"Serializer",
"{",
"return",
"b",
".",
"AddFuncIf",
"(",
"alwaysTrue",
",",
"key",
",",
"f",
")",
"\n",
"}"
] | // AddFunc adds a computed custom field to the result | [
"AddFunc",
"adds",
"a",
"computed",
"custom",
"field",
"to",
"the",
"result"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L251-L253 |
140,042 | danhper/structomap | structomap.go | AddFuncIf | func (b *Base) AddFuncIf(p Predicate, key string, f ValueConverter) Serializer {
b.modifiers = append(b.modifiers, func(m jsonMap) jsonMap {
if p(b.raw) {
m[key] = f(b.raw)
}
return m
})
return b
} | go | func (b *Base) AddFuncIf(p Predicate, key string, f ValueConverter) Serializer {
b.modifiers = append(b.modifiers, func(m jsonMap) jsonMap {
if p(b.raw) {
m[key] = f(b.raw)
}
return m
})
return b
} | [
"func",
"(",
"b",
"*",
"Base",
")",
"AddFuncIf",
"(",
"p",
"Predicate",
",",
"key",
"string",
",",
"f",
"ValueConverter",
")",
"Serializer",
"{",
"b",
".",
"modifiers",
"=",
"append",
"(",
"b",
".",
"modifiers",
",",
"func",
"(",
"m",
"jsonMap",
")",... | // AddFuncIf adds a computed custom field to the result if the Predicate returns true | [
"AddFuncIf",
"adds",
"a",
"computed",
"custom",
"field",
"to",
"the",
"result",
"if",
"the",
"Predicate",
"returns",
"true"
] | 69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186 | https://github.com/danhper/structomap/blob/69b52f7a1bc39a6fa64a4ab9d43acf4b4b125186/structomap.go#L256-L264 |
140,043 | oleksandr/bonjour | service.go | NewServiceRecord | func NewServiceRecord(instance, service, domain string) *ServiceRecord {
return &ServiceRecord{instance, service, domain, "", "", ""}
} | go | func NewServiceRecord(instance, service, domain string) *ServiceRecord {
return &ServiceRecord{instance, service, domain, "", "", ""}
} | [
"func",
"NewServiceRecord",
"(",
"instance",
",",
"service",
",",
"domain",
"string",
")",
"*",
"ServiceRecord",
"{",
"return",
"&",
"ServiceRecord",
"{",
"instance",
",",
"service",
",",
"domain",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
... | // Constructs a ServiceRecord structure by given arguments | [
"Constructs",
"a",
"ServiceRecord",
"structure",
"by",
"given",
"arguments"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/service.go#L56-L58 |
140,044 | oleksandr/bonjour | service.go | NewLookupParams | func NewLookupParams(instance, service, domain string, entries chan<- *ServiceEntry) *LookupParams {
return &LookupParams{
*NewServiceRecord(instance, service, domain),
entries,
}
} | go | func NewLookupParams(instance, service, domain string, entries chan<- *ServiceEntry) *LookupParams {
return &LookupParams{
*NewServiceRecord(instance, service, domain),
entries,
}
} | [
"func",
"NewLookupParams",
"(",
"instance",
",",
"service",
",",
"domain",
"string",
",",
"entries",
"chan",
"<-",
"*",
"ServiceEntry",
")",
"*",
"LookupParams",
"{",
"return",
"&",
"LookupParams",
"{",
"*",
"NewServiceRecord",
"(",
"instance",
",",
"service",... | // Constructs a LookupParams structure by given arguments | [
"Constructs",
"a",
"LookupParams",
"structure",
"by",
"given",
"arguments"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/service.go#L67-L72 |
140,045 | oleksandr/bonjour | service.go | NewServiceEntry | func NewServiceEntry(instance, service, domain string) *ServiceEntry {
return &ServiceEntry{
*NewServiceRecord(instance, service, domain),
"",
0,
[]string{},
0,
nil,
nil,
}
} | go | func NewServiceEntry(instance, service, domain string) *ServiceEntry {
return &ServiceEntry{
*NewServiceRecord(instance, service, domain),
"",
0,
[]string{},
0,
nil,
nil,
}
} | [
"func",
"NewServiceEntry",
"(",
"instance",
",",
"service",
",",
"domain",
"string",
")",
"*",
"ServiceEntry",
"{",
"return",
"&",
"ServiceEntry",
"{",
"*",
"NewServiceRecord",
"(",
"instance",
",",
"service",
",",
"domain",
")",
",",
"\"",
"\"",
",",
"0",... | // Constructs a ServiceEntry structure by given arguments | [
"Constructs",
"a",
"ServiceEntry",
"structure",
"by",
"given",
"arguments"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/service.go#L88-L98 |
140,046 | oleksandr/bonjour | client.go | NewResolver | func NewResolver(iface *net.Interface) (*Resolver, error) {
c, err := newClient(iface)
if err != nil {
return nil, err
}
return &Resolver{c, c.closedCh}, nil
} | go | func NewResolver(iface *net.Interface) (*Resolver, error) {
c, err := newClient(iface)
if err != nil {
return nil, err
}
return &Resolver{c, c.closedCh}, nil
} | [
"func",
"NewResolver",
"(",
"iface",
"*",
"net",
".",
"Interface",
")",
"(",
"*",
"Resolver",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"newClient",
"(",
"iface",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"... | // Resolver structure constructor | [
"Resolver",
"structure",
"constructor"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/client.go#L22-L28 |
140,047 | oleksandr/bonjour | client.go | Lookup | func (r *Resolver) Lookup(instance, service, domain string, entries chan<- *ServiceEntry) error {
params := defaultParams(service)
params.Instance = instance
if domain != "" {
params.Domain = domain
}
params.Entries = entries
go r.c.mainloop(params)
err := r.c.query(params)
if err != nil {
r.Exit <- true
... | go | func (r *Resolver) Lookup(instance, service, domain string, entries chan<- *ServiceEntry) error {
params := defaultParams(service)
params.Instance = instance
if domain != "" {
params.Domain = domain
}
params.Entries = entries
go r.c.mainloop(params)
err := r.c.query(params)
if err != nil {
r.Exit <- true
... | [
"func",
"(",
"r",
"*",
"Resolver",
")",
"Lookup",
"(",
"instance",
",",
"service",
",",
"domain",
"string",
",",
"entries",
"chan",
"<-",
"*",
"ServiceEntry",
")",
"error",
"{",
"params",
":=",
"defaultParams",
"(",
"service",
")",
"\n",
"params",
".",
... | // Look up a specific service by its name and type in a given domain | [
"Look",
"up",
"a",
"specific",
"service",
"by",
"its",
"name",
"and",
"type",
"in",
"a",
"given",
"domain"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/client.go#L50-L67 |
140,048 | oleksandr/bonjour | client.go | newClient | func newClient(iface *net.Interface) (*client, error) {
// Create wildcard connections (because :5353 can be already taken by other apps)
ipv4conn, err := net.ListenUDP("udp4", mdnsWildcardAddrIPv4)
if err != nil {
log.Printf("[ERR] bonjour: Failed to bind to udp4 port: %v", err)
}
ipv6conn, err := net.ListenUDP... | go | func newClient(iface *net.Interface) (*client, error) {
// Create wildcard connections (because :5353 can be already taken by other apps)
ipv4conn, err := net.ListenUDP("udp4", mdnsWildcardAddrIPv4)
if err != nil {
log.Printf("[ERR] bonjour: Failed to bind to udp4 port: %v", err)
}
ipv6conn, err := net.ListenUDP... | [
"func",
"newClient",
"(",
"iface",
"*",
"net",
".",
"Interface",
")",
"(",
"*",
"client",
",",
"error",
")",
"{",
"// Create wildcard connections (because :5353 can be already taken by other apps)",
"ipv4conn",
",",
"err",
":=",
"net",
".",
"ListenUDP",
"(",
"\"",
... | // Client structure constructor | [
"Client",
"structure",
"constructor"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/client.go#L84-L134 |
140,049 | oleksandr/bonjour | client.go | shutdown | func (c *client) shutdown() {
c.closeLock.Lock()
defer c.closeLock.Unlock()
if c.closed {
return
}
c.closed = true
close(c.closedCh)
if c.ipv4conn != nil {
c.ipv4conn.Close()
}
if c.ipv6conn != nil {
c.ipv6conn.Close()
}
} | go | func (c *client) shutdown() {
c.closeLock.Lock()
defer c.closeLock.Unlock()
if c.closed {
return
}
c.closed = true
close(c.closedCh)
if c.ipv4conn != nil {
c.ipv4conn.Close()
}
if c.ipv6conn != nil {
c.ipv6conn.Close()
}
} | [
"func",
"(",
"c",
"*",
"client",
")",
"shutdown",
"(",
")",
"{",
"c",
".",
"closeLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"closeLock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"c",
".",
"closed",
"{",
"return",
"\n",
"}",
"\n",
"c",... | // Shutdown client will close currently open connections & channel | [
"Shutdown",
"client",
"will",
"close",
"currently",
"open",
"connections",
"&",
"channel"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/client.go#L239-L255 |
140,050 | oleksandr/bonjour | server.go | Register | func Register(instance, service, domain string, port int, text []string, iface *net.Interface) (*Server, error) {
entry := NewServiceEntry(instance, service, domain)
entry.Port = port
entry.Text = text
if entry.Instance == "" {
return nil, fmt.Errorf("Missing service instance name")
}
if entry.Service == "" {
... | go | func Register(instance, service, domain string, port int, text []string, iface *net.Interface) (*Server, error) {
entry := NewServiceEntry(instance, service, domain)
entry.Port = port
entry.Text = text
if entry.Instance == "" {
return nil, fmt.Errorf("Missing service instance name")
}
if entry.Service == "" {
... | [
"func",
"Register",
"(",
"instance",
",",
"service",
",",
"domain",
"string",
",",
"port",
"int",
",",
"text",
"[",
"]",
"string",
",",
"iface",
"*",
"net",
".",
"Interface",
")",
"(",
"*",
"Server",
",",
"error",
")",
"{",
"entry",
":=",
"NewService... | // Register a service by given arguments. This call will take the system's hostname
// and lookup IP by that hostname. | [
"Register",
"a",
"service",
"by",
"given",
"arguments",
".",
"This",
"call",
"will",
"take",
"the",
"system",
"s",
"hostname",
"and",
"lookup",
"IP",
"by",
"that",
"hostname",
"."
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/server.go#L46-L101 |
140,051 | oleksandr/bonjour | server.go | newServer | func newServer(iface *net.Interface) (*Server, error) {
// Create wildcard connections (because :5353 can be already taken by other apps)
ipv4conn, err := net.ListenUDP("udp4", mdnsWildcardAddrIPv4)
if err != nil {
log.Printf("[ERR] bonjour: Failed to bind to udp4 port: %v", err)
}
ipv6conn, err := net.ListenUDP... | go | func newServer(iface *net.Interface) (*Server, error) {
// Create wildcard connections (because :5353 can be already taken by other apps)
ipv4conn, err := net.ListenUDP("udp4", mdnsWildcardAddrIPv4)
if err != nil {
log.Printf("[ERR] bonjour: Failed to bind to udp4 port: %v", err)
}
ipv6conn, err := net.ListenUDP... | [
"func",
"newServer",
"(",
"iface",
"*",
"net",
".",
"Interface",
")",
"(",
"*",
"Server",
",",
"error",
")",
"{",
"// Create wildcard connections (because :5353 can be already taken by other apps)",
"ipv4conn",
",",
"err",
":=",
"net",
".",
"ListenUDP",
"(",
"\"",
... | // Constructs server structure | [
"Constructs",
"server",
"structure"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/server.go#L165-L215 |
140,052 | oleksandr/bonjour | server.go | SetText | func (s *Server) SetText(text []string) {
s.service.Text = text
s.announceText()
} | go | func (s *Server) SetText(text []string) {
s.service.Text = text
s.announceText()
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"SetText",
"(",
"text",
"[",
"]",
"string",
")",
"{",
"s",
".",
"service",
".",
"Text",
"=",
"text",
"\n",
"s",
".",
"announceText",
"(",
")",
"\n",
"}"
] | // SetText updates and announces the TXT records | [
"SetText",
"updates",
"and",
"announces",
"the",
"TXT",
"records"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/server.go#L233-L236 |
140,053 | oleksandr/bonjour | server.go | shutdown | func (s *Server) shutdown() error {
s.shutdownLock.Lock()
defer s.shutdownLock.Unlock()
s.unregister()
if s.shouldShutdown {
return nil
}
s.shouldShutdown = true
if s.ipv4conn != nil {
s.ipv4conn.Close()
}
if s.ipv6conn != nil {
s.ipv6conn.Close()
}
return nil
} | go | func (s *Server) shutdown() error {
s.shutdownLock.Lock()
defer s.shutdownLock.Unlock()
s.unregister()
if s.shouldShutdown {
return nil
}
s.shouldShutdown = true
if s.ipv4conn != nil {
s.ipv4conn.Close()
}
if s.ipv6conn != nil {
s.ipv6conn.Close()
}
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"shutdown",
"(",
")",
"error",
"{",
"s",
".",
"shutdownLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"shutdownLock",
".",
"Unlock",
"(",
")",
"\n\n",
"s",
".",
"unregister",
"(",
")",
"\n\n",
"if",
"... | // Shutdown server will close currently open connections & channel | [
"Shutdown",
"server",
"will",
"close",
"currently",
"open",
"connections",
"&",
"channel"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/server.go#L244-L262 |
140,054 | oleksandr/bonjour | server.go | recv | func (s *Server) recv(c *net.UDPConn) {
if c == nil {
return
}
buf := make([]byte, 65536)
for !s.shouldShutdown {
n, from, err := c.ReadFrom(buf)
if err != nil {
continue
}
if err := s.parsePacket(buf[:n], from); err != nil {
log.Printf("[ERR] bonjour: Failed to handle query: %v", err)
}
}
} | go | func (s *Server) recv(c *net.UDPConn) {
if c == nil {
return
}
buf := make([]byte, 65536)
for !s.shouldShutdown {
n, from, err := c.ReadFrom(buf)
if err != nil {
continue
}
if err := s.parsePacket(buf[:n], from); err != nil {
log.Printf("[ERR] bonjour: Failed to handle query: %v", err)
}
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"recv",
"(",
"c",
"*",
"net",
".",
"UDPConn",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"65536",
")",
"\n",
"for",
"!",
"s",
".",... | // recv is a long running routine to receive packets from an interface | [
"recv",
"is",
"a",
"long",
"running",
"routine",
"to",
"receive",
"packets",
"from",
"an",
"interface"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/server.go#L265-L279 |
140,055 | oleksandr/bonjour | server.go | handleQuestion | func (s *Server) handleQuestion(q dns.Question, resp *dns.Msg) error {
if s.service == nil {
return nil
}
switch q.Name {
case s.service.ServiceName():
s.composeBrowsingAnswers(resp, s.ttl)
case s.service.ServiceInstanceName():
s.composeLookupAnswers(resp, s.ttl)
case s.service.ServiceTypeName():
s.servi... | go | func (s *Server) handleQuestion(q dns.Question, resp *dns.Msg) error {
if s.service == nil {
return nil
}
switch q.Name {
case s.service.ServiceName():
s.composeBrowsingAnswers(resp, s.ttl)
case s.service.ServiceInstanceName():
s.composeLookupAnswers(resp, s.ttl)
case s.service.ServiceTypeName():
s.servi... | [
"func",
"(",
"s",
"*",
"Server",
")",
"handleQuestion",
"(",
"q",
"dns",
".",
"Question",
",",
"resp",
"*",
"dns",
".",
"Msg",
")",
"error",
"{",
"if",
"s",
".",
"service",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"switch",
"q",
".",... | // handleQuestion is used to handle an incoming question | [
"handleQuestion",
"is",
"used",
"to",
"handle",
"an",
"incoming",
"question"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/server.go#L339-L354 |
140,056 | oleksandr/bonjour | server.go | announceText | func (s *Server) announceText() {
resp := new(dns.Msg)
resp.MsgHdr.Response = true
txt := &dns.TXT{
Hdr: dns.RR_Header{
Name: s.service.ServiceInstanceName(),
Rrtype: dns.TypeTXT,
Class: dns.ClassINET | 1<<15,
Ttl: s.ttl,
},
Txt: s.service.Text,
}
resp.Answer = []dns.RR{txt}
s.multicastR... | go | func (s *Server) announceText() {
resp := new(dns.Msg)
resp.MsgHdr.Response = true
txt := &dns.TXT{
Hdr: dns.RR_Header{
Name: s.service.ServiceInstanceName(),
Rrtype: dns.TypeTXT,
Class: dns.ClassINET | 1<<15,
Ttl: s.ttl,
},
Txt: s.service.Text,
}
resp.Answer = []dns.RR{txt}
s.multicastR... | [
"func",
"(",
"s",
"*",
"Server",
")",
"announceText",
"(",
")",
"{",
"resp",
":=",
"new",
"(",
"dns",
".",
"Msg",
")",
"\n",
"resp",
".",
"MsgHdr",
".",
"Response",
"=",
"true",
"\n\n",
"txt",
":=",
"&",
"dns",
".",
"TXT",
"{",
"Hdr",
":",
"dns... | // announceText sends a Text announcement with cache flush enabled | [
"announceText",
"sends",
"a",
"Text",
"announcement",
"with",
"cache",
"flush",
"enabled"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/server.go#L572-L588 |
140,057 | oleksandr/bonjour | server.go | unicastResponse | func (s *Server) unicastResponse(resp *dns.Msg, from net.Addr) error {
buf, err := resp.Pack()
if err != nil {
return err
}
addr := from.(*net.UDPAddr)
if addr.IP.To4() != nil {
_, err = s.ipv4conn.WriteToUDP(buf, addr)
return err
} else {
_, err = s.ipv6conn.WriteToUDP(buf, addr)
return err
}
} | go | func (s *Server) unicastResponse(resp *dns.Msg, from net.Addr) error {
buf, err := resp.Pack()
if err != nil {
return err
}
addr := from.(*net.UDPAddr)
if addr.IP.To4() != nil {
_, err = s.ipv4conn.WriteToUDP(buf, addr)
return err
} else {
_, err = s.ipv6conn.WriteToUDP(buf, addr)
return err
}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"unicastResponse",
"(",
"resp",
"*",
"dns",
".",
"Msg",
",",
"from",
"net",
".",
"Addr",
")",
"error",
"{",
"buf",
",",
"err",
":=",
"resp",
".",
"Pack",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retu... | // unicastResponse is used to send a unicast response packet | [
"unicastResponse",
"is",
"used",
"to",
"send",
"a",
"unicast",
"response",
"packet"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/server.go#L600-L613 |
140,058 | oleksandr/bonjour | server.go | multicastResponse | func (c *Server) multicastResponse(msg *dns.Msg) error {
buf, err := msg.Pack()
if err != nil {
log.Println("Failed to pack message!")
return err
}
if c.ipv4conn != nil {
c.ipv4conn.WriteTo(buf, ipv4Addr)
}
if c.ipv6conn != nil {
c.ipv6conn.WriteTo(buf, ipv6Addr)
}
return nil
} | go | func (c *Server) multicastResponse(msg *dns.Msg) error {
buf, err := msg.Pack()
if err != nil {
log.Println("Failed to pack message!")
return err
}
if c.ipv4conn != nil {
c.ipv4conn.WriteTo(buf, ipv4Addr)
}
if c.ipv6conn != nil {
c.ipv6conn.WriteTo(buf, ipv6Addr)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Server",
")",
"multicastResponse",
"(",
"msg",
"*",
"dns",
".",
"Msg",
")",
"error",
"{",
"buf",
",",
"err",
":=",
"msg",
".",
"Pack",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Println",
"(",
"\"",
"\""... | // multicastResponse us used to send a multicast response packet | [
"multicastResponse",
"us",
"used",
"to",
"send",
"a",
"multicast",
"response",
"packet"
] | 5dcf00d8b228be86307f952f550f2191d956b9e2 | https://github.com/oleksandr/bonjour/blob/5dcf00d8b228be86307f952f550f2191d956b9e2/server.go#L616-L629 |
140,059 | rsc/rsc | arq/arq.go | cachedir | func cachedir() string {
if runtime.GOOS == "darwin" {
return filepath.Join(os.Getenv("HOME"), "Library/Caches/arq-cache")
}
return filepath.Join(os.Getenv("HOME"), ".cache/arq-cache")
} | go | func cachedir() string {
if runtime.GOOS == "darwin" {
return filepath.Join(os.Getenv("HOME"), "Library/Caches/arq-cache")
}
return filepath.Join(os.Getenv("HOME"), ".cache/arq-cache")
} | [
"func",
"cachedir",
"(",
")",
"string",
"{",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"return",
"filepath",
".",
"Join",
"(",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"filepath",
".",... | // cachedir returns the canonical directory in which to cache data. | [
"cachedir",
"returns",
"the",
"canonical",
"directory",
"in",
"which",
"to",
"cache",
"data",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/arq/arq.go#L45-L50 |
140,060 | rsc/rsc | arq/arq.go | Dial | func Dial(auth aws.Auth) (*Conn, error) {
buck := fmt.Sprintf("%s-com-haystacksoftware-arq", strings.ToLower(auth.AccessKey))
b := s3.New(auth, aws.USEast).Bucket(buck)
c := &Conn{
b: b,
cache: filepath.Join(cachedir(), buck),
}
if runtime.GOOS == "darwin" {
c.altCache = filepath.Join(os.Getenv("HOME"), ... | go | func Dial(auth aws.Auth) (*Conn, error) {
buck := fmt.Sprintf("%s-com-haystacksoftware-arq", strings.ToLower(auth.AccessKey))
b := s3.New(auth, aws.USEast).Bucket(buck)
c := &Conn{
b: b,
cache: filepath.Join(cachedir(), buck),
}
if runtime.GOOS == "darwin" {
c.altCache = filepath.Join(os.Getenv("HOME"), ... | [
"func",
"Dial",
"(",
"auth",
"aws",
".",
"Auth",
")",
"(",
"*",
"Conn",
",",
"error",
")",
"{",
"buck",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"ToLower",
"(",
"auth",
".",
"AccessKey",
")",
")",
"\n",
"b",
":=",
"s3"... | // Dial establishes a connection to an S3 server holding Arq backups. | [
"Dial",
"establishes",
"a",
"connection",
"to",
"an",
"S3",
"server",
"holding",
"Arq",
"backups",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/arq/arq.go#L53-L72 |
140,061 | rsc/rsc | arq/arq.go | Computers | func (c *Conn) Computers() ([]*Computer, error) {
println("COMPUTERS")
// Each backup is a top-level directory with a computerinfo file in it.
list, err := c.list("", "/", 0)
if err != nil {
println("FAIL", err.Error())
return nil, err
}
var out []*Computer
for _, p := range list.CommonPrefixes {
println("... | go | func (c *Conn) Computers() ([]*Computer, error) {
println("COMPUTERS")
// Each backup is a top-level directory with a computerinfo file in it.
list, err := c.list("", "/", 0)
if err != nil {
println("FAIL", err.Error())
return nil, err
}
var out []*Computer
for _, p := range list.CommonPrefixes {
println("... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Computers",
"(",
")",
"(",
"[",
"]",
"*",
"Computer",
",",
"error",
")",
"{",
"println",
"(",
"\"",
"\"",
")",
"\n",
"// Each backup is a top-level directory with a computerinfo file in it.",
"list",
",",
"err",
":=",
"c"... | // Computers returns a list of the computers with backups available on the S3 server. | [
"Computers",
"returns",
"a",
"list",
"of",
"the",
"computers",
"with",
"backups",
"available",
"on",
"the",
"S3",
"server",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/arq/arq.go#L231-L269 |
140,062 | rsc/rsc | arq/arq.go | Folders | func (c *Computer) Folders() ([]*Folder, error) {
// Each folder is a file under computer/buckets/.
list, err := c.conn.list(c.UUID+"/buckets/", "", 0)
if err != nil {
return nil, err
}
var out []*Folder
for _, obj := range list.Contents {
data, err := c.conn.bget(obj.Key)
if err != nil {
return nil, err... | go | func (c *Computer) Folders() ([]*Folder, error) {
// Each folder is a file under computer/buckets/.
list, err := c.conn.list(c.UUID+"/buckets/", "", 0)
if err != nil {
return nil, err
}
var out []*Folder
for _, obj := range list.Contents {
data, err := c.conn.bget(obj.Key)
if err != nil {
return nil, err... | [
"func",
"(",
"c",
"*",
"Computer",
")",
"Folders",
"(",
")",
"(",
"[",
"]",
"*",
"Folder",
",",
"error",
")",
"{",
"// Each folder is a file under computer/buckets/.",
"list",
",",
"err",
":=",
"c",
".",
"conn",
".",
"list",
"(",
"c",
".",
"UUID",
"+",... | // Folders returns a list of the folders that have been backed up on the computer. | [
"Folders",
"returns",
"a",
"list",
"of",
"the",
"folders",
"that",
"have",
"been",
"backed",
"up",
"on",
"the",
"computer",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/arq/arq.go#L282-L309 |
140,063 | rsc/rsc | arq/arq.go | Unlock | func (c *Computer) Unlock(pw string) {
print("UNLOCK <", pw, ">\n")
print(hex.Dump([]byte(pw)))
c.crypto.unlock(pw)
} | go | func (c *Computer) Unlock(pw string) {
print("UNLOCK <", pw, ">\n")
print(hex.Dump([]byte(pw)))
c.crypto.unlock(pw)
} | [
"func",
"(",
"c",
"*",
"Computer",
")",
"Unlock",
"(",
"pw",
"string",
")",
"{",
"print",
"(",
"\"",
"\"",
",",
"pw",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"print",
"(",
"hex",
".",
"Dump",
"(",
"[",
"]",
"byte",
"(",
"pw",
")",
")",
")",
"\n"... | // Unlock records the password to use when decrypting
// backups from this computer. It must be called before calling Trees
// in any folder obtained for this computer. | [
"Unlock",
"records",
"the",
"password",
"to",
"use",
"when",
"decrypting",
"backups",
"from",
"this",
"computer",
".",
"It",
"must",
"be",
"called",
"before",
"calling",
"Trees",
"in",
"any",
"folder",
"obtained",
"for",
"this",
"computer",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/arq/arq.go#L314-L318 |
140,064 | rsc/rsc | arq/arq.go | Load | func (f *Folder) Load() error {
if err := f.comp.loadPack(f.uuid, "-trees"); err != nil {
return err
}
if err := f.comp.loadPack(f.uuid, "-blobs"); err != nil {
return err
}
return nil
} | go | func (f *Folder) Load() error {
if err := f.comp.loadPack(f.uuid, "-trees"); err != nil {
return err
}
if err := f.comp.loadPack(f.uuid, "-blobs"); err != nil {
return err
}
return nil
} | [
"func",
"(",
"f",
"*",
"Folder",
")",
"Load",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"f",
".",
"comp",
".",
"loadPack",
"(",
"f",
".",
"uuid",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"... | // Load loads xxx | [
"Load",
"loads",
"xxx"
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/arq/arq.go#L395-L403 |
140,065 | rsc/rsc | arq/arq.go | Root | func (t *Tree) Root() (*File, error) {
if !t.haveRaw {
data, err := t.comp.scget(t.Score)
if err != nil {
return nil, err
}
if err := unpack(data, &t.raw); err != nil {
return nil, err
}
t.haveRaw = true
}
dir := &File{
t: t,
dir: &t.raw,
n: &nameNode{"/", node{IsTree: true}},
}
return... | go | func (t *Tree) Root() (*File, error) {
if !t.haveRaw {
data, err := t.comp.scget(t.Score)
if err != nil {
return nil, err
}
if err := unpack(data, &t.raw); err != nil {
return nil, err
}
t.haveRaw = true
}
dir := &File{
t: t,
dir: &t.raw,
n: &nameNode{"/", node{IsTree: true}},
}
return... | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Root",
"(",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"if",
"!",
"t",
".",
"haveRaw",
"{",
"data",
",",
"err",
":=",
"t",
".",
"comp",
".",
"scget",
"(",
"t",
".",
"Score",
")",
"\n",
"if",
"err",
... | // Root returns the File for the tree's root directory. | [
"Root",
"returns",
"the",
"File",
"for",
"the",
"tree",
"s",
"root",
"directory",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/arq/arq.go#L590-L608 |
140,066 | rsc/rsc | qr/web/play.go | Show | func Show(w http.ResponseWriter, req *http.Request) {
ctxt := fs.NewContext(req)
tag := req.URL.Path[len("/qr/show/"):]
png := strings.HasSuffix(tag, ".png")
if png {
tag = tag[:len(tag)-len(".png")]
}
if !isTagName(tag) {
fmt.Fprintf(w, "Sorry, QR code not found\n")
return
}
if req.FormValue("flag") == "... | go | func Show(w http.ResponseWriter, req *http.Request) {
ctxt := fs.NewContext(req)
tag := req.URL.Path[len("/qr/show/"):]
png := strings.HasSuffix(tag, ".png")
if png {
tag = tag[:len(tag)-len(".png")]
}
if !isTagName(tag) {
fmt.Fprintf(w, "Sorry, QR code not found\n")
return
}
if req.FormValue("flag") == "... | [
"func",
"Show",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"ctxt",
":=",
"fs",
".",
"NewContext",
"(",
"req",
")",
"\n",
"tag",
":=",
"req",
".",
"URL",
".",
"Path",
"[",
"len",
"(",
"\"",
"\"",
... | // Show is the handler for showing a stored QR code. | [
"Show",
"is",
"the",
"handler",
"for",
"showing",
"a",
"stored",
"QR",
"code",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/qr/web/play.go#L250-L296 |
140,067 | rsc/rsc | fuse/serve.go | HandleRead | func HandleRead(req *ReadRequest, resp *ReadResponse, data []byte) {
if req.Offset >= int64(len(data)) {
data = nil
} else {
data = data[req.Offset:]
}
if len(data) > req.Size {
data = data[:req.Size]
}
n := copy(resp.Data[:req.Size], data)
resp.Data = resp.Data[:n]
} | go | func HandleRead(req *ReadRequest, resp *ReadResponse, data []byte) {
if req.Offset >= int64(len(data)) {
data = nil
} else {
data = data[req.Offset:]
}
if len(data) > req.Size {
data = data[:req.Size]
}
n := copy(resp.Data[:req.Size], data)
resp.Data = resp.Data[:n]
} | [
"func",
"HandleRead",
"(",
"req",
"*",
"ReadRequest",
",",
"resp",
"*",
"ReadResponse",
",",
"data",
"[",
"]",
"byte",
")",
"{",
"if",
"req",
".",
"Offset",
">=",
"int64",
"(",
"len",
"(",
"data",
")",
")",
"{",
"data",
"=",
"nil",
"\n",
"}",
"el... | // HandleRead handles a read request assuming that data is the entire file content.
// It adjusts the amount returned in resp according to req.Offset and req.Size. | [
"HandleRead",
"handles",
"a",
"read",
"request",
"assuming",
"that",
"data",
"is",
"the",
"entire",
"file",
"content",
".",
"It",
"adjusts",
"the",
"amount",
"returned",
"in",
"resp",
"according",
"to",
"req",
".",
"Offset",
"and",
"req",
".",
"Size",
"."
... | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/fuse/serve.go#L997-L1008 |
140,068 | rsc/rsc | websrv/mux.go | Handle | func Handle(pattern string, fn interface{}) {
elems := strings.Split(pattern, "/")
n := len(elems)
if n == 0 {
panic("empty pattern")
}
if n >= 2 && elems[n-2] == "{" && strings.HasSuffix(elems[n-1], "}") {
elems[n-2] += "/" + elems[n-1]
n--
elems = elems[:n]
}
var vars []string
re := "^"
for i, elem ... | go | func Handle(pattern string, fn interface{}) {
elems := strings.Split(pattern, "/")
n := len(elems)
if n == 0 {
panic("empty pattern")
}
if n >= 2 && elems[n-2] == "{" && strings.HasSuffix(elems[n-1], "}") {
elems[n-2] += "/" + elems[n-1]
n--
elems = elems[:n]
}
var vars []string
re := "^"
for i, elem ... | [
"func",
"Handle",
"(",
"pattern",
"string",
",",
"fn",
"interface",
"{",
"}",
")",
"{",
"elems",
":=",
"strings",
".",
"Split",
"(",
"pattern",
",",
"\"",
"\"",
")",
"\n",
"n",
":=",
"len",
"(",
"elems",
")",
"\n",
"if",
"n",
"==",
"0",
"{",
"p... | // Handle registers fn to handle paths of the form given by pattern. | [
"Handle",
"registers",
"fn",
"to",
"handle",
"paths",
"of",
"the",
"form",
"given",
"by",
"pattern",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/websrv/mux.go#L150-L218 |
140,069 | rsc/rsc | websrv/mux.go | Write | func (ctxt *Context) Write(p []byte) (n int, err error) {
if ctxt.direct {
return ctxt.w.Write(p)
}
return ctxt.buf.Write(p)
} | go | func (ctxt *Context) Write(p []byte) (n int, err error) {
if ctxt.direct {
return ctxt.w.Write(p)
}
return ctxt.buf.Write(p)
} | [
"func",
"(",
"ctxt",
"*",
"Context",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"ctxt",
".",
"direct",
"{",
"return",
"ctxt",
".",
"w",
".",
"Write",
"(",
"p",
")",
"\n",
"}",
"\n",
... | // Write writes HTTP response data. | [
"Write",
"writes",
"HTTP",
"response",
"data",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/websrv/mux.go#L280-L285 |
140,070 | rsc/rsc | websrv/mux.go | Redirect | func (ctxt *Context) Redirect(url string) {
http.Redirect(ctxt, ctxt.Request, url, http.StatusFound)
} | go | func (ctxt *Context) Redirect(url string) {
http.Redirect(ctxt, ctxt.Request, url, http.StatusFound)
} | [
"func",
"(",
"ctxt",
"*",
"Context",
")",
"Redirect",
"(",
"url",
"string",
")",
"{",
"http",
".",
"Redirect",
"(",
"ctxt",
",",
"ctxt",
".",
"Request",
",",
"url",
",",
"http",
".",
"StatusFound",
")",
"\n",
"}"
] | // Redirect sends a redirect to the given URL. | [
"Redirect",
"sends",
"a",
"redirect",
"to",
"the",
"given",
"URL",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/websrv/mux.go#L288-L290 |
140,071 | rsc/rsc | websrv/mux.go | ServeFile | func (ctxt *Context) ServeFile(path string) {
http.ServeFile(ctxt, ctxt.Request, path)
} | go | func (ctxt *Context) ServeFile(path string) {
http.ServeFile(ctxt, ctxt.Request, path)
} | [
"func",
"(",
"ctxt",
"*",
"Context",
")",
"ServeFile",
"(",
"path",
"string",
")",
"{",
"http",
".",
"ServeFile",
"(",
"ctxt",
",",
"ctxt",
".",
"Request",
",",
"path",
")",
"\n",
"}"
] | // ServeFile serves the request using the file at the given path. | [
"ServeFile",
"serves",
"the",
"request",
"using",
"the",
"file",
"at",
"the",
"given",
"path",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/websrv/mux.go#L293-L295 |
140,072 | rsc/rsc | websrv/mux.go | WriteHeader | func (ctxt *Context) WriteHeader(status int) {
if ctxt.status != 0 {
return
}
ctxt.status = status
} | go | func (ctxt *Context) WriteHeader(status int) {
if ctxt.status != 0 {
return
}
ctxt.status = status
} | [
"func",
"(",
"ctxt",
"*",
"Context",
")",
"WriteHeader",
"(",
"status",
"int",
")",
"{",
"if",
"ctxt",
".",
"status",
"!=",
"0",
"{",
"return",
"\n",
"}",
"\n",
"ctxt",
".",
"status",
"=",
"status",
"\n",
"}"
] | // WriteHeader writes the HTTP header, with the given status. | [
"WriteHeader",
"writes",
"the",
"HTTP",
"header",
"with",
"the",
"given",
"status",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/websrv/mux.go#L298-L303 |
140,073 | rsc/rsc | c2go/liblink/pcln.go | addvarint | func addvarint(ctxt *Link, d *Pcdata, val uint32) {
var v uint32
for v = val; v >= 0x80; v >>= 7 {
d.P = append(d.P, uint8(v|0x80))
}
d.P = append(d.P, uint8(v))
} | go | func addvarint(ctxt *Link, d *Pcdata, val uint32) {
var v uint32
for v = val; v >= 0x80; v >>= 7 {
d.P = append(d.P, uint8(v|0x80))
}
d.P = append(d.P, uint8(v))
} | [
"func",
"addvarint",
"(",
"ctxt",
"*",
"Link",
",",
"d",
"*",
"Pcdata",
",",
"val",
"uint32",
")",
"{",
"var",
"v",
"uint32",
"\n",
"for",
"v",
"=",
"val",
";",
"v",
">=",
"0x80",
";",
"v",
">>=",
"7",
"{",
"d",
".",
"P",
"=",
"append",
"(",
... | // Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. | [
"Copyright",
"2013",
"The",
"Go",
"Authors",
".",
"All",
"rights",
"reserved",
".",
"Use",
"of",
"this",
"source",
"code",
"is",
"governed",
"by",
"a",
"BSD",
"-",
"style",
"license",
"that",
"can",
"be",
"found",
"in",
"the",
"LICENSE",
"file",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/c2go/liblink/pcln.go#L11-L17 |
140,074 | rsc/rsc | c2go/liblink/pcln.go | pctospadj | func pctospadj(ctxt *Link, sym *LSym, oldval int, p *Prog, phase int, arg interface{}) int {
if oldval == -1 { // starting
oldval = 0
}
if phase == 0 {
return oldval
}
if int64(oldval)+p.Spadj < -10000 || int64(oldval)+p.Spadj > 1100000000 {
ctxt.Diag("overflow in spadj: %d + %d = %d", oldval, p.Spadj, int64... | go | func pctospadj(ctxt *Link, sym *LSym, oldval int, p *Prog, phase int, arg interface{}) int {
if oldval == -1 { // starting
oldval = 0
}
if phase == 0 {
return oldval
}
if int64(oldval)+p.Spadj < -10000 || int64(oldval)+p.Spadj > 1100000000 {
ctxt.Diag("overflow in spadj: %d + %d = %d", oldval, p.Spadj, int64... | [
"func",
"pctospadj",
"(",
"ctxt",
"*",
"Link",
",",
"sym",
"*",
"LSym",
",",
"oldval",
"int",
",",
"p",
"*",
"Prog",
",",
"phase",
"int",
",",
"arg",
"interface",
"{",
"}",
")",
"int",
"{",
"if",
"oldval",
"==",
"-",
"1",
"{",
"// starting",
"old... | // pctospadj computes the sp adjustment in effect.
// It is oldval plus any adjustment made by p itself.
// The adjustment by p takes effect only after p, so we
// apply the change during phase == 1. | [
"pctospadj",
"computes",
"the",
"sp",
"adjustment",
"in",
"effect",
".",
"It",
"is",
"oldval",
"plus",
"any",
"adjustment",
"made",
"by",
"p",
"itself",
".",
"The",
"adjustment",
"by",
"p",
"takes",
"effect",
"only",
"after",
"p",
"so",
"we",
"apply",
"t... | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/c2go/liblink/pcln.go#L168-L180 |
140,075 | rsc/rsc | c2go/liblink/pcln.go | pctopcdata | func pctopcdata(ctxt *Link, sym *LSym, oldval int, p *Prog, phase int, arg interface{}) int {
if phase == 0 || p.As != ctxt.Arch.APCDATA || p.From.Offset != int64(arg.(int)) {
return oldval
}
if int64(int(p.To.Offset)) != p.To.Offset {
ctxt.Diag("overflow in PCDATA instruction: %P", p)
log.Fatalf("bad code")
... | go | func pctopcdata(ctxt *Link, sym *LSym, oldval int, p *Prog, phase int, arg interface{}) int {
if phase == 0 || p.As != ctxt.Arch.APCDATA || p.From.Offset != int64(arg.(int)) {
return oldval
}
if int64(int(p.To.Offset)) != p.To.Offset {
ctxt.Diag("overflow in PCDATA instruction: %P", p)
log.Fatalf("bad code")
... | [
"func",
"pctopcdata",
"(",
"ctxt",
"*",
"Link",
",",
"sym",
"*",
"LSym",
",",
"oldval",
"int",
",",
"p",
"*",
"Prog",
",",
"phase",
"int",
",",
"arg",
"interface",
"{",
"}",
")",
"int",
"{",
"if",
"phase",
"==",
"0",
"||",
"p",
".",
"As",
"!=",... | // pctopcdata computes the pcdata value in effect at p.
// A PCDATA instruction sets the value in effect at future
// non-PCDATA instructions.
// Since PCDATA instructions have no width in the final code,
// it does not matter which phase we use for the update. | [
"pctopcdata",
"computes",
"the",
"pcdata",
"value",
"in",
"effect",
"at",
"p",
".",
"A",
"PCDATA",
"instruction",
"sets",
"the",
"value",
"in",
"effect",
"at",
"future",
"non",
"-",
"PCDATA",
"instructions",
".",
"Since",
"PCDATA",
"instructions",
"have",
"n... | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/c2go/liblink/pcln.go#L187-L196 |
140,076 | rsc/rsc | c2go/liblink/pcln.go | getvarint | func getvarint(pp *[]uint8) uint32 {
var p []uint8
var shift int
var v uint32
v = 0
p = []uint8(*pp)
for shift = 0; ; shift += 7 {
v |= uint32(p[0]&0x7F) << uint(shift)
tmp7 := p
p = p[1:]
if tmp7[0]&0x80 == 0 {
break
}
}
*pp = p
return v
} | go | func getvarint(pp *[]uint8) uint32 {
var p []uint8
var shift int
var v uint32
v = 0
p = []uint8(*pp)
for shift = 0; ; shift += 7 {
v |= uint32(p[0]&0x7F) << uint(shift)
tmp7 := p
p = p[1:]
if tmp7[0]&0x80 == 0 {
break
}
}
*pp = p
return v
} | [
"func",
"getvarint",
"(",
"pp",
"*",
"[",
"]",
"uint8",
")",
"uint32",
"{",
"var",
"p",
"[",
"]",
"uint8",
"\n",
"var",
"shift",
"int",
"\n",
"var",
"v",
"uint32",
"\n",
"v",
"=",
"0",
"\n",
"p",
"=",
"[",
"]",
"uint8",
"(",
"*",
"pp",
")",
... | // iteration over encoded pcdata tables. | [
"iteration",
"over",
"encoded",
"pcdata",
"tables",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/c2go/liblink/pcln.go#L268-L284 |
140,077 | rsc/rsc | cc/expr.go | Walk | func Walk(x Syntax, before, after func(Syntax)) {
seen := map[Syntax]bool{
nil: true,
(*Decl)(nil): true,
(*Init)(nil): true,
(*Type)(nil): true,
(*Expr)(nil): true,
(*Stmt)(nil): true,
(*Label)(nil): true,
}
walk(x, before, after, seen)
} | go | func Walk(x Syntax, before, after func(Syntax)) {
seen := map[Syntax]bool{
nil: true,
(*Decl)(nil): true,
(*Init)(nil): true,
(*Type)(nil): true,
(*Expr)(nil): true,
(*Stmt)(nil): true,
(*Label)(nil): true,
}
walk(x, before, after, seen)
} | [
"func",
"Walk",
"(",
"x",
"Syntax",
",",
"before",
",",
"after",
"func",
"(",
"Syntax",
")",
")",
"{",
"seen",
":=",
"map",
"[",
"Syntax",
"]",
"bool",
"{",
"nil",
":",
"true",
",",
"(",
"*",
"Decl",
")",
"(",
"nil",
")",
":",
"true",
",",
"(... | // Walk traverses the syntax x, calling before and after on entry to and exit from
// each Syntax encountered during the traversal. In case of cross-linked input,
// the traversal never visits a given Syntax more than once. | [
"Walk",
"traverses",
"the",
"syntax",
"x",
"calling",
"before",
"and",
"after",
"on",
"entry",
"to",
"and",
"exit",
"from",
"each",
"Syntax",
"encountered",
"during",
"the",
"traversal",
".",
"In",
"case",
"of",
"cross",
"-",
"linked",
"input",
"the",
"tra... | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cc/expr.go#L181-L192 |
140,078 | rsc/rsc | fuse/tree.go | Add | func (t *Tree) Add(path string, node Node) {
path = pathpkg.Clean("/" + path)[1:]
elems := strings.Split(path, "/")
dir := Node(&t.tree)
for i, elem := range elems {
dt, ok := dir.(*tree)
if !ok {
panic("fuse: Tree.Add for " + strings.Join(elems[:i], "/") + " and " + path)
}
n := dt.lookup(elem)
if n !... | go | func (t *Tree) Add(path string, node Node) {
path = pathpkg.Clean("/" + path)[1:]
elems := strings.Split(path, "/")
dir := Node(&t.tree)
for i, elem := range elems {
dt, ok := dir.(*tree)
if !ok {
panic("fuse: Tree.Add for " + strings.Join(elems[:i], "/") + " and " + path)
}
n := dt.lookup(elem)
if n !... | [
"func",
"(",
"t",
"*",
"Tree",
")",
"Add",
"(",
"path",
"string",
",",
"node",
"Node",
")",
"{",
"path",
"=",
"pathpkg",
".",
"Clean",
"(",
"\"",
"\"",
"+",
"path",
")",
"[",
"1",
":",
"]",
"\n",
"elems",
":=",
"strings",
".",
"Split",
"(",
"... | // Add adds the path to the tree, resolving to the given node.
// If path or a prefix of path has already been added to the tree,
// Add panics. | [
"Add",
"adds",
"the",
"path",
"to",
"the",
"tree",
"resolving",
"to",
"the",
"given",
"node",
".",
"If",
"path",
"or",
"a",
"prefix",
"of",
"path",
"has",
"already",
"been",
"added",
"to",
"the",
"tree",
"Add",
"panics",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/fuse/tree.go#L27-L51 |
140,079 | rsc/rsc | cloudprint/rpc.go | AuthUser | func AuthUser(auth Auth) (Auth, error) {
// TODO: Stop using package log, package httptest.
config := &oauth.Config{
ClientId: auth.APIClientID,
ClientSecret: auth.APIClientSecret,
Scope: "https://www.googleapis.com/auth/cloudprint https://www.googleapis.com/auth/googletalk",
AuthURL: "https:/... | go | func AuthUser(auth Auth) (Auth, error) {
// TODO: Stop using package log, package httptest.
config := &oauth.Config{
ClientId: auth.APIClientID,
ClientSecret: auth.APIClientSecret,
Scope: "https://www.googleapis.com/auth/cloudprint https://www.googleapis.com/auth/googletalk",
AuthURL: "https:/... | [
"func",
"AuthUser",
"(",
"auth",
"Auth",
")",
"(",
"Auth",
",",
"error",
")",
"{",
"// TODO: Stop using package log, package httptest.",
"config",
":=",
"&",
"oauth",
".",
"Config",
"{",
"ClientId",
":",
"auth",
".",
"APIClientID",
",",
"ClientSecret",
":",
"a... | // AuthUser launches a web browser to ask the user to authenticate
// and records the resulting token. | [
"AuthUser",
"launches",
"a",
"web",
"browser",
"to",
"ask",
"the",
"user",
"to",
"authenticate",
"and",
"records",
"the",
"resulting",
"token",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/rpc.go#L179-L232 |
140,080 | rsc/rsc | crypt/crypt.go | deriveKey | func deriveKey(password string, salt []byte) (aesKey, hmacKey, keyHash []byte) {
const keySize = 16
key := pbkdf2.Key([]byte(password), salt, 4096, 2*keySize, sha1.New)
aesKey = key[:keySize]
hmacKey = key[keySize:]
h := sha1.New()
h.Write(key)
keyHash = h.Sum(nil)[:4]
return
} | go | func deriveKey(password string, salt []byte) (aesKey, hmacKey, keyHash []byte) {
const keySize = 16
key := pbkdf2.Key([]byte(password), salt, 4096, 2*keySize, sha1.New)
aesKey = key[:keySize]
hmacKey = key[keySize:]
h := sha1.New()
h.Write(key)
keyHash = h.Sum(nil)[:4]
return
} | [
"func",
"deriveKey",
"(",
"password",
"string",
",",
"salt",
"[",
"]",
"byte",
")",
"(",
"aesKey",
",",
"hmacKey",
",",
"keyHash",
"[",
"]",
"byte",
")",
"{",
"const",
"keySize",
"=",
"16",
"\n",
"key",
":=",
"pbkdf2",
".",
"Key",
"(",
"[",
"]",
... | // deriveKey returns the AES key, HMAC-SHA1 key, and key hash for
// the given password, salt combination. | [
"deriveKey",
"returns",
"the",
"AES",
"key",
"HMAC",
"-",
"SHA1",
"key",
"and",
"key",
"hash",
"for",
"the",
"given",
"password",
"salt",
"combination",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/crypt/crypt.go#L33-L42 |
140,081 | rsc/rsc | crypt/crypt.go | Encrypt | func Encrypt(password string, plaintext []byte) (encrypted []byte, err error) {
// Derive key material from password and salt.
salt := make([]byte, 8)
_, err = io.ReadFull(rand.Reader, salt)
if err != nil {
return nil, err
}
aesKey, hmacKey, keyHash := deriveKey(password, salt)
// Pad.
n := aes.BlockSize - l... | go | func Encrypt(password string, plaintext []byte) (encrypted []byte, err error) {
// Derive key material from password and salt.
salt := make([]byte, 8)
_, err = io.ReadFull(rand.Reader, salt)
if err != nil {
return nil, err
}
aesKey, hmacKey, keyHash := deriveKey(password, salt)
// Pad.
n := aes.BlockSize - l... | [
"func",
"Encrypt",
"(",
"password",
"string",
",",
"plaintext",
"[",
"]",
"byte",
")",
"(",
"encrypted",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"// Derive key material from password and salt.",
"salt",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"8... | // Encrypt encrypts the plaintext into an encrypted packet
// using the given password. The password is required for
// decryption. | [
"Encrypt",
"encrypts",
"the",
"plaintext",
"into",
"an",
"encrypted",
"packet",
"using",
"the",
"given",
"password",
".",
"The",
"password",
"is",
"required",
"for",
"decryption",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/crypt/crypt.go#L47-L93 |
140,082 | rsc/rsc | crypt/crypt.go | Decrypt | func Decrypt(password string, encrypted []byte) (plaintext []byte, err error) {
// Pull apart packet.
pkt := encrypted
if len(pkt) < 1+8+4+2*aes.BlockSize+sha1.Size {
return nil, fmt.Errorf("encrypted packet too short")
}
vers, pkt := pkt[:1], pkt[1:]
salt, pkt := pkt[:8], pkt[8:]
hash, pkt := pkt[:4], pkt[4:]... | go | func Decrypt(password string, encrypted []byte) (plaintext []byte, err error) {
// Pull apart packet.
pkt := encrypted
if len(pkt) < 1+8+4+2*aes.BlockSize+sha1.Size {
return nil, fmt.Errorf("encrypted packet too short")
}
vers, pkt := pkt[:1], pkt[1:]
salt, pkt := pkt[:8], pkt[8:]
hash, pkt := pkt[:4], pkt[4:]... | [
"func",
"Decrypt",
"(",
"password",
"string",
",",
"encrypted",
"[",
"]",
"byte",
")",
"(",
"plaintext",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"// Pull apart packet.",
"pkt",
":=",
"encrypted",
"\n",
"if",
"len",
"(",
"pkt",
")",
"<",
"1",
... | // Decrypt decrypts the encrypted packet using the given password.
// It returns the decrypted data. | [
"Decrypt",
"decrypts",
"the",
"encrypted",
"packet",
"using",
"the",
"given",
"password",
".",
"It",
"returns",
"the",
"decrypted",
"data",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/crypt/crypt.go#L97-L150 |
140,083 | rsc/rsc | c2go/main.go | rewriteTypes | func rewriteTypes(prog cc.Syntax) {
// Assign overrides to groups.
cc.Postorder(prog, func(x cc.Syntax) {
if d, ok := x.(*cc.Decl); ok {
key := declKey(d)
t := override[key]
if t == nil {
return
}
if t.Kind == cc.Array {
// Override only applies to specific decl. Skip for now.
return
}... | go | func rewriteTypes(prog cc.Syntax) {
// Assign overrides to groups.
cc.Postorder(prog, func(x cc.Syntax) {
if d, ok := x.(*cc.Decl); ok {
key := declKey(d)
t := override[key]
if t == nil {
return
}
if t.Kind == cc.Array {
// Override only applies to specific decl. Skip for now.
return
}... | [
"func",
"rewriteTypes",
"(",
"prog",
"cc",
".",
"Syntax",
")",
"{",
"// Assign overrides to groups.",
"cc",
".",
"Postorder",
"(",
"prog",
",",
"func",
"(",
"x",
"cc",
".",
"Syntax",
")",
"{",
"if",
"d",
",",
"ok",
":=",
"x",
".",
"(",
"*",
"cc",
"... | // Rewrite C types to be Go types. | [
"Rewrite",
"C",
"types",
"to",
"be",
"Go",
"types",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/c2go/main.go#L166-L353 |
140,084 | rsc/rsc | c2go/main.go | fixGoTypes | func fixGoTypes(prog *cc.Prog) {
did := make(map[*cc.Decl]bool)
for _, decl := range prog.Decls {
if did[decl] {
continue
}
did[decl] = true
if decl.Init != nil {
fixGoTypesInit(decl, decl.Init)
}
if decl.Body != nil {
t := decl.Type
if t != nil && t.Kind == cc.Func && t.Base.Is(c2go.Int) && l... | go | func fixGoTypes(prog *cc.Prog) {
did := make(map[*cc.Decl]bool)
for _, decl := range prog.Decls {
if did[decl] {
continue
}
did[decl] = true
if decl.Init != nil {
fixGoTypesInit(decl, decl.Init)
}
if decl.Body != nil {
t := decl.Type
if t != nil && t.Kind == cc.Func && t.Base.Is(c2go.Int) && l... | [
"func",
"fixGoTypes",
"(",
"prog",
"*",
"cc",
".",
"Prog",
")",
"{",
"did",
":=",
"make",
"(",
"map",
"[",
"*",
"cc",
".",
"Decl",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"decl",
":=",
"range",
"prog",
".",
"Decls",
"{",
"if",
"did",
"[",
"d... | // fixGoTypes fixes all the Go type mismatches. | [
"fixGoTypes",
"fixes",
"all",
"the",
"Go",
"type",
"mismatches",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/c2go/main.go#L498-L516 |
140,085 | rsc/rsc | qr/web/pic.go | Frames | func Frames(w http.ResponseWriter, req *http.Request) {
vs := strings.Split(req.FormValue("v"), ",")
arg := func(s string) int { x, _ := strconv.Atoi(req.FormValue(s)); return x }
scale := arg("scale")
if scale == 0 {
scale = 8
}
font := req.FormValue("font")
pt := arg("pt")
dots := arg("dots")
var images ... | go | func Frames(w http.ResponseWriter, req *http.Request) {
vs := strings.Split(req.FormValue("v"), ",")
arg := func(s string) int { x, _ := strconv.Atoi(req.FormValue(s)); return x }
scale := arg("scale")
if scale == 0 {
scale = 8
}
font := req.FormValue("font")
pt := arg("pt")
dots := arg("dots")
var images ... | [
"func",
"Frames",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"vs",
":=",
"strings",
".",
"Split",
"(",
"req",
".",
"FormValue",
"(",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\n\n",
"arg",
":=",
"fun... | // Frames handles a request for multiple QR frames. | [
"Frames",
"handles",
"a",
"request",
"for",
"multiple",
"QR",
"frames",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/qr/web/pic.go#L233-L293 |
140,086 | rsc/rsc | qr/web/pic.go | Mask | func Mask(w http.ResponseWriter, req *http.Request) {
arg := func(s string) int { x, _ := strconv.Atoi(req.FormValue(s)); return x }
v := arg("v")
m := arg("m")
scale := arg("scale")
if scale == 0 {
scale = 8
}
w.Header().Set("Cache-Control", "public, max-age=3600")
w.Write(pngEncode(makeMask(req, req.FormVa... | go | func Mask(w http.ResponseWriter, req *http.Request) {
arg := func(s string) int { x, _ := strconv.Atoi(req.FormValue(s)); return x }
v := arg("v")
m := arg("m")
scale := arg("scale")
if scale == 0 {
scale = 8
}
w.Header().Set("Cache-Control", "public, max-age=3600")
w.Write(pngEncode(makeMask(req, req.FormVa... | [
"func",
"Mask",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"arg",
":=",
"func",
"(",
"s",
"string",
")",
"int",
"{",
"x",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"req",
".",
"FormValue",
"(",
... | // Mask handles a request for a single QR mask. | [
"Mask",
"handles",
"a",
"request",
"for",
"a",
"single",
"QR",
"mask",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/qr/web/pic.go#L296-L307 |
140,087 | rsc/rsc | qr/web/pic.go | Masks | func Masks(w http.ResponseWriter, req *http.Request) {
arg := func(s string) int { x, _ := strconv.Atoi(req.FormValue(s)); return x }
v := arg("v")
scale := arg("scale")
if scale == 0 {
scale = 8
}
font := req.FormValue("font")
pt := arg("pt")
var mm []image.Image
for m := 0; m < 8; m++ {
mm = append(mm, m... | go | func Masks(w http.ResponseWriter, req *http.Request) {
arg := func(s string) int { x, _ := strconv.Atoi(req.FormValue(s)); return x }
v := arg("v")
scale := arg("scale")
if scale == 0 {
scale = 8
}
font := req.FormValue("font")
pt := arg("pt")
var mm []image.Image
for m := 0; m < 8; m++ {
mm = append(mm, m... | [
"func",
"Masks",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"arg",
":=",
"func",
"(",
"s",
"string",
")",
"int",
"{",
"x",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"req",
".",
"FormValue",
"(",... | // Masks handles a request for multiple QR masks. | [
"Masks",
"handles",
"a",
"request",
"for",
"multiple",
"QR",
"masks",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/qr/web/pic.go#L310-L339 |
140,088 | rsc/rsc | qr/web/pic.go | Encode | func Encode(w http.ResponseWriter, req *http.Request) {
val := func(s string) int {
v, _ := strconv.Atoi(req.FormValue(s))
return v
}
l := coding.Level(val("l"))
v := coding.Version(val("v"))
enc := coding.String(req.FormValue("t"))
m := coding.Mask(val("m"))
p, err := coding.NewPlan(v, l, m)
if err != ni... | go | func Encode(w http.ResponseWriter, req *http.Request) {
val := func(s string) int {
v, _ := strconv.Atoi(req.FormValue(s))
return v
}
l := coding.Level(val("l"))
v := coding.Version(val("v"))
enc := coding.String(req.FormValue("t"))
m := coding.Mask(val("m"))
p, err := coding.NewPlan(v, l, m)
if err != ni... | [
"func",
"Encode",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"val",
":=",
"func",
"(",
"s",
"string",
")",
"int",
"{",
"v",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"req",
".",
"FormValue",
"("... | // Encode encodes a string using the given version, level, and mask. | [
"Encode",
"encodes",
"a",
"string",
"using",
"the",
"given",
"version",
"level",
"and",
"mask",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/qr/web/pic.go#L481-L505 |
140,089 | rsc/rsc | c2go/write.go | fprintf | func fprintf(span cc.Span, format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
fmt.Fprintf(os.Stderr, "%s:%d: %s\n", span.Start.File, span.Start.Line, msg)
} | go | func fprintf(span cc.Span, format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
fmt.Fprintf(os.Stderr, "%s:%d: %s\n", span.Start.File, span.Start.Line, msg)
} | [
"func",
"fprintf",
"(",
"span",
"cc",
".",
"Span",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"args",
"...",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"os",
"... | // print an error; fprintf is a bad name but helps go vet. | [
"print",
"an",
"error",
";",
"fprintf",
"is",
"a",
"bad",
"name",
"but",
"helps",
"go",
"vet",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/c2go/write.go#L20-L23 |
140,090 | rsc/rsc | c2go/write.go | write | func write(prog *cc.Prog, filenames []string, cfg *Config) {
files := map[string]*outFile{}
havePkg := map[string]bool{}
for _, decl := range prog.Decls {
if decl.GoPackage == "" {
pkg := findPkg(cfg, decl.Span.Start.File)
if pkg == "" {
continue
}
decl.GoPackage = pkg
}
file := decl.Span.Start... | go | func write(prog *cc.Prog, filenames []string, cfg *Config) {
files := map[string]*outFile{}
havePkg := map[string]bool{}
for _, decl := range prog.Decls {
if decl.GoPackage == "" {
pkg := findPkg(cfg, decl.Span.Start.File)
if pkg == "" {
continue
}
decl.GoPackage = pkg
}
file := decl.Span.Start... | [
"func",
"write",
"(",
"prog",
"*",
"cc",
".",
"Prog",
",",
"filenames",
"[",
"]",
"string",
",",
"cfg",
"*",
"Config",
")",
"{",
"files",
":=",
"map",
"[",
"string",
"]",
"*",
"outFile",
"{",
"}",
"\n",
"havePkg",
":=",
"map",
"[",
"string",
"]",... | // write actual output | [
"write",
"actual",
"output"
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/c2go/write.go#L30-L102 |
140,091 | rsc/rsc | cloudprint/print.go | CreateOpenPrinter | func CreateOpenPrinter(auth Auth, info *PrinterInfo) (*OpenPrinter, error) {
var mr multipartRequest
mr.init()
mr.WriteField("printer", info.Name)
w, _ := mr.CreateFormFile("capabilities", "capabilities")
cap := info.Capabilities
if cap == nil {
cap = []byte(defaultPPD)
}
w.Write(cap)
var resp registerRespo... | go | func CreateOpenPrinter(auth Auth, info *PrinterInfo) (*OpenPrinter, error) {
var mr multipartRequest
mr.init()
mr.WriteField("printer", info.Name)
w, _ := mr.CreateFormFile("capabilities", "capabilities")
cap := info.Capabilities
if cap == nil {
cap = []byte(defaultPPD)
}
w.Write(cap)
var resp registerRespo... | [
"func",
"CreateOpenPrinter",
"(",
"auth",
"Auth",
",",
"info",
"*",
"PrinterInfo",
")",
"(",
"*",
"OpenPrinter",
",",
"error",
")",
"{",
"var",
"mr",
"multipartRequest",
"\n",
"mr",
".",
"init",
"(",
")",
"\n",
"mr",
".",
"WriteField",
"(",
"\"",
"\"",... | // CreateOpenPrinter registers a new open printer with Google.
//
// Only the ClientID, ClientSecret, and ProxyID fields need to be set in auth.
// The Token and TokenUser fields in the auth are ignored. | [
"CreateOpenPrinter",
"registers",
"a",
"new",
"open",
"printer",
"with",
"Google",
".",
"Only",
"the",
"ClientID",
"ClientSecret",
"and",
"ProxyID",
"fields",
"need",
"to",
"be",
"set",
"in",
"auth",
".",
"The",
"Token",
"and",
"TokenUser",
"fields",
"in",
"... | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L201-L226 |
140,092 | rsc/rsc | cloudprint/print.go | ClaimPDF | func (p *OpenPrinter) ClaimPDF() ([]byte, error) {
data, err := httpGET(&p.auth, p.register.InvitePageURL)
if err != nil {
return nil, fmt.Errorf("ClaimPDF: %v", err)
}
return data, nil
} | go | func (p *OpenPrinter) ClaimPDF() ([]byte, error) {
data, err := httpGET(&p.auth, p.register.InvitePageURL)
if err != nil {
return nil, fmt.Errorf("ClaimPDF: %v", err)
}
return data, nil
} | [
"func",
"(",
"p",
"*",
"OpenPrinter",
")",
"ClaimPDF",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"httpGET",
"(",
"&",
"p",
".",
"auth",
",",
"p",
".",
"register",
".",
"InvitePageURL",
")",
"\n",
"if",
"... | // ClaimPDF returns the content of a PDF of instructions
// that can be printed and given to a prospective owner to claim the printer. | [
"ClaimPDF",
"returns",
"the",
"content",
"of",
"a",
"PDF",
"of",
"instructions",
"that",
"can",
"be",
"printed",
"and",
"given",
"to",
"a",
"prospective",
"owner",
"to",
"claim",
"the",
"printer",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L230-L236 |
140,093 | rsc/rsc | cloudprint/print.go | ClaimURL | func (p *OpenPrinter) ClaimURL() string {
// The current implementation returns http://goo.gl/ URLs.
// Return https://goo.gl/ URLs instead.
url := p.register.CompleteInviteURL
if strings.HasPrefix(url, "http://goo.gl") {
url = "https" + url[4:]
}
return url
} | go | func (p *OpenPrinter) ClaimURL() string {
// The current implementation returns http://goo.gl/ URLs.
// Return https://goo.gl/ URLs instead.
url := p.register.CompleteInviteURL
if strings.HasPrefix(url, "http://goo.gl") {
url = "https" + url[4:]
}
return url
} | [
"func",
"(",
"p",
"*",
"OpenPrinter",
")",
"ClaimURL",
"(",
")",
"string",
"{",
"// The current implementation returns http://goo.gl/ URLs.",
"// Return https://goo.gl/ URLs instead.",
"url",
":=",
"p",
".",
"register",
".",
"CompleteInviteURL",
"\n",
"if",
"strings",
"... | // ClaimURL returns a URL that a prospective owner can visit
// to claim the printer. | [
"ClaimURL",
"returns",
"a",
"URL",
"that",
"a",
"prospective",
"owner",
"can",
"visit",
"to",
"claim",
"the",
"printer",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L240-L248 |
140,094 | rsc/rsc | cloudprint/print.go | VerifyClaim | func (p *OpenPrinter) VerifyClaim() error {
if p.verify != nil {
return nil
}
var resp verifyResponse
if err := jsonRPC(&p.auth, "GET", p.register.PollingURL+p.auth.APIClientID, nil, &resp); err != nil {
return fmt.Errorf("VerifyClaim: %v", err)
}
var tr oauth.Transport
tr.Config = &oauth.Config{
ClientI... | go | func (p *OpenPrinter) VerifyClaim() error {
if p.verify != nil {
return nil
}
var resp verifyResponse
if err := jsonRPC(&p.auth, "GET", p.register.PollingURL+p.auth.APIClientID, nil, &resp); err != nil {
return fmt.Errorf("VerifyClaim: %v", err)
}
var tr oauth.Transport
tr.Config = &oauth.Config{
ClientI... | [
"func",
"(",
"p",
"*",
"OpenPrinter",
")",
"VerifyClaim",
"(",
")",
"error",
"{",
"if",
"p",
".",
"verify",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"resp",
"verifyResponse",
"\n",
"if",
"err",
":=",
"jsonRPC",
"(",
"&",
"p",
".... | // VerifyClaim checks that the printer has been claimed.
// If the printer is claimed, VerifyClaim returns no error.
// If the printer is unclaimed, VerifyClaim retruns ErrUnclaimed.
// It is possible for VerifyClaim to return other errors, such as
// in the case of network problems.
//
// A side effect of verifying th... | [
"VerifyClaim",
"checks",
"that",
"the",
"printer",
"has",
"been",
"claimed",
".",
"If",
"the",
"printer",
"is",
"claimed",
"VerifyClaim",
"returns",
"no",
"error",
".",
"If",
"the",
"printer",
"is",
"unclaimed",
"VerifyClaim",
"retruns",
"ErrUnclaimed",
".",
"... | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L264-L293 |
140,095 | rsc/rsc | cloudprint/print.go | ConfirmationPDF | func (p *OpenPrinter) ConfirmationPDF() ([]byte, error) {
if p.verify == nil {
return nil, fmt.Errorf("ConfirmationPDF: VerifyClaim has not succeeded")
}
data, err := httpGET(&p.auth, p.verify.ConfirmationPageURL)
if err != nil {
return nil, fmt.Errorf("ConfirmationPDF: %v", err)
}
return data, nil
} | go | func (p *OpenPrinter) ConfirmationPDF() ([]byte, error) {
if p.verify == nil {
return nil, fmt.Errorf("ConfirmationPDF: VerifyClaim has not succeeded")
}
data, err := httpGET(&p.auth, p.verify.ConfirmationPageURL)
if err != nil {
return nil, fmt.Errorf("ConfirmationPDF: %v", err)
}
return data, nil
} | [
"func",
"(",
"p",
"*",
"OpenPrinter",
")",
"ConfirmationPDF",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"p",
".",
"verify",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n"... | // ConfirmationPDF returns the content of a PDF that can be printed
// to confirm to the owner that the printer has been claimed. | [
"ConfirmationPDF",
"returns",
"the",
"content",
"of",
"a",
"PDF",
"that",
"can",
"be",
"printed",
"to",
"confirm",
"to",
"the",
"owner",
"that",
"the",
"printer",
"has",
"been",
"claimed",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L297-L306 |
140,096 | rsc/rsc | cloudprint/print.go | Auth | func (p *OpenPrinter) Auth() Auth {
if p.verify == nil {
panic(fmt.Errorf("Auth: VerifyClaim has not succeeded"))
}
return p.auth
} | go | func (p *OpenPrinter) Auth() Auth {
if p.verify == nil {
panic(fmt.Errorf("Auth: VerifyClaim has not succeeded"))
}
return p.auth
} | [
"func",
"(",
"p",
"*",
"OpenPrinter",
")",
"Auth",
"(",
")",
"Auth",
"{",
"if",
"p",
".",
"verify",
"==",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"return",
"p",
".",
"auth",
"\n",
"}"
] | // Auth returns a credential that can be used to manage this printer
// in future invocations of the program.
//
// Auth must be called only after VerifyClaim has succeeded. | [
"Auth",
"returns",
"a",
"credential",
"that",
"can",
"be",
"used",
"to",
"manage",
"this",
"printer",
"in",
"future",
"invocations",
"of",
"the",
"program",
".",
"Auth",
"must",
"be",
"called",
"only",
"after",
"VerifyClaim",
"has",
"succeeded",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L312-L317 |
140,097 | rsc/rsc | cloudprint/print.go | NewServer | func NewServer(auth Auth) (*Server, error) {
srv := &Server{
auth: auth,
}
return srv, nil
} | go | func NewServer(auth Auth) (*Server, error) {
srv := &Server{
auth: auth,
}
return srv, nil
} | [
"func",
"NewServer",
"(",
"auth",
"Auth",
")",
"(",
"*",
"Server",
",",
"error",
")",
"{",
"srv",
":=",
"&",
"Server",
"{",
"auth",
":",
"auth",
",",
"}",
"\n",
"return",
"srv",
",",
"nil",
"\n",
"}"
] | // NewServer returns a print server managing the printers owned
// by the user denoted by the auth token. | [
"NewServer",
"returns",
"a",
"print",
"server",
"managing",
"the",
"printers",
"owned",
"by",
"the",
"user",
"denoted",
"by",
"the",
"auth",
"token",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L359-L364 |
140,098 | rsc/rsc | cloudprint/print.go | DeletePrinter | func (s *Server) DeletePrinter(p *Printer) error {
var mr multipartRequest
mr.init()
mr.WriteField("printerid", p.ID)
err := jsonRPC(&s.auth, "POST", cloudprintURL+"/delete", &mr, nil)
if err != nil {
return fmt.Errorf("DeletePrinter: %v", err)
}
return nil
} | go | func (s *Server) DeletePrinter(p *Printer) error {
var mr multipartRequest
mr.init()
mr.WriteField("printerid", p.ID)
err := jsonRPC(&s.auth, "POST", cloudprintURL+"/delete", &mr, nil)
if err != nil {
return fmt.Errorf("DeletePrinter: %v", err)
}
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"DeletePrinter",
"(",
"p",
"*",
"Printer",
")",
"error",
"{",
"var",
"mr",
"multipartRequest",
"\n",
"mr",
".",
"init",
"(",
")",
"\n",
"mr",
".",
"WriteField",
"(",
"\"",
"\"",
",",
"p",
".",
"ID",
")",
"\n\... | // DeletePrinter deletes the given printer. | [
"DeletePrinter",
"deletes",
"the",
"given",
"printer",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L403-L413 |
140,099 | rsc/rsc | cloudprint/print.go | Printers | func (s *Server) Printers() ([]*Printer, error) {
var mr multipartRequest
mr.init()
var resp printersResponse
err := jsonRPC(&s.auth, "POST", cloudprintURL+"/list", &mr, &resp)
if err != nil {
return nil, fmt.Errorf("Printers: %v", err)
}
var list []*Printer
for _, desc := range resp.Printers {
list = app... | go | func (s *Server) Printers() ([]*Printer, error) {
var mr multipartRequest
mr.init()
var resp printersResponse
err := jsonRPC(&s.auth, "POST", cloudprintURL+"/list", &mr, &resp)
if err != nil {
return nil, fmt.Errorf("Printers: %v", err)
}
var list []*Printer
for _, desc := range resp.Printers {
list = app... | [
"func",
"(",
"s",
"*",
"Server",
")",
"Printers",
"(",
")",
"(",
"[",
"]",
"*",
"Printer",
",",
"error",
")",
"{",
"var",
"mr",
"multipartRequest",
"\n",
"mr",
".",
"init",
"(",
")",
"\n\n",
"var",
"resp",
"printersResponse",
"\n",
"err",
":=",
"js... | // Printers returns a list of printers managed by this server. | [
"Printers",
"returns",
"a",
"list",
"of",
"printers",
"managed",
"by",
"this",
"server",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L416-L431 |
Subsets and Splits
SQL Console for google/code_x_glue_ct_code_to_text
This query implements a thoughtful three-tier curation strategy to build a balanced safety dataset, categorizing code by destructive operations, safe I/O operations, and pure computational negatives with subsampling—revealing important patterns about how destructive intent manifests in Python code for model safety research.
SQL Console for google/code_x_glue_ct_code_to_text
This query performs meaningful classification of Python code samples into safety-relevant tiers based on destructive operations, I/O patterns, and pure computation, which could be valuable for building safety classifiers or curating training data, though the output itself is a filtered/ranked dataset rather than revealing novel statistical insights.