id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
142,400 | twmb/algoimpl | go/tree/heap/heap.go | Push | func Push(h Interface, val interface{}) {
h.Push(val)
shuffleUp(h, h.Len()-1)
} | go | func Push(h Interface, val interface{}) {
h.Push(val)
shuffleUp(h, h.Len()-1)
} | [
"func",
"Push",
"(",
"h",
"Interface",
",",
"val",
"interface",
"{",
"}",
")",
"{",
"h",
".",
"Push",
"(",
"val",
")",
"\n",
"shuffleUp",
"(",
"h",
",",
"h",
".",
"Len",
"(",
")",
"-",
"1",
")",
"\n",
"}"
] | // This function will push a new value into a priority queue. | [
"This",
"function",
"will",
"push",
"a",
"new",
"value",
"into",
"a",
"priority",
"queue",
"."
] | 076353e90b94cccf4fe7cc41790d46f421da2d97 | https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/tree/heap/heap.go#L51-L54 |
142,401 | twmb/algoimpl | go/tree/heap/heap.go | Remove | func Remove(h Interface, i int) (v interface{}) {
n := h.Len() - 1
if n != i {
h.Swap(n, i)
shuffleDown(h, i, n)
shuffleUp(h, i)
}
return h.Pop()
} | go | func Remove(h Interface, i int) (v interface{}) {
n := h.Len() - 1
if n != i {
h.Swap(n, i)
shuffleDown(h, i, n)
shuffleUp(h, i)
}
return h.Pop()
} | [
"func",
"Remove",
"(",
"h",
"Interface",
",",
"i",
"int",
")",
"(",
"v",
"interface",
"{",
"}",
")",
"{",
"n",
":=",
"h",
".",
"Len",
"(",
")",
"-",
"1",
"\n",
"if",
"n",
"!=",
"i",
"{",
"h",
".",
"Swap",
"(",
"n",
",",
"i",
")",
"\n",
... | // Removes and returns the element at index i | [
"Removes",
"and",
"returns",
"the",
"element",
"at",
"index",
"i"
] | 076353e90b94cccf4fe7cc41790d46f421da2d97 | https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/tree/heap/heap.go#L57-L65 |
142,402 | MakeNowJust/heredoc | heredoc.go | Doc | func Doc(raw string) string {
skipFirstLine := false
if len(raw) > 0 && raw[0] == '\n' {
raw = raw[1:]
} else {
skipFirstLine = true
}
lines := strings.Split(raw, "\n")
minIndentSize := getMinIndent(lines, skipFirstLine)
lines = removeIndentation(lines, minIndentSize, skipFirstLine)
return strings.Join(l... | go | func Doc(raw string) string {
skipFirstLine := false
if len(raw) > 0 && raw[0] == '\n' {
raw = raw[1:]
} else {
skipFirstLine = true
}
lines := strings.Split(raw, "\n")
minIndentSize := getMinIndent(lines, skipFirstLine)
lines = removeIndentation(lines, minIndentSize, skipFirstLine)
return strings.Join(l... | [
"func",
"Doc",
"(",
"raw",
"string",
")",
"string",
"{",
"skipFirstLine",
":=",
"false",
"\n",
"if",
"len",
"(",
"raw",
")",
">",
"0",
"&&",
"raw",
"[",
"0",
"]",
"==",
"'\\n'",
"{",
"raw",
"=",
"raw",
"[",
"1",
":",
"]",
"\n",
"}",
"else",
"... | // Doc returns un-indented string as here-document. | [
"Doc",
"returns",
"un",
"-",
"indented",
"string",
"as",
"here",
"-",
"document",
"."
] | e9091a26100e9cfb2b6a8f470085bfa541931a91 | https://github.com/MakeNowJust/heredoc/blob/e9091a26100e9cfb2b6a8f470085bfa541931a91/heredoc.go#L34-L48 |
142,403 | MakeNowJust/heredoc | heredoc.go | getMinIndent | func getMinIndent(lines []string, skipFirstLine bool) int {
minIndentSize := maxInt
for i, line := range lines {
if i == 0 && skipFirstLine {
continue
}
indentSize := 0
for _, r := range []rune(line) {
if unicode.IsSpace(r) {
indentSize += 1
} else {
break
}
}
if len(line) == indent... | go | func getMinIndent(lines []string, skipFirstLine bool) int {
minIndentSize := maxInt
for i, line := range lines {
if i == 0 && skipFirstLine {
continue
}
indentSize := 0
for _, r := range []rune(line) {
if unicode.IsSpace(r) {
indentSize += 1
} else {
break
}
}
if len(line) == indent... | [
"func",
"getMinIndent",
"(",
"lines",
"[",
"]",
"string",
",",
"skipFirstLine",
"bool",
")",
"int",
"{",
"minIndentSize",
":=",
"maxInt",
"\n\n",
"for",
"i",
",",
"line",
":=",
"range",
"lines",
"{",
"if",
"i",
"==",
"0",
"&&",
"skipFirstLine",
"{",
"c... | // getMinIndent calculates the minimum indentation in lines, excluding empty lines. | [
"getMinIndent",
"calculates",
"the",
"minimum",
"indentation",
"in",
"lines",
"excluding",
"empty",
"lines",
"."
] | e9091a26100e9cfb2b6a8f470085bfa541931a91 | https://github.com/MakeNowJust/heredoc/blob/e9091a26100e9cfb2b6a8f470085bfa541931a91/heredoc.go#L51-L77 |
142,404 | MakeNowJust/heredoc | heredoc.go | removeIndentation | func removeIndentation(lines []string, n int, skipFirstLine bool) []string {
for i, line := range lines {
if i == 0 && skipFirstLine {
continue
}
if len(lines[i]) >= n {
lines[i] = line[n:]
}
}
return lines
} | go | func removeIndentation(lines []string, n int, skipFirstLine bool) []string {
for i, line := range lines {
if i == 0 && skipFirstLine {
continue
}
if len(lines[i]) >= n {
lines[i] = line[n:]
}
}
return lines
} | [
"func",
"removeIndentation",
"(",
"lines",
"[",
"]",
"string",
",",
"n",
"int",
",",
"skipFirstLine",
"bool",
")",
"[",
"]",
"string",
"{",
"for",
"i",
",",
"line",
":=",
"range",
"lines",
"{",
"if",
"i",
"==",
"0",
"&&",
"skipFirstLine",
"{",
"conti... | // removeIndentation removes n characters from the front of each line in lines.
// Skips first line if skipFirstLine is true, skips empty lines. | [
"removeIndentation",
"removes",
"n",
"characters",
"from",
"the",
"front",
"of",
"each",
"line",
"in",
"lines",
".",
"Skips",
"first",
"line",
"if",
"skipFirstLine",
"is",
"true",
"skips",
"empty",
"lines",
"."
] | e9091a26100e9cfb2b6a8f470085bfa541931a91 | https://github.com/MakeNowJust/heredoc/blob/e9091a26100e9cfb2b6a8f470085bfa541931a91/heredoc.go#L81-L92 |
142,405 | jpfielding/gorets | pkg/rets/compact.go | NewCompactData | func NewCompactData(start xml.StartElement, decoder *xml.Decoder, delim string) (CompactData, error) {
cd := CompactData{}
cd.Element = start.Name.Local
cd.Attr = map[string]string{}
for _, a := range start.Attr {
cd.Attr[a.Name.Local] = a.Value
}
err := decoder.DecodeElement(&cd, &start)
if err != nil {
ret... | go | func NewCompactData(start xml.StartElement, decoder *xml.Decoder, delim string) (CompactData, error) {
cd := CompactData{}
cd.Element = start.Name.Local
cd.Attr = map[string]string{}
for _, a := range start.Attr {
cd.Attr[a.Name.Local] = a.Value
}
err := decoder.DecodeElement(&cd, &start)
if err != nil {
ret... | [
"func",
"NewCompactData",
"(",
"start",
"xml",
".",
"StartElement",
",",
"decoder",
"*",
"xml",
".",
"Decoder",
",",
"delim",
"string",
")",
"(",
"CompactData",
",",
"error",
")",
"{",
"cd",
":=",
"CompactData",
"{",
"}",
"\n",
"cd",
".",
"Element",
"=... | // NewCompactData parses a CompactData from a start element.
// If delim is explicitly passed, it will override the DELIMITER element value, which defaults to \t. Pass
// empty string to automatically parse DELIMITER value or fallback to default of \t. | [
"NewCompactData",
"parses",
"a",
"CompactData",
"from",
"a",
"start",
"element",
".",
"If",
"delim",
"is",
"explicitly",
"passed",
"it",
"will",
"override",
"the",
"DELIMITER",
"element",
"value",
"which",
"defaults",
"to",
"\\",
"t",
".",
"Pass",
"empty",
"... | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/compact.go#L17-L41 |
142,406 | jpfielding/gorets | pkg/rets/compact.go | Rows | func (cd CompactData) Rows(each func(i int, row Row)) {
for i, row := range cd.CompactRows {
each(i, row.Parse(cd.Delimiter))
}
} | go | func (cd CompactData) Rows(each func(i int, row Row)) {
for i, row := range cd.CompactRows {
each(i, row.Parse(cd.Delimiter))
}
} | [
"func",
"(",
"cd",
"CompactData",
")",
"Rows",
"(",
"each",
"func",
"(",
"i",
"int",
",",
"row",
"Row",
")",
")",
"{",
"for",
"i",
",",
"row",
":=",
"range",
"cd",
".",
"CompactRows",
"{",
"each",
"(",
"i",
",",
"row",
".",
"Parse",
"(",
"cd",
... | // Rows provides callback to access each row | [
"Rows",
"provides",
"callback",
"to",
"access",
"each",
"row"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/compact.go#L65-L69 |
142,407 | jpfielding/gorets | pkg/rets/compact.go | Entries | func (cd CompactData) Entries() []CompactEntry {
index := cd.Indexer()
cols := cd.Columns()
var entries []CompactEntry
cd.Rows(func(i int, r Row) {
entry := CompactEntry{}
for _, c := range cols {
val, ok := index(c, r)
if !ok {
continue // declared column wasn't included in DATA row!
}
entry[c]... | go | func (cd CompactData) Entries() []CompactEntry {
index := cd.Indexer()
cols := cd.Columns()
var entries []CompactEntry
cd.Rows(func(i int, r Row) {
entry := CompactEntry{}
for _, c := range cols {
val, ok := index(c, r)
if !ok {
continue // declared column wasn't included in DATA row!
}
entry[c]... | [
"func",
"(",
"cd",
"CompactData",
")",
"Entries",
"(",
")",
"[",
"]",
"CompactEntry",
"{",
"index",
":=",
"cd",
".",
"Indexer",
"(",
")",
"\n",
"cols",
":=",
"cd",
".",
"Columns",
"(",
")",
"\n",
"var",
"entries",
"[",
"]",
"CompactEntry",
"\n",
"c... | // Entries turns all rows into maps | [
"Entries",
"turns",
"all",
"rows",
"into",
"maps"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/compact.go#L88-L104 |
142,408 | jpfielding/gorets | pkg/rets/compact.go | Indexer | func (cd *CompactData) Indexer() Indexer {
index := make(map[string]int)
for i, c := range cd.Columns() {
index[c] = i
}
return func(col string, row Row) (val string, ok bool) {
i, ok := index[col]
if !ok || i >= len(row) {
return "", false // non-existent column, or DATA row contains too few values
}
... | go | func (cd *CompactData) Indexer() Indexer {
index := make(map[string]int)
for i, c := range cd.Columns() {
index[c] = i
}
return func(col string, row Row) (val string, ok bool) {
i, ok := index[col]
if !ok || i >= len(row) {
return "", false // non-existent column, or DATA row contains too few values
}
... | [
"func",
"(",
"cd",
"*",
"CompactData",
")",
"Indexer",
"(",
")",
"Indexer",
"{",
"index",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n",
"for",
"i",
",",
"c",
":=",
"range",
"cd",
".",
"Columns",
"(",
")",
"{",
"index",
"[",
"c... | // Indexer create the cache | [
"Indexer",
"create",
"the",
"cache"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/compact.go#L110-L122 |
142,409 | jpfielding/gorets | pkg/syndication/syndication.go | ToListing | func ToListing(each EachListing) func(io.ReadCloser, error) error {
return func(body io.ReadCloser, err error) error {
if err != nil {
return err
}
listing := Listing{}
err = xml.NewDecoder(body).Decode(&listing)
return each(listing, err)
}
} | go | func ToListing(each EachListing) func(io.ReadCloser, error) error {
return func(body io.ReadCloser, err error) error {
if err != nil {
return err
}
listing := Listing{}
err = xml.NewDecoder(body).Decode(&listing)
return each(listing, err)
}
} | [
"func",
"ToListing",
"(",
"each",
"EachListing",
")",
"func",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"error",
"{",
"return",
"func",
"(",
"body",
"io",
".",
"ReadCloser",
",",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{"... | // ToListing creates an adapter to be used with something that walks a large stream
// and segments it into smaller doms | [
"ToListing",
"creates",
"an",
"adapter",
"to",
"be",
"used",
"with",
"something",
"that",
"walks",
"a",
"large",
"stream",
"and",
"segments",
"it",
"into",
"smaller",
"doms"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/syndication/syndication.go#L14-L23 |
142,410 | jpfielding/gorets | pkg/rets/ua_auth.go | Request | func (ua *UserAgentAuthentication) Request(ctx context.Context, req *http.Request) (*http.Response, error) {
// nothing to do gtfo
if ua.UserAgentPassword == "" {
return ua.Requester(ctx, req)
}
//
retsVersion := ""
if ua.GetRETSVersion != nil {
retsVersion = ua.GetRETSVersion(req)
}
// we generate this and... | go | func (ua *UserAgentAuthentication) Request(ctx context.Context, req *http.Request) (*http.Response, error) {
// nothing to do gtfo
if ua.UserAgentPassword == "" {
return ua.Requester(ctx, req)
}
//
retsVersion := ""
if ua.GetRETSVersion != nil {
retsVersion = ua.GetRETSVersion(req)
}
// we generate this and... | [
"func",
"(",
"ua",
"*",
"UserAgentAuthentication",
")",
"Request",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"// nothing to do gtfo",
"if",
"ua",
".",
... | // Request allows ua-auth to be hooked into requests prior to sending | [
"Request",
"allows",
"ua",
"-",
"auth",
"to",
"be",
"hooked",
"into",
"requests",
"prior",
"to",
"sending"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/ua_auth.go#L29-L54 |
142,411 | jpfielding/gorets | pkg/rets/ua_auth.go | CreateSessionIDer | func CreateSessionIDer(jar http.CookieJar) RequestIDer {
return func(req *http.Request) string {
for _, c := range jar.Cookies(req.URL) {
if c.Name == RETSSessionID {
return c.Value
}
}
return ""
}
} | go | func CreateSessionIDer(jar http.CookieJar) RequestIDer {
return func(req *http.Request) string {
for _, c := range jar.Cookies(req.URL) {
if c.Name == RETSSessionID {
return c.Value
}
}
return ""
}
} | [
"func",
"CreateSessionIDer",
"(",
"jar",
"http",
".",
"CookieJar",
")",
"RequestIDer",
"{",
"return",
"func",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"jar",
".",
"Cookies",
"(",
"req",
".",
"U... | // CreateSessionIDer provides a default implement for extracting the session from a cookie jar | [
"CreateSessionIDer",
"provides",
"a",
"default",
"implement",
"for",
"extracting",
"the",
"session",
"from",
"a",
"cookie",
"jar"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/ua_auth.go#L72-L81 |
142,412 | jpfielding/gorets | pkg/rets/get.go | Get | func Get(ctx context.Context, requester Requester, r GetRequest) error {
req, err := http.NewRequest("GET", r.URL, nil)
if err != nil {
return err
}
resp, err := requester(ctx, req)
if err != nil {
return err
}
_, err = ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
resp.Body.Close()
return n... | go | func Get(ctx context.Context, requester Requester, r GetRequest) error {
req, err := http.NewRequest("GET", r.URL, nil)
if err != nil {
return err
}
resp, err := requester(ctx, req)
if err != nil {
return err
}
_, err = ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
resp.Body.Close()
return n... | [
"func",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"requester",
"Requester",
",",
"r",
"GetRequest",
")",
"error",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"r",
".",
"URL",
",",
"nil",
")",
"\n",
"if",
... | // Get gets an arbitrary file from the server or performs an arbitrary action, specified by URI | [
"Get",
"gets",
"an",
"arbitrary",
"file",
"from",
"the",
"server",
"or",
"performs",
"an",
"arbitrary",
"action",
"specified",
"by",
"URI"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/get.go#L16-L33 |
142,413 | jpfielding/gorets | pkg/proxy/config.go | Clear | func (l *Session) Clear() {
if l.requester == nil {
return
}
ctx := context.Background()
req := rets.LogoutRequest{URL: l.urls.Logout}
rets.Logout(ctx, l.requester, req)
if l.closer != nil {
l.closer.Close()
}
l.requester = nil
} | go | func (l *Session) Clear() {
if l.requester == nil {
return
}
ctx := context.Background()
req := rets.LogoutRequest{URL: l.urls.Logout}
rets.Logout(ctx, l.requester, req)
if l.closer != nil {
l.closer.Close()
}
l.requester = nil
} | [
"func",
"(",
"l",
"*",
"Session",
")",
"Clear",
"(",
")",
"{",
"if",
"l",
".",
"requester",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n",
"req",
":=",
"rets",
".",
"LogoutRequest",
"{",
"U... | // Clear the current session | [
"Clear",
"the",
"current",
"session"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/proxy/config.go#L51-L62 |
142,414 | jpfielding/gorets | pkg/proxy/config.go | Get | func (l *Session) Get() (rets.Requester, *rets.CapabilityURLs, error) {
if l.requester == nil {
req, closer, urls, err := l.create()
if err != nil {
return nil, nil, fmt.Errorf("rets session create")
}
l.requester = req
l.urls = urls
l.closer = closer
}
return l.requester, l.urls, nil
} | go | func (l *Session) Get() (rets.Requester, *rets.CapabilityURLs, error) {
if l.requester == nil {
req, closer, urls, err := l.create()
if err != nil {
return nil, nil, fmt.Errorf("rets session create")
}
l.requester = req
l.urls = urls
l.closer = closer
}
return l.requester, l.urls, nil
} | [
"func",
"(",
"l",
"*",
"Session",
")",
"Get",
"(",
")",
"(",
"rets",
".",
"Requester",
",",
"*",
"rets",
".",
"CapabilityURLs",
",",
"error",
")",
"{",
"if",
"l",
".",
"requester",
"==",
"nil",
"{",
"req",
",",
"closer",
",",
"urls",
",",
"err",
... | // Get returns the cached rets session | [
"Get",
"returns",
"the",
"cached",
"rets",
"session"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/proxy/config.go#L65-L76 |
142,415 | jpfielding/gorets | pkg/proxy/config.go | NewSession | func NewSession(c Config) (rets.Requester, io.Closer, error) {
// start with the default Dialer from http.DefaultTransport
transport := wirelog.NewHTTPTransport()
// if there is a need to proxy
if c.Proxy != "" {
log.Printf("Using proxy %s", c.Proxy)
d, err := proxy.SOCKS5("tcp", c.Proxy, nil, proxy.Direct)
i... | go | func NewSession(c Config) (rets.Requester, io.Closer, error) {
// start with the default Dialer from http.DefaultTransport
transport := wirelog.NewHTTPTransport()
// if there is a need to proxy
if c.Proxy != "" {
log.Printf("Using proxy %s", c.Proxy)
d, err := proxy.SOCKS5("tcp", c.Proxy, nil, proxy.Direct)
i... | [
"func",
"NewSession",
"(",
"c",
"Config",
")",
"(",
"rets",
".",
"Requester",
",",
"io",
".",
"Closer",
",",
"error",
")",
"{",
"// start with the default Dialer from http.DefaultTransport",
"transport",
":=",
"wirelog",
".",
"NewHTTPTransport",
"(",
")",
"\n",
... | // NewSession creates a Rets session from the given config | [
"NewSession",
"creates",
"a",
"Rets",
"session",
"from",
"the",
"given",
"config"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/proxy/config.go#L95-L127 |
142,416 | jpfielding/gorets | pkg/rets/encoding.go | CreateXMLDecoder | func CreateXMLDecoder(input io.Reader, strict bool) *xml.Decoder {
// drop any chars that will blow up the xml decoder and replace with a space
input = filter.NewReader(input, filter.XML10Filter(filter.SpaceChar))
decoder := xml.NewDecoder(input)
decoder.Strict = strict
// this only gets used when a proper xml hea... | go | func CreateXMLDecoder(input io.Reader, strict bool) *xml.Decoder {
// drop any chars that will blow up the xml decoder and replace with a space
input = filter.NewReader(input, filter.XML10Filter(filter.SpaceChar))
decoder := xml.NewDecoder(input)
decoder.Strict = strict
// this only gets used when a proper xml hea... | [
"func",
"CreateXMLDecoder",
"(",
"input",
"io",
".",
"Reader",
",",
"strict",
"bool",
")",
"*",
"xml",
".",
"Decoder",
"{",
"// drop any chars that will blow up the xml decoder and replace with a space",
"input",
"=",
"filter",
".",
"NewReader",
"(",
"input",
",",
"... | // CreateXMLDecoder decodes xml using the given the header if needed | [
"CreateXMLDecoder",
"decodes",
"xml",
"using",
"the",
"given",
"the",
"header",
"if",
"needed"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/encoding.go#L17-L25 |
142,417 | jpfielding/gorets | pkg/rets/encoding.go | ReEncodeReader | func ReEncodeReader(input io.ReadCloser, contentType string) io.ReadCloser {
if e, _, _ := charset.DetermineEncoding([]byte{}, contentType); e != encoding.Nop {
type closer struct {
io.Reader
io.Closer
}
tr := transform.NewReader(input, e.NewDecoder())
return closer{tr, input}
}
return input
} | go | func ReEncodeReader(input io.ReadCloser, contentType string) io.ReadCloser {
if e, _, _ := charset.DetermineEncoding([]byte{}, contentType); e != encoding.Nop {
type closer struct {
io.Reader
io.Closer
}
tr := transform.NewReader(input, e.NewDecoder())
return closer{tr, input}
}
return input
} | [
"func",
"ReEncodeReader",
"(",
"input",
"io",
".",
"ReadCloser",
",",
"contentType",
"string",
")",
"io",
".",
"ReadCloser",
"{",
"if",
"e",
",",
"_",
",",
"_",
":=",
"charset",
".",
"DetermineEncoding",
"(",
"[",
"]",
"byte",
"{",
"}",
",",
"contentTy... | // ReEncodeReader re-encodes a reader based on the http content type provided | [
"ReEncodeReader",
"re",
"-",
"encodes",
"a",
"reader",
"based",
"on",
"the",
"http",
"content",
"type",
"provided"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/encoding.go#L31-L41 |
142,418 | jpfielding/gorets | pkg/explorer/corsCodec.go | CodecWithCors | func CodecWithCors(corsDomains []string, baseCodec rpc.Codec) rpc.Codec {
return corsCodec{corsDomains, baseCodec}
} | go | func CodecWithCors(corsDomains []string, baseCodec rpc.Codec) rpc.Codec {
return corsCodec{corsDomains, baseCodec}
} | [
"func",
"CodecWithCors",
"(",
"corsDomains",
"[",
"]",
"string",
",",
"baseCodec",
"rpc",
".",
"Codec",
")",
"rpc",
".",
"Codec",
"{",
"return",
"corsCodec",
"{",
"corsDomains",
",",
"baseCodec",
"}",
"\n",
"}"
] | // CodecWithCors creates a custom Codec that adds headers to the WriteResponse | [
"CodecWithCors",
"creates",
"a",
"custom",
"Codec",
"that",
"adds",
"headers",
"to",
"the",
"WriteResponse"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/explorer/corsCodec.go#L11-L13 |
142,419 | jpfielding/gorets | pkg/explorer/corsCodec.go | WriteResponse | func (ccr corsCodecRequest) WriteResponse(w http.ResponseWriter, reply interface{}, methodErr error) error {
if len(ccr.corsDomains) > 0 {
w.Header().Add("Access-Control-Allow-Origin", strings.Join(ccr.corsDomains, " "))
}
return ccr.baseCodecRequest.WriteResponse(w, reply, methodErr)
} | go | func (ccr corsCodecRequest) WriteResponse(w http.ResponseWriter, reply interface{}, methodErr error) error {
if len(ccr.corsDomains) > 0 {
w.Header().Add("Access-Control-Allow-Origin", strings.Join(ccr.corsDomains, " "))
}
return ccr.baseCodecRequest.WriteResponse(w, reply, methodErr)
} | [
"func",
"(",
"ccr",
"corsCodecRequest",
")",
"WriteResponse",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"reply",
"interface",
"{",
"}",
",",
"methodErr",
"error",
")",
"error",
"{",
"if",
"len",
"(",
"ccr",
".",
"corsDomains",
")",
">",
"0",
"{",
"... | // WriteResponse adds headers onto the ResponseWriter then calls the baseCodecRequest WriteResponse | [
"WriteResponse",
"adds",
"headers",
"onto",
"the",
"ResponseWriter",
"then",
"calls",
"the",
"baseCodecRequest",
"WriteResponse"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/explorer/corsCodec.go#L31-L36 |
142,420 | jpfielding/gorets | pkg/metadata/util.go | To | func (fields FieldTransfer) To(target interface{}) {
for k, v := range fields {
val := reflect.ValueOf(target).Elem().FieldByNameFunc(func(n string) bool {
return strings.ToLower(n) == strings.ToLower(k)
})
if val.IsValid() && val.CanSet() {
val.SetString(v)
}
}
} | go | func (fields FieldTransfer) To(target interface{}) {
for k, v := range fields {
val := reflect.ValueOf(target).Elem().FieldByNameFunc(func(n string) bool {
return strings.ToLower(n) == strings.ToLower(k)
})
if val.IsValid() && val.CanSet() {
val.SetString(v)
}
}
} | [
"func",
"(",
"fields",
"FieldTransfer",
")",
"To",
"(",
"target",
"interface",
"{",
"}",
")",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"fields",
"{",
"val",
":=",
"reflect",
".",
"ValueOf",
"(",
"target",
")",
".",
"Elem",
"(",
")",
".",
"FieldByN... | // To is the function for moving the fields to the target | [
"To",
"is",
"the",
"function",
"for",
"moving",
"the",
"fields",
"to",
"the",
"target"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/metadata/util.go#L12-L21 |
142,421 | jpfielding/gorets | pkg/rets/metadata.go | PrepMetadataRequest | func PrepMetadataRequest(r MetadataRequest) (*http.Request, error) {
url, err := url.Parse(r.URL)
if err != nil {
return nil, err
}
values := url.Query()
// required
values.Add("Format", r.Format)
values.Add("Type", r.MType)
values.Add("ID", r.ID)
method := "GET"
if r.HTTPMethod != "" {
method = r.HTTPMe... | go | func PrepMetadataRequest(r MetadataRequest) (*http.Request, error) {
url, err := url.Parse(r.URL)
if err != nil {
return nil, err
}
values := url.Query()
// required
values.Add("Format", r.Format)
values.Add("Type", r.MType)
values.Add("ID", r.ID)
method := "GET"
if r.HTTPMethod != "" {
method = r.HTTPMe... | [
"func",
"PrepMetadataRequest",
"(",
"r",
"MetadataRequest",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"url",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"r",
".",
"URL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil"... | // PrepMetadataRequest creates an http.Request from a MetadataRequest | [
"PrepMetadataRequest",
"creates",
"an",
"http",
".",
"Request",
"from",
"a",
"MetadataRequest"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/metadata.go#L26-L50 |
142,422 | jpfielding/gorets | pkg/rets/client.go | DefaultSession | func DefaultSession(user, pwd, userAgent, userAgentPw, retsVersion string, transport http.RoundTripper) (Requester, error) {
if transport == nil {
transport = wirelog.NewHTTPTransport()
}
client := http.Client{
Transport: transport,
}
jar, err := cookiejar.New(nil)
if err != nil {
return nil, err
}
clie... | go | func DefaultSession(user, pwd, userAgent, userAgentPw, retsVersion string, transport http.RoundTripper) (Requester, error) {
if transport == nil {
transport = wirelog.NewHTTPTransport()
}
client := http.Client{
Transport: transport,
}
jar, err := cookiejar.New(nil)
if err != nil {
return nil, err
}
clie... | [
"func",
"DefaultSession",
"(",
"user",
",",
"pwd",
",",
"userAgent",
",",
"userAgentPw",
",",
"retsVersion",
"string",
",",
"transport",
"http",
".",
"RoundTripper",
")",
"(",
"Requester",
",",
"error",
")",
"{",
"if",
"transport",
"==",
"nil",
"{",
"trans... | // DefaultSession configures the default rets session | [
"DefaultSession",
"configures",
"the",
"default",
"rets",
"session"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/client.go#L41-L81 |
142,423 | jpfielding/gorets | pkg/config/config.go | Close | func (s *Session) Close() error {
var err error
if s.close != nil {
err = s.close()
}
s.close = nil
s.requester = nil
return err
} | go | func (s *Session) Close() error {
var err error
if s.close != nil {
err = s.close()
}
s.close = nil
s.requester = nil
return err
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Close",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"s",
".",
"close",
"!=",
"nil",
"{",
"err",
"=",
"s",
".",
"close",
"(",
")",
"\n",
"}",
"\n",
"s",
".",
"close",
"=",
"nil",
"\n",
"... | // Close is an io.Closer | [
"Close",
"is",
"an",
"io",
".",
"Closer"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/config/config.go#L86-L94 |
142,424 | jpfielding/gorets | pkg/config/config.go | Process | func (s *Session) Process(ctx context.Context, ops ...Op) error {
for _, op := range ops {
//op = retry(op, 3)
err := op(s.requester, s.urls)
if err != nil {
return err
}
}
return nil
} | go | func (s *Session) Process(ctx context.Context, ops ...Op) error {
for _, op := range ops {
//op = retry(op, 3)
err := op(s.requester, s.urls)
if err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Process",
"(",
"ctx",
"context",
".",
"Context",
",",
"ops",
"...",
"Op",
")",
"error",
"{",
"for",
"_",
",",
"op",
":=",
"range",
"ops",
"{",
"//op = retry(op, 3)",
"err",
":=",
"op",
"(",
"s",
".",
"request... | // Process processes a set of requests | [
"Process",
"processes",
"a",
"set",
"of",
"requests"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/config/config.go#L100-L109 |
142,425 | jpfielding/gorets | pkg/metadata/extract.go | Open | func (e *Extractor) Open() (RETSResponse, error) {
// TODO extract common work from rets/rets_response.go
rets := RETSResponse{}
e.parser = xml.NewDecoder(e.Body)
start, err := e.skipTo("(RETS|RETS-STATUS)")
if err != nil {
return rets, err
}
attrs := make(map[string]string)
for _, v := range start.Attr {
a... | go | func (e *Extractor) Open() (RETSResponse, error) {
// TODO extract common work from rets/rets_response.go
rets := RETSResponse{}
e.parser = xml.NewDecoder(e.Body)
start, err := e.skipTo("(RETS|RETS-STATUS)")
if err != nil {
return rets, err
}
attrs := make(map[string]string)
for _, v := range start.Attr {
a... | [
"func",
"(",
"e",
"*",
"Extractor",
")",
"Open",
"(",
")",
"(",
"RETSResponse",
",",
"error",
")",
"{",
"// TODO extract common work from rets/rets_response.go",
"rets",
":=",
"RETSResponse",
"{",
"}",
"\n",
"e",
".",
"parser",
"=",
"xml",
".",
"NewDecoder",
... | // Open a metadata stream and read in the RETS response | [
"Open",
"a",
"metadata",
"stream",
"and",
"read",
"in",
"the",
"RETS",
"response"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/metadata/extract.go#L18-L37 |
142,426 | jpfielding/gorets | pkg/metadata/extract.go | DecodeNext | func (e *Extractor) DecodeNext(match string, elem interface{}) error {
next, err := e.skipTo(match)
if err != nil {
return err
}
return e.parser.DecodeElement(elem, &next)
} | go | func (e *Extractor) DecodeNext(match string, elem interface{}) error {
next, err := e.skipTo(match)
if err != nil {
return err
}
return e.parser.DecodeElement(elem, &next)
} | [
"func",
"(",
"e",
"*",
"Extractor",
")",
"DecodeNext",
"(",
"match",
"string",
",",
"elem",
"interface",
"{",
"}",
")",
"error",
"{",
"next",
",",
"err",
":=",
"e",
".",
"skipTo",
"(",
"match",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // DecodeNext the provided elemment | [
"DecodeNext",
"the",
"provided",
"elemment"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/metadata/extract.go#L40-L46 |
142,427 | jpfielding/gorets | pkg/metadata/extract.go | skipTo | func (e *Extractor) skipTo(match string) (xml.StartElement, error) {
next, err := regexp.Compile(match)
if err != nil {
return xml.StartElement{}, err
}
for {
token, err := e.parser.Token()
if err != nil {
return xml.StartElement{}, err
}
switch t := token.(type) {
case xml.StartElement:
if next.M... | go | func (e *Extractor) skipTo(match string) (xml.StartElement, error) {
next, err := regexp.Compile(match)
if err != nil {
return xml.StartElement{}, err
}
for {
token, err := e.parser.Token()
if err != nil {
return xml.StartElement{}, err
}
switch t := token.(type) {
case xml.StartElement:
if next.M... | [
"func",
"(",
"e",
"*",
"Extractor",
")",
"skipTo",
"(",
"match",
"string",
")",
"(",
"xml",
".",
"StartElement",
",",
"error",
")",
"{",
"next",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"match",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"... | // skipTo advances the cursor to the named xml.StartElement | [
"skipTo",
"advances",
"the",
"cursor",
"to",
"the",
"named",
"xml",
".",
"StartElement"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/metadata/extract.go#L49-L66 |
142,428 | jpfielding/gorets | pkg/explorer/metadata.go | fullViaCompact | func fullViaCompact(ctx context.Context, requester rets.Requester, url string) (*metadata.MSystem, error) {
reader, err := rets.MetadataStream(rets.MetadataResponse(ctx, requester, rets.MetadataRequest{
URL: url,
MetadataParams: rets.MetadataParams{
Format: "COMPACT",
MType: "METADATA-SYSTEM",
ID: "*... | go | func fullViaCompact(ctx context.Context, requester rets.Requester, url string) (*metadata.MSystem, error) {
reader, err := rets.MetadataStream(rets.MetadataResponse(ctx, requester, rets.MetadataRequest{
URL: url,
MetadataParams: rets.MetadataParams{
Format: "COMPACT",
MType: "METADATA-SYSTEM",
ID: "*... | [
"func",
"fullViaCompact",
"(",
"ctx",
"context",
".",
"Context",
",",
"requester",
"rets",
".",
"Requester",
",",
"url",
"string",
")",
"(",
"*",
"metadata",
".",
"MSystem",
",",
"error",
")",
"{",
"reader",
",",
"err",
":=",
"rets",
".",
"MetadataStream... | // fullViaCompact retrieve the RETS Compact metadata from the server | [
"fullViaCompact",
"retrieve",
"the",
"RETS",
"Compact",
"metadata",
"from",
"the",
"server"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/explorer/metadata.go#L108-L126 |
142,429 | jpfielding/gorets | pkg/util/metadata_incremental.go | Load | func (ic *IncrementalCompact) Load(ctx context.Context, sess rets.Requester, url string) error {
// extract an id'd subesection of metadata
get := func(id, mtype string) (*rets.CompactMetadata, error) {
if id == "" {
id = "0"
}
params := rets.MetadataParams{
Format: "COMPACT",
MType: mtype,
ID: ... | go | func (ic *IncrementalCompact) Load(ctx context.Context, sess rets.Requester, url string) error {
// extract an id'd subesection of metadata
get := func(id, mtype string) (*rets.CompactMetadata, error) {
if id == "" {
id = "0"
}
params := rets.MetadataParams{
Format: "COMPACT",
MType: mtype,
ID: ... | [
"func",
"(",
"ic",
"*",
"IncrementalCompact",
")",
"Load",
"(",
"ctx",
"context",
".",
"Context",
",",
"sess",
"rets",
".",
"Requester",
",",
"url",
"string",
")",
"error",
"{",
"// extract an id'd subesection of metadata",
"get",
":=",
"func",
"(",
"id",
",... | // Load retrieve the RETS Compact metadata from the server | [
"Load",
"retrieve",
"the",
"RETS",
"Compact",
"metadata",
"from",
"the",
"server"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/util/metadata_incremental.go#L18-L56 |
142,430 | jpfielding/gorets | pkg/metadata/meta.go | ID | func (mi MetaInfo) ID(sub interface{}) string {
if msub, ok := sub.(map[string]string); ok {
return msub[mi.ContentID]
}
val := reflect.ValueOf(sub).Elem().FieldByNameFunc(func(n string) bool {
return strings.ToLower(n) == strings.ToLower(mi.ContentID)
})
if val.IsValid() {
return val.String()
}
return ""
... | go | func (mi MetaInfo) ID(sub interface{}) string {
if msub, ok := sub.(map[string]string); ok {
return msub[mi.ContentID]
}
val := reflect.ValueOf(sub).Elem().FieldByNameFunc(func(n string) bool {
return strings.ToLower(n) == strings.ToLower(mi.ContentID)
})
if val.IsValid() {
return val.String()
}
return ""
... | [
"func",
"(",
"mi",
"MetaInfo",
")",
"ID",
"(",
"sub",
"interface",
"{",
"}",
")",
"string",
"{",
"if",
"msub",
",",
"ok",
":=",
"sub",
".",
"(",
"map",
"[",
"string",
"]",
"string",
")",
";",
"ok",
"{",
"return",
"msub",
"[",
"mi",
".",
"Conten... | // ID returns the id of the given elem for this meta's info | [
"ID",
"returns",
"the",
"id",
"of",
"the",
"given",
"elem",
"for",
"this",
"meta",
"s",
"info"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/metadata/meta.go#L23-L34 |
142,431 | jpfielding/gorets | pkg/rets/search.go | PrepSearchRequest | func PrepSearchRequest(r SearchRequest) (*http.Request, error) {
url, err := url.Parse(r.URL)
if err != nil {
return nil, err
}
values := url.Query()
// required
values.Add("Class", r.Class)
values.Add("SearchType", r.SearchType)
// optional
optionalString := OptionalStringValue(values)
optionalString("For... | go | func PrepSearchRequest(r SearchRequest) (*http.Request, error) {
url, err := url.Parse(r.URL)
if err != nil {
return nil, err
}
values := url.Query()
// required
values.Add("Class", r.Class)
values.Add("SearchType", r.SearchType)
// optional
optionalString := OptionalStringValue(values)
optionalString("For... | [
"func",
"PrepSearchRequest",
"(",
"r",
"SearchRequest",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"url",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"r",
".",
"URL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // PrepSearchRequest creates an http.Request from a SearchRequest | [
"PrepSearchRequest",
"creates",
"an",
"http",
".",
"Request",
"from",
"a",
"SearchRequest"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/search.go#L66-L117 |
142,432 | jpfielding/gorets | pkg/rets/search.go | SearchResponse | func SearchResponse(ctx context.Context, requester Requester, r SearchRequest) (*http.Response, error) {
req, err := PrepSearchRequest(r)
if err != nil {
return nil, err
}
return requester(ctx, req)
} | go | func SearchResponse(ctx context.Context, requester Requester, r SearchRequest) (*http.Response, error) {
req, err := PrepSearchRequest(r)
if err != nil {
return nil, err
}
return requester(ctx, req)
} | [
"func",
"SearchResponse",
"(",
"ctx",
"context",
".",
"Context",
",",
"requester",
"Requester",
",",
"r",
"SearchRequest",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"PrepSearchRequest",
"(",
"r",
")",
"\n",
... | // SearchResponse returns the raw stream from the RETS server response | [
"SearchResponse",
"returns",
"the",
"raw",
"stream",
"from",
"the",
"RETS",
"server",
"response"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/search.go#L120-L126 |
142,433 | jpfielding/gorets | pkg/rets/search.go | SearchStream | func SearchStream(resp *http.Response, err error) (io.ReadCloser, error) {
if err != nil {
return nil, err
}
return DefaultReEncodeReader(resp.Body, resp.Header.Get(ContentType)), nil
} | go | func SearchStream(resp *http.Response, err error) (io.ReadCloser, error) {
if err != nil {
return nil, err
}
return DefaultReEncodeReader(resp.Body, resp.Header.Get(ContentType)), nil
} | [
"func",
"SearchStream",
"(",
"resp",
"*",
"http",
".",
"Response",
",",
"err",
"error",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"DefaultReEncode... | // SearchStream wraps the body with proper content decoding given the content type or char encoding | [
"SearchStream",
"wraps",
"the",
"body",
"with",
"proper",
"content",
"decoding",
"given",
"the",
"content",
"type",
"or",
"char",
"encoding"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/search.go#L129-L134 |
142,434 | jpfielding/gorets | pkg/rets/search_compact.go | SearchCompact | func SearchCompact(ctx context.Context, requester Requester, r SearchRequest) (*CompactSearchResult, error) {
body, err := SearchStream(SearchResponse(ctx, requester, r))
if err != nil {
return nil, err
}
return NewCompactSearchResult(body)
} | go | func SearchCompact(ctx context.Context, requester Requester, r SearchRequest) (*CompactSearchResult, error) {
body, err := SearchStream(SearchResponse(ctx, requester, r))
if err != nil {
return nil, err
}
return NewCompactSearchResult(body)
} | [
"func",
"SearchCompact",
"(",
"ctx",
"context",
".",
"Context",
",",
"requester",
"Requester",
",",
"r",
"SearchRequest",
")",
"(",
"*",
"CompactSearchResult",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"SearchStream",
"(",
"SearchResponse",
"(",
"ctx... | // SearchCompact wraps up most of the intermediate steps | [
"SearchCompact",
"wraps",
"up",
"most",
"of",
"the",
"intermediate",
"steps"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/search_compact.go#L14-L20 |
142,435 | jpfielding/gorets | pkg/rets/search_compact.go | ForEach | func (c *CompactSearchResult) ForEach(each EachRow) (bool, error) {
if c.body == nil {
return false, nil
}
maxRows := false
for {
token, err := c.parser.Token()
if err != nil {
// dont catch io.EOF here since a clean read should exit at the </RETS> tag
if err = each(nil, err); err != nil {
return ma... | go | func (c *CompactSearchResult) ForEach(each EachRow) (bool, error) {
if c.body == nil {
return false, nil
}
maxRows := false
for {
token, err := c.parser.Token()
if err != nil {
// dont catch io.EOF here since a clean read should exit at the </RETS> tag
if err = each(nil, err); err != nil {
return ma... | [
"func",
"(",
"c",
"*",
"CompactSearchResult",
")",
"ForEach",
"(",
"each",
"EachRow",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"c",
".",
"body",
"==",
"nil",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"maxRows",
":=",
"false",
"\n"... | // ForEach returns MaxRows and any error that 'each' wont handle | [
"ForEach",
"returns",
"MaxRows",
"and",
"any",
"error",
"that",
"each",
"wont",
"handle"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/search_compact.go#L38-L77 |
142,436 | jpfielding/gorets | pkg/rets/search_compact.go | NewCompactSearchResult | func NewCompactSearchResult(body io.ReadCloser) (*CompactSearchResult, error) {
parser := DefaultXMLDecoder(body, false)
result := &CompactSearchResult{
body: body,
parser: parser,
}
// extract the basic content before delving into the data
for {
token, err := parser.Token()
if err != nil {
return res... | go | func NewCompactSearchResult(body io.ReadCloser) (*CompactSearchResult, error) {
parser := DefaultXMLDecoder(body, false)
result := &CompactSearchResult{
body: body,
parser: parser,
}
// extract the basic content before delving into the data
for {
token, err := parser.Token()
if err != nil {
return res... | [
"func",
"NewCompactSearchResult",
"(",
"body",
"io",
".",
"ReadCloser",
")",
"(",
"*",
"CompactSearchResult",
",",
"error",
")",
"{",
"parser",
":=",
"DefaultXMLDecoder",
"(",
"body",
",",
"false",
")",
"\n",
"result",
":=",
"&",
"CompactSearchResult",
"{",
... | // NewCompactSearchResult _always_ close this | [
"NewCompactSearchResult",
"_always_",
"close",
"this"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/search_compact.go#L90-L139 |
142,437 | jpfielding/gorets | cmd/gorets/gorets.go | Initialize | func (cnt *Connect) Initialize() (rets.Requester, error) {
transport := wirelog.NewHTTPTransport()
if cnt.WireLog != "" {
wirelog.LogToFile(transport, cnt.WireLog, true, true)
fmt.Println("wire logging enabled:", cnt.WireLog)
}
// should we throw an err here too?
return rets.DefaultSession(
cnt.Username,
... | go | func (cnt *Connect) Initialize() (rets.Requester, error) {
transport := wirelog.NewHTTPTransport()
if cnt.WireLog != "" {
wirelog.LogToFile(transport, cnt.WireLog, true, true)
fmt.Println("wire logging enabled:", cnt.WireLog)
}
// should we throw an err here too?
return rets.DefaultSession(
cnt.Username,
... | [
"func",
"(",
"cnt",
"*",
"Connect",
")",
"Initialize",
"(",
")",
"(",
"rets",
".",
"Requester",
",",
"error",
")",
"{",
"transport",
":=",
"wirelog",
".",
"NewHTTPTransport",
"(",
")",
"\n\n",
"if",
"cnt",
".",
"WireLog",
"!=",
"\"",
"\"",
"{",
"wire... | // Initialize extracts the cmd line params and creates the rets.Requester | [
"Initialize",
"extracts",
"the",
"cmd",
"line",
"params",
"and",
"creates",
"the",
"rets",
".",
"Requester"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/cmd/gorets/gorets.go#L63-L79 |
142,438 | jpfielding/gorets | cmd/gorets/gorets.go | LoadFrom | func LoadFrom(filename string, model interface{}) error {
file, err := os.Open(filename)
defer file.Close()
if err != nil {
return err
}
blob, err := ioutil.ReadAll(file)
if err != nil {
return err
}
err = json.Unmarshal(blob, model)
if err != nil {
return err
}
return nil
} | go | func LoadFrom(filename string, model interface{}) error {
file, err := os.Open(filename)
defer file.Close()
if err != nil {
return err
}
blob, err := ioutil.ReadAll(file)
if err != nil {
return err
}
err = json.Unmarshal(blob, model)
if err != nil {
return err
}
return nil
} | [
"func",
"LoadFrom",
"(",
"filename",
"string",
",",
"model",
"interface",
"{",
"}",
")",
"error",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",... | // LoadFrom loads the model onto the struct | [
"LoadFrom",
"loads",
"the",
"model",
"onto",
"the",
"struct"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/cmd/gorets/gorets.go#L82-L97 |
142,439 | jpfielding/gorets | cmd/gorets/gorets.go | getPersistentFlagValues | func getPersistentFlagValues(f interface{}, cmd *cobra.Command) (Connect, string, time.Duration) {
cFile, err := cmd.Flags().GetString(connectFlag)
handleError(f, err)
output, err := cmd.Flags().GetString(outputFlag)
handleError(f, err)
// TODO investigate using GetDuration
timeout, err := cmd.Flags().GetInt64(... | go | func getPersistentFlagValues(f interface{}, cmd *cobra.Command) (Connect, string, time.Duration) {
cFile, err := cmd.Flags().GetString(connectFlag)
handleError(f, err)
output, err := cmd.Flags().GetString(outputFlag)
handleError(f, err)
// TODO investigate using GetDuration
timeout, err := cmd.Flags().GetInt64(... | [
"func",
"getPersistentFlagValues",
"(",
"f",
"interface",
"{",
"}",
",",
"cmd",
"*",
"cobra",
".",
"Command",
")",
"(",
"Connect",
",",
"string",
",",
"time",
".",
"Duration",
")",
"{",
"cFile",
",",
"err",
":=",
"cmd",
".",
"Flags",
"(",
")",
".",
... | // getPersistentFlagValues extracts the persistent flag values for us in each command | [
"getPersistentFlagValues",
"extracts",
"the",
"persistent",
"flag",
"values",
"for",
"us",
"in",
"each",
"command"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/cmd/gorets/gorets.go#L100-L117 |
142,440 | jpfielding/gorets | pkg/rets/getobject.go | PrepGetObjects | func PrepGetObjects(r GetObjectRequest) (*http.Request, error) {
url, err := url.Parse(r.URL)
if err != nil {
return nil, err
}
values := url.Query()
// required
values.Add("Resource", r.Resource)
values.Add("Type", r.Type)
// optional
optionalString := OptionalStringValue(values)
// one or the other _MU... | go | func PrepGetObjects(r GetObjectRequest) (*http.Request, error) {
url, err := url.Parse(r.URL)
if err != nil {
return nil, err
}
values := url.Query()
// required
values.Add("Resource", r.Resource)
values.Add("Type", r.Type)
// optional
optionalString := OptionalStringValue(values)
// one or the other _MU... | [
"func",
"PrepGetObjects",
"(",
"r",
"GetObjectRequest",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"url",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"r",
".",
"URL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // PrepGetObjects creates an http.Request from a GetObjectRequest | [
"PrepGetObjects",
"creates",
"an",
"http",
".",
"Request",
"from",
"a",
"GetObjectRequest"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/getobject.go#L17-L53 |
142,441 | jpfielding/gorets | pkg/rets/getobject.go | GetObjects | func GetObjects(ctx context.Context, requester Requester, r GetObjectRequest) (*http.Response, error) {
req, err := PrepGetObjects(r)
if err != nil {
return nil, err
}
return requester(ctx, req)
} | go | func GetObjects(ctx context.Context, requester Requester, r GetObjectRequest) (*http.Response, error) {
req, err := PrepGetObjects(r)
if err != nil {
return nil, err
}
return requester(ctx, req)
} | [
"func",
"GetObjects",
"(",
"ctx",
"context",
".",
"Context",
",",
"requester",
"Requester",
",",
"r",
"GetObjectRequest",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"PrepGetObjects",
"(",
"r",
")",
"\n",
"i... | // GetObjects sends the GetObject request | [
"GetObjects",
"sends",
"the",
"GetObject",
"request"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/getobject.go#L56-L62 |
142,442 | jpfielding/gorets | pkg/explorer/util.go | JSONExist | func JSONExist(filename string, ifNewerThan time.Duration) bool {
stat, err := os.Stat(filename + ".gz")
if os.IsNotExist(err) {
return false
}
return time.Since(stat.ModTime()) <= ifNewerThan
} | go | func JSONExist(filename string, ifNewerThan time.Duration) bool {
stat, err := os.Stat(filename + ".gz")
if os.IsNotExist(err) {
return false
}
return time.Since(stat.ModTime()) <= ifNewerThan
} | [
"func",
"JSONExist",
"(",
"filename",
"string",
",",
"ifNewerThan",
"time",
".",
"Duration",
")",
"bool",
"{",
"stat",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"filename",
"+",
"\"",
"\"",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
... | // GZIP the output
//JSONExist ... | [
"GZIP",
"the",
"output",
"JSONExist",
"..."
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/explorer/util.go#L17-L23 |
142,443 | jpfielding/gorets | pkg/explorer/util.go | JSONStore | func JSONStore(filename string, data interface{}) error {
dir := path.Dir(filename)
// TODO dont repeat this for every write
err := os.MkdirAll(dir, os.ModePerm)
if err != nil {
return err
}
f, err := os.Create(filename + ".tmp")
if err != nil {
return err
}
raw, err := json.Marshal(data)
if err != nil {
... | go | func JSONStore(filename string, data interface{}) error {
dir := path.Dir(filename)
// TODO dont repeat this for every write
err := os.MkdirAll(dir, os.ModePerm)
if err != nil {
return err
}
f, err := os.Create(filename + ".tmp")
if err != nil {
return err
}
raw, err := json.Marshal(data)
if err != nil {
... | [
"func",
"JSONStore",
"(",
"filename",
"string",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"dir",
":=",
"path",
".",
"Dir",
"(",
"filename",
")",
"\n",
"// TODO dont repeat this for every write",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"dir",
... | // JSONStore raw file storage | [
"JSONStore",
"raw",
"file",
"storage"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/explorer/util.go#L26-L60 |
142,444 | jpfielding/gorets | pkg/explorer/util.go | JSONLoad | func JSONLoad(filename string, data interface{}) error {
file, err := os.Open(filename + ".gz")
defer file.Close()
if err != nil {
return err
}
gz, err := gzip.NewReader(file)
if err != nil {
return err
}
blob, err := ioutil.ReadAll(gz)
if err != nil {
return err
}
err = json.Unmarshal(blob, data)
if ... | go | func JSONLoad(filename string, data interface{}) error {
file, err := os.Open(filename + ".gz")
defer file.Close()
if err != nil {
return err
}
gz, err := gzip.NewReader(file)
if err != nil {
return err
}
blob, err := ioutil.ReadAll(gz)
if err != nil {
return err
}
err = json.Unmarshal(blob, data)
if ... | [
"func",
"JSONLoad",
"(",
"filename",
"string",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n",
"if",
"... | // JSONLoad raw file load | [
"JSONLoad",
"raw",
"file",
"load"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/explorer/util.go#L63-L82 |
142,445 | jpfielding/gorets | pkg/rets/search_xml.go | StandardXMLSearch | func StandardXMLSearch(ctx context.Context, requester Requester, r SearchRequest) (*StandardXMLSearchResult, error) {
body, err := SearchStream(SearchResponse(ctx, requester, r))
if err != nil {
return nil, err
}
return NewStandardXMLSearchResult(body)
} | go | func StandardXMLSearch(ctx context.Context, requester Requester, r SearchRequest) (*StandardXMLSearchResult, error) {
body, err := SearchStream(SearchResponse(ctx, requester, r))
if err != nil {
return nil, err
}
return NewStandardXMLSearchResult(body)
} | [
"func",
"StandardXMLSearch",
"(",
"ctx",
"context",
".",
"Context",
",",
"requester",
"Requester",
",",
"r",
"SearchRequest",
")",
"(",
"*",
"StandardXMLSearchResult",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"SearchStream",
"(",
"SearchResponse",
"("... | // StandardXMLSearch if you set the wrong request Format you will get nothing back | [
"StandardXMLSearch",
"if",
"you",
"set",
"the",
"wrong",
"request",
"Format",
"you",
"will",
"get",
"nothing",
"back"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/search_xml.go#L13-L19 |
142,446 | jpfielding/gorets | pkg/rets/search_xml.go | ForEach | func (c *StandardXMLSearchResult) ForEach(match minidom.Matcher, each minidom.EachDOM) (int, bool, error) {
defer c.body.Close()
count := 0
maxrows := false
md := minidom.MiniDom{
StartFunc: func(start xml.StartElement) {
switch start.Name.Local {
case "COUNT":
count, _ = countTag(start).Parse()
case... | go | func (c *StandardXMLSearchResult) ForEach(match minidom.Matcher, each minidom.EachDOM) (int, bool, error) {
defer c.body.Close()
count := 0
maxrows := false
md := minidom.MiniDom{
StartFunc: func(start xml.StartElement) {
switch start.Name.Local {
case "COUNT":
count, _ = countTag(start).Parse()
case... | [
"func",
"(",
"c",
"*",
"StandardXMLSearchResult",
")",
"ForEach",
"(",
"match",
"minidom",
".",
"Matcher",
",",
"each",
"minidom",
".",
"EachDOM",
")",
"(",
"int",
",",
"bool",
",",
"error",
")",
"{",
"defer",
"c",
".",
"body",
".",
"Close",
"(",
")"... | // ForEach returns Count and MaxRows and any error that 'each' wont handle | [
"ForEach",
"returns",
"Count",
"and",
"MaxRows",
"and",
"any",
"error",
"that",
"each",
"wont",
"handle"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/search_xml.go#L30-L54 |
142,447 | jpfielding/gorets | pkg/rets/search_xml.go | Close | func (c *StandardXMLSearchResult) Close() error {
if c == nil || c.body == nil {
return nil
}
return c.body.Close()
} | go | func (c *StandardXMLSearchResult) Close() error {
if c == nil || c.body == nil {
return nil
}
return c.body.Close()
} | [
"func",
"(",
"c",
"*",
"StandardXMLSearchResult",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"c",
"==",
"nil",
"||",
"c",
".",
"body",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"c",
".",
"body",
".",
"Close",
"(",
")",
"\n",
... | // Close closesthe connection | [
"Close",
"closesthe",
"connection"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/search_xml.go#L57-L62 |
142,448 | jpfielding/gorets | pkg/rets/search_xml.go | NewStandardXMLSearchResult | func NewStandardXMLSearchResult(body io.ReadCloser) (*StandardXMLSearchResult, error) {
parser := DefaultXMLDecoder(body, false)
result := &StandardXMLSearchResult{
body: body,
parser: parser,
}
// extract the basic content before delving into the data
for {
token, err := parser.Token()
if err != nil {
... | go | func NewStandardXMLSearchResult(body io.ReadCloser) (*StandardXMLSearchResult, error) {
parser := DefaultXMLDecoder(body, false)
result := &StandardXMLSearchResult{
body: body,
parser: parser,
}
// extract the basic content before delving into the data
for {
token, err := parser.Token()
if err != nil {
... | [
"func",
"NewStandardXMLSearchResult",
"(",
"body",
"io",
".",
"ReadCloser",
")",
"(",
"*",
"StandardXMLSearchResult",
",",
"error",
")",
"{",
"parser",
":=",
"DefaultXMLDecoder",
"(",
"body",
",",
"false",
")",
"\n",
"result",
":=",
"&",
"StandardXMLSearchResult... | // NewStandardXMLSearchResult returns an XML search result handler to listen to elements | [
"NewStandardXMLSearchResult",
"returns",
"an",
"XML",
"search",
"result",
"handler",
"to",
"listen",
"to",
"elements"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/search_xml.go#L65-L87 |
142,449 | jpfielding/gorets | pkg/rets/get_payload_list.go | PrepGetPayloadList | func PrepGetPayloadList(r PayloadListRequest) (*http.Request, error) {
url, err := url.Parse(r.URL)
if err != nil {
return nil, err
}
values := url.Query()
// required
values.Add("ID", r.ID)
method := DefaultHTTPMethod
if r.HTTPMethod != "" {
method = r.HTTPMethod
}
url.RawQuery = values.Encode()
retur... | go | func PrepGetPayloadList(r PayloadListRequest) (*http.Request, error) {
url, err := url.Parse(r.URL)
if err != nil {
return nil, err
}
values := url.Query()
// required
values.Add("ID", r.ID)
method := DefaultHTTPMethod
if r.HTTPMethod != "" {
method = r.HTTPMethod
}
url.RawQuery = values.Encode()
retur... | [
"func",
"PrepGetPayloadList",
"(",
"r",
"PayloadListRequest",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"url",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"r",
".",
"URL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ni... | // PrepGetPayloadList creates an http.Request from a PayloadListRequest | [
"PrepGetPayloadList",
"creates",
"an",
"http",
".",
"Request",
"from",
"a",
"PayloadListRequest"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/get_payload_list.go#L18-L34 |
142,450 | jpfielding/gorets | pkg/rets/get_payload_list.go | NewPayloadList | func NewPayloadList(body io.ReadCloser) (PayloadList, error) {
parser := xml.NewDecoder(body)
// return a composite result and offer walk/close options
pl := PayloadList{
body: body,
parser: parser,
delim: CompactDefaultDelim,
}
for {
token, err := parser.Token()
if err != nil {
return pl, err
}... | go | func NewPayloadList(body io.ReadCloser) (PayloadList, error) {
parser := xml.NewDecoder(body)
// return a composite result and offer walk/close options
pl := PayloadList{
body: body,
parser: parser,
delim: CompactDefaultDelim,
}
for {
token, err := parser.Token()
if err != nil {
return pl, err
}... | [
"func",
"NewPayloadList",
"(",
"body",
"io",
".",
"ReadCloser",
")",
"(",
"PayloadList",
",",
"error",
")",
"{",
"parser",
":=",
"xml",
".",
"NewDecoder",
"(",
"body",
")",
"\n\n",
"// return a composite result and offer walk/close options",
"pl",
":=",
"PayloadLi... | // NewPayloadList parse a stream and reads PayloadLists | [
"NewPayloadList",
"parse",
"a",
"stream",
"and",
"reads",
"PayloadLists"
] | 1fe0f2d805aec564b6a18e24909e0f544a71e0a3 | https://github.com/jpfielding/gorets/blob/1fe0f2d805aec564b6a18e24909e0f544a71e0a3/pkg/rets/get_payload_list.go#L92-L124 |
142,451 | asim/go-os | kv/os.go | setup | func (o *os) setup() {
for i := 0; i < 10; i++ {
// wait till there's a valid address from the server
if p := strings.Split(o.address(), ":"); len(p) < 2 {
time.Sleep(GossipEvent / 100.0)
continue
}
// have a valid address, setup, now
o.subscriber(context.Background(), &Announcement{
Namespace: o.op... | go | func (o *os) setup() {
for i := 0; i < 10; i++ {
// wait till there's a valid address from the server
if p := strings.Split(o.address(), ":"); len(p) < 2 {
time.Sleep(GossipEvent / 100.0)
continue
}
// have a valid address, setup, now
o.subscriber(context.Background(), &Announcement{
Namespace: o.op... | [
"func",
"(",
"o",
"*",
"os",
")",
"setup",
"(",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"10",
";",
"i",
"++",
"{",
"// wait till there's a valid address from the server",
"if",
"p",
":=",
"strings",
".",
"Split",
"(",
"o",
".",
"address",
"("... | // immediately add self to ring | [
"immediately",
"add",
"self",
"to",
"ring"
] | 2efaa0cdc33a4f7c7fd7cec4a8b2ff9449cca308 | https://github.com/asim/go-os/blob/2efaa0cdc33a4f7c7fd7cec4a8b2ff9449cca308/kv/os.go#L210-L225 |
142,452 | asim/go-os | discovery/options.go | Client | func Client(c client.Client) registry.Option {
return func(o *registry.Options) {
opts := getOptions(o.Context)
opts.Client = c
o.Context = setOptions(o.Context, opts)
}
} | go | func Client(c client.Client) registry.Option {
return func(o *registry.Options) {
opts := getOptions(o.Context)
opts.Client = c
o.Context = setOptions(o.Context, opts)
}
} | [
"func",
"Client",
"(",
"c",
"client",
".",
"Client",
")",
"registry",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"registry",
".",
"Options",
")",
"{",
"opts",
":=",
"getOptions",
"(",
"o",
".",
"Context",
")",
"\n",
"opts",
".",
"Client",
... | // Client used to call the discovery service | [
"Client",
"used",
"to",
"call",
"the",
"discovery",
"service"
] | 2efaa0cdc33a4f7c7fd7cec4a8b2ff9449cca308 | https://github.com/asim/go-os/blob/2efaa0cdc33a4f7c7fd7cec4a8b2ff9449cca308/discovery/options.go#L31-L37 |
142,453 | asim/go-os | discovery/options.go | Interval | func Interval(i time.Duration) registry.Option {
return func(o *registry.Options) {
opts := getOptions(o.Context)
opts.Interval = i
o.Context = setOptions(o.Context, opts)
}
} | go | func Interval(i time.Duration) registry.Option {
return func(o *registry.Options) {
opts := getOptions(o.Context)
opts.Interval = i
o.Context = setOptions(o.Context, opts)
}
} | [
"func",
"Interval",
"(",
"i",
"time",
".",
"Duration",
")",
"registry",
".",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"registry",
".",
"Options",
")",
"{",
"opts",
":=",
"getOptions",
"(",
"o",
".",
"Context",
")",
"\n",
"opts",
".",
"Interval... | // Interval on which to publish heartbeats | [
"Interval",
"on",
"which",
"to",
"publish",
"heartbeats"
] | 2efaa0cdc33a4f7c7fd7cec4a8b2ff9449cca308 | https://github.com/asim/go-os/blob/2efaa0cdc33a4f7c7fd7cec4a8b2ff9449cca308/discovery/options.go#L40-L46 |
142,454 | asim/go-os | config/options.go | PollInterval | func PollInterval(i time.Duration) Option {
return func(o *Options) {
o.PollInterval = i
}
} | go | func PollInterval(i time.Duration) Option {
return func(o *Options) {
o.PollInterval = i
}
} | [
"func",
"PollInterval",
"(",
"i",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"Options",
")",
"{",
"o",
".",
"PollInterval",
"=",
"i",
"\n",
"}",
"\n",
"}"
] | // PollInterval is the time interval at which the sources are polled
// to retrieve config. | [
"PollInterval",
"is",
"the",
"time",
"interval",
"at",
"which",
"the",
"sources",
"are",
"polled",
"to",
"retrieve",
"config",
"."
] | 2efaa0cdc33a4f7c7fd7cec4a8b2ff9449cca308 | https://github.com/asim/go-os/blob/2efaa0cdc33a4f7c7fd7cec4a8b2ff9449cca308/config/options.go#L32-L36 |
142,455 | asim/go-os | config/options.go | WithSource | func WithSource(s Source) Option {
return func(o *Options) {
o.Sources = append(o.Sources, s)
}
} | go | func WithSource(s Source) Option {
return func(o *Options) {
o.Sources = append(o.Sources, s)
}
} | [
"func",
"WithSource",
"(",
"s",
"Source",
")",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"Options",
")",
"{",
"o",
".",
"Sources",
"=",
"append",
"(",
"o",
".",
"Sources",
",",
"s",
")",
"\n",
"}",
"\n",
"}"
] | // WithSource appends a source to our list of sources.
// This forms a hierarchy whereby all the configs are
// merged down with the last specified as favoured. | [
"WithSource",
"appends",
"a",
"source",
"to",
"our",
"list",
"of",
"sources",
".",
"This",
"forms",
"a",
"hierarchy",
"whereby",
"all",
"the",
"configs",
"are",
"merged",
"down",
"with",
"the",
"last",
"specified",
"as",
"favoured",
"."
] | 2efaa0cdc33a4f7c7fd7cec4a8b2ff9449cca308 | https://github.com/asim/go-os/blob/2efaa0cdc33a4f7c7fd7cec4a8b2ff9449cca308/config/options.go#L41-L45 |
142,456 | tonistiigi/fsutil | copy/copy.go | Copy | func Copy(ctx context.Context, srcRoot, src, dstRoot, dst string, opts ...Opt) error {
var ci CopyInfo
for _, o := range opts {
o(&ci)
}
ensureDstPath := dst
if d, f := filepath.Split(dst); f != "" && f != "." {
ensureDstPath = d
}
if ensureDstPath != "" {
ensureDstPath, err := fs.RootPath(dstRoot, ensureD... | go | func Copy(ctx context.Context, srcRoot, src, dstRoot, dst string, opts ...Opt) error {
var ci CopyInfo
for _, o := range opts {
o(&ci)
}
ensureDstPath := dst
if d, f := filepath.Split(dst); f != "" && f != "." {
ensureDstPath = d
}
if ensureDstPath != "" {
ensureDstPath, err := fs.RootPath(dstRoot, ensureD... | [
"func",
"Copy",
"(",
"ctx",
"context",
".",
"Context",
",",
"srcRoot",
",",
"src",
",",
"dstRoot",
",",
"dst",
"string",
",",
"opts",
"...",
"Opt",
")",
"error",
"{",
"var",
"ci",
"CopyInfo",
"\n",
"for",
"_",
",",
"o",
":=",
"range",
"opts",
"{",
... | // Copy copies files using `cp -a` semantics.
// Copy is likely unsafe to be used in non-containerized environments. | [
"Copy",
"copies",
"files",
"using",
"cp",
"-",
"a",
"semantics",
".",
"Copy",
"is",
"likely",
"unsafe",
"to",
"be",
"used",
"in",
"non",
"-",
"containerized",
"environments",
"."
] | 524c23dab7263a29f44aec5b451921cb892fe2a4 | https://github.com/tonistiigi/fsutil/blob/524c23dab7263a29f44aec5b451921cb892fe2a4/copy/copy.go#L65-L118 |
142,457 | tonistiigi/fsutil | copy/copy.go | copy | func (c *copier) copy(ctx context.Context, src, target string, overwriteTargetMetadata bool) error {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
fi, err := os.Lstat(src)
if err != nil {
return errors.Wrapf(err, "failed to stat %s", src)
}
if !fi.IsDir() {
if err := ensureEmptyFileTarget(targe... | go | func (c *copier) copy(ctx context.Context, src, target string, overwriteTargetMetadata bool) error {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
fi, err := os.Lstat(src)
if err != nil {
return errors.Wrapf(err, "failed to stat %s", src)
}
if !fi.IsDir() {
if err := ensureEmptyFileTarget(targe... | [
"func",
"(",
"c",
"*",
"copier",
")",
"copy",
"(",
"ctx",
"context",
".",
"Context",
",",
"src",
",",
"target",
"string",
",",
"overwriteTargetMetadata",
"bool",
")",
"error",
"{",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"retu... | // dest is always clean | [
"dest",
"is",
"always",
"clean"
] | 524c23dab7263a29f44aec5b451921cb892fe2a4 | https://github.com/tonistiigi/fsutil/blob/524c23dab7263a29f44aec5b451921cb892fe2a4/copy/copy.go#L214-L279 |
142,458 | tonistiigi/fsutil | copy/copy.go | rel | func rel(basepath, targpath string) (string, error) {
// filepath.Rel can't handle UUID paths in windows
if runtime.GOOS == "windows" {
pfx := basepath + `\`
if strings.HasPrefix(targpath, pfx) {
p := strings.TrimPrefix(targpath, pfx)
if p == "" {
p = "."
}
return p, nil
}
}
return filepath.Re... | go | func rel(basepath, targpath string) (string, error) {
// filepath.Rel can't handle UUID paths in windows
if runtime.GOOS == "windows" {
pfx := basepath + `\`
if strings.HasPrefix(targpath, pfx) {
p := strings.TrimPrefix(targpath, pfx)
if p == "" {
p = "."
}
return p, nil
}
}
return filepath.Re... | [
"func",
"rel",
"(",
"basepath",
",",
"targpath",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"// filepath.Rel can't handle UUID paths in windows",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"pfx",
":=",
"basepath",
"+",
"`\\`",
"\n",
"if"... | // rel makes a path relative to base path. Same as `filepath.Rel` but can also
// handle UUID paths in windows. | [
"rel",
"makes",
"a",
"path",
"relative",
"to",
"base",
"path",
".",
"Same",
"as",
"filepath",
".",
"Rel",
"but",
"can",
"also",
"handle",
"UUID",
"paths",
"in",
"windows",
"."
] | 524c23dab7263a29f44aec5b451921cb892fe2a4 | https://github.com/tonistiigi/fsutil/blob/524c23dab7263a29f44aec5b451921cb892fe2a4/copy/copy.go#L395-L408 |
142,459 | tonistiigi/fsutil | diff_containerd.go | doubleWalkDiff | func doubleWalkDiff(ctx context.Context, changeFn ChangeFunc, a, b walkerFn) (err error) {
g, ctx := errgroup.WithContext(ctx)
var (
c1 = make(chan *currentPath, 128)
c2 = make(chan *currentPath, 128)
f1, f2 *currentPath
rmdir string
)
g.Go(func() error {
defer close(c1)
return a(ctx, c1)
})
g.Go(f... | go | func doubleWalkDiff(ctx context.Context, changeFn ChangeFunc, a, b walkerFn) (err error) {
g, ctx := errgroup.WithContext(ctx)
var (
c1 = make(chan *currentPath, 128)
c2 = make(chan *currentPath, 128)
f1, f2 *currentPath
rmdir string
)
g.Go(func() error {
defer close(c1)
return a(ctx, c1)
})
g.Go(f... | [
"func",
"doubleWalkDiff",
"(",
"ctx",
"context",
".",
"Context",
",",
"changeFn",
"ChangeFunc",
",",
"a",
",",
"b",
"walkerFn",
")",
"(",
"err",
"error",
")",
"{",
"g",
",",
"ctx",
":=",
"errgroup",
".",
"WithContext",
"(",
"ctx",
")",
"\n\n",
"var",
... | // doubleWalkDiff walks both directories to create a diff | [
"doubleWalkDiff",
"walks",
"both",
"directories",
"to",
"create",
"a",
"diff"
] | 524c23dab7263a29f44aec5b451921cb892fe2a4 | https://github.com/tonistiigi/fsutil/blob/524c23dab7263a29f44aec5b451921cb892fe2a4/diff_containerd.go#L45-L135 |
142,460 | tonistiigi/fsutil | diff_containerd.go | compareStat | func compareStat(ls1, ls2 *types.Stat) (bool, error) {
return ls1.Mode == ls2.Mode && ls1.Uid == ls2.Uid && ls1.Gid == ls2.Gid && ls1.Devmajor == ls2.Devmajor && ls1.Devminor == ls2.Devminor && ls1.Linkname == ls2.Linkname, nil
} | go | func compareStat(ls1, ls2 *types.Stat) (bool, error) {
return ls1.Mode == ls2.Mode && ls1.Uid == ls2.Uid && ls1.Gid == ls2.Gid && ls1.Devmajor == ls2.Devmajor && ls1.Devminor == ls2.Devminor && ls1.Linkname == ls2.Linkname, nil
} | [
"func",
"compareStat",
"(",
"ls1",
",",
"ls2",
"*",
"types",
".",
"Stat",
")",
"(",
"bool",
",",
"error",
")",
"{",
"return",
"ls1",
".",
"Mode",
"==",
"ls2",
".",
"Mode",
"&&",
"ls1",
".",
"Uid",
"==",
"ls2",
".",
"Uid",
"&&",
"ls1",
".",
"Gid... | // compareStat returns whether the stats are equivalent,
// whether the files are considered the same file, and
// an error | [
"compareStat",
"returns",
"whether",
"the",
"stats",
"are",
"equivalent",
"whether",
"the",
"files",
"are",
"considered",
"the",
"same",
"file",
"and",
"an",
"error"
] | 524c23dab7263a29f44aec5b451921cb892fe2a4 | https://github.com/tonistiigi/fsutil/blob/524c23dab7263a29f44aec5b451921cb892fe2a4/diff_containerd.go#L189-L191 |
142,461 | tonistiigi/fsutil | followlinks.go | dedupePaths | func dedupePaths(in []string) []string {
out := make([]string, 0, len(in))
var last string
for _, s := range in {
// if one of the paths is root there is no filter
if s == "." {
return nil
}
if strings.HasPrefix(s, last+string(filepath.Separator)) {
continue
}
out = append(out, s)
last = s
}
re... | go | func dedupePaths(in []string) []string {
out := make([]string, 0, len(in))
var last string
for _, s := range in {
// if one of the paths is root there is no filter
if s == "." {
return nil
}
if strings.HasPrefix(s, last+string(filepath.Separator)) {
continue
}
out = append(out, s)
last = s
}
re... | [
"func",
"dedupePaths",
"(",
"in",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"in",
")",
")",
"\n",
"var",
"last",
"string",
"\n",
"for",
"_",
",",
"s",
":=",
"ran... | // dedupePaths expects input as a sorted list | [
"dedupePaths",
"expects",
"input",
"as",
"a",
"sorted",
"list"
] | 524c23dab7263a29f44aec5b451921cb892fe2a4 | https://github.com/tonistiigi/fsutil/blob/524c23dab7263a29f44aec5b451921cb892fe2a4/followlinks.go#L135-L150 |
142,462 | tonistiigi/fsutil | copy/mkdir.go | MkdirAll | func MkdirAll(path string, perm os.FileMode, user *ChownOpt, tm *time.Time) error {
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
dir, err := os.Stat(path)
if err == nil {
if dir.IsDir() {
return nil
}
return &os.PathError{Op: "mkdir", Path: path, Err: syscall... | go | func MkdirAll(path string, perm os.FileMode, user *ChownOpt, tm *time.Time) error {
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
dir, err := os.Stat(path)
if err == nil {
if dir.IsDir() {
return nil
}
return &os.PathError{Op: "mkdir", Path: path, Err: syscall... | [
"func",
"MkdirAll",
"(",
"path",
"string",
",",
"perm",
"os",
".",
"FileMode",
",",
"user",
"*",
"ChownOpt",
",",
"tm",
"*",
"time",
".",
"Time",
")",
"error",
"{",
"// Fast path: if we can tell whether path is a directory or file, stop with success or error.",
"dir",... | // MkdirAll is forked os.MkdirAll | [
"MkdirAll",
"is",
"forked",
"os",
".",
"MkdirAll"
] | 524c23dab7263a29f44aec5b451921cb892fe2a4 | https://github.com/tonistiigi/fsutil/blob/524c23dab7263a29f44aec5b451921cb892fe2a4/copy/mkdir.go#L19-L74 |
142,463 | vishalkuo/bimap | bimap.go | Insert | func (b *BiMap) Insert(k interface{}, v interface{}) {
b.s.RLock()
if b.immutable {
panic("Cannot modify immutable map")
}
b.s.RUnlock()
b.s.Lock()
defer b.s.Unlock()
b.forward[k] = v
b.inverse[v] = k
} | go | func (b *BiMap) Insert(k interface{}, v interface{}) {
b.s.RLock()
if b.immutable {
panic("Cannot modify immutable map")
}
b.s.RUnlock()
b.s.Lock()
defer b.s.Unlock()
b.forward[k] = v
b.inverse[v] = k
} | [
"func",
"(",
"b",
"*",
"BiMap",
")",
"Insert",
"(",
"k",
"interface",
"{",
"}",
",",
"v",
"interface",
"{",
"}",
")",
"{",
"b",
".",
"s",
".",
"RLock",
"(",
")",
"\n",
"if",
"b",
".",
"immutable",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"... | // Insert puts a key and value into the BiMap, provided its mutable. Also creates the reverse mapping from value to key. | [
"Insert",
"puts",
"a",
"key",
"and",
"value",
"into",
"the",
"BiMap",
"provided",
"its",
"mutable",
".",
"Also",
"creates",
"the",
"reverse",
"mapping",
"from",
"value",
"to",
"key",
"."
] | 09cff281464521368a6976f06c75e4ee9745ab7c | https://github.com/vishalkuo/bimap/blob/09cff281464521368a6976f06c75e4ee9745ab7c/bimap.go#L20-L31 |
142,464 | vishalkuo/bimap | bimap.go | Exists | func (b *BiMap) Exists(k interface{}) bool {
b.s.RLock()
defer b.s.RUnlock()
_, ok := b.forward[k]
return ok
} | go | func (b *BiMap) Exists(k interface{}) bool {
b.s.RLock()
defer b.s.RUnlock()
_, ok := b.forward[k]
return ok
} | [
"func",
"(",
"b",
"*",
"BiMap",
")",
"Exists",
"(",
"k",
"interface",
"{",
"}",
")",
"bool",
"{",
"b",
".",
"s",
".",
"RLock",
"(",
")",
"\n",
"defer",
"b",
".",
"s",
".",
"RUnlock",
"(",
")",
"\n",
"_",
",",
"ok",
":=",
"b",
".",
"forward"... | // Exists checks whether or not a key exists in the BiMap | [
"Exists",
"checks",
"whether",
"or",
"not",
"a",
"key",
"exists",
"in",
"the",
"BiMap"
] | 09cff281464521368a6976f06c75e4ee9745ab7c | https://github.com/vishalkuo/bimap/blob/09cff281464521368a6976f06c75e4ee9745ab7c/bimap.go#L34-L39 |
142,465 | vishalkuo/bimap | bimap.go | ExistsInverse | func (b *BiMap) ExistsInverse(k interface{}) bool {
b.s.RLock()
defer b.s.RUnlock()
_, ok := b.inverse[k]
return ok
} | go | func (b *BiMap) ExistsInverse(k interface{}) bool {
b.s.RLock()
defer b.s.RUnlock()
_, ok := b.inverse[k]
return ok
} | [
"func",
"(",
"b",
"*",
"BiMap",
")",
"ExistsInverse",
"(",
"k",
"interface",
"{",
"}",
")",
"bool",
"{",
"b",
".",
"s",
".",
"RLock",
"(",
")",
"\n",
"defer",
"b",
".",
"s",
".",
"RUnlock",
"(",
")",
"\n\n",
"_",
",",
"ok",
":=",
"b",
".",
... | // ExistsInverse checks whether or not a value exists in the BiMap | [
"ExistsInverse",
"checks",
"whether",
"or",
"not",
"a",
"value",
"exists",
"in",
"the",
"BiMap"
] | 09cff281464521368a6976f06c75e4ee9745ab7c | https://github.com/vishalkuo/bimap/blob/09cff281464521368a6976f06c75e4ee9745ab7c/bimap.go#L42-L48 |
142,466 | vishalkuo/bimap | bimap.go | Get | func (b *BiMap) Get(k interface{}) (interface{}, bool) {
if !b.Exists(k) {
return "", false
}
b.s.RLock()
defer b.s.RUnlock()
return b.forward[k], true
} | go | func (b *BiMap) Get(k interface{}) (interface{}, bool) {
if !b.Exists(k) {
return "", false
}
b.s.RLock()
defer b.s.RUnlock()
return b.forward[k], true
} | [
"func",
"(",
"b",
"*",
"BiMap",
")",
"Get",
"(",
"k",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"if",
"!",
"b",
".",
"Exists",
"(",
"k",
")",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n",
"b"... | // Get returns the value for a given key in the BiMap and whether or not the element was present. | [
"Get",
"returns",
"the",
"value",
"for",
"a",
"given",
"key",
"in",
"the",
"BiMap",
"and",
"whether",
"or",
"not",
"the",
"element",
"was",
"present",
"."
] | 09cff281464521368a6976f06c75e4ee9745ab7c | https://github.com/vishalkuo/bimap/blob/09cff281464521368a6976f06c75e4ee9745ab7c/bimap.go#L51-L59 |
142,467 | vishalkuo/bimap | bimap.go | GetInverse | func (b *BiMap) GetInverse(v interface{}) (interface{}, bool) {
if !b.ExistsInverse(v) {
return "", false
}
b.s.RLock()
defer b.s.RUnlock()
return b.inverse[v], true
} | go | func (b *BiMap) GetInverse(v interface{}) (interface{}, bool) {
if !b.ExistsInverse(v) {
return "", false
}
b.s.RLock()
defer b.s.RUnlock()
return b.inverse[v], true
} | [
"func",
"(",
"b",
"*",
"BiMap",
")",
"GetInverse",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"if",
"!",
"b",
".",
"ExistsInverse",
"(",
"v",
")",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",... | // GetInverse returns the key for a given value in the BiMap and whether or not the element was present. | [
"GetInverse",
"returns",
"the",
"key",
"for",
"a",
"given",
"value",
"in",
"the",
"BiMap",
"and",
"whether",
"or",
"not",
"the",
"element",
"was",
"present",
"."
] | 09cff281464521368a6976f06c75e4ee9745ab7c | https://github.com/vishalkuo/bimap/blob/09cff281464521368a6976f06c75e4ee9745ab7c/bimap.go#L62-L70 |
142,468 | vishalkuo/bimap | bimap.go | Delete | func (b *BiMap) Delete(k interface{}) {
b.s.RLock()
if b.immutable {
panic("Cannot modify immutable map")
}
b.s.RUnlock()
if !b.Exists(k) {
return
}
val, _ := b.Get(k)
b.s.Lock()
defer b.s.Unlock()
delete(b.forward, k)
delete(b.inverse, val)
} | go | func (b *BiMap) Delete(k interface{}) {
b.s.RLock()
if b.immutable {
panic("Cannot modify immutable map")
}
b.s.RUnlock()
if !b.Exists(k) {
return
}
val, _ := b.Get(k)
b.s.Lock()
defer b.s.Unlock()
delete(b.forward, k)
delete(b.inverse, val)
} | [
"func",
"(",
"b",
"*",
"BiMap",
")",
"Delete",
"(",
"k",
"interface",
"{",
"}",
")",
"{",
"b",
".",
"s",
".",
"RLock",
"(",
")",
"\n",
"if",
"b",
".",
"immutable",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"b",
".",
"s",
".",
"... | // Delete removes a key-value pair from the BiMap for a given key. Returns if the key doesn't exist | [
"Delete",
"removes",
"a",
"key",
"-",
"value",
"pair",
"from",
"the",
"BiMap",
"for",
"a",
"given",
"key",
".",
"Returns",
"if",
"the",
"key",
"doesn",
"t",
"exist"
] | 09cff281464521368a6976f06c75e4ee9745ab7c | https://github.com/vishalkuo/bimap/blob/09cff281464521368a6976f06c75e4ee9745ab7c/bimap.go#L73-L88 |
142,469 | vishalkuo/bimap | bimap.go | DeleteInverse | func (b *BiMap) DeleteInverse(v interface{}) {
b.s.RLock()
if b.immutable {
panic("Cannot modify immutable map")
}
b.s.RUnlock()
if !b.ExistsInverse(v) {
return
}
key, _ := b.GetInverse(v)
b.s.Lock()
defer b.s.Unlock()
delete(b.inverse, v)
delete(b.forward, key)
} | go | func (b *BiMap) DeleteInverse(v interface{}) {
b.s.RLock()
if b.immutable {
panic("Cannot modify immutable map")
}
b.s.RUnlock()
if !b.ExistsInverse(v) {
return
}
key, _ := b.GetInverse(v)
b.s.Lock()
defer b.s.Unlock()
delete(b.inverse, v)
delete(b.forward, key)
} | [
"func",
"(",
"b",
"*",
"BiMap",
")",
"DeleteInverse",
"(",
"v",
"interface",
"{",
"}",
")",
"{",
"b",
".",
"s",
".",
"RLock",
"(",
")",
"\n",
"if",
"b",
".",
"immutable",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"b",
".",
"s",
"... | // DeleteInverse emoves a key-value pair from the BiMap for a given value. Returns if the value doesn't exist | [
"DeleteInverse",
"emoves",
"a",
"key",
"-",
"value",
"pair",
"from",
"the",
"BiMap",
"for",
"a",
"given",
"value",
".",
"Returns",
"if",
"the",
"value",
"doesn",
"t",
"exist"
] | 09cff281464521368a6976f06c75e4ee9745ab7c | https://github.com/vishalkuo/bimap/blob/09cff281464521368a6976f06c75e4ee9745ab7c/bimap.go#L91-L108 |
142,470 | vishalkuo/bimap | bimap.go | Size | func (b *BiMap) Size() int {
b.s.RLock()
defer b.s.RUnlock()
return len(b.forward)
} | go | func (b *BiMap) Size() int {
b.s.RLock()
defer b.s.RUnlock()
return len(b.forward)
} | [
"func",
"(",
"b",
"*",
"BiMap",
")",
"Size",
"(",
")",
"int",
"{",
"b",
".",
"s",
".",
"RLock",
"(",
")",
"\n",
"defer",
"b",
".",
"s",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"len",
"(",
"b",
".",
"forward",
")",
"\n",
"}"
] | // Size returns the number of elements in the bimap | [
"Size",
"returns",
"the",
"number",
"of",
"elements",
"in",
"the",
"bimap"
] | 09cff281464521368a6976f06c75e4ee9745ab7c | https://github.com/vishalkuo/bimap/blob/09cff281464521368a6976f06c75e4ee9745ab7c/bimap.go#L111-L115 |
142,471 | vishalkuo/bimap | bimap.go | MakeImmutable | func (b *BiMap) MakeImmutable() {
b.s.Lock()
defer b.s.Unlock()
b.immutable = true
} | go | func (b *BiMap) MakeImmutable() {
b.s.Lock()
defer b.s.Unlock()
b.immutable = true
} | [
"func",
"(",
"b",
"*",
"BiMap",
")",
"MakeImmutable",
"(",
")",
"{",
"b",
".",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"b",
".",
"s",
".",
"Unlock",
"(",
")",
"\n",
"b",
".",
"immutable",
"=",
"true",
"\n",
"}"
] | // MakeImmutable freezes the BiMap preventing any further write actions from taking place | [
"MakeImmutable",
"freezes",
"the",
"BiMap",
"preventing",
"any",
"further",
"write",
"actions",
"from",
"taking",
"place"
] | 09cff281464521368a6976f06c75e4ee9745ab7c | https://github.com/vishalkuo/bimap/blob/09cff281464521368a6976f06c75e4ee9745ab7c/bimap.go#L118-L122 |
142,472 | AaronO/go-git-http | utils.go | requestReader | func requestReader(req *http.Request) (io.ReadCloser, error) {
switch req.Header.Get("content-encoding") {
case "gzip":
return gzip.NewReader(req.Body)
case "deflate":
return flate.NewReader(req.Body), nil
}
// If no encoding, use raw body
return req.Body, nil
} | go | func requestReader(req *http.Request) (io.ReadCloser, error) {
switch req.Header.Get("content-encoding") {
case "gzip":
return gzip.NewReader(req.Body)
case "deflate":
return flate.NewReader(req.Body), nil
}
// If no encoding, use raw body
return req.Body, nil
} | [
"func",
"requestReader",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"switch",
"req",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"{",
"case",
"\"",
"\"",
":",
"return",
"gzip",
".",
"N... | // requestReader returns an io.ReadCloser
// that will decode data if needed, depending on the
// "content-encoding" header | [
"requestReader",
"returns",
"an",
"io",
".",
"ReadCloser",
"that",
"will",
"decode",
"data",
"if",
"needed",
"depending",
"on",
"the",
"content",
"-",
"encoding",
"header"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/utils.go#L17-L27 |
142,473 | AaronO/go-git-http | utils.go | getServiceType | func getServiceType(r *http.Request) string {
service_type := r.FormValue("service")
if s := strings.HasPrefix(service_type, "git-"); !s {
return ""
}
return strings.Replace(service_type, "git-", "", 1)
} | go | func getServiceType(r *http.Request) string {
service_type := r.FormValue("service")
if s := strings.HasPrefix(service_type, "git-"); !s {
return ""
}
return strings.Replace(service_type, "git-", "", 1)
} | [
"func",
"getServiceType",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"service_type",
":=",
"r",
".",
"FormValue",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"s",
":=",
"strings",
".",
"HasPrefix",
"(",
"service_type",
",",
"\"",
"\"",
")",
"... | // HTTP parsing utility functions | [
"HTTP",
"parsing",
"utility",
"functions"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/utils.go#L31-L39 |
142,474 | AaronO/go-git-http | utils.go | renderMethodNotAllowed | func renderMethodNotAllowed(w http.ResponseWriter, r *http.Request) {
if r.Proto == "HTTP/1.1" {
w.WriteHeader(http.StatusMethodNotAllowed)
w.Write([]byte("Method Not Allowed"))
} else {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("Bad Request"))
}
} | go | func renderMethodNotAllowed(w http.ResponseWriter, r *http.Request) {
if r.Proto == "HTTP/1.1" {
w.WriteHeader(http.StatusMethodNotAllowed)
w.Write([]byte("Method Not Allowed"))
} else {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("Bad Request"))
}
} | [
"func",
"renderMethodNotAllowed",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"r",
".",
"Proto",
"==",
"\"",
"\"",
"{",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusMethodNotAllowed",
")",
"\n",
... | // HTTP error response handling functions | [
"HTTP",
"error",
"response",
"handling",
"functions"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/utils.go#L43-L51 |
142,475 | AaronO/go-git-http | utils.go | hdrNocache | func hdrNocache(w http.ResponseWriter) {
w.Header().Set("Expires", "Fri, 01 Jan 1980 00:00:00 GMT")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Cache-Control", "no-cache, max-age=0, must-revalidate")
} | go | func hdrNocache(w http.ResponseWriter) {
w.Header().Set("Expires", "Fri, 01 Jan 1980 00:00:00 GMT")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Cache-Control", "no-cache, max-age=0, must-revalidate")
} | [
"func",
"hdrNocache",
"(",
"w",
"http",
".",
"ResponseWriter",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
... | // Header writing functions | [
"Header",
"writing",
"functions"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/utils.go#L81-L85 |
142,476 | AaronO/go-git-http | routing.go | getService | func (g *GitHttp) getService(path string) (string, *Service) {
for re, service := range g.services() {
if m := re.FindStringSubmatch(path); m != nil {
return m[1], &service
}
}
// No match
return "", nil
} | go | func (g *GitHttp) getService(path string) (string, *Service) {
for re, service := range g.services() {
if m := re.FindStringSubmatch(path); m != nil {
return m[1], &service
}
}
// No match
return "", nil
} | [
"func",
"(",
"g",
"*",
"GitHttp",
")",
"getService",
"(",
"path",
"string",
")",
"(",
"string",
",",
"*",
"Service",
")",
"{",
"for",
"re",
",",
"service",
":=",
"range",
"g",
".",
"services",
"(",
")",
"{",
"if",
"m",
":=",
"re",
".",
"FindStrin... | // getService return's the service corresponding to the
// current http.Request's URL
// as well as the name of the repo | [
"getService",
"return",
"s",
"the",
"service",
"corresponding",
"to",
"the",
"current",
"http",
".",
"Request",
"s",
"URL",
"as",
"well",
"as",
"the",
"name",
"of",
"the",
"repo"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/routing.go#L58-L67 |
142,477 | AaronO/go-git-http | routing.go | requestHandler | func (g *GitHttp) requestHandler(w http.ResponseWriter, r *http.Request) {
// Get service for URL
repo, service := g.getService(r.URL.Path)
// No url match
if service == nil {
renderNotFound(w)
return
}
// Bad method
if service.Method != r.Method {
renderMethodNotAllowed(w, r)
return
}
// Rpc type
... | go | func (g *GitHttp) requestHandler(w http.ResponseWriter, r *http.Request) {
// Get service for URL
repo, service := g.getService(r.URL.Path)
// No url match
if service == nil {
renderNotFound(w)
return
}
// Bad method
if service.Method != r.Method {
renderMethodNotAllowed(w, r)
return
}
// Rpc type
... | [
"func",
"(",
"g",
"*",
"GitHttp",
")",
"requestHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"// Get service for URL",
"repo",
",",
"service",
":=",
"g",
".",
"getService",
"(",
"r",
".",
"URL",
"."... | // Request handling function | [
"Request",
"handling",
"function"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/routing.go#L70-L117 |
142,478 | AaronO/go-git-http | pktparser.go | step | func (p *pktLineParser) step() error {
switch p.state {
case ready:
p.state = readingLen
p.next = pktLenSize
return nil
case readingLen:
// len(p.buf) is 4.
pktLen, err := parsePktLen(p.buf)
if err != nil {
return err
}
switch {
case pktLen == 0:
p.state = done
p.next = 0
p.buf = nil
... | go | func (p *pktLineParser) step() error {
switch p.state {
case ready:
p.state = readingLen
p.next = pktLenSize
return nil
case readingLen:
// len(p.buf) is 4.
pktLen, err := parsePktLen(p.buf)
if err != nil {
return err
}
switch {
case pktLen == 0:
p.state = done
p.next = 0
p.buf = nil
... | [
"func",
"(",
"p",
"*",
"pktLineParser",
")",
"step",
"(",
")",
"error",
"{",
"switch",
"p",
".",
"state",
"{",
"case",
"ready",
":",
"p",
".",
"state",
"=",
"readingLen",
"\n",
"p",
".",
"next",
"=",
"pktLenSize",
"\n",
"return",
"nil",
"\n",
"case... | // step moves the state machine to the next state.
// buf must contain all the data ready for consumption for current state.
// It must not be called when state is done. | [
"step",
"moves",
"the",
"state",
"machine",
"to",
"the",
"next",
"state",
".",
"buf",
"must",
"contain",
"all",
"the",
"data",
"ready",
"for",
"consumption",
"for",
"current",
"state",
".",
"It",
"must",
"not",
"be",
"called",
"when",
"state",
"is",
"don... | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/pktparser.go#L79-L113 |
142,479 | AaronO/go-git-http | githttp.go | ServeHTTP | func (g *GitHttp) ServeHTTP(w http.ResponseWriter, r *http.Request) {
g.requestHandler(w, r)
return
} | go | func (g *GitHttp) ServeHTTP(w http.ResponseWriter, r *http.Request) {
g.requestHandler(w, r)
return
} | [
"func",
"(",
"g",
"*",
"GitHttp",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"g",
".",
"requestHandler",
"(",
"w",
",",
"r",
")",
"\n",
"return",
"\n",
"}"
] | // Implement the http.Handler interface | [
"Implement",
"the",
"http",
".",
"Handler",
"interface"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/githttp.go#L29-L32 |
142,480 | AaronO/go-git-http | githttp.go | New | func New(root string) *GitHttp {
return &GitHttp{
ProjectRoot: root,
GitBinPath: "/usr/bin/git",
UploadPack: true,
ReceivePack: true,
}
} | go | func New(root string) *GitHttp {
return &GitHttp{
ProjectRoot: root,
GitBinPath: "/usr/bin/git",
UploadPack: true,
ReceivePack: true,
}
} | [
"func",
"New",
"(",
"root",
"string",
")",
"*",
"GitHttp",
"{",
"return",
"&",
"GitHttp",
"{",
"ProjectRoot",
":",
"root",
",",
"GitBinPath",
":",
"\"",
"\"",
",",
"UploadPack",
":",
"true",
",",
"ReceivePack",
":",
"true",
",",
"}",
"\n",
"}"
] | // Shorthand constructor for most common scenario | [
"Shorthand",
"constructor",
"for",
"most",
"common",
"scenario"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/githttp.go#L35-L42 |
142,481 | AaronO/go-git-http | githttp.go | Init | func (g *GitHttp) Init() (*GitHttp, error) {
if err := os.MkdirAll(g.ProjectRoot, os.ModePerm); err != nil {
return nil, err
}
return g, nil
} | go | func (g *GitHttp) Init() (*GitHttp, error) {
if err := os.MkdirAll(g.ProjectRoot, os.ModePerm); err != nil {
return nil, err
}
return g, nil
} | [
"func",
"(",
"g",
"*",
"GitHttp",
")",
"Init",
"(",
")",
"(",
"*",
"GitHttp",
",",
"error",
")",
"{",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"g",
".",
"ProjectRoot",
",",
"os",
".",
"ModePerm",
")",
";",
"err",
"!=",
"nil",
"{",
"return... | // Build root directory if doesn't exist | [
"Build",
"root",
"directory",
"if",
"doesn",
"t",
"exist"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/githttp.go#L45-L50 |
142,482 | AaronO/go-git-http | githttp.go | event | func (g *GitHttp) event(e Event) {
if g.EventHandler != nil {
g.EventHandler(e)
} else {
fmt.Printf("EVENT: %q\n", e)
}
} | go | func (g *GitHttp) event(e Event) {
if g.EventHandler != nil {
g.EventHandler(e)
} else {
fmt.Printf("EVENT: %q\n", e)
}
} | [
"func",
"(",
"g",
"*",
"GitHttp",
")",
"event",
"(",
"e",
"Event",
")",
"{",
"if",
"g",
".",
"EventHandler",
"!=",
"nil",
"{",
"g",
".",
"EventHandler",
"(",
"e",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
... | // Publish event if EventHandler is set | [
"Publish",
"event",
"if",
"EventHandler",
"is",
"set"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/githttp.go#L53-L59 |
142,483 | AaronO/go-git-http | githttp.go | serviceRpc | func (g *GitHttp) serviceRpc(hr HandlerReq) error {
w, r, rpc, dir := hr.w, hr.r, hr.Rpc, hr.Dir
access, err := g.hasAccess(r, dir, rpc, true)
if err != nil {
return err
}
if access == false {
return &ErrorNoAccess{hr.Dir}
}
// Reader that decompresses if necessary
reader, err := requestReader(r)
if err... | go | func (g *GitHttp) serviceRpc(hr HandlerReq) error {
w, r, rpc, dir := hr.w, hr.r, hr.Rpc, hr.Dir
access, err := g.hasAccess(r, dir, rpc, true)
if err != nil {
return err
}
if access == false {
return &ErrorNoAccess{hr.Dir}
}
// Reader that decompresses if necessary
reader, err := requestReader(r)
if err... | [
"func",
"(",
"g",
"*",
"GitHttp",
")",
"serviceRpc",
"(",
"hr",
"HandlerReq",
")",
"error",
"{",
"w",
",",
"r",
",",
"rpc",
",",
"dir",
":=",
"hr",
".",
"w",
",",
"hr",
".",
"r",
",",
"hr",
".",
"Rpc",
",",
"hr",
".",
"Dir",
"\n\n",
"access",... | // Actual command handling functions | [
"Actual",
"command",
"handling",
"functions"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/githttp.go#L63-L143 |
142,484 | AaronO/go-git-http | githttp.go | sendFile | func sendFile(content_type string, hr HandlerReq) error {
w, r := hr.w, hr.r
req_file := path.Join(hr.Dir, hr.File)
f, err := os.Stat(req_file)
if err != nil {
return err
}
w.Header().Set("Content-Type", content_type)
w.Header().Set("Content-Length", fmt.Sprintf("%d", f.Size()))
w.Header().Set("Last-Modifie... | go | func sendFile(content_type string, hr HandlerReq) error {
w, r := hr.w, hr.r
req_file := path.Join(hr.Dir, hr.File)
f, err := os.Stat(req_file)
if err != nil {
return err
}
w.Header().Set("Content-Type", content_type)
w.Header().Set("Content-Length", fmt.Sprintf("%d", f.Size()))
w.Header().Set("Last-Modifie... | [
"func",
"sendFile",
"(",
"content_type",
"string",
",",
"hr",
"HandlerReq",
")",
"error",
"{",
"w",
",",
"r",
":=",
"hr",
".",
"w",
",",
"hr",
".",
"r",
"\n",
"req_file",
":=",
"path",
".",
"Join",
"(",
"hr",
".",
"Dir",
",",
"hr",
".",
"File",
... | // Logic helping functions | [
"Logic",
"helping",
"functions"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/githttp.go#L202-L217 |
142,485 | AaronO/go-git-http | git_reader.go | Read | func (g *GitReader) Read(p []byte) (n int, err error) {
// Relay call
n, err = g.Reader.Read(p)
// Scan for errors
g.scan(p)
return n, err
} | go | func (g *GitReader) Read(p []byte) (n int, err error) {
// Relay call
n, err = g.Reader.Read(p)
// Scan for errors
g.scan(p)
return n, err
} | [
"func",
"(",
"g",
"*",
"GitReader",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"// Relay call",
"n",
",",
"err",
"=",
"g",
".",
"Reader",
".",
"Read",
"(",
"p",
")",
"\n\n",
"// Scan for errors",... | // Implement the io.Reader interface | [
"Implement",
"the",
"io",
".",
"Reader",
"interface"
] | 1d9485b3a98f7484772acb5f0dda28b69b958fdd | https://github.com/AaronO/go-git-http/blob/1d9485b3a98f7484772acb5f0dda28b69b958fdd/git_reader.go#L24-L32 |
142,486 | jhillyerd/go.enmime | mail.go | IsMultipartMessage | func IsMultipartMessage(mailMsg *mail.Message) bool {
// Parse top-level multipart
ctype := mailMsg.Header.Get("Content-Type")
mediatype, _, err := mime.ParseMediaType(ctype)
if err != nil {
return false
}
// According to rfc2046#section-5.1.7 all other multipart should
// be treated as multipart/mixed
return... | go | func IsMultipartMessage(mailMsg *mail.Message) bool {
// Parse top-level multipart
ctype := mailMsg.Header.Get("Content-Type")
mediatype, _, err := mime.ParseMediaType(ctype)
if err != nil {
return false
}
// According to rfc2046#section-5.1.7 all other multipart should
// be treated as multipart/mixed
return... | [
"func",
"IsMultipartMessage",
"(",
"mailMsg",
"*",
"mail",
".",
"Message",
")",
"bool",
"{",
"// Parse top-level multipart",
"ctype",
":=",
"mailMsg",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"mediatype",
",",
"_",
",",
"err",
":=",
"mime",
... | // IsMultipartMessage returns true if the message has a recognized multipart Content-Type header.
// You don't need to check this before calling ParseMIMEBody, it can handle non-multipart messages. | [
"IsMultipartMessage",
"returns",
"true",
"if",
"the",
"message",
"has",
"a",
"recognized",
"multipart",
"Content",
"-",
"Type",
"header",
".",
"You",
"don",
"t",
"need",
"to",
"check",
"this",
"before",
"calling",
"ParseMIMEBody",
"it",
"can",
"handle",
"non",... | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/mail.go#L29-L39 |
142,487 | jhillyerd/go.enmime | mail.go | IsBinaryBody | func IsBinaryBody(mailMsg *mail.Message) bool {
if IsAttachment(mailMsg.Header) == true {
return true
}
return !IsPlain(mailMsg.Header, true)
} | go | func IsBinaryBody(mailMsg *mail.Message) bool {
if IsAttachment(mailMsg.Header) == true {
return true
}
return !IsPlain(mailMsg.Header, true)
} | [
"func",
"IsBinaryBody",
"(",
"mailMsg",
"*",
"mail",
".",
"Message",
")",
"bool",
"{",
"if",
"IsAttachment",
"(",
"mailMsg",
".",
"Header",
")",
"==",
"true",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"!",
"IsPlain",
"(",
"mailMsg",
".",
"Hea... | // IsBinaryBody returns true if the mail header defines a binary body. | [
"IsBinaryBody",
"returns",
"true",
"if",
"the",
"mail",
"header",
"defines",
"a",
"binary",
"body",
"."
] | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/mail.go#L90-L96 |
142,488 | jhillyerd/go.enmime | mail.go | ParseMIMEBody | func ParseMIMEBody(mailMsg *mail.Message) (*MIMEBody, error) {
mimeMsg := &MIMEBody{
IsTextFromHTML: false,
header: mailMsg.Header,
}
if IsMultipartMessage(mailMsg) {
// Multi-part message (message with attachments, etc)
if err := parseMultiPartBody(mailMsg, mimeMsg); err != nil {
return nil, err... | go | func ParseMIMEBody(mailMsg *mail.Message) (*MIMEBody, error) {
mimeMsg := &MIMEBody{
IsTextFromHTML: false,
header: mailMsg.Header,
}
if IsMultipartMessage(mailMsg) {
// Multi-part message (message with attachments, etc)
if err := parseMultiPartBody(mailMsg, mimeMsg); err != nil {
return nil, err... | [
"func",
"ParseMIMEBody",
"(",
"mailMsg",
"*",
"mail",
".",
"Message",
")",
"(",
"*",
"MIMEBody",
",",
"error",
")",
"{",
"mimeMsg",
":=",
"&",
"MIMEBody",
"{",
"IsTextFromHTML",
":",
"false",
",",
"header",
":",
"mailMsg",
".",
"Header",
",",
"}",
"\n\... | // ParseMIMEBody parses the body of the message object into a tree of MIMEPart objects, each of
// which is aware of its content type, filename and headers. If the part was encoded in
// quoted-printable or base64, it is decoded before being stored in the MIMEPart object. | [
"ParseMIMEBody",
"parses",
"the",
"body",
"of",
"the",
"message",
"object",
"into",
"a",
"tree",
"of",
"MIMEPart",
"objects",
"each",
"of",
"which",
"is",
"aware",
"of",
"its",
"content",
"type",
"filename",
"and",
"headers",
".",
"If",
"the",
"part",
"was... | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/mail.go#L101-L137 |
142,489 | jhillyerd/go.enmime | mail.go | parseTextOnlyBody | func parseTextOnlyBody(mailMsg *mail.Message, mimeMsg *MIMEBody) error {
bodyBytes, err := decodeSection(
mailMsg.Header.Get("Content-Transfer-Encoding"), mailMsg.Body)
if err != nil {
return fmt.Errorf("Error decoding text-only message: %v", err)
}
// Handle plain ASCII text, content-type unspecified, may be ... | go | func parseTextOnlyBody(mailMsg *mail.Message, mimeMsg *MIMEBody) error {
bodyBytes, err := decodeSection(
mailMsg.Header.Get("Content-Transfer-Encoding"), mailMsg.Body)
if err != nil {
return fmt.Errorf("Error decoding text-only message: %v", err)
}
// Handle plain ASCII text, content-type unspecified, may be ... | [
"func",
"parseTextOnlyBody",
"(",
"mailMsg",
"*",
"mail",
".",
"Message",
",",
"mimeMsg",
"*",
"MIMEBody",
")",
"error",
"{",
"bodyBytes",
",",
"err",
":=",
"decodeSection",
"(",
"mailMsg",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
",",
"mailMsg",... | // parseTextOnlyBody parses a plain text message in mailMsg that has MIME-like headers, but
// only contains a single part - no boundaries, etc. The result is placed in mimeMsg. | [
"parseTextOnlyBody",
"parses",
"a",
"plain",
"text",
"message",
"in",
"mailMsg",
"that",
"has",
"MIME",
"-",
"like",
"headers",
"but",
"only",
"contains",
"a",
"single",
"part",
"-",
"no",
"boundaries",
"etc",
".",
"The",
"result",
"is",
"placed",
"in",
"m... | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/mail.go#L141-L181 |
142,490 | jhillyerd/go.enmime | mail.go | parseBinaryOnlyBody | func parseBinaryOnlyBody(mailMsg *mail.Message, mimeMsg *MIMEBody) error {
// Determine mediatype
ctype := mailMsg.Header.Get("Content-Type")
mediatype, mparams, err := mime.ParseMediaType(ctype)
if err != nil {
mediatype = "attachment"
}
// Build the MIME part representing most of this message
p := NewMIMEPa... | go | func parseBinaryOnlyBody(mailMsg *mail.Message, mimeMsg *MIMEBody) error {
// Determine mediatype
ctype := mailMsg.Header.Get("Content-Type")
mediatype, mparams, err := mime.ParseMediaType(ctype)
if err != nil {
mediatype = "attachment"
}
// Build the MIME part representing most of this message
p := NewMIMEPa... | [
"func",
"parseBinaryOnlyBody",
"(",
"mailMsg",
"*",
"mail",
".",
"Message",
",",
"mimeMsg",
"*",
"MIMEBody",
")",
"error",
"{",
"// Determine mediatype",
"ctype",
":=",
"mailMsg",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"mediatype",
",",
"mp... | // parseBinaryOnlyBody parses a message where the only content is a binary attachment with no
// other parts. The result is placed in mimeMsg. | [
"parseBinaryOnlyBody",
"parses",
"a",
"message",
"where",
"the",
"only",
"content",
"is",
"a",
"binary",
"attachment",
"with",
"no",
"other",
"parts",
".",
"The",
"result",
"is",
"placed",
"in",
"mimeMsg",
"."
] | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/mail.go#L185-L232 |
142,491 | jhillyerd/go.enmime | mail.go | GetHeader | func (m *MIMEBody) GetHeader(name string) string {
return DecodeHeader(m.header.Get(name))
} | go | func (m *MIMEBody) GetHeader(name string) string {
return DecodeHeader(m.header.Get(name))
} | [
"func",
"(",
"m",
"*",
"MIMEBody",
")",
"GetHeader",
"(",
"name",
"string",
")",
"string",
"{",
"return",
"DecodeHeader",
"(",
"m",
".",
"header",
".",
"Get",
"(",
"name",
")",
")",
"\n",
"}"
] | // GetHeader processes the specified header for RFC 2047 encoded words and return the result | [
"GetHeader",
"processes",
"the",
"specified",
"header",
"for",
"RFC",
"2047",
"encoded",
"words",
"and",
"return",
"the",
"result"
] | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/mail.go#L339-L341 |
142,492 | jhillyerd/go.enmime | mail.go | AddressList | func (m *MIMEBody) AddressList(key string) ([]*mail.Address, error) {
isAddrHeader := false
for _, hkey := range AddressHeaders {
if strings.ToLower(hkey) == strings.ToLower(key) {
isAddrHeader = true
break
}
}
if !isAddrHeader {
return nil, fmt.Errorf("%s is not address header", key)
}
str := Decode... | go | func (m *MIMEBody) AddressList(key string) ([]*mail.Address, error) {
isAddrHeader := false
for _, hkey := range AddressHeaders {
if strings.ToLower(hkey) == strings.ToLower(key) {
isAddrHeader = true
break
}
}
if !isAddrHeader {
return nil, fmt.Errorf("%s is not address header", key)
}
str := Decode... | [
"func",
"(",
"m",
"*",
"MIMEBody",
")",
"AddressList",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"*",
"mail",
".",
"Address",
",",
"error",
")",
"{",
"isAddrHeader",
":=",
"false",
"\n",
"for",
"_",
",",
"hkey",
":=",
"range",
"AddressHeaders",
"{",
... | // AddressList returns a mail.Address slice with RFC 2047 encoded encoded names. | [
"AddressList",
"returns",
"a",
"mail",
".",
"Address",
"slice",
"with",
"RFC",
"2047",
"encoded",
"encoded",
"names",
"."
] | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/mail.go#L344-L368 |
142,493 | jhillyerd/go.enmime | mime-dump/mime-dump.go | printPart | func printPart(p enmime.MIMEPart, indent string) {
sibling := p.NextSibling()
child := p.FirstChild()
// Compute indent strings
myindent := indent + "`-- "
childindent := indent + " "
if sibling != nil {
myindent = indent + "|-- "
childindent = indent + "| "
}
if p.Parent() == nil {
// Root shouldn'... | go | func printPart(p enmime.MIMEPart, indent string) {
sibling := p.NextSibling()
child := p.FirstChild()
// Compute indent strings
myindent := indent + "`-- "
childindent := indent + " "
if sibling != nil {
myindent = indent + "|-- "
childindent = indent + "| "
}
if p.Parent() == nil {
// Root shouldn'... | [
"func",
"printPart",
"(",
"p",
"enmime",
".",
"MIMEPart",
",",
"indent",
"string",
")",
"{",
"sibling",
":=",
"p",
".",
"NextSibling",
"(",
")",
"\n",
"child",
":=",
"p",
".",
"FirstChild",
"(",
")",
"\n\n",
"// Compute indent strings",
"myindent",
":=",
... | // printPart pretty prints the MIMEPart tree | [
"printPart",
"pretty",
"prints",
"the",
"MIMEPart",
"tree"
] | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/mime-dump/mime-dump.go#L107-L146 |
142,494 | jhillyerd/go.enmime | header.go | DecodeToUTF8Base64Header | func DecodeToUTF8Base64Header(input string) string {
if !strings.Contains(input, "=?") {
// Don't scan if there is nothing to do here
return input
}
debug("input = %q", input)
tokens := strings.FieldsFunc(input, isWhiteSpaceRune)
output := make([]string, len(tokens), len(tokens))
for i, token := range tokens... | go | func DecodeToUTF8Base64Header(input string) string {
if !strings.Contains(input, "=?") {
// Don't scan if there is nothing to do here
return input
}
debug("input = %q", input)
tokens := strings.FieldsFunc(input, isWhiteSpaceRune)
output := make([]string, len(tokens), len(tokens))
for i, token := range tokens... | [
"func",
"DecodeToUTF8Base64Header",
"(",
"input",
"string",
")",
"string",
"{",
"if",
"!",
"strings",
".",
"Contains",
"(",
"input",
",",
"\"",
"\"",
")",
"{",
"// Don't scan if there is nothing to do here",
"return",
"input",
"\n",
"}",
"\n\n",
"debug",
"(",
... | // DecodeToUTF8Base64Header decodes a MIME header per RFC 2047, reencoding to =?utf-8b? | [
"DecodeToUTF8Base64Header",
"decodes",
"a",
"MIME",
"header",
"per",
"RFC",
"2047",
"reencoding",
"to",
"=",
"?utf",
"-",
"8b?"
] | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/header.go#L39-L71 |
142,495 | jhillyerd/go.enmime | header.go | isWhiteSpaceRune | func isWhiteSpaceRune(r rune) bool {
switch r {
case ' ':
return true
case '\t':
return true
case '\r':
return true
case '\n':
return true
default:
return false
}
} | go | func isWhiteSpaceRune(r rune) bool {
switch r {
case ' ':
return true
case '\t':
return true
case '\r':
return true
case '\n':
return true
default:
return false
}
} | [
"func",
"isWhiteSpaceRune",
"(",
"r",
"rune",
")",
"bool",
"{",
"switch",
"r",
"{",
"case",
"' '",
":",
"return",
"true",
"\n",
"case",
"'\\t'",
":",
"return",
"true",
"\n",
"case",
"'\\r'",
":",
"return",
"true",
"\n",
"case",
"'\\n'",
":",
"return",
... | // Detects a RFC-822 linear-white-space, passed to strings.FieldsFunc | [
"Detects",
"a",
"RFC",
"-",
"822",
"linear",
"-",
"white",
"-",
"space",
"passed",
"to",
"strings",
".",
"FieldsFunc"
] | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/header.go#L74-L87 |
142,496 | jhillyerd/go.enmime | match.go | DepthMatchFirst | func DepthMatchFirst(p MIMEPart, matcher MIMEPartMatcher) MIMEPart {
root := p
for {
if matcher(p) {
return p
}
c := p.FirstChild()
if c != nil {
p = c
} else {
for p.NextSibling() == nil {
if p == root {
return nil
}
p = p.Parent()
}
p = p.NextSibling()
}
}
} | go | func DepthMatchFirst(p MIMEPart, matcher MIMEPartMatcher) MIMEPart {
root := p
for {
if matcher(p) {
return p
}
c := p.FirstChild()
if c != nil {
p = c
} else {
for p.NextSibling() == nil {
if p == root {
return nil
}
p = p.Parent()
}
p = p.NextSibling()
}
}
} | [
"func",
"DepthMatchFirst",
"(",
"p",
"MIMEPart",
",",
"matcher",
"MIMEPartMatcher",
")",
"MIMEPart",
"{",
"root",
":=",
"p",
"\n",
"for",
"{",
"if",
"matcher",
"(",
"p",
")",
"{",
"return",
"p",
"\n",
"}",
"\n",
"c",
":=",
"p",
".",
"FirstChild",
"("... | // DepthMatchFirst performs a depth first search of the MIMEPart tree and returns the
// first part that causes the given matcher to return true | [
"DepthMatchFirst",
"performs",
"a",
"depth",
"first",
"search",
"of",
"the",
"MIMEPart",
"tree",
"and",
"returns",
"the",
"first",
"part",
"that",
"causes",
"the",
"given",
"matcher",
"to",
"return",
"true"
] | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/match.go#L64-L83 |
142,497 | jhillyerd/go.enmime | match.go | DepthMatchAll | func DepthMatchAll(p MIMEPart, matcher MIMEPartMatcher) []MIMEPart {
root := p
matches := make([]MIMEPart, 0, 10)
for {
if matcher(p) {
matches = append(matches, p)
}
c := p.FirstChild()
if c != nil {
p = c
} else {
for p.NextSibling() == nil {
if p == root {
return matches
}
p = ... | go | func DepthMatchAll(p MIMEPart, matcher MIMEPartMatcher) []MIMEPart {
root := p
matches := make([]MIMEPart, 0, 10)
for {
if matcher(p) {
matches = append(matches, p)
}
c := p.FirstChild()
if c != nil {
p = c
} else {
for p.NextSibling() == nil {
if p == root {
return matches
}
p = ... | [
"func",
"DepthMatchAll",
"(",
"p",
"MIMEPart",
",",
"matcher",
"MIMEPartMatcher",
")",
"[",
"]",
"MIMEPart",
"{",
"root",
":=",
"p",
"\n",
"matches",
":=",
"make",
"(",
"[",
"]",
"MIMEPart",
",",
"0",
",",
"10",
")",
"\n",
"for",
"{",
"if",
"matcher"... | // DepthMatchAll performs a depth first search of the MIMEPart tree and returns all parts
// that causes the given matcher to return true | [
"DepthMatchAll",
"performs",
"a",
"depth",
"first",
"search",
"of",
"the",
"MIMEPart",
"tree",
"and",
"returns",
"all",
"parts",
"that",
"causes",
"the",
"given",
"matcher",
"to",
"return",
"true"
] | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/match.go#L87-L107 |
142,498 | jhillyerd/go.enmime | part.go | NewMIMEPart | func NewMIMEPart(parent MIMEPart, contentType string) MIMEPart {
return &memMIMEPart{parent: parent, contentType: contentType}
} | go | func NewMIMEPart(parent MIMEPart, contentType string) MIMEPart {
return &memMIMEPart{parent: parent, contentType: contentType}
} | [
"func",
"NewMIMEPart",
"(",
"parent",
"MIMEPart",
",",
"contentType",
"string",
")",
"MIMEPart",
"{",
"return",
"&",
"memMIMEPart",
"{",
"parent",
":",
"parent",
",",
"contentType",
":",
"contentType",
"}",
"\n",
"}"
] | // NewMIMEPart creates a new memMIMEPart object. It does not update the parents FirstChild
// attribute. | [
"NewMIMEPart",
"creates",
"a",
"new",
"memMIMEPart",
"object",
".",
"It",
"does",
"not",
"update",
"the",
"parents",
"FirstChild",
"attribute",
"."
] | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/part.go#L59-L61 |
142,499 | jhillyerd/go.enmime | part.go | ParseMIME | func ParseMIME(reader *bufio.Reader) (MIMEPart, error) {
tr := textproto.NewReader(reader)
header, err := tr.ReadMIMEHeader()
if err != nil {
return nil, err
}
mediatype, params, err := mime.ParseMediaType(header.Get("Content-Type"))
if err != nil {
return nil, err
}
root := &memMIMEPart{header: header, con... | go | func ParseMIME(reader *bufio.Reader) (MIMEPart, error) {
tr := textproto.NewReader(reader)
header, err := tr.ReadMIMEHeader()
if err != nil {
return nil, err
}
mediatype, params, err := mime.ParseMediaType(header.Get("Content-Type"))
if err != nil {
return nil, err
}
root := &memMIMEPart{header: header, con... | [
"func",
"ParseMIME",
"(",
"reader",
"*",
"bufio",
".",
"Reader",
")",
"(",
"MIMEPart",
",",
"error",
")",
"{",
"tr",
":=",
"textproto",
".",
"NewReader",
"(",
"reader",
")",
"\n",
"header",
",",
"err",
":=",
"tr",
".",
"ReadMIMEHeader",
"(",
")",
"\n... | // ParseMIME reads a MIME document from the provided reader and parses it into
// tree of MIMEPart objects. | [
"ParseMIME",
"reads",
"a",
"MIME",
"document",
"from",
"the",
"provided",
"reader",
"and",
"parses",
"it",
"into",
"tree",
"of",
"MIMEPart",
"objects",
"."
] | 1b38e76723aa41be23ca88adbb21df1972c10b7f | https://github.com/jhillyerd/go.enmime/blob/1b38e76723aa41be23ca88adbb21df1972c10b7f/part.go#L157-L185 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.