id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
18,000 | 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 |
18,001 | 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 |
18,002 | 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 |
18,003 | 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 |
18,004 | 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 |
18,005 | 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 |
18,006 | 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 |
18,007 | 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 |
18,008 | 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 |
18,009 | 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 |
18,010 | 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 |
18,011 | 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 |
18,012 | 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 |
18,013 | 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 |
18,014 | 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 |
18,015 | 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 |
18,016 | 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 |
18,017 | 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 |
18,018 | 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 |
18,019 | 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 |
18,020 | 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 |
18,021 | 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 |
18,022 | 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 |
18,023 | 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 |
18,024 | 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 |
18,025 | 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 |
18,026 | 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 |
18,027 | 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 |
18,028 | 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 |
18,029 | 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 |
18,030 | 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 |
18,031 | 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 |
18,032 | 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 |
18,033 | 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 |
18,034 | 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 |
18,035 | 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 |
18,036 | 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 |
18,037 | 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 |
18,038 | 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 |
18,039 | 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 |
18,040 | 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 |
18,041 | 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 |
18,042 | 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 |
18,043 | 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 |
18,044 | 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 |
18,045 | 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 |
18,046 | 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 |
18,047 | 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 |
18,048 | 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 |
18,049 | 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 |
18,050 | 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 |
18,051 | 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 |
18,052 | 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 |
18,053 | 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 |
18,054 | 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 |
18,055 | 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 |
18,056 | 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 |
18,057 | 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 |
18,058 | 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 |
18,059 | 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 |
18,060 | 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 |
18,061 | 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 |
18,062 | 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 |
18,063 | 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 |
18,064 | 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 |
18,065 | 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 |
18,066 | 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 |
18,067 | 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 |
18,068 | 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 |
18,069 | 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 |
18,070 | 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 |
18,071 | 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 |
18,072 | 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 |
18,073 | 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 |
18,074 | 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 |
18,075 | 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 |
18,076 | 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 |
18,077 | 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 |
18,078 | 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 |
18,079 | 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 |
18,080 | 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 |
18,081 | 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 |
18,082 | 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 |
18,083 | 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 |
18,084 | rsc/rsc | cloudprint/print.go | UpdateJob | func (s *Server) UpdateJob(j *Job, status JobStatus, code int, message string) error {
var mr multipartRequest
mr.init()
mr.WriteField("jobid", j.ID)
mr.WriteField("printerid", j.PrinterID)
mr.WriteField("status", string(status))
if status == JobError {
mr.WriteField("code", fmt.Sprint(code))
mr.WriteField("m... | go | func (s *Server) UpdateJob(j *Job, status JobStatus, code int, message string) error {
var mr multipartRequest
mr.init()
mr.WriteField("jobid", j.ID)
mr.WriteField("printerid", j.PrinterID)
mr.WriteField("status", string(status))
if status == JobError {
mr.WriteField("code", fmt.Sprint(code))
mr.WriteField("m... | [
"func",
"(",
"s",
"*",
"Server",
")",
"UpdateJob",
"(",
"j",
"*",
"Job",
",",
"status",
"JobStatus",
",",
"code",
"int",
",",
"message",
"string",
")",
"error",
"{",
"var",
"mr",
"multipartRequest",
"\n",
"mr",
".",
"init",
"(",
")",
"\n",
"mr",
".... | // UpdateJob updates information about the given job.
// The only field that is stored back to the server is j.Status. | [
"UpdateJob",
"updates",
"information",
"about",
"the",
"given",
"job",
".",
"The",
"only",
"field",
"that",
"is",
"stored",
"back",
"to",
"the",
"server",
"is",
"j",
".",
"Status",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L460-L476 |
18,085 | rsc/rsc | cloudprint/print.go | ReadFile | func (s *Server) ReadFile(j *Job) ([]byte, error) {
data, err := httpGET(&s.auth, j.FileURL)
if err != nil {
return nil, fmt.Errorf("ReadFile: %v", err)
}
return data, nil
} | go | func (s *Server) ReadFile(j *Job) ([]byte, error) {
data, err := httpGET(&s.auth, j.FileURL)
if err != nil {
return nil, fmt.Errorf("ReadFile: %v", err)
}
return data, nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"ReadFile",
"(",
"j",
"*",
"Job",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"httpGET",
"(",
"&",
"s",
".",
"auth",
",",
"j",
".",
"FileURL",
")",
"\n",
"if",
"err",
"... | // ReadFile reads the raw data to be printed by the given job. | [
"ReadFile",
"reads",
"the",
"raw",
"data",
"to",
"be",
"printed",
"by",
"the",
"given",
"job",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L479-L485 |
18,086 | rsc/rsc | cloudprint/print.go | NewClient | func NewClient(auth Auth) (*Client, error) {
c := &Client{
auth: auth,
}
return c, nil
} | go | func NewClient(auth Auth) (*Client, error) {
c := &Client{
auth: auth,
}
return c, nil
} | [
"func",
"NewClient",
"(",
"auth",
"Auth",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"c",
":=",
"&",
"Client",
"{",
"auth",
":",
"auth",
",",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // NewClient returns a new client using the given auth information. | [
"NewClient",
"returns",
"a",
"new",
"client",
"using",
"the",
"given",
"auth",
"information",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L493-L498 |
18,087 | rsc/rsc | cloudprint/print.go | Search | func (c *Client) Search(query string, all bool) ([]*Printer, error) {
var mr multipartRequest
mr.init()
if query != "" {
mr.WriteField("q", query)
}
if all {
mr.WriteField("connection_status", "ALL")
}
var resp printersResponse
err := jsonRPC(&c.auth, "POST", cloudprintURL+"/search", &mr, &resp)
if err != ... | go | func (c *Client) Search(query string, all bool) ([]*Printer, error) {
var mr multipartRequest
mr.init()
if query != "" {
mr.WriteField("q", query)
}
if all {
mr.WriteField("connection_status", "ALL")
}
var resp printersResponse
err := jsonRPC(&c.auth, "POST", cloudprintURL+"/search", &mr, &resp)
if err != ... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Search",
"(",
"query",
"string",
",",
"all",
"bool",
")",
"(",
"[",
"]",
"*",
"Printer",
",",
"error",
")",
"{",
"var",
"mr",
"multipartRequest",
"\n",
"mr",
".",
"init",
"(",
")",
"\n",
"if",
"query",
"!=",... | // Search searches for printers the client can use.
// The query can be empty to return all printers.
// By default only printers that have been online recently are returned.
// To return all printers, pass all = true. | [
"Search",
"searches",
"for",
"printers",
"the",
"client",
"can",
"use",
".",
"The",
"query",
"can",
"be",
"empty",
"to",
"return",
"all",
"printers",
".",
"By",
"default",
"only",
"printers",
"that",
"have",
"been",
"online",
"recently",
"are",
"returned",
... | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L504-L523 |
18,088 | rsc/rsc | cloudprint/print.go | Printer | func (c *Client) Printer(id string) (*Printer, error) {
var mr multipartRequest
mr.init()
mr.WriteField("printerid", id)
mr.WriteField("printer_connection_Status", "true")
var resp printersResponse
err := jsonRPC(&c.auth, "POST", cloudprintURL+"/printer", &mr, &resp)
if err != nil {
return nil, fmt.Errorf("Pri... | go | func (c *Client) Printer(id string) (*Printer, error) {
var mr multipartRequest
mr.init()
mr.WriteField("printerid", id)
mr.WriteField("printer_connection_Status", "true")
var resp printersResponse
err := jsonRPC(&c.auth, "POST", cloudprintURL+"/printer", &mr, &resp)
if err != nil {
return nil, fmt.Errorf("Pri... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Printer",
"(",
"id",
"string",
")",
"(",
"*",
"Printer",
",",
"error",
")",
"{",
"var",
"mr",
"multipartRequest",
"\n",
"mr",
".",
"init",
"(",
")",
"\n",
"mr",
".",
"WriteField",
"(",
"\"",
"\"",
",",
"id",... | // Printer searches for the printer with the given ID. | [
"Printer",
"searches",
"for",
"the",
"printer",
"with",
"the",
"given",
"ID",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L526-L540 |
18,089 | rsc/rsc | cloudprint/print.go | DeleteJob | func (c *Client) DeleteJob(j *Job) error {
var mr multipartRequest
mr.init()
mr.WriteField("jobid", j.ID)
mr.WriteField("printerid", j.PrinterID)
err := jsonRPC(&c.auth, "POST", cloudprintURL+"/deletejob", &mr, nil)
if err != nil {
return fmt.Errorf("DeleteJob: %v", err)
}
return nil
} | go | func (c *Client) DeleteJob(j *Job) error {
var mr multipartRequest
mr.init()
mr.WriteField("jobid", j.ID)
mr.WriteField("printerid", j.PrinterID)
err := jsonRPC(&c.auth, "POST", cloudprintURL+"/deletejob", &mr, nil)
if err != nil {
return fmt.Errorf("DeleteJob: %v", err)
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DeleteJob",
"(",
"j",
"*",
"Job",
")",
"error",
"{",
"var",
"mr",
"multipartRequest",
"\n",
"mr",
".",
"init",
"(",
")",
"\n",
"mr",
".",
"WriteField",
"(",
"\"",
"\"",
",",
"j",
".",
"ID",
")",
"\n",
"mr"... | // DeleteJob deletes the given print job. | [
"DeleteJob",
"deletes",
"the",
"given",
"print",
"job",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L548-L558 |
18,090 | rsc/rsc | cloudprint/print.go | Jobs | func (c *Client) Jobs(p *Printer) ([]*Job, error) {
var mr multipartRequest
mr.init()
if p != nil {
mr.WriteField("printerid", p.ID)
}
var resp jobsResponse
err := jsonRPC(&c.auth, "POST", cloudprintURL+"/jobs", &mr, &resp)
if err != nil {
return nil, fmt.Errorf("Jobs: %v", err)
}
var jobs []*Job
for _, d... | go | func (c *Client) Jobs(p *Printer) ([]*Job, error) {
var mr multipartRequest
mr.init()
if p != nil {
mr.WriteField("printerid", p.ID)
}
var resp jobsResponse
err := jsonRPC(&c.auth, "POST", cloudprintURL+"/jobs", &mr, &resp)
if err != nil {
return nil, fmt.Errorf("Jobs: %v", err)
}
var jobs []*Job
for _, d... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Jobs",
"(",
"p",
"*",
"Printer",
")",
"(",
"[",
"]",
"*",
"Job",
",",
"error",
")",
"{",
"var",
"mr",
"multipartRequest",
"\n",
"mr",
".",
"init",
"(",
")",
"\n",
"if",
"p",
"!=",
"nil",
"{",
"mr",
".",
... | // Jobs returns a list of jobs waiting to be printed.
// If p is not nil, the list is restricted to jobs sent to the given printer. | [
"Jobs",
"returns",
"a",
"list",
"of",
"jobs",
"waiting",
"to",
"be",
"printed",
".",
"If",
"p",
"is",
"not",
"nil",
"the",
"list",
"is",
"restricted",
"to",
"jobs",
"sent",
"to",
"the",
"given",
"printer",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L562-L578 |
18,091 | rsc/rsc | cloudprint/print.go | Print | func (c *Client) Print(p *Printer, info *JobInfo, data []byte) (*Job, error) {
var mr multipartRequest
mr.init()
mr.WriteField("printerid", p.ID)
mr.WriteField("title", info.Title)
mr.WriteField("contentType", "application/pdf")
for _, tag := range info.Tags {
mr.WriteField("tag", tag)
}
cap := info.Capabilit... | go | func (c *Client) Print(p *Printer, info *JobInfo, data []byte) (*Job, error) {
var mr multipartRequest
mr.init()
mr.WriteField("printerid", p.ID)
mr.WriteField("title", info.Title)
mr.WriteField("contentType", "application/pdf")
for _, tag := range info.Tags {
mr.WriteField("tag", tag)
}
cap := info.Capabilit... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Print",
"(",
"p",
"*",
"Printer",
",",
"info",
"*",
"JobInfo",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"Job",
",",
"error",
")",
"{",
"var",
"mr",
"multipartRequest",
"\n",
"mr",
".",
"init",
"(",
")... | // Print creates a new print job printing to p with the given job information.
// The data is the raw PDF to print. | [
"Print",
"creates",
"a",
"new",
"print",
"job",
"printing",
"to",
"p",
"with",
"the",
"given",
"job",
"information",
".",
"The",
"data",
"is",
"the",
"raw",
"PDF",
"to",
"print",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cloudprint/print.go#L594-L619 |
18,092 | rsc/rsc | cc/parse.go | removeDuplicates | func removeDuplicates(prog *Prog) {
count := map[*Decl]int{}
for _, d := range prog.Decls {
count[d]++
}
var out []*Decl
for _, d := range prog.Decls {
count[d]--
if count[d] == 0 {
out = append(out, d)
}
}
prog.Decls = out
} | go | func removeDuplicates(prog *Prog) {
count := map[*Decl]int{}
for _, d := range prog.Decls {
count[d]++
}
var out []*Decl
for _, d := range prog.Decls {
count[d]--
if count[d] == 0 {
out = append(out, d)
}
}
prog.Decls = out
} | [
"func",
"removeDuplicates",
"(",
"prog",
"*",
"Prog",
")",
"{",
"count",
":=",
"map",
"[",
"*",
"Decl",
"]",
"int",
"{",
"}",
"\n",
"for",
"_",
",",
"d",
":=",
"range",
"prog",
".",
"Decls",
"{",
"count",
"[",
"d",
"]",
"++",
"\n",
"}",
"\n",
... | // removeDuplicates drops the duplicated declarations
// caused by forward decls from prog.
// It keeps the _last_ of each given declaration,
// assuming that's the complete one.
// This heuristic tends to preserve something like
// source order.
// It would be defeated by someone writing a "forward"
// declaration fol... | [
"removeDuplicates",
"drops",
"the",
"duplicated",
"declarations",
"caused",
"by",
"forward",
"decls",
"from",
"prog",
".",
"It",
"keeps",
"the",
"_last_",
"of",
"each",
"given",
"declaration",
"assuming",
"that",
"s",
"the",
"complete",
"one",
".",
"This",
"he... | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/cc/parse.go#L102-L115 |
18,093 | rsc/rsc | rosetta/maze/maze.go | move | func (m *Maze) move(x, y int, dir Dir) (nx, ny int, ok bool) {
nx = x + dirs[dir].δx
ny = y + dirs[dir].δy
ok = 0 <= nx && nx < m.w && 0 <= ny && ny < m.h
return
} | go | func (m *Maze) move(x, y int, dir Dir) (nx, ny int, ok bool) {
nx = x + dirs[dir].δx
ny = y + dirs[dir].δy
ok = 0 <= nx && nx < m.w && 0 <= ny && ny < m.h
return
} | [
"func",
"(",
"m",
"*",
"Maze",
")",
"move",
"(",
"x",
",",
"y",
"int",
",",
"dir",
"Dir",
")",
"(",
"nx",
",",
"ny",
"int",
",",
"ok",
"bool",
")",
"{",
"nx",
"=",
"x",
"+",
"dirs",
"[",
"dir",
"]",
".",
"δx",
"\n",
"ny",
"=",
"y",
"+",... | // move returns the cell in the direction dir from position r, c.
// It returns ok==false if there is no cell in that direction. | [
"move",
"returns",
"the",
"cell",
"in",
"the",
"direction",
"dir",
"from",
"position",
"r",
"c",
".",
"It",
"returns",
"ok",
"==",
"false",
"if",
"there",
"is",
"no",
"cell",
"in",
"that",
"direction",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/rosetta/maze/maze.go#L52-L57 |
18,094 | rsc/rsc | rosetta/maze/maze.go | Move | func (m *Maze) Move(x, y int, dir Dir) (nx, ny int, ok bool) {
nx, ny, ok = m.move(x, y, dir)
ok = ok && m.grid[y][x]&(1<<dir) == 0
return
} | go | func (m *Maze) Move(x, y int, dir Dir) (nx, ny int, ok bool) {
nx, ny, ok = m.move(x, y, dir)
ok = ok && m.grid[y][x]&(1<<dir) == 0
return
} | [
"func",
"(",
"m",
"*",
"Maze",
")",
"Move",
"(",
"x",
",",
"y",
"int",
",",
"dir",
"Dir",
")",
"(",
"nx",
",",
"ny",
"int",
",",
"ok",
"bool",
")",
"{",
"nx",
",",
"ny",
",",
"ok",
"=",
"m",
".",
"move",
"(",
"x",
",",
"y",
",",
"dir",
... | // Move returns the cell in the direction dir from position x, y
// It returns ok==false if there is no cell in that direction
// or if a wall blocks movement in that direction. | [
"Move",
"returns",
"the",
"cell",
"in",
"the",
"direction",
"dir",
"from",
"position",
"x",
"y",
"It",
"returns",
"ok",
"==",
"false",
"if",
"there",
"is",
"no",
"cell",
"in",
"that",
"direction",
"or",
"if",
"a",
"wall",
"blocks",
"movement",
"in",
"t... | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/rosetta/maze/maze.go#L62-L66 |
18,095 | rsc/rsc | rosetta/maze/maze.go | NewMaze | func NewMaze(w, h int) *Maze {
// Allocate one slice for the whole 2-d cell grid and break up into rows.
all := make([]walls, w*h)
for i := range all {
all[i] = allWalls
}
m := &Maze{w: w, h: h, grid: make([][]walls, h)}
for i := range m.grid {
m.grid[i], all = all[:w], all[w:]
}
// All cells start with al... | go | func NewMaze(w, h int) *Maze {
// Allocate one slice for the whole 2-d cell grid and break up into rows.
all := make([]walls, w*h)
for i := range all {
all[i] = allWalls
}
m := &Maze{w: w, h: h, grid: make([][]walls, h)}
for i := range m.grid {
m.grid[i], all = all[:w], all[w:]
}
// All cells start with al... | [
"func",
"NewMaze",
"(",
"w",
",",
"h",
"int",
")",
"*",
"Maze",
"{",
"// Allocate one slice for the whole 2-d cell grid and break up into rows.",
"all",
":=",
"make",
"(",
"[",
"]",
"walls",
",",
"w",
"*",
"h",
")",
"\n",
"for",
"i",
":=",
"range",
"all",
... | // NewMaze returns a new, randomly generated maze
// of width w and height h. | [
"NewMaze",
"returns",
"a",
"new",
"randomly",
"generated",
"maze",
"of",
"width",
"w",
"and",
"height",
"h",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/rosetta/maze/maze.go#L70-L85 |
18,096 | rsc/rsc | rosetta/maze/maze.go | PathString | func (m *Maze) PathString(path []graph.Vertex) string {
var b bytes.Buffer
wall := func(w, m walls, ch byte) {
if w&m != 0 {
b.WriteByte(ch)
} else {
b.WriteByte(' ')
}
}
for _, row := range m.grid {
b.WriteByte('+')
for _, cell := range row {
wall(cell, 1<<North, '-')
b.WriteByte('+')
}
b... | go | func (m *Maze) PathString(path []graph.Vertex) string {
var b bytes.Buffer
wall := func(w, m walls, ch byte) {
if w&m != 0 {
b.WriteByte(ch)
} else {
b.WriteByte(' ')
}
}
for _, row := range m.grid {
b.WriteByte('+')
for _, cell := range row {
wall(cell, 1<<North, '-')
b.WriteByte('+')
}
b... | [
"func",
"(",
"m",
"*",
"Maze",
")",
"PathString",
"(",
"path",
"[",
"]",
"graph",
".",
"Vertex",
")",
"string",
"{",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"wall",
":=",
"func",
"(",
"w",
",",
"m",
"walls",
",",
"ch",
"byte",
")",
"{",
"if",... | // PathString returns the multi-line string representation of the
// maze with the path marked on it. | [
"PathString",
"returns",
"the",
"multi",
"-",
"line",
"string",
"representation",
"of",
"the",
"maze",
"with",
"the",
"path",
"marked",
"on",
"it",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/rosetta/maze/maze.go#L107-L148 |
18,097 | rsc/rsc | smugmug/smug.go | Categories | func (c *Conn) Categories(nick string) ([]*Category, error) {
var out struct {
Categories []*Category
}
if err := c.do("smugmug.categories.get", &out, "NickName", nick); err != nil {
return nil, err
}
return out.Categories, nil
} | go | func (c *Conn) Categories(nick string) ([]*Category, error) {
var out struct {
Categories []*Category
}
if err := c.do("smugmug.categories.get", &out, "NickName", nick); err != nil {
return nil, err
}
return out.Categories, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"Categories",
"(",
"nick",
"string",
")",
"(",
"[",
"]",
"*",
"Category",
",",
"error",
")",
"{",
"var",
"out",
"struct",
"{",
"Categories",
"[",
"]",
"*",
"Category",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
... | // Categories returns the album categories for the user identified by the nick name. | [
"Categories",
"returns",
"the",
"album",
"categories",
"for",
"the",
"user",
"identified",
"by",
"the",
"nick",
"name",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/smugmug/smug.go#L82-L90 |
18,098 | rsc/rsc | smugmug/smug.go | CreateCategory | func (c *Conn) CreateCategory(name string) (*Category, error) {
var out struct {
Category *Category
}
if err := c.do("smugmug.categories.create", &out, "Name", name); err != nil {
return nil, err
}
return out.Category, nil
} | go | func (c *Conn) CreateCategory(name string) (*Category, error) {
var out struct {
Category *Category
}
if err := c.do("smugmug.categories.create", &out, "Name", name); err != nil {
return nil, err
}
return out.Category, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"CreateCategory",
"(",
"name",
"string",
")",
"(",
"*",
"Category",
",",
"error",
")",
"{",
"var",
"out",
"struct",
"{",
"Category",
"*",
"Category",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"do",
"(",
"\"... | // CreateCategory creates a category with the given name. | [
"CreateCategory",
"creates",
"a",
"category",
"with",
"the",
"given",
"name",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/smugmug/smug.go#L93-L101 |
18,099 | rsc/rsc | smugmug/smug.go | DeleteCategory | func (c *Conn) DeleteCategory(cat *Category) error {
return c.do("smugmug.categories.delete", nil, "CategoryID", itoa64(cat.ID))
} | go | func (c *Conn) DeleteCategory(cat *Category) error {
return c.do("smugmug.categories.delete", nil, "CategoryID", itoa64(cat.ID))
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"DeleteCategory",
"(",
"cat",
"*",
"Category",
")",
"error",
"{",
"return",
"c",
".",
"do",
"(",
"\"",
"\"",
",",
"nil",
",",
"\"",
"\"",
",",
"itoa64",
"(",
"cat",
".",
"ID",
")",
")",
"\n",
"}"
] | // DeleteCategory deletes the category. | [
"DeleteCategory",
"deletes",
"the",
"category",
"."
] | fc62025902295658a9c7e89418e095fd598b2682 | https://github.com/rsc/rsc/blob/fc62025902295658a9c7e89418e095fd598b2682/smugmug/smug.go#L104-L106 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.