id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
13,700 | abiosoft/ishell | progress.go | Indeterminate | func (p ProgressDisplayFunc) Indeterminate() []string {
// loop through until we get back to the first string
set := []string{p(-1)}
for {
next := p(-1)
if next == set[0] {
break
}
set = append(set, next)
}
return set
} | go | func (p ProgressDisplayFunc) Indeterminate() []string {
// loop through until we get back to the first string
set := []string{p(-1)}
for {
next := p(-1)
if next == set[0] {
break
}
set = append(set, next)
}
return set
} | [
"func",
"(",
"p",
"ProgressDisplayFunc",
")",
"Indeterminate",
"(",
")",
"[",
"]",
"string",
"{",
"// loop through until we get back to the first string",
"set",
":=",
"[",
"]",
"string",
"{",
"p",
"(",
"-",
"1",
")",
"}",
"\n",
"for",
"{",
"next",
":=",
"p",
"(",
"-",
"1",
")",
"\n",
"if",
"next",
"==",
"set",
"[",
"0",
"]",
"{",
"break",
"\n",
"}",
"\n",
"set",
"=",
"append",
"(",
"set",
",",
"next",
")",
"\n",
"}",
"\n",
"return",
"set",
"\n",
"}"
]
| // Indeterminate satisfies ProgressDisplay interface. | [
"Indeterminate",
"satisfies",
"ProgressDisplay",
"interface",
"."
]
| 8b8aa74a85127192b469453a72fd7971b47481fb | https://github.com/abiosoft/ishell/blob/8b8aa74a85127192b469453a72fd7971b47481fb/progress.go#L232-L243 |
13,701 | abiosoft/ishell | context.go | Set | func (c *contextValues) Set(key string, value interface{}) {
if *c == nil {
*c = make(map[string]interface{})
}
(*c)[key] = value
} | go | func (c *contextValues) Set(key string, value interface{}) {
if *c == nil {
*c = make(map[string]interface{})
}
(*c)[key] = value
} | [
"func",
"(",
"c",
"*",
"contextValues",
")",
"Set",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"if",
"*",
"c",
"==",
"nil",
"{",
"*",
"c",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"(",
"*",
"c",
")",
"[",
"key",
"]",
"=",
"value",
"\n",
"}"
]
| // Set sets the key in this context to value. | [
"Set",
"sets",
"the",
"key",
"in",
"this",
"context",
"to",
"value",
"."
]
| 8b8aa74a85127192b469453a72fd7971b47481fb | https://github.com/abiosoft/ishell/blob/8b8aa74a85127192b469453a72fd7971b47481fb/context.go#L43-L48 |
13,702 | abiosoft/ishell | context.go | Keys | func (c contextValues) Keys() (keys []string) {
for key := range c {
keys = append(keys, key)
}
return
} | go | func (c contextValues) Keys() (keys []string) {
for key := range c {
keys = append(keys, key)
}
return
} | [
"func",
"(",
"c",
"contextValues",
")",
"Keys",
"(",
")",
"(",
"keys",
"[",
"]",
"string",
")",
"{",
"for",
"key",
":=",
"range",
"c",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"key",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
]
| // Keys returns all keys in the context. | [
"Keys",
"returns",
"all",
"keys",
"in",
"the",
"context",
"."
]
| 8b8aa74a85127192b469453a72fd7971b47481fb | https://github.com/abiosoft/ishell/blob/8b8aa74a85127192b469453a72fd7971b47481fb/context.go#L56-L61 |
13,703 | abiosoft/ishell | reader.go | rlPrompt | func (s *shellReader) rlPrompt() string {
if s.showPrompt {
if s.readingMulti {
return s.multiPrompt
}
return s.prompt
}
return ""
} | go | func (s *shellReader) rlPrompt() string {
if s.showPrompt {
if s.readingMulti {
return s.multiPrompt
}
return s.prompt
}
return ""
} | [
"func",
"(",
"s",
"*",
"shellReader",
")",
"rlPrompt",
"(",
")",
"string",
"{",
"if",
"s",
".",
"showPrompt",
"{",
"if",
"s",
".",
"readingMulti",
"{",
"return",
"s",
".",
"multiPrompt",
"\n",
"}",
"\n",
"return",
"s",
".",
"prompt",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
]
| // rlPrompt returns the proper prompt for readline based on showPrompt and
// prompt members. | [
"rlPrompt",
"returns",
"the",
"proper",
"prompt",
"for",
"readline",
"based",
"on",
"showPrompt",
"and",
"prompt",
"members",
"."
]
| 8b8aa74a85127192b469453a72fd7971b47481fb | https://github.com/abiosoft/ishell/blob/8b8aa74a85127192b469453a72fd7971b47481fb/reader.go#L34-L42 |
13,704 | headzoo/surf | jar/history.go | Push | func (his *MemoryHistory) Push(p *State) int {
his.list.PushFront(p)
// Trim history if maxHist is set
if his.maxHist > 0 {
if l := his.list.Len(); l > his.maxHist {
for i := 0; i < l-his.maxHist; i++ {
his.list.Remove(his.list.Back())
}
}
}
return his.list.Len()
} | go | func (his *MemoryHistory) Push(p *State) int {
his.list.PushFront(p)
// Trim history if maxHist is set
if his.maxHist > 0 {
if l := his.list.Len(); l > his.maxHist {
for i := 0; i < l-his.maxHist; i++ {
his.list.Remove(his.list.Back())
}
}
}
return his.list.Len()
} | [
"func",
"(",
"his",
"*",
"MemoryHistory",
")",
"Push",
"(",
"p",
"*",
"State",
")",
"int",
"{",
"his",
".",
"list",
".",
"PushFront",
"(",
"p",
")",
"\n\n",
"// Trim history if maxHist is set",
"if",
"his",
".",
"maxHist",
">",
"0",
"{",
"if",
"l",
":=",
"his",
".",
"list",
".",
"Len",
"(",
")",
";",
"l",
">",
"his",
".",
"maxHist",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"l",
"-",
"his",
".",
"maxHist",
";",
"i",
"++",
"{",
"his",
".",
"list",
".",
"Remove",
"(",
"his",
".",
"list",
".",
"Back",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"his",
".",
"list",
".",
"Len",
"(",
")",
"\n",
"}"
]
| // Push adds a new State at the front of the history. | [
"Push",
"adds",
"a",
"new",
"State",
"at",
"the",
"front",
"of",
"the",
"history",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/jar/history.go#L70-L82 |
13,705 | headzoo/surf | jar/history.go | Pop | func (his *MemoryHistory) Pop() *State {
if his.list.Len() > 0 {
return his.list.Remove(his.list.Front()).(*State)
}
return nil
} | go | func (his *MemoryHistory) Pop() *State {
if his.list.Len() > 0 {
return his.list.Remove(his.list.Front()).(*State)
}
return nil
} | [
"func",
"(",
"his",
"*",
"MemoryHistory",
")",
"Pop",
"(",
")",
"*",
"State",
"{",
"if",
"his",
".",
"list",
".",
"Len",
"(",
")",
">",
"0",
"{",
"return",
"his",
".",
"list",
".",
"Remove",
"(",
"his",
".",
"list",
".",
"Front",
"(",
")",
")",
".",
"(",
"*",
"State",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // Pop removes and returns the State at the front of the history. | [
"Pop",
"removes",
"and",
"returns",
"the",
"State",
"at",
"the",
"front",
"of",
"the",
"history",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/jar/history.go#L85-L90 |
13,706 | headzoo/surf | jar/history.go | Top | func (his *MemoryHistory) Top() *State {
if his.list.Len() == 0 {
return nil
}
return his.list.Front().Value.(*State)
} | go | func (his *MemoryHistory) Top() *State {
if his.list.Len() == 0 {
return nil
}
return his.list.Front().Value.(*State)
} | [
"func",
"(",
"his",
"*",
"MemoryHistory",
")",
"Top",
"(",
")",
"*",
"State",
"{",
"if",
"his",
".",
"list",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"his",
".",
"list",
".",
"Front",
"(",
")",
".",
"Value",
".",
"(",
"*",
"State",
")",
"\n",
"}"
]
| // Top returns the State at the front of the history without removing it. | [
"Top",
"returns",
"the",
"State",
"at",
"the",
"front",
"of",
"the",
"history",
"without",
"removing",
"it",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/jar/history.go#L93-L98 |
13,707 | headzoo/surf | jar/bookmarks.go | Has | func (b *MemoryBookmarks) Has(name string) bool {
_, ok := b.bookmarks[name]
return ok
} | go | func (b *MemoryBookmarks) Has(name string) bool {
_, ok := b.bookmarks[name]
return ok
} | [
"func",
"(",
"b",
"*",
"MemoryBookmarks",
")",
"Has",
"(",
"name",
"string",
")",
"bool",
"{",
"_",
",",
"ok",
":=",
"b",
".",
"bookmarks",
"[",
"name",
"]",
"\n",
"return",
"ok",
"\n",
"}"
]
| // Has returns a boolean value indicating whether a bookmark exists with the given name. | [
"Has",
"returns",
"a",
"boolean",
"value",
"indicating",
"whether",
"a",
"bookmark",
"exists",
"with",
"the",
"given",
"name",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/jar/bookmarks.go#L86-L89 |
13,708 | headzoo/surf | jar/bookmarks.go | writeToFile | func (b *FileBookmarks) writeToFile() (err error) {
j, err := json.Marshal(b.bookmarks)
if err != nil {
return err
}
fout, err := os.Create(b.file)
if err != nil {
return err
}
defer func() {
err = fout.Close()
}()
_, err = fout.Write(j)
if err != nil {
return err
}
return err
} | go | func (b *FileBookmarks) writeToFile() (err error) {
j, err := json.Marshal(b.bookmarks)
if err != nil {
return err
}
fout, err := os.Create(b.file)
if err != nil {
return err
}
defer func() {
err = fout.Close()
}()
_, err = fout.Write(j)
if err != nil {
return err
}
return err
} | [
"func",
"(",
"b",
"*",
"FileBookmarks",
")",
"writeToFile",
"(",
")",
"(",
"err",
"error",
")",
"{",
"j",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"b",
".",
"bookmarks",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"fout",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"b",
".",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"err",
"=",
"fout",
".",
"Close",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"_",
",",
"err",
"=",
"fout",
".",
"Write",
"(",
"j",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
]
| // writeToFile writes the bookmarks to the file. | [
"writeToFile",
"writes",
"the",
"bookmarks",
"to",
"the",
"file",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/jar/bookmarks.go#L179-L197 |
13,709 | headzoo/surf | browser/assets.go | Download | func (at *DownloadableAsset) Download(out io.Writer) (int64, error) {
return DownloadAsset(at, out)
} | go | func (at *DownloadableAsset) Download(out io.Writer) (int64, error) {
return DownloadAsset(at, out)
} | [
"func",
"(",
"at",
"*",
"DownloadableAsset",
")",
"Download",
"(",
"out",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"return",
"DownloadAsset",
"(",
"at",
",",
"out",
")",
"\n",
"}"
]
| // Download writes the asset to the given io.Writer type. | [
"Download",
"writes",
"the",
"asset",
"to",
"the",
"given",
"io",
".",
"Writer",
"type",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/assets.go#L106-L108 |
13,710 | headzoo/surf | browser/assets.go | DownloadAsync | func (at *DownloadableAsset) DownloadAsync(out io.Writer, ch AsyncDownloadChannel) {
DownloadAssetAsync(at, out, ch)
} | go | func (at *DownloadableAsset) DownloadAsync(out io.Writer, ch AsyncDownloadChannel) {
DownloadAssetAsync(at, out, ch)
} | [
"func",
"(",
"at",
"*",
"DownloadableAsset",
")",
"DownloadAsync",
"(",
"out",
"io",
".",
"Writer",
",",
"ch",
"AsyncDownloadChannel",
")",
"{",
"DownloadAssetAsync",
"(",
"at",
",",
"out",
",",
"ch",
")",
"\n",
"}"
]
| // DownloadAsync downloads the asset asynchronously. | [
"DownloadAsync",
"downloads",
"the",
"asset",
"asynchronously",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/assets.go#L111-L113 |
13,711 | headzoo/surf | browser/assets.go | DownloadAsset | func DownloadAsset(asset Downloadable, out io.Writer) (int64, error) {
resp, err := http.Get(asset.Url().String())
if err != nil {
return 0, err
}
defer resp.Body.Close()
return io.Copy(out, resp.Body)
} | go | func DownloadAsset(asset Downloadable, out io.Writer) (int64, error) {
resp, err := http.Get(asset.Url().String())
if err != nil {
return 0, err
}
defer resp.Body.Close()
return io.Copy(out, resp.Body)
} | [
"func",
"DownloadAsset",
"(",
"asset",
"Downloadable",
",",
"out",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"asset",
".",
"Url",
"(",
")",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"return",
"io",
".",
"Copy",
"(",
"out",
",",
"resp",
".",
"Body",
")",
"\n",
"}"
]
| // DownloadAsset copies a remote file to the given writer. | [
"DownloadAsset",
"copies",
"a",
"remote",
"file",
"to",
"the",
"given",
"writer",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/assets.go#L210-L218 |
13,712 | headzoo/surf | browser/assets.go | DownloadAssetAsync | func DownloadAssetAsync(asset Downloadable, out io.Writer, c AsyncDownloadChannel) {
go func() {
results := &AsyncDownloadResult{Asset: asset, Writer: out}
size, err := DownloadAsset(asset, out)
if err != nil {
results.Error = err
} else {
results.Size = size
}
c <- results
}()
} | go | func DownloadAssetAsync(asset Downloadable, out io.Writer, c AsyncDownloadChannel) {
go func() {
results := &AsyncDownloadResult{Asset: asset, Writer: out}
size, err := DownloadAsset(asset, out)
if err != nil {
results.Error = err
} else {
results.Size = size
}
c <- results
}()
} | [
"func",
"DownloadAssetAsync",
"(",
"asset",
"Downloadable",
",",
"out",
"io",
".",
"Writer",
",",
"c",
"AsyncDownloadChannel",
")",
"{",
"go",
"func",
"(",
")",
"{",
"results",
":=",
"&",
"AsyncDownloadResult",
"{",
"Asset",
":",
"asset",
",",
"Writer",
":",
"out",
"}",
"\n",
"size",
",",
"err",
":=",
"DownloadAsset",
"(",
"asset",
",",
"out",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"results",
".",
"Error",
"=",
"err",
"\n",
"}",
"else",
"{",
"results",
".",
"Size",
"=",
"size",
"\n",
"}",
"\n",
"c",
"<-",
"results",
"\n",
"}",
"(",
")",
"\n",
"}"
]
| // DownloadAssetAsync downloads an asset asynchronously and notifies the given channel
// when the download is complete. | [
"DownloadAssetAsync",
"downloads",
"an",
"asset",
"asynchronously",
"and",
"notifies",
"the",
"given",
"channel",
"when",
"the",
"download",
"is",
"complete",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/assets.go#L222-L233 |
13,713 | headzoo/surf | errors/errors.go | New | func New(msg string, a ...interface{}) Error {
msg = fmt.Sprintf(msg, a...)
return Error{
error: errors.New(msg),
}
} | go | func New(msg string, a ...interface{}) Error {
msg = fmt.Sprintf(msg, a...)
return Error{
error: errors.New(msg),
}
} | [
"func",
"New",
"(",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"Error",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"msg",
",",
"a",
"...",
")",
"\n",
"return",
"Error",
"{",
"error",
":",
"errors",
".",
"New",
"(",
"msg",
")",
",",
"}",
"\n",
"}"
]
| // New creates and returns an Error type. | [
"New",
"creates",
"and",
"returns",
"an",
"Error",
"type",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/errors/errors.go#L15-L20 |
13,714 | headzoo/surf | errors/errors.go | NewPageNotFound | func NewPageNotFound(msg string, a ...interface{}) PageNotFound {
msg = fmt.Sprintf("Not Found: "+msg, a...)
return PageNotFound{
error: errors.New(msg),
}
} | go | func NewPageNotFound(msg string, a ...interface{}) PageNotFound {
msg = fmt.Sprintf("Not Found: "+msg, a...)
return PageNotFound{
error: errors.New(msg),
}
} | [
"func",
"NewPageNotFound",
"(",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"PageNotFound",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
"+",
"msg",
",",
"a",
"...",
")",
"\n",
"return",
"PageNotFound",
"{",
"error",
":",
"errors",
".",
"New",
"(",
"msg",
")",
",",
"}",
"\n",
"}"
]
| // NewPageNotFound creates and returns a NotFound type. | [
"NewPageNotFound",
"creates",
"and",
"returns",
"a",
"NotFound",
"type",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/errors/errors.go#L29-L34 |
13,715 | headzoo/surf | errors/errors.go | NewLinkNotFound | func NewLinkNotFound(msg string, a ...interface{}) LinkNotFound {
msg = fmt.Sprintf("Link Not Found: "+msg, a...)
return LinkNotFound{
error: errors.New(msg),
}
} | go | func NewLinkNotFound(msg string, a ...interface{}) LinkNotFound {
msg = fmt.Sprintf("Link Not Found: "+msg, a...)
return LinkNotFound{
error: errors.New(msg),
}
} | [
"func",
"NewLinkNotFound",
"(",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"LinkNotFound",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
"+",
"msg",
",",
"a",
"...",
")",
"\n",
"return",
"LinkNotFound",
"{",
"error",
":",
"errors",
".",
"New",
"(",
"msg",
")",
",",
"}",
"\n",
"}"
]
| // NewLinkNotFound creates and returns a LinkNotFound type. | [
"NewLinkNotFound",
"creates",
"and",
"returns",
"a",
"LinkNotFound",
"type",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/errors/errors.go#L42-L47 |
13,716 | headzoo/surf | errors/errors.go | NewAttributeNotFound | func NewAttributeNotFound(msg string, a ...interface{}) AttributeNotFound {
msg = fmt.Sprintf(msg, a...)
return AttributeNotFound{
error: errors.New(msg),
}
} | go | func NewAttributeNotFound(msg string, a ...interface{}) AttributeNotFound {
msg = fmt.Sprintf(msg, a...)
return AttributeNotFound{
error: errors.New(msg),
}
} | [
"func",
"NewAttributeNotFound",
"(",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"AttributeNotFound",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"msg",
",",
"a",
"...",
")",
"\n",
"return",
"AttributeNotFound",
"{",
"error",
":",
"errors",
".",
"New",
"(",
"msg",
")",
",",
"}",
"\n",
"}"
]
| // NewAttributeNotFound creates and returns a AttributeNotFound type. | [
"NewAttributeNotFound",
"creates",
"and",
"returns",
"a",
"AttributeNotFound",
"type",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/errors/errors.go#L55-L60 |
13,717 | headzoo/surf | errors/errors.go | NewLocation | func NewLocation(msg string, a ...interface{}) Location {
msg = fmt.Sprintf(msg, a...)
return Location{
error: errors.New(msg),
}
} | go | func NewLocation(msg string, a ...interface{}) Location {
msg = fmt.Sprintf(msg, a...)
return Location{
error: errors.New(msg),
}
} | [
"func",
"NewLocation",
"(",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"Location",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"msg",
",",
"a",
"...",
")",
"\n",
"return",
"Location",
"{",
"error",
":",
"errors",
".",
"New",
"(",
"msg",
")",
",",
"}",
"\n",
"}"
]
| // NewLocation creates and returns a Location type. | [
"NewLocation",
"creates",
"and",
"returns",
"a",
"Location",
"type",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/errors/errors.go#L68-L73 |
13,718 | headzoo/surf | errors/errors.go | NewPageNotLoaded | func NewPageNotLoaded(msg string, a ...interface{}) PageNotLoaded {
msg = fmt.Sprintf("Page Not Loaded: "+msg, a...)
return PageNotLoaded{
error: errors.New(msg),
}
} | go | func NewPageNotLoaded(msg string, a ...interface{}) PageNotLoaded {
msg = fmt.Sprintf("Page Not Loaded: "+msg, a...)
return PageNotLoaded{
error: errors.New(msg),
}
} | [
"func",
"NewPageNotLoaded",
"(",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"PageNotLoaded",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
"+",
"msg",
",",
"a",
"...",
")",
"\n",
"return",
"PageNotLoaded",
"{",
"error",
":",
"errors",
".",
"New",
"(",
"msg",
")",
",",
"}",
"\n",
"}"
]
| // NewPageNotLoaded creates and returns a PageNotLoaded type. | [
"NewPageNotLoaded",
"creates",
"and",
"returns",
"a",
"PageNotLoaded",
"type",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/errors/errors.go#L81-L86 |
13,719 | headzoo/surf | errors/errors.go | NewElementNotFound | func NewElementNotFound(msg string, a ...interface{}) ElementNotFound {
msg = fmt.Sprintf(msg, a...)
return ElementNotFound{
error: errors.New(msg),
}
} | go | func NewElementNotFound(msg string, a ...interface{}) ElementNotFound {
msg = fmt.Sprintf(msg, a...)
return ElementNotFound{
error: errors.New(msg),
}
} | [
"func",
"NewElementNotFound",
"(",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"ElementNotFound",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"msg",
",",
"a",
"...",
")",
"\n",
"return",
"ElementNotFound",
"{",
"error",
":",
"errors",
".",
"New",
"(",
"msg",
")",
",",
"}",
"\n",
"}"
]
| // NewElementNotFound creates and returns a ElementNotFound type. | [
"NewElementNotFound",
"creates",
"and",
"returns",
"a",
"ElementNotFound",
"type",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/errors/errors.go#L94-L99 |
13,720 | headzoo/surf | errors/errors.go | NewInvalidFormValue | func NewInvalidFormValue(msg string, a ...interface{}) InvalidFormValue {
msg = fmt.Sprintf(msg, a...)
return InvalidFormValue{
error: errors.New(msg),
}
} | go | func NewInvalidFormValue(msg string, a ...interface{}) InvalidFormValue {
msg = fmt.Sprintf(msg, a...)
return InvalidFormValue{
error: errors.New(msg),
}
} | [
"func",
"NewInvalidFormValue",
"(",
"msg",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"InvalidFormValue",
"{",
"msg",
"=",
"fmt",
".",
"Sprintf",
"(",
"msg",
",",
"a",
"...",
")",
"\n",
"return",
"InvalidFormValue",
"{",
"error",
":",
"errors",
".",
"New",
"(",
"msg",
")",
",",
"}",
"\n",
"}"
]
| // NewInvalidFormValue creates and returns a InvalidFormValue type. | [
"NewInvalidFormValue",
"creates",
"and",
"returns",
"a",
"InvalidFormValue",
"type",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/errors/errors.go#L107-L112 |
13,721 | headzoo/surf | browser/form.go | Input | func (f *Form) Input(name, value string) error {
if _, ok := f.fields[name]; ok {
f.fields.Set(name, value)
return nil
}
return errors.NewElementNotFound("No input found with name '%s'.", name)
} | go | func (f *Form) Input(name, value string) error {
if _, ok := f.fields[name]; ok {
f.fields.Set(name, value)
return nil
}
return errors.NewElementNotFound("No input found with name '%s'.", name)
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"Input",
"(",
"name",
",",
"value",
"string",
")",
"error",
"{",
"if",
"_",
",",
"ok",
":=",
"f",
".",
"fields",
"[",
"name",
"]",
";",
"ok",
"{",
"f",
".",
"fields",
".",
"Set",
"(",
"name",
",",
"value",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
]
| // Input sets the value of a form field.
// it returns an ElementNotFound error if the field does not exist | [
"Input",
"sets",
"the",
"value",
"of",
"a",
"form",
"field",
".",
"it",
"returns",
"an",
"ElementNotFound",
"error",
"if",
"the",
"field",
"does",
"not",
"exist"
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L118-L124 |
13,722 | headzoo/surf | browser/form.go | File | func (f *Form) File(name string, fileName string, data io.Reader) error {
if _, ok := f.files[name]; ok {
f.files[name] = &File{fileName: fileName, data: data}
return nil
}
return errors.NewElementNotFound(
"No input type 'file' found with name '%s'.", name)
} | go | func (f *Form) File(name string, fileName string, data io.Reader) error {
if _, ok := f.files[name]; ok {
f.files[name] = &File{fileName: fileName, data: data}
return nil
}
return errors.NewElementNotFound(
"No input type 'file' found with name '%s'.", name)
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"File",
"(",
"name",
"string",
",",
"fileName",
"string",
",",
"data",
"io",
".",
"Reader",
")",
"error",
"{",
"if",
"_",
",",
"ok",
":=",
"f",
".",
"files",
"[",
"name",
"]",
";",
"ok",
"{",
"f",
".",
"files",
"[",
"name",
"]",
"=",
"&",
"File",
"{",
"fileName",
":",
"fileName",
",",
"data",
":",
"data",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
]
| // File sets the value for an form input type file,
// it returns an ElementNotFound error if the field does not exists | [
"File",
"sets",
"the",
"value",
"for",
"an",
"form",
"input",
"type",
"file",
"it",
"returns",
"an",
"ElementNotFound",
"error",
"if",
"the",
"field",
"does",
"not",
"exists"
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L128-L136 |
13,723 | headzoo/surf | browser/form.go | SetFile | func (f *Form) SetFile(name string, fileName string, data io.Reader) {
f.files[name] = &File{fileName: fileName, data: data}
} | go | func (f *Form) SetFile(name string, fileName string, data io.Reader) {
f.files[name] = &File{fileName: fileName, data: data}
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"SetFile",
"(",
"name",
"string",
",",
"fileName",
"string",
",",
"data",
"io",
".",
"Reader",
")",
"{",
"f",
".",
"files",
"[",
"name",
"]",
"=",
"&",
"File",
"{",
"fileName",
":",
"fileName",
",",
"data",
":",
"data",
"}",
"\n",
"}"
]
| // SetFile sets the value for a form input type file.
// It will add the field to the form if necessary | [
"SetFile",
"sets",
"the",
"value",
"for",
"a",
"form",
"input",
"type",
"file",
".",
"It",
"will",
"add",
"the",
"field",
"to",
"the",
"form",
"if",
"necessary"
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L140-L142 |
13,724 | headzoo/surf | browser/form.go | Check | func (f *Form) Check(name string) error {
if _, ok := f.checkboxs[name]; ok {
f.fields.Set(name, f.checkboxs.Get(name))
return nil
}
return errors.NewElementNotFound("No checkbox found with name '%s'.", name)
} | go | func (f *Form) Check(name string) error {
if _, ok := f.checkboxs[name]; ok {
f.fields.Set(name, f.checkboxs.Get(name))
return nil
}
return errors.NewElementNotFound("No checkbox found with name '%s'.", name)
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"Check",
"(",
"name",
"string",
")",
"error",
"{",
"if",
"_",
",",
"ok",
":=",
"f",
".",
"checkboxs",
"[",
"name",
"]",
";",
"ok",
"{",
"f",
".",
"fields",
".",
"Set",
"(",
"name",
",",
"f",
".",
"checkboxs",
".",
"Get",
"(",
"name",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
]
| // Check sets the checkbox value to its active state. | [
"Check",
"sets",
"the",
"checkbox",
"value",
"to",
"its",
"active",
"state",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L155-L161 |
13,725 | headzoo/surf | browser/form.go | UnCheck | func (f *Form) UnCheck(name string) error {
if _, ok := f.checkboxs[name]; ok {
f.fields.Del(name)
return nil
}
return errors.NewElementNotFound("No checkbox found with name '%s'.", name)
} | go | func (f *Form) UnCheck(name string) error {
if _, ok := f.checkboxs[name]; ok {
f.fields.Del(name)
return nil
}
return errors.NewElementNotFound("No checkbox found with name '%s'.", name)
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"UnCheck",
"(",
"name",
"string",
")",
"error",
"{",
"if",
"_",
",",
"ok",
":=",
"f",
".",
"checkboxs",
"[",
"name",
"]",
";",
"ok",
"{",
"f",
".",
"fields",
".",
"Del",
"(",
"name",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
]
| // UnCheck sets the checkbox value to inactive state. | [
"UnCheck",
"sets",
"the",
"checkbox",
"value",
"to",
"inactive",
"state",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L164-L170 |
13,726 | headzoo/surf | browser/form.go | IsChecked | func (f *Form) IsChecked(name string) (bool, error) {
if _, ok := f.checkboxs[name]; ok {
_, found := f.fields[name]
return found, nil
}
return false, errors.NewElementNotFound("No checkbox found with name '%s'.", name)
} | go | func (f *Form) IsChecked(name string) (bool, error) {
if _, ok := f.checkboxs[name]; ok {
_, found := f.fields[name]
return found, nil
}
return false, errors.NewElementNotFound("No checkbox found with name '%s'.", name)
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"IsChecked",
"(",
"name",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"f",
".",
"checkboxs",
"[",
"name",
"]",
";",
"ok",
"{",
"_",
",",
"found",
":=",
"f",
".",
"fields",
"[",
"name",
"]",
"\n",
"return",
"found",
",",
"nil",
"\n",
"}",
"\n",
"return",
"false",
",",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
]
| // IsChecked returns the current state of the checkbox | [
"IsChecked",
"returns",
"the",
"current",
"state",
"of",
"the",
"checkbox"
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L173-L179 |
13,727 | headzoo/surf | browser/form.go | Value | func (f *Form) Value(name string) (string, error) {
if _, ok := f.fields[name]; ok {
return f.fields.Get(name), nil
}
return "", errors.NewElementNotFound("No input found with name '%s'.", name)
} | go | func (f *Form) Value(name string) (string, error) {
if _, ok := f.fields[name]; ok {
return f.fields.Get(name), nil
}
return "", errors.NewElementNotFound("No input found with name '%s'.", name)
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"Value",
"(",
"name",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"f",
".",
"fields",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"f",
".",
"fields",
".",
"Get",
"(",
"name",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
]
| // Value returns the current value of a form element whose name matches. If name is not
// found, error is returned. For multiple value form element such as select multiple,
// the first value is returned. | [
"Value",
"returns",
"the",
"current",
"value",
"of",
"a",
"form",
"element",
"whose",
"name",
"matches",
".",
"If",
"name",
"is",
"not",
"found",
"error",
"is",
"returned",
".",
"For",
"multiple",
"value",
"form",
"element",
"such",
"as",
"select",
"multiple",
"the",
"first",
"value",
"is",
"returned",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L189-L194 |
13,728 | headzoo/surf | browser/form.go | RemoveValue | func (f *Form) RemoveValue(name, val string) error {
if _, ok := f.fields[name]; !ok {
return errors.NewElementNotFound("No input found with name '%s'.", name)
}
var save []string
for _, v := range f.fields[name] {
if v != val {
save = append(save, v)
}
}
if len(save) == 0 {
f.fields.Del(name)
} else {
f.fields[name] = save
}
return nil
} | go | func (f *Form) RemoveValue(name, val string) error {
if _, ok := f.fields[name]; !ok {
return errors.NewElementNotFound("No input found with name '%s'.", name)
}
var save []string
for _, v := range f.fields[name] {
if v != val {
save = append(save, v)
}
}
if len(save) == 0 {
f.fields.Del(name)
} else {
f.fields[name] = save
}
return nil
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"RemoveValue",
"(",
"name",
",",
"val",
"string",
")",
"error",
"{",
"if",
"_",
",",
"ok",
":=",
"f",
".",
"fields",
"[",
"name",
"]",
";",
"!",
"ok",
"{",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"var",
"save",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"f",
".",
"fields",
"[",
"name",
"]",
"{",
"if",
"v",
"!=",
"val",
"{",
"save",
"=",
"append",
"(",
"save",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"save",
")",
"==",
"0",
"{",
"f",
".",
"fields",
".",
"Del",
"(",
"name",
")",
"\n",
"}",
"else",
"{",
"f",
".",
"fields",
"[",
"name",
"]",
"=",
"save",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // RemoveValue will remove a single instance of a form value whose name and value match.
// This is valuable for removing a single value from a select multiple. | [
"RemoveValue",
"will",
"remove",
"a",
"single",
"instance",
"of",
"a",
"form",
"value",
"whose",
"name",
"and",
"value",
"match",
".",
"This",
"is",
"valuable",
"for",
"removing",
"a",
"single",
"value",
"from",
"a",
"select",
"multiple",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L198-L214 |
13,729 | headzoo/surf | browser/form.go | SelectByOptionLabel | func (f *Form) SelectByOptionLabel(name string, optionLabel ...string) error {
s, ok := f.selects[name]
if !ok {
return errors.NewElementNotFound("No select element found with name '%s'.", name)
}
if len(optionLabel) > 1 && !s.multiple {
return errors.NewElementNotFound("The select element with name '%s' is not a select miltiple.", name)
}
f.fields.Del(name)
for _, l := range optionLabel {
if _, ok := s.labels[l]; !ok {
return errors.NewElementNotFound("The select element with name %q does not have an option with label %q", name, l)
}
f.fields.Add(name, s.labels.Get(l))
}
return nil
} | go | func (f *Form) SelectByOptionLabel(name string, optionLabel ...string) error {
s, ok := f.selects[name]
if !ok {
return errors.NewElementNotFound("No select element found with name '%s'.", name)
}
if len(optionLabel) > 1 && !s.multiple {
return errors.NewElementNotFound("The select element with name '%s' is not a select miltiple.", name)
}
f.fields.Del(name)
for _, l := range optionLabel {
if _, ok := s.labels[l]; !ok {
return errors.NewElementNotFound("The select element with name %q does not have an option with label %q", name, l)
}
f.fields.Add(name, s.labels.Get(l))
}
return nil
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"SelectByOptionLabel",
"(",
"name",
"string",
",",
"optionLabel",
"...",
"string",
")",
"error",
"{",
"s",
",",
"ok",
":=",
"f",
".",
"selects",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"optionLabel",
")",
">",
"1",
"&&",
"!",
"s",
".",
"multiple",
"{",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"f",
".",
"fields",
".",
"Del",
"(",
"name",
")",
"\n",
"for",
"_",
",",
"l",
":=",
"range",
"optionLabel",
"{",
"if",
"_",
",",
"ok",
":=",
"s",
".",
"labels",
"[",
"l",
"]",
";",
"!",
"ok",
"{",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
",",
"l",
")",
"\n",
"}",
"\n",
"f",
".",
"fields",
".",
"Add",
"(",
"name",
",",
"s",
".",
"labels",
".",
"Get",
"(",
"l",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // SelectByOptionLabel sets the current value of a select form element acording to the
// options label. If the element is a select multiple, multiple options may be selected. | [
"SelectByOptionLabel",
"sets",
"the",
"current",
"value",
"of",
"a",
"select",
"form",
"element",
"acording",
"to",
"the",
"options",
"label",
".",
"If",
"the",
"element",
"is",
"a",
"select",
"multiple",
"multiple",
"options",
"may",
"be",
"selected",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L218-L234 |
13,730 | headzoo/surf | browser/form.go | SelectByOptionValue | func (f *Form) SelectByOptionValue(name string, optionValue ...string) error {
s, ok := f.selects[name]
if !ok {
return errors.NewElementNotFound("No select element found with name '%s'.", name)
}
if len(optionValue) > 1 && !s.multiple {
return errors.NewElementNotFound("The select element with name '%s' is not a select miltiple.", name)
}
f.fields.Del(name)
for _, v := range optionValue {
if _, ok := s.values[v]; !ok {
return errors.NewElementNotFound("The select element with name %q does not have an option with value %q", name, v)
}
f.fields.Add(name, v)
}
return nil
} | go | func (f *Form) SelectByOptionValue(name string, optionValue ...string) error {
s, ok := f.selects[name]
if !ok {
return errors.NewElementNotFound("No select element found with name '%s'.", name)
}
if len(optionValue) > 1 && !s.multiple {
return errors.NewElementNotFound("The select element with name '%s' is not a select miltiple.", name)
}
f.fields.Del(name)
for _, v := range optionValue {
if _, ok := s.values[v]; !ok {
return errors.NewElementNotFound("The select element with name %q does not have an option with value %q", name, v)
}
f.fields.Add(name, v)
}
return nil
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"SelectByOptionValue",
"(",
"name",
"string",
",",
"optionValue",
"...",
"string",
")",
"error",
"{",
"s",
",",
"ok",
":=",
"f",
".",
"selects",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"optionValue",
")",
">",
"1",
"&&",
"!",
"s",
".",
"multiple",
"{",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"f",
".",
"fields",
".",
"Del",
"(",
"name",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"optionValue",
"{",
"if",
"_",
",",
"ok",
":=",
"s",
".",
"values",
"[",
"v",
"]",
";",
"!",
"ok",
"{",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
",",
"v",
")",
"\n",
"}",
"\n",
"f",
".",
"fields",
".",
"Add",
"(",
"name",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
]
| // SelectByOptionValue sets the current value of a select form element acording to the
// options value. If the element is a select multiple, multiple options may be selected. | [
"SelectByOptionValue",
"sets",
"the",
"current",
"value",
"of",
"a",
"select",
"form",
"element",
"acording",
"to",
"the",
"options",
"value",
".",
"If",
"the",
"element",
"is",
"a",
"select",
"multiple",
"multiple",
"options",
"may",
"be",
"selected",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L238-L254 |
13,731 | headzoo/surf | browser/form.go | SelectValues | func (f *Form) SelectValues(name string) ([]string, error) {
if _, ok := f.fields[name]; ok {
return f.fields[name], nil
}
return nil, errors.NewElementNotFound("No input found with name '%s'.", name)
} | go | func (f *Form) SelectValues(name string) ([]string, error) {
if _, ok := f.fields[name]; ok {
return f.fields[name], nil
}
return nil, errors.NewElementNotFound("No input found with name '%s'.", name)
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"SelectValues",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"f",
".",
"fields",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"f",
".",
"fields",
"[",
"name",
"]",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
]
| // SelectValues returns the current values of a form element whose name matches. If name is not
// found, error is returned. For select multiple elements, all values are returned. | [
"SelectValues",
"returns",
"the",
"current",
"values",
"of",
"a",
"form",
"element",
"whose",
"name",
"matches",
".",
"If",
"name",
"is",
"not",
"found",
"error",
"is",
"returned",
".",
"For",
"select",
"multiple",
"elements",
"all",
"values",
"are",
"returned",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L258-L263 |
13,732 | headzoo/surf | browser/form.go | SelectLabels | func (f *Form) SelectLabels(name string) ([]string, error) {
s, ok := f.selects[name]
if !ok {
return nil, errors.NewElementNotFound("No select element found with name '%s'.", name)
}
var labels []string
for _, v := range f.fields[name] {
labels = append(labels, s.values.Get(v))
}
return labels, nil
} | go | func (f *Form) SelectLabels(name string) ([]string, error) {
s, ok := f.selects[name]
if !ok {
return nil, errors.NewElementNotFound("No select element found with name '%s'.", name)
}
var labels []string
for _, v := range f.fields[name] {
labels = append(labels, s.values.Get(v))
}
return labels, nil
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"SelectLabels",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"s",
",",
"ok",
":=",
"f",
".",
"selects",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"var",
"labels",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"f",
".",
"fields",
"[",
"name",
"]",
"{",
"labels",
"=",
"append",
"(",
"labels",
",",
"s",
".",
"values",
".",
"Get",
"(",
"v",
")",
")",
"\n",
"}",
"\n",
"return",
"labels",
",",
"nil",
"\n",
"}"
]
| // SelectLabels returns the labels for the selected options for a select form element whose name
// matches. If name is not found, error is returned. | [
"SelectLabels",
"returns",
"the",
"labels",
"for",
"the",
"selected",
"options",
"for",
"a",
"select",
"form",
"element",
"whose",
"name",
"matches",
".",
"If",
"name",
"is",
"not",
"found",
"error",
"is",
"returned",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L267-L277 |
13,733 | headzoo/surf | browser/form.go | ClickByValue | func (f *Form) ClickByValue(name, value string) error {
if _, ok := f.buttons[name]; !ok {
return errors.NewInvalidFormValue(
"Form does not contain a button with the name '%s'.", name)
}
valueNotFound := true
for _, val := range f.buttons[name] {
if val == value {
valueNotFound = false
break
}
}
if valueNotFound {
return errors.NewInvalidFormValue(
"Form does not contain a button with the name '%s' and value '%s'.", name, value)
}
return f.send(name, value)
} | go | func (f *Form) ClickByValue(name, value string) error {
if _, ok := f.buttons[name]; !ok {
return errors.NewInvalidFormValue(
"Form does not contain a button with the name '%s'.", name)
}
valueNotFound := true
for _, val := range f.buttons[name] {
if val == value {
valueNotFound = false
break
}
}
if valueNotFound {
return errors.NewInvalidFormValue(
"Form does not contain a button with the name '%s' and value '%s'.", name, value)
}
return f.send(name, value)
} | [
"func",
"(",
"f",
"*",
"Form",
")",
"ClickByValue",
"(",
"name",
",",
"value",
"string",
")",
"error",
"{",
"if",
"_",
",",
"ok",
":=",
"f",
".",
"buttons",
"[",
"name",
"]",
";",
"!",
"ok",
"{",
"return",
"errors",
".",
"NewInvalidFormValue",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"valueNotFound",
":=",
"true",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"f",
".",
"buttons",
"[",
"name",
"]",
"{",
"if",
"val",
"==",
"value",
"{",
"valueNotFound",
"=",
"false",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"valueNotFound",
"{",
"return",
"errors",
".",
"NewInvalidFormValue",
"(",
"\"",
"\"",
",",
"name",
",",
"value",
")",
"\n",
"}",
"\n",
"return",
"f",
".",
"send",
"(",
"name",
",",
"value",
")",
"\n",
"}"
]
| // Click submits the form by clicking the button with the given name and value. | [
"Click",
"submits",
"the",
"form",
"by",
"clicking",
"the",
"button",
"with",
"the",
"given",
"name",
"and",
"value",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/form.go#L301-L318 |
13,734 | headzoo/surf | browser/browser.go | Open | func (bow *Browser) Open(u string) error {
ur, err := url.Parse(u)
if err != nil {
return err
}
return bow.httpGET(ur, nil)
} | go | func (bow *Browser) Open(u string) error {
ur, err := url.Parse(u)
if err != nil {
return err
}
return bow.httpGET(ur, nil)
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Open",
"(",
"u",
"string",
")",
"error",
"{",
"ur",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"bow",
".",
"httpGET",
"(",
"ur",
",",
"nil",
")",
"\n",
"}"
]
| // Open requests the given URL using the GET method. | [
"Open",
"requests",
"the",
"given",
"URL",
"using",
"the",
"GET",
"method",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L228-L234 |
13,735 | headzoo/surf | browser/browser.go | Head | func (bow *Browser) Head(u string) error {
ur, err := url.Parse(u)
if err != nil {
return err
}
return bow.httpHEAD(ur, nil)
} | go | func (bow *Browser) Head(u string) error {
ur, err := url.Parse(u)
if err != nil {
return err
}
return bow.httpHEAD(ur, nil)
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Head",
"(",
"u",
"string",
")",
"error",
"{",
"ur",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"bow",
".",
"httpHEAD",
"(",
"ur",
",",
"nil",
")",
"\n",
"}"
]
| // Head requests the given URL using the HEAD method. | [
"Head",
"requests",
"the",
"given",
"URL",
"using",
"the",
"HEAD",
"method",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L237-L243 |
13,736 | headzoo/surf | browser/browser.go | OpenForm | func (bow *Browser) OpenForm(u string, data url.Values) error {
ul, err := url.Parse(u)
if err != nil {
return err
}
ul.RawQuery = data.Encode()
return bow.Open(ul.String())
} | go | func (bow *Browser) OpenForm(u string, data url.Values) error {
ul, err := url.Parse(u)
if err != nil {
return err
}
ul.RawQuery = data.Encode()
return bow.Open(ul.String())
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"OpenForm",
"(",
"u",
"string",
",",
"data",
"url",
".",
"Values",
")",
"error",
"{",
"ul",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ul",
".",
"RawQuery",
"=",
"data",
".",
"Encode",
"(",
")",
"\n\n",
"return",
"bow",
".",
"Open",
"(",
"ul",
".",
"String",
"(",
")",
")",
"\n",
"}"
]
| // OpenForm appends the data values to the given URL and sends a GET request. | [
"OpenForm",
"appends",
"the",
"data",
"values",
"to",
"the",
"given",
"URL",
"and",
"sends",
"a",
"GET",
"request",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L246-L254 |
13,737 | headzoo/surf | browser/browser.go | Post | func (bow *Browser) Post(u string, contentType string, body io.Reader) error {
ur, err := url.Parse(u)
if err != nil {
return err
}
return bow.httpPOST(ur, bow.Url(), contentType, body)
} | go | func (bow *Browser) Post(u string, contentType string, body io.Reader) error {
ur, err := url.Parse(u)
if err != nil {
return err
}
return bow.httpPOST(ur, bow.Url(), contentType, body)
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Post",
"(",
"u",
"string",
",",
"contentType",
"string",
",",
"body",
"io",
".",
"Reader",
")",
"error",
"{",
"ur",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"bow",
".",
"httpPOST",
"(",
"ur",
",",
"bow",
".",
"Url",
"(",
")",
",",
"contentType",
",",
"body",
")",
"\n",
"}"
]
| // Post requests the given URL using the POST method. | [
"Post",
"requests",
"the",
"given",
"URL",
"using",
"the",
"POST",
"method",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L266-L272 |
13,738 | headzoo/surf | browser/browser.go | PostForm | func (bow *Browser) PostForm(u string, data url.Values) error {
return bow.Post(u, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
} | go | func (bow *Browser) PostForm(u string, data url.Values) error {
return bow.Post(u, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"PostForm",
"(",
"u",
"string",
",",
"data",
"url",
".",
"Values",
")",
"error",
"{",
"return",
"bow",
".",
"Post",
"(",
"u",
",",
"\"",
"\"",
",",
"strings",
".",
"NewReader",
"(",
"data",
".",
"Encode",
"(",
")",
")",
")",
"\n",
"}"
]
| // PostForm requests the given URL using the POST method with the given data. | [
"PostForm",
"requests",
"the",
"given",
"URL",
"using",
"the",
"POST",
"method",
"with",
"the",
"given",
"data",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L275-L277 |
13,739 | headzoo/surf | browser/browser.go | Back | func (bow *Browser) Back() bool {
if bow.history.Len() > 1 {
bow.state = bow.history.Pop()
return true
}
return false
} | go | func (bow *Browser) Back() bool {
if bow.history.Len() > 1 {
bow.state = bow.history.Pop()
return true
}
return false
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Back",
"(",
")",
"bool",
"{",
"if",
"bow",
".",
"history",
".",
"Len",
"(",
")",
">",
"1",
"{",
"bow",
".",
"state",
"=",
"bow",
".",
"history",
".",
"Pop",
"(",
")",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
]
| // Back loads the previously requested page.
//
// Returns a boolean value indicating whether a previous page existed, and was
// successfully loaded. | [
"Back",
"loads",
"the",
"previously",
"requested",
"page",
".",
"Returns",
"a",
"boolean",
"value",
"indicating",
"whether",
"a",
"previous",
"page",
"existed",
"and",
"was",
"successfully",
"loaded",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L313-L319 |
13,740 | headzoo/surf | browser/browser.go | Reload | func (bow *Browser) Reload() error {
if bow.state.Request != nil {
return bow.httpRequest(bow.state.Request)
}
return errors.NewPageNotLoaded("Cannot reload, the previous request failed.")
} | go | func (bow *Browser) Reload() error {
if bow.state.Request != nil {
return bow.httpRequest(bow.state.Request)
}
return errors.NewPageNotLoaded("Cannot reload, the previous request failed.")
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Reload",
"(",
")",
"error",
"{",
"if",
"bow",
".",
"state",
".",
"Request",
"!=",
"nil",
"{",
"return",
"bow",
".",
"httpRequest",
"(",
"bow",
".",
"state",
".",
"Request",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"NewPageNotLoaded",
"(",
"\"",
"\"",
")",
"\n",
"}"
]
| // Reload duplicates the last successful request. | [
"Reload",
"duplicates",
"the",
"last",
"successful",
"request",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L322-L327 |
13,741 | headzoo/surf | browser/browser.go | Bookmark | func (bow *Browser) Bookmark(name string) error {
return bow.bookmarks.Save(name, bow.ResolveUrl(bow.Url()).String())
} | go | func (bow *Browser) Bookmark(name string) error {
return bow.bookmarks.Save(name, bow.ResolveUrl(bow.Url()).String())
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Bookmark",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"bow",
".",
"bookmarks",
".",
"Save",
"(",
"name",
",",
"bow",
".",
"ResolveUrl",
"(",
"bow",
".",
"Url",
"(",
")",
")",
".",
"String",
"(",
")",
")",
"\n",
"}"
]
| // Bookmark saves the page URL in the bookmarks with the given name. | [
"Bookmark",
"saves",
"the",
"page",
"URL",
"in",
"the",
"bookmarks",
"with",
"the",
"given",
"name",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L330-L332 |
13,742 | headzoo/surf | browser/browser.go | Click | func (bow *Browser) Click(expr string) error {
sel := bow.Find(expr)
if sel.Length() == 0 {
return errors.NewElementNotFound(
"Element not found matching expr '%s'.", expr)
}
if !sel.Is("a") {
return errors.NewElementNotFound(
"Expr '%s' must match an anchor tag.", expr)
}
href, err := bow.attrToResolvedUrl("href", sel)
if err != nil {
return err
}
return bow.httpGET(href, bow.Url())
} | go | func (bow *Browser) Click(expr string) error {
sel := bow.Find(expr)
if sel.Length() == 0 {
return errors.NewElementNotFound(
"Element not found matching expr '%s'.", expr)
}
if !sel.Is("a") {
return errors.NewElementNotFound(
"Expr '%s' must match an anchor tag.", expr)
}
href, err := bow.attrToResolvedUrl("href", sel)
if err != nil {
return err
}
return bow.httpGET(href, bow.Url())
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Click",
"(",
"expr",
"string",
")",
"error",
"{",
"sel",
":=",
"bow",
".",
"Find",
"(",
"expr",
")",
"\n",
"if",
"sel",
".",
"Length",
"(",
")",
"==",
"0",
"{",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"expr",
")",
"\n",
"}",
"\n",
"if",
"!",
"sel",
".",
"Is",
"(",
"\"",
"\"",
")",
"{",
"return",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"expr",
")",
"\n",
"}",
"\n\n",
"href",
",",
"err",
":=",
"bow",
".",
"attrToResolvedUrl",
"(",
"\"",
"\"",
",",
"sel",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"bow",
".",
"httpGET",
"(",
"href",
",",
"bow",
".",
"Url",
"(",
")",
")",
"\n",
"}"
]
| // Click clicks on the page element matched by the given expression.
//
// Currently this is only useful for click on links, which will cause the browser
// to load the page pointed at by the link. Future versions of Surf may support
// JavaScript and clicking on elements will fire the click event. | [
"Click",
"clicks",
"on",
"the",
"page",
"element",
"matched",
"by",
"the",
"given",
"expression",
".",
"Currently",
"this",
"is",
"only",
"useful",
"for",
"click",
"on",
"links",
"which",
"will",
"cause",
"the",
"browser",
"to",
"load",
"the",
"page",
"pointed",
"at",
"by",
"the",
"link",
".",
"Future",
"versions",
"of",
"Surf",
"may",
"support",
"JavaScript",
"and",
"clicking",
"on",
"elements",
"will",
"fire",
"the",
"click",
"event",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L339-L356 |
13,743 | headzoo/surf | browser/browser.go | Form | func (bow *Browser) Form(expr string) (Submittable, error) {
sel := bow.Find(expr)
if sel.Length() == 0 {
return nil, errors.NewElementNotFound(
"Form not found matching expr '%s'.", expr)
}
if !sel.Is("form") {
return nil, errors.NewElementNotFound(
"Expr '%s' does not match a form tag.", expr)
}
return NewForm(bow, sel), nil
} | go | func (bow *Browser) Form(expr string) (Submittable, error) {
sel := bow.Find(expr)
if sel.Length() == 0 {
return nil, errors.NewElementNotFound(
"Form not found matching expr '%s'.", expr)
}
if !sel.Is("form") {
return nil, errors.NewElementNotFound(
"Expr '%s' does not match a form tag.", expr)
}
return NewForm(bow, sel), nil
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Form",
"(",
"expr",
"string",
")",
"(",
"Submittable",
",",
"error",
")",
"{",
"sel",
":=",
"bow",
".",
"Find",
"(",
"expr",
")",
"\n",
"if",
"sel",
".",
"Length",
"(",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"expr",
")",
"\n",
"}",
"\n",
"if",
"!",
"sel",
".",
"Is",
"(",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NewElementNotFound",
"(",
"\"",
"\"",
",",
"expr",
")",
"\n",
"}",
"\n\n",
"return",
"NewForm",
"(",
"bow",
",",
"sel",
")",
",",
"nil",
"\n",
"}"
]
| // Form returns the form in the current page that matches the given expr. | [
"Form",
"returns",
"the",
"form",
"in",
"the",
"current",
"page",
"that",
"matches",
"the",
"given",
"expr",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L359-L371 |
13,744 | headzoo/surf | browser/browser.go | Forms | func (bow *Browser) Forms() []Submittable {
sel := bow.Find("form")
len := sel.Length()
if len == 0 {
return nil
}
forms := make([]Submittable, len)
sel.Each(func(_ int, s *goquery.Selection) {
forms = append(forms, NewForm(bow, s))
})
return forms
} | go | func (bow *Browser) Forms() []Submittable {
sel := bow.Find("form")
len := sel.Length()
if len == 0 {
return nil
}
forms := make([]Submittable, len)
sel.Each(func(_ int, s *goquery.Selection) {
forms = append(forms, NewForm(bow, s))
})
return forms
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Forms",
"(",
")",
"[",
"]",
"Submittable",
"{",
"sel",
":=",
"bow",
".",
"Find",
"(",
"\"",
"\"",
")",
"\n",
"len",
":=",
"sel",
".",
"Length",
"(",
")",
"\n",
"if",
"len",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"forms",
":=",
"make",
"(",
"[",
"]",
"Submittable",
",",
"len",
")",
"\n",
"sel",
".",
"Each",
"(",
"func",
"(",
"_",
"int",
",",
"s",
"*",
"goquery",
".",
"Selection",
")",
"{",
"forms",
"=",
"append",
"(",
"forms",
",",
"NewForm",
"(",
"bow",
",",
"s",
")",
")",
"\n",
"}",
")",
"\n",
"return",
"forms",
"\n",
"}"
]
| // Forms returns an array of every form in the page. | [
"Forms",
"returns",
"an",
"array",
"of",
"every",
"form",
"in",
"the",
"page",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L374-L386 |
13,745 | headzoo/surf | browser/browser.go | Links | func (bow *Browser) Links() []*Link {
links := make([]*Link, 0, InitialAssetsSliceSize)
bow.Find("a").Each(func(_ int, s *goquery.Selection) {
href, err := bow.attrToResolvedUrl("href", s)
if err == nil {
links = append(links, NewLinkAsset(
href,
bow.attrOrDefault("id", "", s),
s.Text(),
))
}
})
return links
} | go | func (bow *Browser) Links() []*Link {
links := make([]*Link, 0, InitialAssetsSliceSize)
bow.Find("a").Each(func(_ int, s *goquery.Selection) {
href, err := bow.attrToResolvedUrl("href", s)
if err == nil {
links = append(links, NewLinkAsset(
href,
bow.attrOrDefault("id", "", s),
s.Text(),
))
}
})
return links
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Links",
"(",
")",
"[",
"]",
"*",
"Link",
"{",
"links",
":=",
"make",
"(",
"[",
"]",
"*",
"Link",
",",
"0",
",",
"InitialAssetsSliceSize",
")",
"\n",
"bow",
".",
"Find",
"(",
"\"",
"\"",
")",
".",
"Each",
"(",
"func",
"(",
"_",
"int",
",",
"s",
"*",
"goquery",
".",
"Selection",
")",
"{",
"href",
",",
"err",
":=",
"bow",
".",
"attrToResolvedUrl",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"links",
"=",
"append",
"(",
"links",
",",
"NewLinkAsset",
"(",
"href",
",",
"bow",
".",
"attrOrDefault",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"s",
")",
",",
"s",
".",
"Text",
"(",
")",
",",
")",
")",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"links",
"\n",
"}"
]
| // Links returns an array of every link found in the page. | [
"Links",
"returns",
"an",
"array",
"of",
"every",
"link",
"found",
"in",
"the",
"page",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L389-L403 |
13,746 | headzoo/surf | browser/browser.go | Images | func (bow *Browser) Images() []*Image {
images := make([]*Image, 0, InitialAssetsSliceSize)
bow.Find("img").Each(func(_ int, s *goquery.Selection) {
src, err := bow.attrToResolvedUrl("src", s)
if err == nil {
images = append(images, NewImageAsset(
src,
bow.attrOrDefault("id", "", s),
bow.attrOrDefault("alt", "", s),
bow.attrOrDefault("title", "", s),
))
}
})
return images
} | go | func (bow *Browser) Images() []*Image {
images := make([]*Image, 0, InitialAssetsSliceSize)
bow.Find("img").Each(func(_ int, s *goquery.Selection) {
src, err := bow.attrToResolvedUrl("src", s)
if err == nil {
images = append(images, NewImageAsset(
src,
bow.attrOrDefault("id", "", s),
bow.attrOrDefault("alt", "", s),
bow.attrOrDefault("title", "", s),
))
}
})
return images
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Images",
"(",
")",
"[",
"]",
"*",
"Image",
"{",
"images",
":=",
"make",
"(",
"[",
"]",
"*",
"Image",
",",
"0",
",",
"InitialAssetsSliceSize",
")",
"\n",
"bow",
".",
"Find",
"(",
"\"",
"\"",
")",
".",
"Each",
"(",
"func",
"(",
"_",
"int",
",",
"s",
"*",
"goquery",
".",
"Selection",
")",
"{",
"src",
",",
"err",
":=",
"bow",
".",
"attrToResolvedUrl",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"images",
"=",
"append",
"(",
"images",
",",
"NewImageAsset",
"(",
"src",
",",
"bow",
".",
"attrOrDefault",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"s",
")",
",",
"bow",
".",
"attrOrDefault",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"s",
")",
",",
"bow",
".",
"attrOrDefault",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"s",
")",
",",
")",
")",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"images",
"\n",
"}"
]
| // Images returns an array of every image found in the page. | [
"Images",
"returns",
"an",
"array",
"of",
"every",
"image",
"found",
"in",
"the",
"page",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L406-L421 |
13,747 | headzoo/surf | browser/browser.go | Stylesheets | func (bow *Browser) Stylesheets() []*Stylesheet {
stylesheets := make([]*Stylesheet, 0, InitialAssetsSliceSize)
bow.Find("link").Each(func(_ int, s *goquery.Selection) {
rel, ok := s.Attr("rel")
if ok && rel == "stylesheet" {
href, err := bow.attrToResolvedUrl("href", s)
if err == nil {
stylesheets = append(stylesheets, NewStylesheetAsset(
href,
bow.attrOrDefault("id", "", s),
bow.attrOrDefault("media", "all", s),
bow.attrOrDefault("type", "text/css", s),
))
}
}
})
return stylesheets
} | go | func (bow *Browser) Stylesheets() []*Stylesheet {
stylesheets := make([]*Stylesheet, 0, InitialAssetsSliceSize)
bow.Find("link").Each(func(_ int, s *goquery.Selection) {
rel, ok := s.Attr("rel")
if ok && rel == "stylesheet" {
href, err := bow.attrToResolvedUrl("href", s)
if err == nil {
stylesheets = append(stylesheets, NewStylesheetAsset(
href,
bow.attrOrDefault("id", "", s),
bow.attrOrDefault("media", "all", s),
bow.attrOrDefault("type", "text/css", s),
))
}
}
})
return stylesheets
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Stylesheets",
"(",
")",
"[",
"]",
"*",
"Stylesheet",
"{",
"stylesheets",
":=",
"make",
"(",
"[",
"]",
"*",
"Stylesheet",
",",
"0",
",",
"InitialAssetsSliceSize",
")",
"\n",
"bow",
".",
"Find",
"(",
"\"",
"\"",
")",
".",
"Each",
"(",
"func",
"(",
"_",
"int",
",",
"s",
"*",
"goquery",
".",
"Selection",
")",
"{",
"rel",
",",
"ok",
":=",
"s",
".",
"Attr",
"(",
"\"",
"\"",
")",
"\n",
"if",
"ok",
"&&",
"rel",
"==",
"\"",
"\"",
"{",
"href",
",",
"err",
":=",
"bow",
".",
"attrToResolvedUrl",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"stylesheets",
"=",
"append",
"(",
"stylesheets",
",",
"NewStylesheetAsset",
"(",
"href",
",",
"bow",
".",
"attrOrDefault",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"s",
")",
",",
"bow",
".",
"attrOrDefault",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"s",
")",
",",
"bow",
".",
"attrOrDefault",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"s",
")",
",",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"stylesheets",
"\n",
"}"
]
| // Stylesheets returns an array of every stylesheet linked to the document. | [
"Stylesheets",
"returns",
"an",
"array",
"of",
"every",
"stylesheet",
"linked",
"to",
"the",
"document",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L424-L442 |
13,748 | headzoo/surf | browser/browser.go | Scripts | func (bow *Browser) Scripts() []*Script {
scripts := make([]*Script, 0, InitialAssetsSliceSize)
bow.Find("script").Each(func(_ int, s *goquery.Selection) {
src, err := bow.attrToResolvedUrl("src", s)
if err == nil {
scripts = append(scripts, NewScriptAsset(
src,
bow.attrOrDefault("id", "", s),
bow.attrOrDefault("type", "text/javascript", s),
))
}
})
return scripts
} | go | func (bow *Browser) Scripts() []*Script {
scripts := make([]*Script, 0, InitialAssetsSliceSize)
bow.Find("script").Each(func(_ int, s *goquery.Selection) {
src, err := bow.attrToResolvedUrl("src", s)
if err == nil {
scripts = append(scripts, NewScriptAsset(
src,
bow.attrOrDefault("id", "", s),
bow.attrOrDefault("type", "text/javascript", s),
))
}
})
return scripts
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Scripts",
"(",
")",
"[",
"]",
"*",
"Script",
"{",
"scripts",
":=",
"make",
"(",
"[",
"]",
"*",
"Script",
",",
"0",
",",
"InitialAssetsSliceSize",
")",
"\n",
"bow",
".",
"Find",
"(",
"\"",
"\"",
")",
".",
"Each",
"(",
"func",
"(",
"_",
"int",
",",
"s",
"*",
"goquery",
".",
"Selection",
")",
"{",
"src",
",",
"err",
":=",
"bow",
".",
"attrToResolvedUrl",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"scripts",
"=",
"append",
"(",
"scripts",
",",
"NewScriptAsset",
"(",
"src",
",",
"bow",
".",
"attrOrDefault",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"s",
")",
",",
"bow",
".",
"attrOrDefault",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"s",
")",
",",
")",
")",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"return",
"scripts",
"\n",
"}"
]
| // Scripts returns an array of every script linked to the document. | [
"Scripts",
"returns",
"an",
"array",
"of",
"every",
"script",
"linked",
"to",
"the",
"document",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L445-L459 |
13,749 | headzoo/surf | browser/browser.go | SiteCookies | func (bow *Browser) SiteCookies() []*http.Cookie {
if bow.client == nil {
bow.client = bow.buildClient()
}
return bow.client.Jar.Cookies(bow.Url())
} | go | func (bow *Browser) SiteCookies() []*http.Cookie {
if bow.client == nil {
bow.client = bow.buildClient()
}
return bow.client.Jar.Cookies(bow.Url())
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"SiteCookies",
"(",
")",
"[",
"]",
"*",
"http",
".",
"Cookie",
"{",
"if",
"bow",
".",
"client",
"==",
"nil",
"{",
"bow",
".",
"client",
"=",
"bow",
".",
"buildClient",
"(",
")",
"\n",
"}",
"\n",
"return",
"bow",
".",
"client",
".",
"Jar",
".",
"Cookies",
"(",
"bow",
".",
"Url",
"(",
")",
")",
"\n",
"}"
]
| // SiteCookies returns the cookies for the current site. | [
"SiteCookies",
"returns",
"the",
"cookies",
"for",
"the",
"current",
"site",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L462-L467 |
13,750 | headzoo/surf | browser/browser.go | SetCookieJar | func (bow *Browser) SetCookieJar(cj http.CookieJar) {
if bow.client == nil {
bow.client = bow.buildClient()
}
bow.client.Jar = cj
} | go | func (bow *Browser) SetCookieJar(cj http.CookieJar) {
if bow.client == nil {
bow.client = bow.buildClient()
}
bow.client.Jar = cj
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"SetCookieJar",
"(",
"cj",
"http",
".",
"CookieJar",
")",
"{",
"if",
"bow",
".",
"client",
"==",
"nil",
"{",
"bow",
".",
"client",
"=",
"bow",
".",
"buildClient",
"(",
")",
"\n",
"}",
"\n",
"bow",
".",
"client",
".",
"Jar",
"=",
"cj",
"\n",
"}"
]
| // SetCookieJar is used to set the cookie jar the browser uses. | [
"SetCookieJar",
"is",
"used",
"to",
"set",
"the",
"cookie",
"jar",
"the",
"browser",
"uses",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L480-L485 |
13,751 | headzoo/surf | browser/browser.go | SetAttribute | func (bow *Browser) SetAttribute(a Attribute, v bool) {
bow.attributes[a] = v
} | go | func (bow *Browser) SetAttribute(a Attribute, v bool) {
bow.attributes[a] = v
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"SetAttribute",
"(",
"a",
"Attribute",
",",
"v",
"bool",
")",
"{",
"bow",
".",
"attributes",
"[",
"a",
"]",
"=",
"v",
"\n",
"}"
]
| // SetAttribute sets a browser instruction attribute. | [
"SetAttribute",
"sets",
"a",
"browser",
"instruction",
"attribute",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L501-L503 |
13,752 | headzoo/surf | browser/browser.go | SetTimeout | func (bow *Browser) SetTimeout(t time.Duration) {
if bow.client == nil {
bow.client = bow.buildClient()
}
bow.client.Timeout = t
} | go | func (bow *Browser) SetTimeout(t time.Duration) {
if bow.client == nil {
bow.client = bow.buildClient()
}
bow.client.Timeout = t
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"SetTimeout",
"(",
"t",
"time",
".",
"Duration",
")",
"{",
"if",
"bow",
".",
"client",
"==",
"nil",
"{",
"bow",
".",
"client",
"=",
"bow",
".",
"buildClient",
"(",
")",
"\n",
"}",
"\n",
"bow",
".",
"client",
".",
"Timeout",
"=",
"t",
"\n",
"}"
]
| // SetTransport sets the http library transport mechanism for each request.
// SetTimeout sets the timeout for requests. | [
"SetTransport",
"sets",
"the",
"http",
"library",
"transport",
"mechanism",
"for",
"each",
"request",
".",
"SetTimeout",
"sets",
"the",
"timeout",
"for",
"requests",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L537-L542 |
13,753 | headzoo/surf | browser/browser.go | SetTransport | func (bow *Browser) SetTransport(rt http.RoundTripper) {
if bow.client == nil {
bow.client = bow.buildClient()
}
bow.client.Transport = rt
} | go | func (bow *Browser) SetTransport(rt http.RoundTripper) {
if bow.client == nil {
bow.client = bow.buildClient()
}
bow.client.Transport = rt
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"SetTransport",
"(",
"rt",
"http",
".",
"RoundTripper",
")",
"{",
"if",
"bow",
".",
"client",
"==",
"nil",
"{",
"bow",
".",
"client",
"=",
"bow",
".",
"buildClient",
"(",
")",
"\n",
"}",
"\n",
"bow",
".",
"client",
".",
"Transport",
"=",
"rt",
"\n",
"}"
]
| // SetTransport sets the http library transport mechanism for each request. | [
"SetTransport",
"sets",
"the",
"http",
"library",
"transport",
"mechanism",
"for",
"each",
"request",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L545-L550 |
13,754 | headzoo/surf | browser/browser.go | AddRequestHeader | func (bow *Browser) AddRequestHeader(name, value string) {
bow.headers.Set(name, value)
} | go | func (bow *Browser) AddRequestHeader(name, value string) {
bow.headers.Set(name, value)
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"AddRequestHeader",
"(",
"name",
",",
"value",
"string",
")",
"{",
"bow",
".",
"headers",
".",
"Set",
"(",
"name",
",",
"value",
")",
"\n",
"}"
]
| // AddRequestHeader sets a header the browser sends with each request. | [
"AddRequestHeader",
"sets",
"a",
"header",
"the",
"browser",
"sends",
"with",
"each",
"request",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L553-L555 |
13,755 | headzoo/surf | browser/browser.go | ResolveUrl | func (bow *Browser) ResolveUrl(u *url.URL) *url.URL {
return bow.Url().ResolveReference(u)
} | go | func (bow *Browser) ResolveUrl(u *url.URL) *url.URL {
return bow.Url().ResolveReference(u)
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"ResolveUrl",
"(",
"u",
"*",
"url",
".",
"URL",
")",
"*",
"url",
".",
"URL",
"{",
"return",
"bow",
".",
"Url",
"(",
")",
".",
"ResolveReference",
"(",
"u",
")",
"\n",
"}"
]
| // ResolveUrl returns an absolute URL for a possibly relative URL. | [
"ResolveUrl",
"returns",
"an",
"absolute",
"URL",
"for",
"a",
"possibly",
"relative",
"URL",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L563-L565 |
13,756 | headzoo/surf | browser/browser.go | ResolveStringUrl | func (bow *Browser) ResolveStringUrl(u string) (string, error) {
pu, err := url.Parse(u)
if err != nil {
return "", err
}
pu = bow.Url().ResolveReference(pu)
return pu.String(), nil
} | go | func (bow *Browser) ResolveStringUrl(u string) (string, error) {
pu, err := url.Parse(u)
if err != nil {
return "", err
}
pu = bow.Url().ResolveReference(pu)
return pu.String(), nil
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"ResolveStringUrl",
"(",
"u",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"pu",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"pu",
"=",
"bow",
".",
"Url",
"(",
")",
".",
"ResolveReference",
"(",
"pu",
")",
"\n",
"return",
"pu",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
]
| // ResolveStringUrl works just like ResolveUrl, but the argument and return value are strings. | [
"ResolveStringUrl",
"works",
"just",
"like",
"ResolveUrl",
"but",
"the",
"argument",
"and",
"return",
"value",
"are",
"strings",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L568-L575 |
13,757 | headzoo/surf | browser/browser.go | Download | func (bow *Browser) Download(o io.Writer) (int64, error) {
buff := bytes.NewBuffer(bow.body)
return io.Copy(o, buff)
} | go | func (bow *Browser) Download(o io.Writer) (int64, error) {
buff := bytes.NewBuffer(bow.body)
return io.Copy(o, buff)
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Download",
"(",
"o",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"buff",
":=",
"bytes",
".",
"NewBuffer",
"(",
"bow",
".",
"body",
")",
"\n",
"return",
"io",
".",
"Copy",
"(",
"o",
",",
"buff",
")",
"\n",
"}"
]
| // Download writes the contents of the document to the given writer. | [
"Download",
"writes",
"the",
"contents",
"of",
"the",
"document",
"to",
"the",
"given",
"writer",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L578-L581 |
13,758 | headzoo/surf | browser/browser.go | Url | func (bow *Browser) Url() *url.URL {
if bow.state.Response == nil {
// there is a possibility that we issued a request, but for
// whatever reason the request failed.
if bow.state.Request != nil {
return bow.state.Request.URL
}
return nil
}
return bow.state.Response.Request.URL
} | go | func (bow *Browser) Url() *url.URL {
if bow.state.Response == nil {
// there is a possibility that we issued a request, but for
// whatever reason the request failed.
if bow.state.Request != nil {
return bow.state.Request.URL
}
return nil
}
return bow.state.Response.Request.URL
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Url",
"(",
")",
"*",
"url",
".",
"URL",
"{",
"if",
"bow",
".",
"state",
".",
"Response",
"==",
"nil",
"{",
"// there is a possibility that we issued a request, but for",
"// whatever reason the request failed.",
"if",
"bow",
".",
"state",
".",
"Request",
"!=",
"nil",
"{",
"return",
"bow",
".",
"state",
".",
"Request",
".",
"URL",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"bow",
".",
"state",
".",
"Response",
".",
"Request",
".",
"URL",
"\n",
"}"
]
| // Url returns the page URL as a string. | [
"Url",
"returns",
"the",
"page",
"URL",
"as",
"a",
"string",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L584-L595 |
13,759 | headzoo/surf | browser/browser.go | Body | func (bow *Browser) Body() string {
body, _ := bow.state.Dom.Find("body").Html()
return body
} | go | func (bow *Browser) Body() string {
body, _ := bow.state.Dom.Find("body").Html()
return body
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Body",
"(",
")",
"string",
"{",
"body",
",",
"_",
":=",
"bow",
".",
"state",
".",
"Dom",
".",
"Find",
"(",
"\"",
"\"",
")",
".",
"Html",
"(",
")",
"\n",
"return",
"body",
"\n",
"}"
]
| // Body returns the page body as a string of html. | [
"Body",
"returns",
"the",
"page",
"body",
"as",
"a",
"string",
"of",
"html",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L613-L616 |
13,760 | headzoo/surf | browser/browser.go | Find | func (bow *Browser) Find(expr string) *goquery.Selection {
return bow.state.Dom.Find(expr)
} | go | func (bow *Browser) Find(expr string) *goquery.Selection {
return bow.state.Dom.Find(expr)
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"Find",
"(",
"expr",
"string",
")",
"*",
"goquery",
".",
"Selection",
"{",
"return",
"bow",
".",
"state",
".",
"Dom",
".",
"Find",
"(",
"expr",
")",
"\n",
"}"
]
| // Find returns the dom selections matching the given expression. | [
"Find",
"returns",
"the",
"dom",
"selections",
"matching",
"the",
"given",
"expression",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L624-L626 |
13,761 | headzoo/surf | browser/browser.go | httpGET | func (bow *Browser) httpGET(u *url.URL, ref *url.URL) error {
req, err := bow.buildRequest("GET", u.String(), ref, nil)
if err != nil {
return err
}
return bow.httpRequest(req)
} | go | func (bow *Browser) httpGET(u *url.URL, ref *url.URL) error {
req, err := bow.buildRequest("GET", u.String(), ref, nil)
if err != nil {
return err
}
return bow.httpRequest(req)
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"httpGET",
"(",
"u",
"*",
"url",
".",
"URL",
",",
"ref",
"*",
"url",
".",
"URL",
")",
"error",
"{",
"req",
",",
"err",
":=",
"bow",
".",
"buildRequest",
"(",
"\"",
"\"",
",",
"u",
".",
"String",
"(",
")",
",",
"ref",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"bow",
".",
"httpRequest",
"(",
"req",
")",
"\n",
"}"
]
| // httpGET makes an HTTP GET request for the given URL.
// When via is not nil, and AttributeSendReferer is true, the Referer header will
// be set to ref. | [
"httpGET",
"makes",
"an",
"HTTP",
"GET",
"request",
"for",
"the",
"given",
"URL",
".",
"When",
"via",
"is",
"not",
"nil",
"and",
"AttributeSendReferer",
"is",
"true",
"the",
"Referer",
"header",
"will",
"be",
"set",
"to",
"ref",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L673-L679 |
13,762 | headzoo/surf | browser/browser.go | httpPOST | func (bow *Browser) httpPOST(u *url.URL, ref *url.URL, contentType string, body io.Reader) error {
req, err := bow.buildRequest("POST", u.String(), ref, body)
if err != nil {
return err
}
req.Header.Set("Content-Type", contentType)
return bow.httpRequest(req)
} | go | func (bow *Browser) httpPOST(u *url.URL, ref *url.URL, contentType string, body io.Reader) error {
req, err := bow.buildRequest("POST", u.String(), ref, body)
if err != nil {
return err
}
req.Header.Set("Content-Type", contentType)
return bow.httpRequest(req)
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"httpPOST",
"(",
"u",
"*",
"url",
".",
"URL",
",",
"ref",
"*",
"url",
".",
"URL",
",",
"contentType",
"string",
",",
"body",
"io",
".",
"Reader",
")",
"error",
"{",
"req",
",",
"err",
":=",
"bow",
".",
"buildRequest",
"(",
"\"",
"\"",
",",
"u",
".",
"String",
"(",
")",
",",
"ref",
",",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"contentType",
")",
"\n\n",
"return",
"bow",
".",
"httpRequest",
"(",
"req",
")",
"\n",
"}"
]
| // httpPOST makes an HTTP POST request for the given URL.
// When via is not nil, and AttributeSendReferer is true, the Referer header will
// be set to ref. | [
"httpPOST",
"makes",
"an",
"HTTP",
"POST",
"request",
"for",
"the",
"given",
"URL",
".",
"When",
"via",
"is",
"not",
"nil",
"and",
"AttributeSendReferer",
"is",
"true",
"the",
"Referer",
"header",
"will",
"be",
"set",
"to",
"ref",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L695-L703 |
13,763 | headzoo/surf | browser/browser.go | postSend | func (bow *Browser) postSend() {
if isContentTypeHtml(bow.state.Response) && bow.attributes[MetaRefreshHandling] {
sel := bow.Find("meta[http-equiv='refresh']")
if sel.Length() > 0 {
attr, ok := sel.Attr("content")
if ok {
dur, err := time.ParseDuration(attr + "s")
if err == nil {
bow.refresh = time.NewTimer(dur)
go func() {
<-bow.refresh.C
bow.Reload()
}()
}
}
}
}
} | go | func (bow *Browser) postSend() {
if isContentTypeHtml(bow.state.Response) && bow.attributes[MetaRefreshHandling] {
sel := bow.Find("meta[http-equiv='refresh']")
if sel.Length() > 0 {
attr, ok := sel.Attr("content")
if ok {
dur, err := time.ParseDuration(attr + "s")
if err == nil {
bow.refresh = time.NewTimer(dur)
go func() {
<-bow.refresh.C
bow.Reload()
}()
}
}
}
}
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"postSend",
"(",
")",
"{",
"if",
"isContentTypeHtml",
"(",
"bow",
".",
"state",
".",
"Response",
")",
"&&",
"bow",
".",
"attributes",
"[",
"MetaRefreshHandling",
"]",
"{",
"sel",
":=",
"bow",
".",
"Find",
"(",
"\"",
"\"",
")",
"\n",
"if",
"sel",
".",
"Length",
"(",
")",
">",
"0",
"{",
"attr",
",",
"ok",
":=",
"sel",
".",
"Attr",
"(",
"\"",
"\"",
")",
"\n",
"if",
"ok",
"{",
"dur",
",",
"err",
":=",
"time",
".",
"ParseDuration",
"(",
"attr",
"+",
"\"",
"\"",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"bow",
".",
"refresh",
"=",
"time",
".",
"NewTimer",
"(",
"dur",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"<-",
"bow",
".",
"refresh",
".",
"C",
"\n",
"bow",
".",
"Reload",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
]
| // postSend sets browser state after sending a request. | [
"postSend",
"sets",
"browser",
"state",
"after",
"sending",
"a",
"request",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L757-L774 |
13,764 | headzoo/surf | browser/browser.go | shouldRedirect | func (bow *Browser) shouldRedirect(req *http.Request, _ []*http.Request) error {
if bow.attributes[FollowRedirects] {
req.Header.Set("User-Agent", bow.userAgent)
return nil
}
return errors.NewLocation(
"Redirects are disabled. Cannot follow '%s'.", req.URL.String())
} | go | func (bow *Browser) shouldRedirect(req *http.Request, _ []*http.Request) error {
if bow.attributes[FollowRedirects] {
req.Header.Set("User-Agent", bow.userAgent)
return nil
}
return errors.NewLocation(
"Redirects are disabled. Cannot follow '%s'.", req.URL.String())
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"shouldRedirect",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"_",
"[",
"]",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"if",
"bow",
".",
"attributes",
"[",
"FollowRedirects",
"]",
"{",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"bow",
".",
"userAgent",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"NewLocation",
"(",
"\"",
"\"",
",",
"req",
".",
"URL",
".",
"String",
"(",
")",
")",
"\n",
"}"
]
| // shouldRedirect is used as the value to http.Client.CheckRedirect. | [
"shouldRedirect",
"is",
"used",
"as",
"the",
"value",
"to",
"http",
".",
"Client",
".",
"CheckRedirect",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L777-L784 |
13,765 | headzoo/surf | browser/browser.go | attrToResolvedUrl | func (bow *Browser) attrToResolvedUrl(name string, sel *goquery.Selection) (*url.URL, error) {
src, ok := sel.Attr(name)
if !ok {
return nil, errors.NewAttributeNotFound(
"Attribute '%s' not found.", name)
}
ur, err := url.Parse(src)
if err != nil {
return nil, err
}
return bow.ResolveUrl(ur), nil
} | go | func (bow *Browser) attrToResolvedUrl(name string, sel *goquery.Selection) (*url.URL, error) {
src, ok := sel.Attr(name)
if !ok {
return nil, errors.NewAttributeNotFound(
"Attribute '%s' not found.", name)
}
ur, err := url.Parse(src)
if err != nil {
return nil, err
}
return bow.ResolveUrl(ur), nil
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"attrToResolvedUrl",
"(",
"name",
"string",
",",
"sel",
"*",
"goquery",
".",
"Selection",
")",
"(",
"*",
"url",
".",
"URL",
",",
"error",
")",
"{",
"src",
",",
"ok",
":=",
"sel",
".",
"Attr",
"(",
"name",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"NewAttributeNotFound",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"ur",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"src",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"bow",
".",
"ResolveUrl",
"(",
"ur",
")",
",",
"nil",
"\n",
"}"
]
| // attributeToUrl reads an attribute from an element and returns a url. | [
"attributeToUrl",
"reads",
"an",
"attribute",
"from",
"an",
"element",
"and",
"returns",
"a",
"url",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L787-L799 |
13,766 | headzoo/surf | browser/browser.go | attrOrDefault | func (bow *Browser) attrOrDefault(name, def string, sel *goquery.Selection) string {
a, ok := sel.Attr(name)
if ok {
return a
}
return def
} | go | func (bow *Browser) attrOrDefault(name, def string, sel *goquery.Selection) string {
a, ok := sel.Attr(name)
if ok {
return a
}
return def
} | [
"func",
"(",
"bow",
"*",
"Browser",
")",
"attrOrDefault",
"(",
"name",
",",
"def",
"string",
",",
"sel",
"*",
"goquery",
".",
"Selection",
")",
"string",
"{",
"a",
",",
"ok",
":=",
"sel",
".",
"Attr",
"(",
"name",
")",
"\n",
"if",
"ok",
"{",
"return",
"a",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
]
| // attributeOrDefault reads an attribute and returns it or the default value when it's empty. | [
"attributeOrDefault",
"reads",
"an",
"attribute",
"and",
"returns",
"it",
"or",
"the",
"default",
"value",
"when",
"it",
"s",
"empty",
"."
]
| a4a8c16c01dc47ef3a25326d21745806f3e6797a | https://github.com/headzoo/surf/blob/a4a8c16c01dc47ef3a25326d21745806f3e6797a/browser/browser.go#L802-L808 |
13,767 | iikira/Baidu-Login | bdcrypto/aes.go | PKCS5Padding | func PKCS5Padding(ciphertext []byte, blockSize int) []byte {
padding := blockSize - len(ciphertext)%blockSize
if padding < 0 {
padding = 0
}
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
return append(ciphertext, padtext...)
} | go | func PKCS5Padding(ciphertext []byte, blockSize int) []byte {
padding := blockSize - len(ciphertext)%blockSize
if padding < 0 {
padding = 0
}
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
return append(ciphertext, padtext...)
} | [
"func",
"PKCS5Padding",
"(",
"ciphertext",
"[",
"]",
"byte",
",",
"blockSize",
"int",
")",
"[",
"]",
"byte",
"{",
"padding",
":=",
"blockSize",
"-",
"len",
"(",
"ciphertext",
")",
"%",
"blockSize",
"\n",
"if",
"padding",
"<",
"0",
"{",
"padding",
"=",
"0",
"\n",
"}",
"\n\n",
"padtext",
":=",
"bytes",
".",
"Repeat",
"(",
"[",
"]",
"byte",
"{",
"byte",
"(",
"padding",
")",
"}",
",",
"padding",
")",
"\n",
"return",
"append",
"(",
"ciphertext",
",",
"padtext",
"...",
")",
"\n",
"}"
]
| // PKCS5Padding PKCS5 Padding | [
"PKCS5Padding",
"PKCS5",
"Padding"
]
| ecf146973528ebe6cc85a677fd5781ec7f919b3a | https://github.com/iikira/Baidu-Login/blob/ecf146973528ebe6cc85a677fd5781ec7f919b3a/bdcrypto/aes.go#L365-L373 |
13,768 | iikira/Baidu-Login | bdcrypto/aes.go | PKCS5UnPadding | func PKCS5UnPadding(plaintext []byte) []byte {
length := len(plaintext)
if length <= 0 {
return nil
}
unpadding := int(plaintext[length-1])
if length-unpadding < 0 {
return nil
}
return plaintext[:(length - unpadding)]
} | go | func PKCS5UnPadding(plaintext []byte) []byte {
length := len(plaintext)
if length <= 0 {
return nil
}
unpadding := int(plaintext[length-1])
if length-unpadding < 0 {
return nil
}
return plaintext[:(length - unpadding)]
} | [
"func",
"PKCS5UnPadding",
"(",
"plaintext",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"length",
":=",
"len",
"(",
"plaintext",
")",
"\n",
"if",
"length",
"<=",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"unpadding",
":=",
"int",
"(",
"plaintext",
"[",
"length",
"-",
"1",
"]",
")",
"\n",
"if",
"length",
"-",
"unpadding",
"<",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"plaintext",
"[",
":",
"(",
"length",
"-",
"unpadding",
")",
"]",
"\n",
"}"
]
| // PKCS5UnPadding PKCS5 UnPadding | [
"PKCS5UnPadding",
"PKCS5",
"UnPadding"
]
| ecf146973528ebe6cc85a677fd5781ec7f919b3a | https://github.com/iikira/Baidu-Login/blob/ecf146973528ebe6cc85a677fd5781ec7f919b3a/bdcrypto/aes.go#L376-L388 |
13,769 | rollbar/rollbar-go | rollbar.go | Errorf | func Errorf(level string, format string, args ...interface{}) {
std.Errorf(level, format, args...)
} | go | func Errorf(level string, format string, args ...interface{}) {
std.Errorf(level, format, args...)
} | [
"func",
"Errorf",
"(",
"level",
"string",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"Errorf",
"(",
"level",
",",
"format",
",",
"args",
"...",
")",
"\n",
"}"
]
| // Errorf sends an error to Rollbar with the given level using the format string and arguments. | [
"Errorf",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"level",
"using",
"the",
"format",
"string",
"and",
"arguments",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L389-L391 |
13,770 | rollbar/rollbar-go | rollbar.go | ErrorWithExtras | func ErrorWithExtras(level string, err error, extras map[string]interface{}) {
std.ErrorWithExtras(level, err, extras)
} | go | func ErrorWithExtras(level string, err error, extras map[string]interface{}) {
std.ErrorWithExtras(level, err, extras)
} | [
"func",
"ErrorWithExtras",
"(",
"level",
"string",
",",
"err",
"error",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"ErrorWithExtras",
"(",
"level",
",",
"err",
",",
"extras",
")",
"\n",
"}"
]
| // ErrorWithExtras asynchronously sends an error to Rollbar with the given
// severity level with extra custom data. | [
"ErrorWithExtras",
"asynchronously",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"with",
"extra",
"custom",
"data",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L395-L397 |
13,771 | rollbar/rollbar-go | rollbar.go | ErrorWithExtrasAndContext | func ErrorWithExtrasAndContext(ctx context.Context, level string, err error, extras map[string]interface{}) {
std.ErrorWithExtrasAndContext(ctx, level, err, extras)
} | go | func ErrorWithExtrasAndContext(ctx context.Context, level string, err error, extras map[string]interface{}) {
std.ErrorWithExtrasAndContext(ctx, level, err, extras)
} | [
"func",
"ErrorWithExtrasAndContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"err",
"error",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"ErrorWithExtrasAndContext",
"(",
"ctx",
",",
"level",
",",
"err",
",",
"extras",
")",
"\n",
"}"
]
| // ErrorWithExtrasAndContext asynchronously sends an error to Rollbar with the given
// severity level with extra custom data, within the given context. | [
"ErrorWithExtrasAndContext",
"asynchronously",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"with",
"extra",
"custom",
"data",
"within",
"the",
"given",
"context",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L401-L403 |
13,772 | rollbar/rollbar-go | rollbar.go | RequestError | func RequestError(level string, r *http.Request, err error) {
std.RequestError(level, r, err)
} | go | func RequestError(level string, r *http.Request, err error) {
std.RequestError(level, r, err)
} | [
"func",
"RequestError",
"(",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
")",
"{",
"std",
".",
"RequestError",
"(",
"level",
",",
"r",
",",
"err",
")",
"\n",
"}"
]
| // RequestError asynchronously sends an error to Rollbar with the given
// severity level and request-specific information. | [
"RequestError",
"asynchronously",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"request",
"-",
"specific",
"information",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L407-L409 |
13,773 | rollbar/rollbar-go | rollbar.go | RequestErrorWithExtras | func RequestErrorWithExtras(level string, r *http.Request, err error, extras map[string]interface{}) {
std.RequestErrorWithExtras(level, r, err, extras)
} | go | func RequestErrorWithExtras(level string, r *http.Request, err error, extras map[string]interface{}) {
std.RequestErrorWithExtras(level, r, err, extras)
} | [
"func",
"RequestErrorWithExtras",
"(",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"RequestErrorWithExtras",
"(",
"level",
",",
"r",
",",
"err",
",",
"extras",
")",
"\n",
"}"
]
| // RequestErrorWithExtras asynchronously sends an error to Rollbar with the given
// severity level and request-specific information with extra custom data. | [
"RequestErrorWithExtras",
"asynchronously",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"request",
"-",
"specific",
"information",
"with",
"extra",
"custom",
"data",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L413-L415 |
13,774 | rollbar/rollbar-go | rollbar.go | RequestErrorWithExtrasAndContext | func RequestErrorWithExtrasAndContext(ctx context.Context, level string, r *http.Request, err error, extras map[string]interface{}) {
std.RequestErrorWithExtrasAndContext(ctx, level, r, err, extras)
} | go | func RequestErrorWithExtrasAndContext(ctx context.Context, level string, r *http.Request, err error, extras map[string]interface{}) {
std.RequestErrorWithExtrasAndContext(ctx, level, r, err, extras)
} | [
"func",
"RequestErrorWithExtrasAndContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"RequestErrorWithExtrasAndContext",
"(",
"ctx",
",",
"level",
",",
"r",
",",
"err",
",",
"extras",
")",
"\n",
"}"
]
| // RequestErrorWithExtrasAndContext asynchronously sends an error to Rollbar with the given
// severity level and request-specific information with extra custom data. | [
"RequestErrorWithExtrasAndContext",
"asynchronously",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"request",
"-",
"specific",
"information",
"with",
"extra",
"custom",
"data",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L419-L421 |
13,775 | rollbar/rollbar-go | rollbar.go | ErrorWithStackSkip | func ErrorWithStackSkip(level string, err error, skip int) {
std.ErrorWithStackSkip(level, err, skip)
} | go | func ErrorWithStackSkip(level string, err error, skip int) {
std.ErrorWithStackSkip(level, err, skip)
} | [
"func",
"ErrorWithStackSkip",
"(",
"level",
"string",
",",
"err",
"error",
",",
"skip",
"int",
")",
"{",
"std",
".",
"ErrorWithStackSkip",
"(",
"level",
",",
"err",
",",
"skip",
")",
"\n",
"}"
]
| // ErrorWithStackSkip asynchronously sends an error to Rollbar with the given
// severity level and a given number of stack trace frames skipped. | [
"ErrorWithStackSkip",
"asynchronously",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"a",
"given",
"number",
"of",
"stack",
"trace",
"frames",
"skipped",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L425-L427 |
13,776 | rollbar/rollbar-go | rollbar.go | ErrorWithStackSkipWithExtras | func ErrorWithStackSkipWithExtras(level string, err error, skip int, extras map[string]interface{}) {
std.ErrorWithStackSkipWithExtras(level, err, skip, extras)
} | go | func ErrorWithStackSkipWithExtras(level string, err error, skip int, extras map[string]interface{}) {
std.ErrorWithStackSkipWithExtras(level, err, skip, extras)
} | [
"func",
"ErrorWithStackSkipWithExtras",
"(",
"level",
"string",
",",
"err",
"error",
",",
"skip",
"int",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"ErrorWithStackSkipWithExtras",
"(",
"level",
",",
"err",
",",
"skip",
",",
"extras",
")",
"\n",
"}"
]
| // ErrorWithStackSkipWithExtras asynchronously sends an error to Rollbar with the given
// severity level and a given number of stack trace frames skipped with extra custom data. | [
"ErrorWithStackSkipWithExtras",
"asynchronously",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"a",
"given",
"number",
"of",
"stack",
"trace",
"frames",
"skipped",
"with",
"extra",
"custom",
"data",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L431-L433 |
13,777 | rollbar/rollbar-go | rollbar.go | ErrorWithStackSkipWithExtrasAndContext | func ErrorWithStackSkipWithExtrasAndContext(ctx context.Context, level string, err error, skip int, extras map[string]interface{}) {
std.ErrorWithStackSkipWithExtrasAndContext(ctx, level, err, skip, extras)
} | go | func ErrorWithStackSkipWithExtrasAndContext(ctx context.Context, level string, err error, skip int, extras map[string]interface{}) {
std.ErrorWithStackSkipWithExtrasAndContext(ctx, level, err, skip, extras)
} | [
"func",
"ErrorWithStackSkipWithExtrasAndContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"err",
"error",
",",
"skip",
"int",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"ErrorWithStackSkipWithExtrasAndContext",
"(",
"ctx",
",",
"level",
",",
"err",
",",
"skip",
",",
"extras",
")",
"\n",
"}"
]
| // ErrorWithStackSkipWithExtrasAndContext asynchronously sends an error to Rollbar with the given
// severity level and a given number of stack trace frames skipped with extra custom data, within
// the given context. | [
"ErrorWithStackSkipWithExtrasAndContext",
"asynchronously",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"a",
"given",
"number",
"of",
"stack",
"trace",
"frames",
"skipped",
"with",
"extra",
"custom",
"data",
"within",
"the",
"given",
"context",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L438-L440 |
13,778 | rollbar/rollbar-go | rollbar.go | RequestErrorWithStackSkip | func RequestErrorWithStackSkip(level string, r *http.Request, err error, skip int) {
std.RequestErrorWithStackSkip(level, r, err, skip)
} | go | func RequestErrorWithStackSkip(level string, r *http.Request, err error, skip int) {
std.RequestErrorWithStackSkip(level, r, err, skip)
} | [
"func",
"RequestErrorWithStackSkip",
"(",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
",",
"skip",
"int",
")",
"{",
"std",
".",
"RequestErrorWithStackSkip",
"(",
"level",
",",
"r",
",",
"err",
",",
"skip",
")",
"\n",
"}"
]
| // RequestErrorWithStackSkip asynchronously sends an error to Rollbar with the
// RequestErrorWithStackSkip asynchronously sends an error to Rollbar with the
// given severity level and a given number of stack trace frames skipped, in
// addition to extra request-specific information. | [
"RequestErrorWithStackSkip",
"asynchronously",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"RequestErrorWithStackSkip",
"asynchronously",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"a",
"given",
"number",
"of",
"stack",
"trace",
"frames",
"skipped",
"in",
"addition",
"to",
"extra",
"request",
"-",
"specific",
"information",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L446-L448 |
13,779 | rollbar/rollbar-go | rollbar.go | RequestErrorWithStackSkipWithExtras | func RequestErrorWithStackSkipWithExtras(level string, r *http.Request, err error, skip int, extras map[string]interface{}) {
std.RequestErrorWithStackSkipWithExtras(level, r, err, skip, extras)
} | go | func RequestErrorWithStackSkipWithExtras(level string, r *http.Request, err error, skip int, extras map[string]interface{}) {
std.RequestErrorWithStackSkipWithExtras(level, r, err, skip, extras)
} | [
"func",
"RequestErrorWithStackSkipWithExtras",
"(",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
",",
"skip",
"int",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"RequestErrorWithStackSkipWithExtras",
"(",
"level",
",",
"r",
",",
"err",
",",
"skip",
",",
"extras",
")",
"\n",
"}"
]
| // RequestErrorWithStackSkipWithExtras asynchronously sends an error to Rollbar
// with the given severity level and a given number of stack trace frames skipped,
// in addition to extra request-specific information and extra custom data. | [
"RequestErrorWithStackSkipWithExtras",
"asynchronously",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"a",
"given",
"number",
"of",
"stack",
"trace",
"frames",
"skipped",
"in",
"addition",
"to",
"extra",
"request",
"-",
"specific",
"information",
"and",
"extra",
"custom",
"data",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L453-L455 |
13,780 | rollbar/rollbar-go | rollbar.go | RequestErrorWithStackSkipWithExtrasAndContext | func RequestErrorWithStackSkipWithExtrasAndContext(ctx context.Context, level string, r *http.Request, err error, skip int, extras map[string]interface{}) {
std.RequestErrorWithStackSkipWithExtrasAndContext(ctx, level, r, err, skip, extras)
} | go | func RequestErrorWithStackSkipWithExtrasAndContext(ctx context.Context, level string, r *http.Request, err error, skip int, extras map[string]interface{}) {
std.RequestErrorWithStackSkipWithExtrasAndContext(ctx, level, r, err, skip, extras)
} | [
"func",
"RequestErrorWithStackSkipWithExtrasAndContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
",",
"skip",
"int",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"RequestErrorWithStackSkipWithExtrasAndContext",
"(",
"ctx",
",",
"level",
",",
"r",
",",
"err",
",",
"skip",
",",
"extras",
")",
"\n",
"}"
]
| // RequestErrorWithStackSkipWithExtrasAndContext asynchronously sends an error to Rollbar
// with the given severity level and a given number of stack trace frames skipped,
// in addition to extra request-specific information and extra custom data, within the given context. | [
"RequestErrorWithStackSkipWithExtrasAndContext",
"asynchronously",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"a",
"given",
"number",
"of",
"stack",
"trace",
"frames",
"skipped",
"in",
"addition",
"to",
"extra",
"request",
"-",
"specific",
"information",
"and",
"extra",
"custom",
"data",
"within",
"the",
"given",
"context",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L460-L462 |
13,781 | rollbar/rollbar-go | rollbar.go | MessageWithExtras | func MessageWithExtras(level string, msg string, extras map[string]interface{}) {
std.MessageWithExtras(level, msg, extras)
} | go | func MessageWithExtras(level string, msg string, extras map[string]interface{}) {
std.MessageWithExtras(level, msg, extras)
} | [
"func",
"MessageWithExtras",
"(",
"level",
"string",
",",
"msg",
"string",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"MessageWithExtras",
"(",
"level",
",",
"msg",
",",
"extras",
")",
"\n",
"}"
]
| // MessageWithExtras asynchronously sends a message to Rollbar with the given severity
// level with extra custom data. Rollbar request is asynchronous. | [
"MessageWithExtras",
"asynchronously",
"sends",
"a",
"message",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"with",
"extra",
"custom",
"data",
".",
"Rollbar",
"request",
"is",
"asynchronous",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L474-L476 |
13,782 | rollbar/rollbar-go | rollbar.go | MessageWithExtrasAndContext | func MessageWithExtrasAndContext(ctx context.Context, level string, msg string, extras map[string]interface{}) {
std.MessageWithExtrasAndContext(ctx, level, msg, extras)
} | go | func MessageWithExtrasAndContext(ctx context.Context, level string, msg string, extras map[string]interface{}) {
std.MessageWithExtrasAndContext(ctx, level, msg, extras)
} | [
"func",
"MessageWithExtrasAndContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"msg",
"string",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"MessageWithExtrasAndContext",
"(",
"ctx",
",",
"level",
",",
"msg",
",",
"extras",
")",
"\n",
"}"
]
| // MessageWithExtrasAndContext asynchronously sends a message to Rollbar with the given severity
// level with extra custom data, within the given context. Rollbar request is asynchronous. | [
"MessageWithExtrasAndContext",
"asynchronously",
"sends",
"a",
"message",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"with",
"extra",
"custom",
"data",
"within",
"the",
"given",
"context",
".",
"Rollbar",
"request",
"is",
"asynchronous",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L480-L482 |
13,783 | rollbar/rollbar-go | rollbar.go | RequestMessage | func RequestMessage(level string, r *http.Request, msg string) {
std.RequestMessage(level, r, msg)
} | go | func RequestMessage(level string, r *http.Request, msg string) {
std.RequestMessage(level, r, msg)
} | [
"func",
"RequestMessage",
"(",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"msg",
"string",
")",
"{",
"std",
".",
"RequestMessage",
"(",
"level",
",",
"r",
",",
"msg",
")",
"\n",
"}"
]
| // RequestMessage asynchronously sends a message to Rollbar with the given
// severity level and request-specific information. | [
"RequestMessage",
"asynchronously",
"sends",
"a",
"message",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"request",
"-",
"specific",
"information",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L486-L488 |
13,784 | rollbar/rollbar-go | rollbar.go | RequestMessageWithExtras | func RequestMessageWithExtras(level string, r *http.Request, msg string, extras map[string]interface{}) {
std.RequestMessageWithExtras(level, r, msg, extras)
} | go | func RequestMessageWithExtras(level string, r *http.Request, msg string, extras map[string]interface{}) {
std.RequestMessageWithExtras(level, r, msg, extras)
} | [
"func",
"RequestMessageWithExtras",
"(",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"msg",
"string",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"RequestMessageWithExtras",
"(",
"level",
",",
"r",
",",
"msg",
",",
"extras",
")",
"\n",
"}"
]
| // RequestMessageWithExtras asynchronously sends a message to Rollbar with the given severity
// level with extra custom data in addition to extra request-specific information.
// Rollbar request is asynchronous. | [
"RequestMessageWithExtras",
"asynchronously",
"sends",
"a",
"message",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"with",
"extra",
"custom",
"data",
"in",
"addition",
"to",
"extra",
"request",
"-",
"specific",
"information",
".",
"Rollbar",
"request",
"is",
"asynchronous",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L493-L495 |
13,785 | rollbar/rollbar-go | rollbar.go | RequestMessageWithExtrasAndContext | func RequestMessageWithExtrasAndContext(ctx context.Context, level string, r *http.Request, msg string, extras map[string]interface{}) {
std.RequestMessageWithExtrasAndContext(ctx, level, r, msg, extras)
} | go | func RequestMessageWithExtrasAndContext(ctx context.Context, level string, r *http.Request, msg string, extras map[string]interface{}) {
std.RequestMessageWithExtrasAndContext(ctx, level, r, msg, extras)
} | [
"func",
"RequestMessageWithExtrasAndContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"msg",
"string",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"std",
".",
"RequestMessageWithExtrasAndContext",
"(",
"ctx",
",",
"level",
",",
"r",
",",
"msg",
",",
"extras",
")",
"\n",
"}"
]
| // RequestMessageWithExtrasAndContext asynchronously sends a message to Rollbar with the given severity
// level with extra custom data in addition to extra request-specific information, within the given
// context. Rollbar request is asynchronous. | [
"RequestMessageWithExtrasAndContext",
"asynchronously",
"sends",
"a",
"message",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"with",
"extra",
"custom",
"data",
"in",
"addition",
"to",
"extra",
"request",
"-",
"specific",
"information",
"within",
"the",
"given",
"context",
".",
"Rollbar",
"request",
"is",
"asynchronous",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/rollbar.go#L500-L502 |
13,786 | rollbar/rollbar-go | transforms.go | remoteIP | func remoteIP(req *http.Request) string {
realIP := req.Header.Get("X-Real-IP")
if realIP != "" {
return realIP
}
forwardedIPs := req.Header.Get("X-Forwarded-For")
if forwardedIPs != "" {
ips := strings.Split(forwardedIPs, ", ")
return ips[0]
}
return req.RemoteAddr
} | go | func remoteIP(req *http.Request) string {
realIP := req.Header.Get("X-Real-IP")
if realIP != "" {
return realIP
}
forwardedIPs := req.Header.Get("X-Forwarded-For")
if forwardedIPs != "" {
ips := strings.Split(forwardedIPs, ", ")
return ips[0]
}
return req.RemoteAddr
} | [
"func",
"remoteIP",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"realIP",
":=",
"req",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"realIP",
"!=",
"\"",
"\"",
"{",
"return",
"realIP",
"\n",
"}",
"\n",
"forwardedIPs",
":=",
"req",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"forwardedIPs",
"!=",
"\"",
"\"",
"{",
"ips",
":=",
"strings",
".",
"Split",
"(",
"forwardedIPs",
",",
"\"",
"\"",
")",
"\n",
"return",
"ips",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"req",
".",
"RemoteAddr",
"\n",
"}"
]
| // remoteIP attempts to extract the real remote IP address by looking first at the headers X-Real-IP
// and X-Forwarded-For, and then falling back to RemoteAddr defined in http.Request | [
"remoteIP",
"attempts",
"to",
"extract",
"the",
"real",
"remote",
"IP",
"address",
"by",
"looking",
"first",
"at",
"the",
"headers",
"X",
"-",
"Real",
"-",
"IP",
"and",
"X",
"-",
"Forwarded",
"-",
"For",
"and",
"then",
"falling",
"back",
"to",
"RemoteAddr",
"defined",
"in",
"http",
".",
"Request"
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/transforms.go#L109-L120 |
13,787 | rollbar/rollbar-go | transforms.go | filterFlatten | func filterFlatten(pattern *regexp.Regexp, values map[string][]string, specialKeys map[string]struct{}) map[string]interface{} {
result := make(map[string]interface{})
for k, v := range values {
switch _, special := specialKeys[k]; {
case pattern.Match([]byte(k)):
result[k] = FILTERED
case special || len(v) == 1:
result[k] = v[0]
default:
result[k] = v
}
}
return result
} | go | func filterFlatten(pattern *regexp.Regexp, values map[string][]string, specialKeys map[string]struct{}) map[string]interface{} {
result := make(map[string]interface{})
for k, v := range values {
switch _, special := specialKeys[k]; {
case pattern.Match([]byte(k)):
result[k] = FILTERED
case special || len(v) == 1:
result[k] = v[0]
default:
result[k] = v
}
}
return result
} | [
"func",
"filterFlatten",
"(",
"pattern",
"*",
"regexp",
".",
"Regexp",
",",
"values",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
",",
"specialKeys",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"values",
"{",
"switch",
"_",
",",
"special",
":=",
"specialKeys",
"[",
"k",
"]",
";",
"{",
"case",
"pattern",
".",
"Match",
"(",
"[",
"]",
"byte",
"(",
"k",
")",
")",
":",
"result",
"[",
"k",
"]",
"=",
"FILTERED",
"\n",
"case",
"special",
"||",
"len",
"(",
"v",
")",
"==",
"1",
":",
"result",
"[",
"k",
"]",
"=",
"v",
"[",
"0",
"]",
"\n",
"default",
":",
"result",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
]
| // filterFlatten filters sensitive information like passwords from being sent to Rollbar, and
// also lifts any values with length one up to be a standalone string. The optional specialKeys map
// will force strings that exist in that map and also in values to have a single string value in the
// resulting map by taking the first element in the list of strings if there are more than one.
// This is essentially the same as the composition of filterParams and filterValues, plus the bit
// extra about the special keys. The composition would range of the values twice when we really only
// need to do it once, so I decided to combine them as the result is still quite easy to follow.
// We keep the other two so that we can use url.Values.Encode on the filtered query params and not
// run the filtering twice for the query. | [
"filterFlatten",
"filters",
"sensitive",
"information",
"like",
"passwords",
"from",
"being",
"sent",
"to",
"Rollbar",
"and",
"also",
"lifts",
"any",
"values",
"with",
"length",
"one",
"up",
"to",
"be",
"a",
"standalone",
"string",
".",
"The",
"optional",
"specialKeys",
"map",
"will",
"force",
"strings",
"that",
"exist",
"in",
"that",
"map",
"and",
"also",
"in",
"values",
"to",
"have",
"a",
"single",
"string",
"value",
"in",
"the",
"resulting",
"map",
"by",
"taking",
"the",
"first",
"element",
"in",
"the",
"list",
"of",
"strings",
"if",
"there",
"are",
"more",
"than",
"one",
".",
"This",
"is",
"essentially",
"the",
"same",
"as",
"the",
"composition",
"of",
"filterParams",
"and",
"filterValues",
"plus",
"the",
"bit",
"extra",
"about",
"the",
"special",
"keys",
".",
"The",
"composition",
"would",
"range",
"of",
"the",
"values",
"twice",
"when",
"we",
"really",
"only",
"need",
"to",
"do",
"it",
"once",
"so",
"I",
"decided",
"to",
"combine",
"them",
"as",
"the",
"result",
"is",
"still",
"quite",
"easy",
"to",
"follow",
".",
"We",
"keep",
"the",
"other",
"two",
"so",
"that",
"we",
"can",
"use",
"url",
".",
"Values",
".",
"Encode",
"on",
"the",
"filtered",
"query",
"params",
"and",
"not",
"run",
"the",
"filtering",
"twice",
"for",
"the",
"query",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/transforms.go#L131-L146 |
13,788 | rollbar/rollbar-go | transforms.go | flattenValues | func flattenValues(values map[string][]string) map[string]interface{} {
result := make(map[string]interface{})
for k, v := range values {
if len(v) == 1 {
result[k] = v[0]
} else {
result[k] = v
}
}
return result
} | go | func flattenValues(values map[string][]string) map[string]interface{} {
result := make(map[string]interface{})
for k, v := range values {
if len(v) == 1 {
result[k] = v[0]
} else {
result[k] = v
}
}
return result
} | [
"func",
"flattenValues",
"(",
"values",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"values",
"{",
"if",
"len",
"(",
"v",
")",
"==",
"1",
"{",
"result",
"[",
"k",
"]",
"=",
"v",
"[",
"0",
"]",
"\n",
"}",
"else",
"{",
"result",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
]
| // flattenValues takes a map from strings to lists of strings and performs a lift
// on values which have length 1. | [
"flattenValues",
"takes",
"a",
"map",
"from",
"strings",
"to",
"lists",
"of",
"strings",
"and",
"performs",
"a",
"lift",
"on",
"values",
"which",
"have",
"length",
"1",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/transforms.go#L162-L174 |
13,789 | rollbar/rollbar-go | transforms.go | filterIp | func filterIp(ip string, captureIp captureIp) string {
switch captureIp {
case CaptureIpFull:
return ip
case CaptureIpAnonymize:
if strings.Contains(ip, ".") {
parts := strings.Split(ip, ".")
parts[len(parts)-1] = "0"
return strings.Join(parts, ".")
}
if strings.Contains(ip, ":") {
parts := strings.Split(ip, ":")
if len(parts) > 2 {
parts = parts[0:3]
parts = append(parts, "0000:0000:0000:0000:0000")
return strings.Join(parts, ":")
}
return ip
}
return ip
case CaptureIpNone:
return ""
default:
return ""
}
} | go | func filterIp(ip string, captureIp captureIp) string {
switch captureIp {
case CaptureIpFull:
return ip
case CaptureIpAnonymize:
if strings.Contains(ip, ".") {
parts := strings.Split(ip, ".")
parts[len(parts)-1] = "0"
return strings.Join(parts, ".")
}
if strings.Contains(ip, ":") {
parts := strings.Split(ip, ":")
if len(parts) > 2 {
parts = parts[0:3]
parts = append(parts, "0000:0000:0000:0000:0000")
return strings.Join(parts, ":")
}
return ip
}
return ip
case CaptureIpNone:
return ""
default:
return ""
}
} | [
"func",
"filterIp",
"(",
"ip",
"string",
",",
"captureIp",
"captureIp",
")",
"string",
"{",
"switch",
"captureIp",
"{",
"case",
"CaptureIpFull",
":",
"return",
"ip",
"\n",
"case",
"CaptureIpAnonymize",
":",
"if",
"strings",
".",
"Contains",
"(",
"ip",
",",
"\"",
"\"",
")",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"ip",
",",
"\"",
"\"",
")",
"\n",
"parts",
"[",
"len",
"(",
"parts",
")",
"-",
"1",
"]",
"=",
"\"",
"\"",
"\n",
"return",
"strings",
".",
"Join",
"(",
"parts",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"strings",
".",
"Contains",
"(",
"ip",
",",
"\"",
"\"",
")",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"ip",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
">",
"2",
"{",
"parts",
"=",
"parts",
"[",
"0",
":",
"3",
"]",
"\n",
"parts",
"=",
"append",
"(",
"parts",
",",
"\"",
"\"",
")",
"\n",
"return",
"strings",
".",
"Join",
"(",
"parts",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"ip",
"\n",
"}",
"\n",
"return",
"ip",
"\n",
"case",
"CaptureIpNone",
":",
"return",
"\"",
"\"",
"\n",
"default",
":",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"}"
]
| // filterIp takes an ip address string and a capture policy and returns a possibly
// transformed ip address string. | [
"filterIp",
"takes",
"an",
"ip",
"address",
"string",
"and",
"a",
"capture",
"policy",
"and",
"returns",
"a",
"possibly",
"transformed",
"ip",
"address",
"string",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/transforms.go#L178-L203 |
13,790 | rollbar/rollbar-go | transforms.go | errorBody | func errorBody(configuration configuration, err error, skip int) (map[string]interface{}, string) {
var parent error
// allocate the slice at all times since it will get marshaled into JSON later
traceChain := []map[string]interface{}{}
fingerprint := ""
for {
stack := buildStack(getOrBuildFrames(err, parent, 1+skip))
traceChain = append(traceChain, buildTrace(err, stack))
if configuration.fingerprint {
fingerprint = fingerprint + stack.Fingerprint()
}
parent = err
err = getCause(err)
if err == nil {
break
}
}
errBody := map[string]interface{}{"trace_chain": traceChain}
return errBody, fingerprint
} | go | func errorBody(configuration configuration, err error, skip int) (map[string]interface{}, string) {
var parent error
// allocate the slice at all times since it will get marshaled into JSON later
traceChain := []map[string]interface{}{}
fingerprint := ""
for {
stack := buildStack(getOrBuildFrames(err, parent, 1+skip))
traceChain = append(traceChain, buildTrace(err, stack))
if configuration.fingerprint {
fingerprint = fingerprint + stack.Fingerprint()
}
parent = err
err = getCause(err)
if err == nil {
break
}
}
errBody := map[string]interface{}{"trace_chain": traceChain}
return errBody, fingerprint
} | [
"func",
"errorBody",
"(",
"configuration",
"configuration",
",",
"err",
"error",
",",
"skip",
"int",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"string",
")",
"{",
"var",
"parent",
"error",
"\n",
"// allocate the slice at all times since it will get marshaled into JSON later",
"traceChain",
":=",
"[",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"fingerprint",
":=",
"\"",
"\"",
"\n",
"for",
"{",
"stack",
":=",
"buildStack",
"(",
"getOrBuildFrames",
"(",
"err",
",",
"parent",
",",
"1",
"+",
"skip",
")",
")",
"\n",
"traceChain",
"=",
"append",
"(",
"traceChain",
",",
"buildTrace",
"(",
"err",
",",
"stack",
")",
")",
"\n",
"if",
"configuration",
".",
"fingerprint",
"{",
"fingerprint",
"=",
"fingerprint",
"+",
"stack",
".",
"Fingerprint",
"(",
")",
"\n",
"}",
"\n",
"parent",
"=",
"err",
"\n",
"err",
"=",
"getCause",
"(",
"err",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"errBody",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"traceChain",
"}",
"\n",
"return",
"errBody",
",",
"fingerprint",
"\n",
"}"
]
| // Build an error inner-body for the given error. If skip is provided, that
// number of stack trace frames will be skipped. If the error has a Cause
// method, the causes will be traversed until nil. | [
"Build",
"an",
"error",
"inner",
"-",
"body",
"for",
"the",
"given",
"error",
".",
"If",
"skip",
"is",
"provided",
"that",
"number",
"of",
"stack",
"trace",
"frames",
"will",
"be",
"skipped",
".",
"If",
"the",
"error",
"has",
"a",
"Cause",
"method",
"the",
"causes",
"will",
"be",
"traversed",
"until",
"nil",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/transforms.go#L208-L227 |
13,791 | rollbar/rollbar-go | transforms.go | buildTrace | func buildTrace(err error, stack stack) map[string]interface{} {
message := nilErrTitle
if err != nil {
message = err.Error()
}
return map[string]interface{}{
"frames": stack,
"exception": map[string]interface{}{
"class": errorClass(err),
"message": message,
},
}
} | go | func buildTrace(err error, stack stack) map[string]interface{} {
message := nilErrTitle
if err != nil {
message = err.Error()
}
return map[string]interface{}{
"frames": stack,
"exception": map[string]interface{}{
"class": errorClass(err),
"message": message,
},
}
} | [
"func",
"buildTrace",
"(",
"err",
"error",
",",
"stack",
"stack",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"message",
":=",
"nilErrTitle",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"message",
"=",
"err",
".",
"Error",
"(",
")",
"\n",
"}",
"\n",
"return",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"stack",
",",
"\"",
"\"",
":",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"errorClass",
"(",
"err",
")",
",",
"\"",
"\"",
":",
"message",
",",
"}",
",",
"}",
"\n",
"}"
]
| // builds one trace element in trace_chain | [
"builds",
"one",
"trace",
"element",
"in",
"trace_chain"
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/transforms.go#L230-L242 |
13,792 | rollbar/rollbar-go | transforms.go | getOrBuildFrames | func getOrBuildFrames(err error, parent error, skip int) []runtime.Frame {
if cs, ok := err.(CauseStacker); ok {
return cs.Stack()
} else if _, ok := parent.(CauseStacker); !ok {
return getCallersFrames(1 + skip)
}
return nil
} | go | func getOrBuildFrames(err error, parent error, skip int) []runtime.Frame {
if cs, ok := err.(CauseStacker); ok {
return cs.Stack()
} else if _, ok := parent.(CauseStacker); !ok {
return getCallersFrames(1 + skip)
}
return nil
} | [
"func",
"getOrBuildFrames",
"(",
"err",
"error",
",",
"parent",
"error",
",",
"skip",
"int",
")",
"[",
"]",
"runtime",
".",
"Frame",
"{",
"if",
"cs",
",",
"ok",
":=",
"err",
".",
"(",
"CauseStacker",
")",
";",
"ok",
"{",
"return",
"cs",
".",
"Stack",
"(",
")",
"\n",
"}",
"else",
"if",
"_",
",",
"ok",
":=",
"parent",
".",
"(",
"CauseStacker",
")",
";",
"!",
"ok",
"{",
"return",
"getCallersFrames",
"(",
"1",
"+",
"skip",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
]
| // gets stack frames from errors that provide one of their own
// otherwise, builds a new stack trace | [
"gets",
"stack",
"frames",
"from",
"errors",
"that",
"provide",
"one",
"of",
"their",
"own",
"otherwise",
"builds",
"a",
"new",
"stack",
"trace"
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/transforms.go#L253-L261 |
13,793 | rollbar/rollbar-go | sync_transport.go | NewSyncTransport | func NewSyncTransport(token, endpoint string) *SyncTransport {
return &SyncTransport{
Token: token,
Endpoint: endpoint,
RetryAttempts: DefaultRetryAttempts,
PrintPayloadOnError: true,
}
} | go | func NewSyncTransport(token, endpoint string) *SyncTransport {
return &SyncTransport{
Token: token,
Endpoint: endpoint,
RetryAttempts: DefaultRetryAttempts,
PrintPayloadOnError: true,
}
} | [
"func",
"NewSyncTransport",
"(",
"token",
",",
"endpoint",
"string",
")",
"*",
"SyncTransport",
"{",
"return",
"&",
"SyncTransport",
"{",
"Token",
":",
"token",
",",
"Endpoint",
":",
"endpoint",
",",
"RetryAttempts",
":",
"DefaultRetryAttempts",
",",
"PrintPayloadOnError",
":",
"true",
",",
"}",
"\n",
"}"
]
| // NewSyncTransport builds a synchronous transport which sends data to the Rollbar API at the
// specified endpoint using the given access token. | [
"NewSyncTransport",
"builds",
"a",
"synchronous",
"transport",
"which",
"sends",
"data",
"to",
"the",
"Rollbar",
"API",
"at",
"the",
"specified",
"endpoint",
"using",
"the",
"given",
"access",
"token",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/sync_transport.go#L25-L32 |
13,794 | rollbar/rollbar-go | sync_transport.go | Send | func (t *SyncTransport) Send(body map[string]interface{}) error {
return t.doSend(body, t.RetryAttempts)
} | go | func (t *SyncTransport) Send(body map[string]interface{}) error {
return t.doSend(body, t.RetryAttempts)
} | [
"func",
"(",
"t",
"*",
"SyncTransport",
")",
"Send",
"(",
"body",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"t",
".",
"doSend",
"(",
"body",
",",
"t",
".",
"RetryAttempts",
")",
"\n",
"}"
]
| // Send the body to Rollbar.
// Returns errors associated with the http request if any.
// If the access token has not been set or is empty then this will
// not send anything and will return nil. | [
"Send",
"the",
"body",
"to",
"Rollbar",
".",
"Returns",
"errors",
"associated",
"with",
"the",
"http",
"request",
"if",
"any",
".",
"If",
"the",
"access",
"token",
"has",
"not",
"been",
"set",
"or",
"is",
"empty",
"then",
"this",
"will",
"not",
"send",
"anything",
"and",
"will",
"return",
"nil",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/sync_transport.go#L38-L40 |
13,795 | rollbar/rollbar-go | client.go | New | func New(token, environment, codeVersion, serverHost, serverRoot string) *Client {
return NewAsync(token, environment, codeVersion, serverHost, serverRoot)
} | go | func New(token, environment, codeVersion, serverHost, serverRoot string) *Client {
return NewAsync(token, environment, codeVersion, serverHost, serverRoot)
} | [
"func",
"New",
"(",
"token",
",",
"environment",
",",
"codeVersion",
",",
"serverHost",
",",
"serverRoot",
"string",
")",
"*",
"Client",
"{",
"return",
"NewAsync",
"(",
"token",
",",
"environment",
",",
"codeVersion",
",",
"serverHost",
",",
"serverRoot",
")",
"\n",
"}"
]
| // New returns the default implementation of a Client.
// This uses the AsyncTransport. | [
"New",
"returns",
"the",
"default",
"implementation",
"of",
"a",
"Client",
".",
"This",
"uses",
"the",
"AsyncTransport",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L32-L34 |
13,796 | rollbar/rollbar-go | client.go | NewAsync | func NewAsync(token, environment, codeVersion, serverHost, serverRoot string) *Client {
configuration := createConfiguration(token, environment, codeVersion, serverHost, serverRoot)
transport := NewTransport(token, configuration.endpoint)
return &Client{
Transport: transport,
configuration: configuration,
}
} | go | func NewAsync(token, environment, codeVersion, serverHost, serverRoot string) *Client {
configuration := createConfiguration(token, environment, codeVersion, serverHost, serverRoot)
transport := NewTransport(token, configuration.endpoint)
return &Client{
Transport: transport,
configuration: configuration,
}
} | [
"func",
"NewAsync",
"(",
"token",
",",
"environment",
",",
"codeVersion",
",",
"serverHost",
",",
"serverRoot",
"string",
")",
"*",
"Client",
"{",
"configuration",
":=",
"createConfiguration",
"(",
"token",
",",
"environment",
",",
"codeVersion",
",",
"serverHost",
",",
"serverRoot",
")",
"\n",
"transport",
":=",
"NewTransport",
"(",
"token",
",",
"configuration",
".",
"endpoint",
")",
"\n",
"return",
"&",
"Client",
"{",
"Transport",
":",
"transport",
",",
"configuration",
":",
"configuration",
",",
"}",
"\n",
"}"
]
| // NewAsync builds a Client with the asynchronous implementation of the transport interface. | [
"NewAsync",
"builds",
"a",
"Client",
"with",
"the",
"asynchronous",
"implementation",
"of",
"the",
"transport",
"interface",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L37-L44 |
13,797 | rollbar/rollbar-go | client.go | NewSync | func NewSync(token, environment, codeVersion, serverHost, serverRoot string) *Client {
configuration := createConfiguration(token, environment, codeVersion, serverHost, serverRoot)
transport := NewSyncTransport(token, configuration.endpoint)
return &Client{
Transport: transport,
configuration: configuration,
}
} | go | func NewSync(token, environment, codeVersion, serverHost, serverRoot string) *Client {
configuration := createConfiguration(token, environment, codeVersion, serverHost, serverRoot)
transport := NewSyncTransport(token, configuration.endpoint)
return &Client{
Transport: transport,
configuration: configuration,
}
} | [
"func",
"NewSync",
"(",
"token",
",",
"environment",
",",
"codeVersion",
",",
"serverHost",
",",
"serverRoot",
"string",
")",
"*",
"Client",
"{",
"configuration",
":=",
"createConfiguration",
"(",
"token",
",",
"environment",
",",
"codeVersion",
",",
"serverHost",
",",
"serverRoot",
")",
"\n",
"transport",
":=",
"NewSyncTransport",
"(",
"token",
",",
"configuration",
".",
"endpoint",
")",
"\n",
"return",
"&",
"Client",
"{",
"Transport",
":",
"transport",
",",
"configuration",
":",
"configuration",
",",
"}",
"\n",
"}"
]
| // NewSync builds a Client with the synchronous implementation of the transport interface. | [
"NewSync",
"builds",
"a",
"Client",
"with",
"the",
"synchronous",
"implementation",
"of",
"the",
"transport",
"interface",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L47-L54 |
13,798 | rollbar/rollbar-go | client.go | SetToken | func (c *Client) SetToken(token string) {
c.configuration.token = token
c.Transport.SetToken(token)
} | go | func (c *Client) SetToken(token string) {
c.configuration.token = token
c.Transport.SetToken(token)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetToken",
"(",
"token",
"string",
")",
"{",
"c",
".",
"configuration",
".",
"token",
"=",
"token",
"\n",
"c",
".",
"Transport",
".",
"SetToken",
"(",
"token",
")",
"\n",
"}"
]
| // SetToken sets the token used by this client.
// The value is a Rollbar access token with scope "post_server_item".
// It is required to set this value before any of the other functions herein will be able to work
// properly. This also configures the underlying Transport. | [
"SetToken",
"sets",
"the",
"token",
"used",
"by",
"this",
"client",
".",
"The",
"value",
"is",
"a",
"Rollbar",
"access",
"token",
"with",
"scope",
"post_server_item",
".",
"It",
"is",
"required",
"to",
"set",
"this",
"value",
"before",
"any",
"of",
"the",
"other",
"functions",
"herein",
"will",
"be",
"able",
"to",
"work",
"properly",
".",
"This",
"also",
"configures",
"the",
"underlying",
"Transport",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L68-L71 |
13,799 | rollbar/rollbar-go | client.go | SetEndpoint | func (c *Client) SetEndpoint(endpoint string) {
c.configuration.endpoint = endpoint
c.Transport.SetEndpoint(endpoint)
} | go | func (c *Client) SetEndpoint(endpoint string) {
c.configuration.endpoint = endpoint
c.Transport.SetEndpoint(endpoint)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetEndpoint",
"(",
"endpoint",
"string",
")",
"{",
"c",
".",
"configuration",
".",
"endpoint",
"=",
"endpoint",
"\n",
"c",
".",
"Transport",
".",
"SetEndpoint",
"(",
"endpoint",
")",
"\n",
"}"
]
| // SetEndpoint sets the endpoint to post items to. This also configures the underlying Transport. | [
"SetEndpoint",
"sets",
"the",
"endpoint",
"to",
"post",
"items",
"to",
".",
"This",
"also",
"configures",
"the",
"underlying",
"Transport",
"."
]
| 5729d3754c053614e806190ad972ddede06e741a | https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L79-L82 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.