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
partition
stringclasses
1 value
golang/example
gotypes/weave.go
include
func include(file, tag string) (string, error) { f, err := os.Open(file) if err != nil { return "", err } defer f.Close() startre, err := regexp.Compile("!\\+" + tag + "$") if err != nil { return "", err } endre, err := regexp.Compile("!\\-" + tag + "$") if err != nil { return "", err } var text bytes.Buffer in := bufio.NewScanner(f) var on bool for in.Scan() { line := in.Text() switch { case startre.MatchString(line): on = true case endre.MatchString(line): on = false case on: text.WriteByte('\t') text.WriteString(line) text.WriteByte('\n') } } if text.Len() == 0 { return "", fmt.Errorf("no lines of %s matched tag %q", file, tag) } return text.String(), nil }
go
func include(file, tag string) (string, error) { f, err := os.Open(file) if err != nil { return "", err } defer f.Close() startre, err := regexp.Compile("!\\+" + tag + "$") if err != nil { return "", err } endre, err := regexp.Compile("!\\-" + tag + "$") if err != nil { return "", err } var text bytes.Buffer in := bufio.NewScanner(f) var on bool for in.Scan() { line := in.Text() switch { case startre.MatchString(line): on = true case endre.MatchString(line): on = false case on: text.WriteByte('\t') text.WriteString(line) text.WriteByte('\n') } } if text.Len() == 0 { return "", fmt.Errorf("no lines of %s matched tag %q", file, tag) } return text.String(), nil }
[ "func", "include", "(", "file", ",", "tag", "string", ")", "(", "string", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\...
// include processes an included file, and returns the included text. // Only lines between those matching !+tag and !-tag will be returned. // This is true even if tag=="".
[ "include", "processes", "an", "included", "file", "and", "returns", "the", "included", "text", ".", "Only", "lines", "between", "those", "matching", "!", "+", "tag", "and", "!", "-", "tag", "will", "be", "returned", ".", "This", "is", "true", "even", "if...
46695d81d1fae905a270fb7db8a4d11a334562fe
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/gotypes/weave.go#L105-L141
train
golang/example
gotypes/weave.go
cleanListing
func cleanListing(text string) string { lines := strings.Split(text, "\n") // remove minimum number of leading tabs from all non-blank lines tabs := 999 for i, line := range lines { if strings.TrimSpace(line) == "" { lines[i] = "" } else { if n := leadingTabs(line); n < tabs { tabs = n } } } for i, line := range lines { if line != "" { line := line[tabs:] lines[i] = line // remove leading tabs } } // remove leading blank lines for len(lines) > 0 && lines[0] == "" { lines = lines[1:] } // remove trailing blank lines for len(lines) > 0 && lines[len(lines)-1] == "" { lines = lines[:len(lines)-1] } return strings.Join(lines, "\n") }
go
func cleanListing(text string) string { lines := strings.Split(text, "\n") // remove minimum number of leading tabs from all non-blank lines tabs := 999 for i, line := range lines { if strings.TrimSpace(line) == "" { lines[i] = "" } else { if n := leadingTabs(line); n < tabs { tabs = n } } } for i, line := range lines { if line != "" { line := line[tabs:] lines[i] = line // remove leading tabs } } // remove leading blank lines for len(lines) > 0 && lines[0] == "" { lines = lines[1:] } // remove trailing blank lines for len(lines) > 0 && lines[len(lines)-1] == "" { lines = lines[:len(lines)-1] } return strings.Join(lines, "\n") }
[ "func", "cleanListing", "(", "text", "string", ")", "string", "{", "lines", ":=", "strings", ".", "Split", "(", "text", ",", "\"", "\\n", "\"", ")", "\n\n", "// remove minimum number of leading tabs from all non-blank lines", "tabs", ":=", "999", "\n", "for", "i...
// cleanListing removes entirely blank leading and trailing lines from // text, and removes n leading tabs.
[ "cleanListing", "removes", "entirely", "blank", "leading", "and", "trailing", "lines", "from", "text", "and", "removes", "n", "leading", "tabs", "." ]
46695d81d1fae905a270fb7db8a4d11a334562fe
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/gotypes/weave.go#L151-L181
train
golang/example
gotypes/typeandvalue/main.go
nodeString
func nodeString(n ast.Node) string { var buf bytes.Buffer format.Node(&buf, fset, n) return buf.String() }
go
func nodeString(n ast.Node) string { var buf bytes.Buffer format.Node(&buf, fset, n) return buf.String() }
[ "func", "nodeString", "(", "n", "ast", ".", "Node", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "format", ".", "Node", "(", "&", "buf", ",", "fset", ",", "n", ")", "\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// nodeString formats a syntax tree in the style of gofmt.
[ "nodeString", "formats", "a", "syntax", "tree", "in", "the", "style", "of", "gofmt", "." ]
46695d81d1fae905a270fb7db8a4d11a334562fe
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/gotypes/typeandvalue/main.go#L61-L65
train
golang/example
gotypes/typeandvalue/main.go
mode
func mode(tv types.TypeAndValue) string { s := "" if tv.IsVoid() { s += ",void" } if tv.IsType() { s += ",type" } if tv.IsBuiltin() { s += ",builtin" } if tv.IsValue() { s += ",value" } if tv.IsNil() { s += ",nil" } if tv.Addressable() { s += ",addressable" } if tv.Assignable() { s += ",assignable" } if tv.HasOk() { s += ",ok" } return s[1:] }
go
func mode(tv types.TypeAndValue) string { s := "" if tv.IsVoid() { s += ",void" } if tv.IsType() { s += ",type" } if tv.IsBuiltin() { s += ",builtin" } if tv.IsValue() { s += ",value" } if tv.IsNil() { s += ",nil" } if tv.Addressable() { s += ",addressable" } if tv.Assignable() { s += ",assignable" } if tv.HasOk() { s += ",ok" } return s[1:] }
[ "func", "mode", "(", "tv", "types", ".", "TypeAndValue", ")", "string", "{", "s", ":=", "\"", "\"", "\n", "if", "tv", ".", "IsVoid", "(", ")", "{", "s", "+=", "\"", "\"", "\n", "}", "\n", "if", "tv", ".", "IsType", "(", ")", "{", "s", "+=", ...
// mode returns a string describing the mode of an expression.
[ "mode", "returns", "a", "string", "describing", "the", "mode", "of", "an", "expression", "." ]
46695d81d1fae905a270fb7db8a4d11a334562fe
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/gotypes/typeandvalue/main.go#L68-L95
train
golang/example
outyet/main.go
NewServer
func NewServer(version, url string, period time.Duration) *Server { s := &Server{version: version, url: url, period: period} go s.poll() return s }
go
func NewServer(version, url string, period time.Duration) *Server { s := &Server{version: version, url: url, period: period} go s.poll() return s }
[ "func", "NewServer", "(", "version", ",", "url", "string", ",", "period", "time", ".", "Duration", ")", "*", "Server", "{", "s", ":=", "&", "Server", "{", "version", ":", "version", ",", "url", ":", "url", ",", "period", ":", "period", "}", "\n", "...
// NewServer returns an initialized outyet server.
[ "NewServer", "returns", "an", "initialized", "outyet", "server", "." ]
46695d81d1fae905a270fb7db8a4d11a334562fe
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/outyet/main.go#L70-L74
train
golang/example
outyet/main.go
poll
func (s *Server) poll() { for !isTagged(s.url) { pollSleep(s.period) } s.mu.Lock() s.yes = true s.mu.Unlock() pollDone() }
go
func (s *Server) poll() { for !isTagged(s.url) { pollSleep(s.period) } s.mu.Lock() s.yes = true s.mu.Unlock() pollDone() }
[ "func", "(", "s", "*", "Server", ")", "poll", "(", ")", "{", "for", "!", "isTagged", "(", "s", ".", "url", ")", "{", "pollSleep", "(", "s", ".", "period", ")", "\n", "}", "\n", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "s", ".", "yes", ...
// poll polls the change URL for the specified period until the tag exists. // Then it sets the Server's yes field true and exits.
[ "poll", "polls", "the", "change", "URL", "for", "the", "specified", "period", "until", "the", "tag", "exists", ".", "Then", "it", "sets", "the", "Server", "s", "yes", "field", "true", "and", "exits", "." ]
46695d81d1fae905a270fb7db8a4d11a334562fe
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/outyet/main.go#L78-L86
train
golang/example
outyet/main.go
isTagged
func isTagged(url string) bool { pollCount.Add(1) r, err := http.Head(url) if err != nil { log.Print(err) pollError.Set(err.Error()) pollErrorCount.Add(1) return false } return r.StatusCode == http.StatusOK }
go
func isTagged(url string) bool { pollCount.Add(1) r, err := http.Head(url) if err != nil { log.Print(err) pollError.Set(err.Error()) pollErrorCount.Add(1) return false } return r.StatusCode == http.StatusOK }
[ "func", "isTagged", "(", "url", "string", ")", "bool", "{", "pollCount", ".", "Add", "(", "1", ")", "\n", "r", ",", "err", ":=", "http", ".", "Head", "(", "url", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Print", "(", "err", ")", ...
// isTagged makes an HTTP HEAD request to the given URL and reports whether it // returned a 200 OK response.
[ "isTagged", "makes", "an", "HTTP", "HEAD", "request", "to", "the", "given", "URL", "and", "reports", "whether", "it", "returned", "a", "200", "OK", "response", "." ]
46695d81d1fae905a270fb7db8a4d11a334562fe
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/outyet/main.go#L96-L106
train
golang/example
outyet/main.go
ServeHTTP
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { hitCount.Add(1) s.mu.RLock() data := struct { URL string Version string Yes bool }{ s.url, s.version, s.yes, } s.mu.RUnlock() err := tmpl.Execute(w, data) if err != nil { log.Print(err) } }
go
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { hitCount.Add(1) s.mu.RLock() data := struct { URL string Version string Yes bool }{ s.url, s.version, s.yes, } s.mu.RUnlock() err := tmpl.Execute(w, data) if err != nil { log.Print(err) } }
[ "func", "(", "s", "*", "Server", ")", "ServeHTTP", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "hitCount", ".", "Add", "(", "1", ")", "\n", "s", ".", "mu", ".", "RLock", "(", ")", "\n", "data", ":="...
// ServeHTTP implements the HTTP user interface.
[ "ServeHTTP", "implements", "the", "HTTP", "user", "interface", "." ]
46695d81d1fae905a270fb7db8a4d11a334562fe
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/outyet/main.go#L109-L126
train
golang/example
gotypes/lookup/lookup.go
main
func main() { fset := token.NewFileSet() f, err := parser.ParseFile(fset, "hello.go", hello, parser.ParseComments) if err != nil { log.Fatal(err) // parse error } conf := types.Config{Importer: importer.Default()} pkg, err := conf.Check("cmd/hello", fset, []*ast.File{f}, nil) if err != nil { log.Fatal(err) // type error } // Each comment contains a name. // Look up that name in the innermost scope enclosing the comment. for _, comment := range f.Comments { pos := comment.Pos() name := strings.TrimSpace(comment.Text()) fmt.Printf("At %s,\t%q = ", fset.Position(pos), name) inner := pkg.Scope().Innermost(pos) if _, obj := inner.LookupParent(name, pos); obj != nil { fmt.Println(obj) } else { fmt.Println("not found") } } }
go
func main() { fset := token.NewFileSet() f, err := parser.ParseFile(fset, "hello.go", hello, parser.ParseComments) if err != nil { log.Fatal(err) // parse error } conf := types.Config{Importer: importer.Default()} pkg, err := conf.Check("cmd/hello", fset, []*ast.File{f}, nil) if err != nil { log.Fatal(err) // type error } // Each comment contains a name. // Look up that name in the innermost scope enclosing the comment. for _, comment := range f.Comments { pos := comment.Pos() name := strings.TrimSpace(comment.Text()) fmt.Printf("At %s,\t%q = ", fset.Position(pos), name) inner := pkg.Scope().Innermost(pos) if _, obj := inner.LookupParent(name, pos); obj != nil { fmt.Println(obj) } else { fmt.Println("not found") } } }
[ "func", "main", "(", ")", "{", "fset", ":=", "token", ".", "NewFileSet", "(", ")", "\n", "f", ",", "err", ":=", "parser", ".", "ParseFile", "(", "fset", ",", "\"", "\"", ",", "hello", ",", "parser", ".", "ParseComments", ")", "\n", "if", "err", "...
//!-input //!+main
[ "!", "-", "input", "!", "+", "main" ]
46695d81d1fae905a270fb7db8a4d11a334562fe
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/gotypes/lookup/lookup.go#L36-L62
train
golang/example
gotypes/implements/main.go
main
func main() { // Parse one file. fset := token.NewFileSet() f, err := parser.ParseFile(fset, "input.go", input, 0) if err != nil { log.Fatal(err) // parse error } conf := types.Config{Importer: importer.Default()} pkg, err := conf.Check("hello", fset, []*ast.File{f}, nil) if err != nil { log.Fatal(err) // type error } //!+implements // Find all named types at package level. var allNamed []*types.Named for _, name := range pkg.Scope().Names() { if obj, ok := pkg.Scope().Lookup(name).(*types.TypeName); ok { allNamed = append(allNamed, obj.Type().(*types.Named)) } } // Test assignability of all distinct pairs of // named types (T, U) where U is an interface. for _, T := range allNamed { for _, U := range allNamed { if T == U || !types.IsInterface(U) { continue } if types.AssignableTo(T, U) { fmt.Printf("%s satisfies %s\n", T, U) } else if !types.IsInterface(T) && types.AssignableTo(types.NewPointer(T), U) { fmt.Printf("%s satisfies %s\n", types.NewPointer(T), U) } } } //!-implements }
go
func main() { // Parse one file. fset := token.NewFileSet() f, err := parser.ParseFile(fset, "input.go", input, 0) if err != nil { log.Fatal(err) // parse error } conf := types.Config{Importer: importer.Default()} pkg, err := conf.Check("hello", fset, []*ast.File{f}, nil) if err != nil { log.Fatal(err) // type error } //!+implements // Find all named types at package level. var allNamed []*types.Named for _, name := range pkg.Scope().Names() { if obj, ok := pkg.Scope().Lookup(name).(*types.TypeName); ok { allNamed = append(allNamed, obj.Type().(*types.Named)) } } // Test assignability of all distinct pairs of // named types (T, U) where U is an interface. for _, T := range allNamed { for _, U := range allNamed { if T == U || !types.IsInterface(U) { continue } if types.AssignableTo(T, U) { fmt.Printf("%s satisfies %s\n", T, U) } else if !types.IsInterface(T) && types.AssignableTo(types.NewPointer(T), U) { fmt.Printf("%s satisfies %s\n", types.NewPointer(T), U) } } } //!-implements }
[ "func", "main", "(", ")", "{", "// Parse one file.", "fset", ":=", "token", ".", "NewFileSet", "(", ")", "\n", "f", ",", "err", ":=", "parser", ".", "ParseFile", "(", "fset", ",", "\"", "\"", ",", "input", ",", "0", ")", "\n", "if", "err", "!=", ...
//!-input
[ "!", "-", "input" ]
46695d81d1fae905a270fb7db8a4d11a334562fe
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/gotypes/implements/main.go#L29-L67
train
golang/example
template/main.go
indexHandler
func indexHandler(w http.ResponseWriter, r *http.Request) { data := &Index{ Title: "Image gallery", Body: "Welcome to the image gallery.", } for name, img := range images { data.Links = append(data.Links, Link{ URL: "/image/" + name, Title: img.Title, }) } if err := indexTemplate.Execute(w, data); err != nil { log.Println(err) } }
go
func indexHandler(w http.ResponseWriter, r *http.Request) { data := &Index{ Title: "Image gallery", Body: "Welcome to the image gallery.", } for name, img := range images { data.Links = append(data.Links, Link{ URL: "/image/" + name, Title: img.Title, }) } if err := indexTemplate.Execute(w, data); err != nil { log.Println(err) } }
[ "func", "indexHandler", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "data", ":=", "&", "Index", "{", "Title", ":", "\"", "\"", ",", "Body", ":", "\"", "\"", ",", "}", "\n", "for", "name", ",", "img", ...
// indexHandler is an HTTP handler that serves the index page.
[ "indexHandler", "is", "an", "HTTP", "handler", "that", "serves", "the", "index", "page", "." ]
46695d81d1fae905a270fb7db8a4d11a334562fe
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/template/main.go#L55-L69
train
golang/example
template/main.go
imageHandler
func imageHandler(w http.ResponseWriter, r *http.Request) { data, ok := images[strings.TrimPrefix(r.URL.Path, "/image/")] if !ok { http.NotFound(w, r) return } if err := imageTemplate.Execute(w, data); err != nil { log.Println(err) } }
go
func imageHandler(w http.ResponseWriter, r *http.Request) { data, ok := images[strings.TrimPrefix(r.URL.Path, "/image/")] if !ok { http.NotFound(w, r) return } if err := imageTemplate.Execute(w, data); err != nil { log.Println(err) } }
[ "func", "imageHandler", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "data", ",", "ok", ":=", "images", "[", "strings", ".", "TrimPrefix", "(", "r", ".", "URL", ".", "Path", ",", "\"", "\"", ")", "]", ...
// imageHandler is an HTTP handler that serves the image pages.
[ "imageHandler", "is", "an", "HTTP", "handler", "that", "serves", "the", "image", "pages", "." ]
46695d81d1fae905a270fb7db8a4d11a334562fe
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/template/main.go#L82-L91
train
kardianos/govendor
context/label.go
FindLabel
func FindLabel(version string, labels []Label) Label { list := make([]*labelAnalysis, 0, 6) exact := strings.HasPrefix(version, "=") version = strings.TrimPrefix(version, "=") for _, label := range labels { if exact { if label.Text == version { return label } continue } if !strings.HasPrefix(label.Text, version) { continue } remain := strings.TrimPrefix(label.Text, version) if len(remain) > 0 { next := remain[0] // The stated version must either be the full label, // followed by a "." or "-". if next != '.' && next != '-' { continue } } list = append(list, &labelAnalysis{ Label: label, Groups: make([]labelGroup, 0, 3), }) } if len(list) == 0 { return Label{Source: LabelNone} } buf := &bytes.Buffer{} for _, item := range list { item.fillSections(buf) buf.Reset() } sort.Sort(labelAnalysisList(list)) return list[0].Label }
go
func FindLabel(version string, labels []Label) Label { list := make([]*labelAnalysis, 0, 6) exact := strings.HasPrefix(version, "=") version = strings.TrimPrefix(version, "=") for _, label := range labels { if exact { if label.Text == version { return label } continue } if !strings.HasPrefix(label.Text, version) { continue } remain := strings.TrimPrefix(label.Text, version) if len(remain) > 0 { next := remain[0] // The stated version must either be the full label, // followed by a "." or "-". if next != '.' && next != '-' { continue } } list = append(list, &labelAnalysis{ Label: label, Groups: make([]labelGroup, 0, 3), }) } if len(list) == 0 { return Label{Source: LabelNone} } buf := &bytes.Buffer{} for _, item := range list { item.fillSections(buf) buf.Reset() } sort.Sort(labelAnalysisList(list)) return list[0].Label }
[ "func", "FindLabel", "(", "version", "string", ",", "labels", "[", "]", "Label", ")", "Label", "{", "list", ":=", "make", "(", "[", "]", "*", "labelAnalysis", ",", "0", ",", "6", ")", "\n\n", "exact", ":=", "strings", ".", "HasPrefix", "(", "version"...
// FindLabel matches a single label from a list of labels, given a version. // If the returning label.Source is LabelNone, then no labels match. // // Labels are first broken into sections separated by "-". Shortest wins. // If they have the same number of above sections, then they are compared // further. Number sequences are treated as numbers. Numbers do not need a // separator. The "." is a break point as well.
[ "FindLabel", "matches", "a", "single", "label", "from", "a", "list", "of", "labels", "given", "a", "version", ".", "If", "the", "returning", "label", ".", "Source", "is", "LabelNone", "then", "no", "labels", "match", ".", "Labels", "are", "first", "broken"...
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/label.go#L199-L240
train
kardianos/govendor
context/version.go
isVersion
func isVersion(s string) bool { hasPunct := false onlyNumber := true onlyHexLetter := true for _, r := range s { isNumber := unicode.IsNumber(r) isLetter := unicode.IsLetter(r) hasPunct = hasPunct || unicode.IsPunct(r) onlyNumber = onlyNumber && isNumber if isLetter { low := unicode.ToLower(r) onlyHexLetter = onlyHexLetter && low <= 'f' } } if hasPunct { return true } if !onlyHexLetter { return true } num, err := strconv.ParseInt(s, 10, 64) if err == nil { if num > 100 { return false // numeric revision. } } if len(s) > 5 && onlyHexLetter { return false // hex revision } return true }
go
func isVersion(s string) bool { hasPunct := false onlyNumber := true onlyHexLetter := true for _, r := range s { isNumber := unicode.IsNumber(r) isLetter := unicode.IsLetter(r) hasPunct = hasPunct || unicode.IsPunct(r) onlyNumber = onlyNumber && isNumber if isLetter { low := unicode.ToLower(r) onlyHexLetter = onlyHexLetter && low <= 'f' } } if hasPunct { return true } if !onlyHexLetter { return true } num, err := strconv.ParseInt(s, 10, 64) if err == nil { if num > 100 { return false // numeric revision. } } if len(s) > 5 && onlyHexLetter { return false // hex revision } return true }
[ "func", "isVersion", "(", "s", "string", ")", "bool", "{", "hasPunct", ":=", "false", "\n", "onlyNumber", ":=", "true", "\n", "onlyHexLetter", ":=", "true", "\n", "for", "_", ",", "r", ":=", "range", "s", "{", "isNumber", ":=", "unicode", ".", "IsNumbe...
// IsVersion returns true if the string is a version.
[ "IsVersion", "returns", "true", "if", "the", "string", "is", "a", "version", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/version.go#L13-L47
train
kardianos/govendor
context/path.go
isStdLib
func (ctx *Context) isStdLib(importPath string) (yes bool, err error) { if importPath == "builtin" || importPath == "unsafe" || importPath == "C" { yes = true return } dir := filepath.Join(ctx.Goroot, importPath) fi, _ := os.Stat(dir) if fi == nil { return } if !fi.IsDir() { return } yes, err = hasGoFileInFolder(dir) return }
go
func (ctx *Context) isStdLib(importPath string) (yes bool, err error) { if importPath == "builtin" || importPath == "unsafe" || importPath == "C" { yes = true return } dir := filepath.Join(ctx.Goroot, importPath) fi, _ := os.Stat(dir) if fi == nil { return } if !fi.IsDir() { return } yes, err = hasGoFileInFolder(dir) return }
[ "func", "(", "ctx", "*", "Context", ")", "isStdLib", "(", "importPath", "string", ")", "(", "yes", "bool", ",", "err", "error", ")", "{", "if", "importPath", "==", "\"", "\"", "||", "importPath", "==", "\"", "\"", "||", "importPath", "==", "\"", "\""...
// Import path is in GOROOT or is a special package.
[ "Import", "path", "is", "in", "GOROOT", "or", "is", "a", "special", "package", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/path.go#L16-L33
train
kardianos/govendor
context/path.go
findImportDir
func (ctx *Context) findImportDir(relative, importPath string) (dir, gopath string, err error) { if importPath == "builtin" || importPath == "unsafe" || importPath == "C" { return filepath.Join(ctx.Goroot, importPath), ctx.Goroot, nil } if len(relative) != 0 { rel := relative for { look := filepath.Join(rel, ctx.VendorDiscoverFolder, importPath) nextRel := filepath.Join(rel, "..") if rel == nextRel { break } rel = nextRel fi, err := os.Stat(look) if os.IsNotExist(err) { continue } if err != nil { continue } if !fi.IsDir() { continue } for _, gopath = range ctx.GopathList { if pathos.FileHasPrefix(look, gopath) { hasGo, err := hasGoFileInFolder(look) if err != nil { return "", "", err } if hasGo { return look, gopath, nil } } } } } for _, gopath = range ctx.GopathList { dir := filepath.Join(gopath, importPath) fi, err := os.Stat(dir) if os.IsNotExist(err) { continue } if fi == nil { continue } if !fi.IsDir() { continue } return dir, gopath, nil } return "", "", ErrNotInGOPATH{importPath} }
go
func (ctx *Context) findImportDir(relative, importPath string) (dir, gopath string, err error) { if importPath == "builtin" || importPath == "unsafe" || importPath == "C" { return filepath.Join(ctx.Goroot, importPath), ctx.Goroot, nil } if len(relative) != 0 { rel := relative for { look := filepath.Join(rel, ctx.VendorDiscoverFolder, importPath) nextRel := filepath.Join(rel, "..") if rel == nextRel { break } rel = nextRel fi, err := os.Stat(look) if os.IsNotExist(err) { continue } if err != nil { continue } if !fi.IsDir() { continue } for _, gopath = range ctx.GopathList { if pathos.FileHasPrefix(look, gopath) { hasGo, err := hasGoFileInFolder(look) if err != nil { return "", "", err } if hasGo { return look, gopath, nil } } } } } for _, gopath = range ctx.GopathList { dir := filepath.Join(gopath, importPath) fi, err := os.Stat(dir) if os.IsNotExist(err) { continue } if fi == nil { continue } if !fi.IsDir() { continue } return dir, gopath, nil } return "", "", ErrNotInGOPATH{importPath} }
[ "func", "(", "ctx", "*", "Context", ")", "findImportDir", "(", "relative", ",", "importPath", "string", ")", "(", "dir", ",", "gopath", "string", ",", "err", "error", ")", "{", "if", "importPath", "==", "\"", "\"", "||", "importPath", "==", "\"", "\"",...
// findImportDir finds the absolute directory. If rel is empty vendor folders // are not looked in.
[ "findImportDir", "finds", "the", "absolute", "directory", ".", "If", "rel", "is", "empty", "vendor", "folders", "are", "not", "looked", "in", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/path.go#L37-L90
train
kardianos/govendor
context/path.go
findImportPath
func (ctx *Context) findImportPath(dir string) (importPath, gopath string, err error) { dirResolved, err := filepath.EvalSymlinks(dir) if err != nil { return "", "", err } dirs := make([]string, 1) dirs = append(dirs, dir) if dir != dirResolved { dirs = append(dirs, dirResolved) } for _, gopath := range ctx.GopathList { for _, dir := range dirs { if pathos.FileHasPrefix(dir, gopath) || pathos.FileStringEquals(dir, gopath) { importPath = pathos.FileTrimPrefix(dir, gopath) importPath = pathos.SlashToImportPath(importPath) return importPath, gopath, nil } } } return "", "", ErrNotInGOPATH{dir} }
go
func (ctx *Context) findImportPath(dir string) (importPath, gopath string, err error) { dirResolved, err := filepath.EvalSymlinks(dir) if err != nil { return "", "", err } dirs := make([]string, 1) dirs = append(dirs, dir) if dir != dirResolved { dirs = append(dirs, dirResolved) } for _, gopath := range ctx.GopathList { for _, dir := range dirs { if pathos.FileHasPrefix(dir, gopath) || pathos.FileStringEquals(dir, gopath) { importPath = pathos.FileTrimPrefix(dir, gopath) importPath = pathos.SlashToImportPath(importPath) return importPath, gopath, nil } } } return "", "", ErrNotInGOPATH{dir} }
[ "func", "(", "ctx", "*", "Context", ")", "findImportPath", "(", "dir", "string", ")", "(", "importPath", ",", "gopath", "string", ",", "err", "error", ")", "{", "dirResolved", ",", "err", ":=", "filepath", ".", "EvalSymlinks", "(", "dir", ")", "\n", "i...
// findImportPath takes a absolute directory and returns the import path and go path.
[ "findImportPath", "takes", "a", "absolute", "directory", "and", "returns", "the", "import", "path", "and", "go", "path", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/path.go#L93-L114
train
kardianos/govendor
context/path.go
RemovePackage
func RemovePackage(path, root string, tree bool) error { // Ensure the path is empty of files. dir, err := os.Open(path) if err != nil { if os.IsNotExist(err) { return nil } return err } // Remove package files. fl, err := dir.Readdir(-1) dir.Close() if err != nil { return err } for _, fi := range fl { fullPath := filepath.Join(path, fi.Name()) if fi.IsDir() { if tree { // If tree == true then remove sub-directories too. err = os.RemoveAll(fullPath) if err != nil { return err } } continue } err = os.Remove(fullPath) if err != nil { return err } } // Remove empty parent folders. // Ignore errors here. for i := 0; i <= looplimit; i++ { if pathos.FileStringEquals(path, root) { return nil } dir, err := os.Open(path) if err != nil { // fmt.Fprintf(os.Stderr, "Failedd to open directory %q: %v\n", path, err) return nil } fl, err := dir.Readdir(1) dir.Close() if err != nil && err != io.EOF { // fmt.Fprintf(os.Stderr, "Failedd to list directory %q: %v\n", path, err) return nil } if len(fl) > 0 { allAreLicense := true for _, fi := range fl { if !isLicenseFile(fi.Name()) { allAreLicense = false break } } if !allAreLicense { return nil } } err = os.RemoveAll(path) if err != nil { // fmt.Fprintf(os.Stderr, "Failedd to remove empty directory %q: %v\n", path, err) return nil } nextPath := filepath.Clean(filepath.Join(path, "..")) // Check for root. if nextPath == path { return nil } path = nextPath } panic("removePackage() remove parent folders") }
go
func RemovePackage(path, root string, tree bool) error { // Ensure the path is empty of files. dir, err := os.Open(path) if err != nil { if os.IsNotExist(err) { return nil } return err } // Remove package files. fl, err := dir.Readdir(-1) dir.Close() if err != nil { return err } for _, fi := range fl { fullPath := filepath.Join(path, fi.Name()) if fi.IsDir() { if tree { // If tree == true then remove sub-directories too. err = os.RemoveAll(fullPath) if err != nil { return err } } continue } err = os.Remove(fullPath) if err != nil { return err } } // Remove empty parent folders. // Ignore errors here. for i := 0; i <= looplimit; i++ { if pathos.FileStringEquals(path, root) { return nil } dir, err := os.Open(path) if err != nil { // fmt.Fprintf(os.Stderr, "Failedd to open directory %q: %v\n", path, err) return nil } fl, err := dir.Readdir(1) dir.Close() if err != nil && err != io.EOF { // fmt.Fprintf(os.Stderr, "Failedd to list directory %q: %v\n", path, err) return nil } if len(fl) > 0 { allAreLicense := true for _, fi := range fl { if !isLicenseFile(fi.Name()) { allAreLicense = false break } } if !allAreLicense { return nil } } err = os.RemoveAll(path) if err != nil { // fmt.Fprintf(os.Stderr, "Failedd to remove empty directory %q: %v\n", path, err) return nil } nextPath := filepath.Clean(filepath.Join(path, "..")) // Check for root. if nextPath == path { return nil } path = nextPath } panic("removePackage() remove parent folders") }
[ "func", "RemovePackage", "(", "path", ",", "root", "string", ",", "tree", "bool", ")", "error", "{", "// Ensure the path is empty of files.", "dir", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "if", "os", ...
// RemovePackage removes the specified folder files. If folder is empty when // done (no nested folders, remove the folder and any empty parent folders.
[ "RemovePackage", "removes", "the", "specified", "folder", "files", ".", "If", "folder", "is", "empty", "when", "done", "(", "no", "nested", "folders", "remove", "the", "folder", "and", "any", "empty", "parent", "folders", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/path.go#L158-L235
train
kardianos/govendor
internal/gt/vcs.go
Setup
func (h *HttpHandler) Setup() VcsHandle { vcs := h.newer(h) vcs.create() h.g.onClean(vcs.remove) h.handles[vcs.pkg()] = vcs return vcs }
go
func (h *HttpHandler) Setup() VcsHandle { vcs := h.newer(h) vcs.create() h.g.onClean(vcs.remove) h.handles[vcs.pkg()] = vcs return vcs }
[ "func", "(", "h", "*", "HttpHandler", ")", "Setup", "(", ")", "VcsHandle", "{", "vcs", ":=", "h", ".", "newer", "(", "h", ")", "\n", "vcs", ".", "create", "(", ")", "\n", "h", ".", "g", ".", "onClean", "(", "vcs", ".", "remove", ")", "\n\n", ...
// Setup returns type with Remove function that can be defer'ed.
[ "Setup", "returns", "type", "with", "Remove", "function", "that", "can", "be", "defer", "ed", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/internal/gt/vcs.go#L65-L72
train
kardianos/govendor
context/resolve.go
loadPackage
func (ctx *Context) loadPackage() error { ctx.loaded = true ctx.dirty = false ctx.statusCache = nil ctx.Package = make(map[string]*Package, len(ctx.Package)) // We following the root symlink only in case the root of the repo is symlinked into the GOPATH // This could happen during on some CI that didn't checkout into the GOPATH rootdir, err := filepath.EvalSymlinks(ctx.RootDir) if err != nil { return err } err = filepath.Walk(rootdir, func(path string, info os.FileInfo, err error) error { if info == nil { return err } if !info.IsDir() { // We replace the directory path (followed by the symlink), to the real go repo package name/path // ex : replace "<somewhere>/govendor.source.repo" to "github.com/kardianos/govendor" path = strings.Replace(path, rootdir, ctx.RootDir, 1) _, err = ctx.addFileImports(path, ctx.RootGopath) return err } name := info.Name() // Still go into "_workspace" to aid godep migration. if name == "_workspace" { return nil } switch name[0] { case '.', '_': return filepath.SkipDir } switch name { case "testdata", "node_modules": return filepath.SkipDir } return nil }) if err != nil { return err } // Finally, set any unset status. return ctx.determinePackageStatus() }
go
func (ctx *Context) loadPackage() error { ctx.loaded = true ctx.dirty = false ctx.statusCache = nil ctx.Package = make(map[string]*Package, len(ctx.Package)) // We following the root symlink only in case the root of the repo is symlinked into the GOPATH // This could happen during on some CI that didn't checkout into the GOPATH rootdir, err := filepath.EvalSymlinks(ctx.RootDir) if err != nil { return err } err = filepath.Walk(rootdir, func(path string, info os.FileInfo, err error) error { if info == nil { return err } if !info.IsDir() { // We replace the directory path (followed by the symlink), to the real go repo package name/path // ex : replace "<somewhere>/govendor.source.repo" to "github.com/kardianos/govendor" path = strings.Replace(path, rootdir, ctx.RootDir, 1) _, err = ctx.addFileImports(path, ctx.RootGopath) return err } name := info.Name() // Still go into "_workspace" to aid godep migration. if name == "_workspace" { return nil } switch name[0] { case '.', '_': return filepath.SkipDir } switch name { case "testdata", "node_modules": return filepath.SkipDir } return nil }) if err != nil { return err } // Finally, set any unset status. return ctx.determinePackageStatus() }
[ "func", "(", "ctx", "*", "Context", ")", "loadPackage", "(", ")", "error", "{", "ctx", ".", "loaded", "=", "true", "\n", "ctx", ".", "dirty", "=", "false", "\n", "ctx", ".", "statusCache", "=", "nil", "\n", "ctx", ".", "Package", "=", "make", "(", ...
// loadPackage sets up the context with package information and // is called before any initial operation is performed.
[ "loadPackage", "sets", "up", "the", "context", "with", "package", "information", "and", "is", "called", "before", "any", "initial", "operation", "is", "performed", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/resolve.go#L36-L78
train
kardianos/govendor
vcs/vcs.go
RegisterVCS
func RegisterVCS(vcs Vcs) { registerSync.Lock() defer registerSync.Unlock() vcsRegistry = append(vcsRegistry, vcs) }
go
func RegisterVCS(vcs Vcs) { registerSync.Lock() defer registerSync.Unlock() vcsRegistry = append(vcsRegistry, vcs) }
[ "func", "RegisterVCS", "(", "vcs", "Vcs", ")", "{", "registerSync", ".", "Lock", "(", ")", "\n", "defer", "registerSync", ".", "Unlock", "(", ")", "\n\n", "vcsRegistry", "=", "append", "(", "vcsRegistry", ",", "vcs", ")", "\n", "}" ]
// RegisterVCS adds a new VCS to use.
[ "RegisterVCS", "adds", "a", "new", "VCS", "to", "use", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/vcs/vcs.go#L38-L43
train
kardianos/govendor
vcs/vcs.go
FindVcs
func FindVcs(root, packageDir string) (info *VcsInfo, err error) { if !filepath.IsAbs(root) { return nil, nil } if !filepath.IsAbs(packageDir) { return nil, nil } path := packageDir for i := 0; i <= looplimit; i++ { for _, vcs := range vcsRegistry { info, err = vcs.Find(path) if err != nil { return nil, err } if info != nil { return info, nil } } nextPath := filepath.Clean(filepath.Join(path, "..")) // Check for root. if nextPath == path { return nil, nil } if !pathos.FileHasPrefix(nextPath, root) { return nil, nil } path = nextPath } panic("loop limit") }
go
func FindVcs(root, packageDir string) (info *VcsInfo, err error) { if !filepath.IsAbs(root) { return nil, nil } if !filepath.IsAbs(packageDir) { return nil, nil } path := packageDir for i := 0; i <= looplimit; i++ { for _, vcs := range vcsRegistry { info, err = vcs.Find(path) if err != nil { return nil, err } if info != nil { return info, nil } } nextPath := filepath.Clean(filepath.Join(path, "..")) // Check for root. if nextPath == path { return nil, nil } if !pathos.FileHasPrefix(nextPath, root) { return nil, nil } path = nextPath } panic("loop limit") }
[ "func", "FindVcs", "(", "root", ",", "packageDir", "string", ")", "(", "info", "*", "VcsInfo", ",", "err", "error", ")", "{", "if", "!", "filepath", ".", "IsAbs", "(", "root", ")", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "if", "!", "fi...
// FindVcs determines the version control information given a package dir and // lowest root dir.
[ "FindVcs", "determines", "the", "version", "control", "information", "given", "a", "package", "dir", "and", "lowest", "root", "dir", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/vcs/vcs.go#L49-L79
train
kardianos/govendor
migrate/migrate.go
MigrateWD
func MigrateWD(from From) error { wd, err := os.Getwd() if err != nil { return err } return Migrate(from, wd) }
go
func MigrateWD(from From) error { wd, err := os.Getwd() if err != nil { return err } return Migrate(from, wd) }
[ "func", "MigrateWD", "(", "from", "From", ")", "error", "{", "wd", ",", "err", ":=", "os", ".", "Getwd", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "Migrate", "(", "from", ",", "wd", ")", "\n", "}...
// Migrate from the given system using the current working directory.
[ "Migrate", "from", "the", "given", "system", "using", "the", "current", "working", "directory", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/migrate/migrate.go#L30-L36
train
kardianos/govendor
migrate/migrate.go
SystemList
func SystemList() []string { list := make([]string, 0, len(registered)) for key := range registered { list = append(list, string(key)) } sort.Strings(list) return list }
go
func SystemList() []string { list := make([]string, 0, len(registered)) for key := range registered { list = append(list, string(key)) } sort.Strings(list) return list }
[ "func", "SystemList", "(", ")", "[", "]", "string", "{", "list", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "registered", ")", ")", "\n", "for", "key", ":=", "range", "registered", "{", "list", "=", "append", "(", "list", "...
// SystemList list available migration systems.
[ "SystemList", "list", "available", "migration", "systems", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/migrate/migrate.go#L39-L46
train
kardianos/govendor
migrate/migrate.go
Migrate
func Migrate(from From, root string) error { sys, found := registered[from] if !found { return ErrNoSuchSystem{ NotExist: string(from), Has: SystemList(), } } sys, err := sys.Check(root) if err != nil { return err } if sys == nil { return errors.New("Root not found.") } return sys.Migrate(root) }
go
func Migrate(from From, root string) error { sys, found := registered[from] if !found { return ErrNoSuchSystem{ NotExist: string(from), Has: SystemList(), } } sys, err := sys.Check(root) if err != nil { return err } if sys == nil { return errors.New("Root not found.") } return sys.Migrate(root) }
[ "func", "Migrate", "(", "from", "From", ",", "root", "string", ")", "error", "{", "sys", ",", "found", ":=", "registered", "[", "from", "]", "\n", "if", "!", "found", "{", "return", "ErrNoSuchSystem", "{", "NotExist", ":", "string", "(", "from", ")", ...
// Migrate from the given system using the given root.
[ "Migrate", "from", "the", "given", "system", "using", "the", "given", "root", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/migrate/migrate.go#L49-L65
train
kardianos/govendor
run/run.go
Run
func Run(w io.Writer, appArgs []string, ask prompt.Prompt) (help.HelpMessage, error) { r := &runner{} return r.run(w, appArgs, ask) }
go
func Run(w io.Writer, appArgs []string, ask prompt.Prompt) (help.HelpMessage, error) { r := &runner{} return r.run(w, appArgs, ask) }
[ "func", "Run", "(", "w", "io", ".", "Writer", ",", "appArgs", "[", "]", "string", ",", "ask", "prompt", ".", "Prompt", ")", "(", "help", ".", "HelpMessage", ",", "error", ")", "{", "r", ":=", "&", "runner", "{", "}", "\n", "return", "r", ".", "...
// Run is isoloated from main and os.Args to help with testing. // Shouldn't directly print to console, just write through w.
[ "Run", "is", "isoloated", "from", "main", "and", "os", ".", "Args", "to", "help", "with", "testing", ".", "Shouldn", "t", "directly", "print", "to", "console", "just", "write", "through", "w", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/run/run.go#L42-L45
train
kardianos/govendor
context/license.go
licenseWalk
func licenseWalk(root, startIn string, found func(folder, name string) error) error { folder := startIn for i := 0; i <= looplimit; i++ { dir, err := os.Open(folder) if err != nil { return err } fl, err := dir.Readdir(-1) dir.Close() if err != nil { return err } for _, fi := range fl { name := fi.Name() if name[0] == '.' { continue } if fi.IsDir() { continue } if !isLicenseFile(name) { continue } err = found(folder, name) if err != nil { return err } } if len(folder) <= len(root) { return nil } nextFolder := filepath.Clean(filepath.Join(folder, "..")) if nextFolder == folder { return nil } folder = nextFolder } panic("licenseFind loop limit") }
go
func licenseWalk(root, startIn string, found func(folder, name string) error) error { folder := startIn for i := 0; i <= looplimit; i++ { dir, err := os.Open(folder) if err != nil { return err } fl, err := dir.Readdir(-1) dir.Close() if err != nil { return err } for _, fi := range fl { name := fi.Name() if name[0] == '.' { continue } if fi.IsDir() { continue } if !isLicenseFile(name) { continue } err = found(folder, name) if err != nil { return err } } if len(folder) <= len(root) { return nil } nextFolder := filepath.Clean(filepath.Join(folder, "..")) if nextFolder == folder { return nil } folder = nextFolder } panic("licenseFind loop limit") }
[ "func", "licenseWalk", "(", "root", ",", "startIn", "string", ",", "found", "func", "(", "folder", ",", "name", "string", ")", "error", ")", "error", "{", "folder", ":=", "startIn", "\n", "for", "i", ":=", "0", ";", "i", "<=", "looplimit", ";", "i", ...
// licenseWalk starts in a folder and searches up the folder tree // for license like files. Found files are reported to the found function.
[ "licenseWalk", "starts", "in", "a", "folder", "and", "searches", "up", "the", "folder", "tree", "for", "license", "like", "files", ".", "Found", "files", "are", "reported", "to", "the", "found", "function", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/license.go#L110-L153
train
kardianos/govendor
context/license.go
licenseCopy
func licenseCopy(root, startIn, vendorRoot, pkgPath string) error { addTo, _ := pathos.TrimCommonSuffix(pathos.SlashToFilepath(pkgPath), startIn) startIn = filepath.Clean(filepath.Join(startIn, "..")) return licenseWalk(root, startIn, func(folder, name string) error { srcPath := filepath.Join(folder, name) trimTo := pathos.FileTrimPrefix(getLastVendorRoot(folder), root) /* Path: "golang.org/x/tools/go/vcs" Root: "/tmp/govendor-cache280388238/1" StartIn: "/tmp/govendor-cache280388238/1/go/vcs" addTo: "golang.org/x/tools" $PROJ/vendor + addTo + pathos.FileTrimPrefix(folder, root) + "LICENSE" */ destPath := filepath.Join(vendorRoot, addTo, trimTo, name) // Only copy if file does not exist. _, err := os.Stat(srcPath) if err != nil { return errors.Errorf("Source license path doesn't exist %q", srcPath) } destDir, _ := filepath.Split(destPath) if err = os.MkdirAll(destDir, 0777); err != nil { return errors.Wrapf(err, "Failed to create the directory %q", destDir) } return errors.Wrapf(copyFile(destPath, srcPath, nil), "copyFile dest=%q src=%q", destPath, srcPath) }) }
go
func licenseCopy(root, startIn, vendorRoot, pkgPath string) error { addTo, _ := pathos.TrimCommonSuffix(pathos.SlashToFilepath(pkgPath), startIn) startIn = filepath.Clean(filepath.Join(startIn, "..")) return licenseWalk(root, startIn, func(folder, name string) error { srcPath := filepath.Join(folder, name) trimTo := pathos.FileTrimPrefix(getLastVendorRoot(folder), root) /* Path: "golang.org/x/tools/go/vcs" Root: "/tmp/govendor-cache280388238/1" StartIn: "/tmp/govendor-cache280388238/1/go/vcs" addTo: "golang.org/x/tools" $PROJ/vendor + addTo + pathos.FileTrimPrefix(folder, root) + "LICENSE" */ destPath := filepath.Join(vendorRoot, addTo, trimTo, name) // Only copy if file does not exist. _, err := os.Stat(srcPath) if err != nil { return errors.Errorf("Source license path doesn't exist %q", srcPath) } destDir, _ := filepath.Split(destPath) if err = os.MkdirAll(destDir, 0777); err != nil { return errors.Wrapf(err, "Failed to create the directory %q", destDir) } return errors.Wrapf(copyFile(destPath, srcPath, nil), "copyFile dest=%q src=%q", destPath, srcPath) }) }
[ "func", "licenseCopy", "(", "root", ",", "startIn", ",", "vendorRoot", ",", "pkgPath", "string", ")", "error", "{", "addTo", ",", "_", ":=", "pathos", ".", "TrimCommonSuffix", "(", "pathos", ".", "SlashToFilepath", "(", "pkgPath", ")", ",", "startIn", ")",...
// licenseCopy starts the search in the parent of "startIn" folder. // Looks in all sub-folders until root is reached. The root itself is not // searched.
[ "licenseCopy", "starts", "the", "search", "in", "the", "parent", "of", "startIn", "folder", ".", "Looks", "in", "all", "sub", "-", "folders", "until", "root", "is", "reached", ".", "The", "root", "itself", "is", "not", "searched", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/license.go#L158-L185
train
kardianos/govendor
context/license.go
LicenseDiscover
func LicenseDiscover(root, startIn, overridePath string, list map[string]License) error { return licenseWalk(root, startIn, func(folder, name string) error { ipath := pathos.SlashToImportPath(strings.TrimPrefix(folder, root)) if len(overridePath) > 0 { ipath = overridePath } if _, found := list[ipath]; found { return nil } p := filepath.Join(folder, name) text, err := ioutil.ReadFile(p) if err != nil { return fmt.Errorf("Failed to read license file %q %v", p, err) } key := path.Join(ipath, name) list[key] = License{ Path: ipath, Filename: name, Text: string(text), } return nil }) }
go
func LicenseDiscover(root, startIn, overridePath string, list map[string]License) error { return licenseWalk(root, startIn, func(folder, name string) error { ipath := pathos.SlashToImportPath(strings.TrimPrefix(folder, root)) if len(overridePath) > 0 { ipath = overridePath } if _, found := list[ipath]; found { return nil } p := filepath.Join(folder, name) text, err := ioutil.ReadFile(p) if err != nil { return fmt.Errorf("Failed to read license file %q %v", p, err) } key := path.Join(ipath, name) list[key] = License{ Path: ipath, Filename: name, Text: string(text), } return nil }) }
[ "func", "LicenseDiscover", "(", "root", ",", "startIn", ",", "overridePath", "string", ",", "list", "map", "[", "string", "]", "License", ")", "error", "{", "return", "licenseWalk", "(", "root", ",", "startIn", ",", "func", "(", "folder", ",", "name", "s...
// LicenseDiscover looks for license files in a given path.
[ "LicenseDiscover", "looks", "for", "license", "files", "in", "a", "given", "path", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/license.go#L197-L219
train
kardianos/govendor
context/sync.go
run1
func (vcsCmd *VCSCmd) run1(dir string, cmdline string, keyval []string, verbose bool) ([]byte, error) { v := vcsCmd.Cmd m := make(map[string]string) for i := 0; i < len(keyval); i += 2 { m[keyval[i]] = keyval[i+1] } args := strings.Fields(cmdline) for i, arg := range args { args[i] = expand(m, arg) } _, err := exec.LookPath(v.Cmd) if err != nil { fmt.Fprintf(os.Stderr, "go: missing %s command. See http://golang.org/s/gogetcmd\n", v.Name) return nil, err } cmd := exec.Command(v.Cmd, args...) cmd.Dir = dir cmd.Env = envForDir(cmd.Dir) if vcs.ShowCmd { fmt.Printf("cd %s\n", dir) fmt.Printf("%s %s\n", v.Cmd, strings.Join(args, " ")) } var buf bytes.Buffer cmd.Stdout = &buf cmd.Stderr = &buf err = cmd.Run() out := buf.Bytes() if err != nil { if verbose { fmt.Fprintf(os.Stderr, "# cd %s; %s %s\n", dir, v.Cmd, strings.Join(args, " ")) os.Stderr.Write(out) } return nil, err } return out, nil }
go
func (vcsCmd *VCSCmd) run1(dir string, cmdline string, keyval []string, verbose bool) ([]byte, error) { v := vcsCmd.Cmd m := make(map[string]string) for i := 0; i < len(keyval); i += 2 { m[keyval[i]] = keyval[i+1] } args := strings.Fields(cmdline) for i, arg := range args { args[i] = expand(m, arg) } _, err := exec.LookPath(v.Cmd) if err != nil { fmt.Fprintf(os.Stderr, "go: missing %s command. See http://golang.org/s/gogetcmd\n", v.Name) return nil, err } cmd := exec.Command(v.Cmd, args...) cmd.Dir = dir cmd.Env = envForDir(cmd.Dir) if vcs.ShowCmd { fmt.Printf("cd %s\n", dir) fmt.Printf("%s %s\n", v.Cmd, strings.Join(args, " ")) } var buf bytes.Buffer cmd.Stdout = &buf cmd.Stderr = &buf err = cmd.Run() out := buf.Bytes() if err != nil { if verbose { fmt.Fprintf(os.Stderr, "# cd %s; %s %s\n", dir, v.Cmd, strings.Join(args, " ")) os.Stderr.Write(out) } return nil, err } return out, nil }
[ "func", "(", "vcsCmd", "*", "VCSCmd", ")", "run1", "(", "dir", "string", ",", "cmdline", "string", ",", "keyval", "[", "]", "string", ",", "verbose", "bool", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "v", ":=", "vcsCmd", ".", "Cmd", "\n...
// run1 is the generalized implementation of run and runOutput.
[ "run1", "is", "the", "generalized", "implementation", "of", "run", "and", "runOutput", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/sync.go#L155-L194
train
kardianos/govendor
context/sync.go
mergeEnvLists
func mergeEnvLists(in, out []string) []string { NextVar: for _, inkv := range in { k := strings.SplitAfterN(inkv, "=", 2)[0] for i, outkv := range out { if strings.HasPrefix(outkv, k) { out[i] = inkv continue NextVar } } out = append(out, inkv) } return out }
go
func mergeEnvLists(in, out []string) []string { NextVar: for _, inkv := range in { k := strings.SplitAfterN(inkv, "=", 2)[0] for i, outkv := range out { if strings.HasPrefix(outkv, k) { out[i] = inkv continue NextVar } } out = append(out, inkv) } return out }
[ "func", "mergeEnvLists", "(", "in", ",", "out", "[", "]", "string", ")", "[", "]", "string", "{", "NextVar", ":", "for", "_", ",", "inkv", ":=", "range", "in", "{", "k", ":=", "strings", ".", "SplitAfterN", "(", "inkv", ",", "\"", "\"", ",", "2",...
// mergeEnvLists merges the two environment lists such that // variables with the same name in "in" replace those in "out".
[ "mergeEnvLists", "merges", "the", "two", "environment", "lists", "such", "that", "variables", "with", "the", "same", "name", "in", "in", "replace", "those", "in", "out", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/sync.go#L218-L231
train
kardianos/govendor
internal/pathos/path.go
ParseGoEnvLine
func ParseGoEnvLine(line string) (key, value string, ok bool) { // Remove any leading "set " found on windows. // Match the name to the env var + "=". // Remove any quotes. // Return result. line = strings.TrimPrefix(line, "set ") parts := strings.SplitN(line, "=", 2) if len(parts) < 2 { return "", "", false } un, err := strconv.Unquote(parts[1]) if err != nil { return parts[0], parts[1], true } return parts[0], un, true }
go
func ParseGoEnvLine(line string) (key, value string, ok bool) { // Remove any leading "set " found on windows. // Match the name to the env var + "=". // Remove any quotes. // Return result. line = strings.TrimPrefix(line, "set ") parts := strings.SplitN(line, "=", 2) if len(parts) < 2 { return "", "", false } un, err := strconv.Unquote(parts[1]) if err != nil { return parts[0], parts[1], true } return parts[0], un, true }
[ "func", "ParseGoEnvLine", "(", "line", "string", ")", "(", "key", ",", "value", "string", ",", "ok", "bool", ")", "{", "// Remove any leading \"set \" found on windows.", "// Match the name to the env var + \"=\".", "// Remove any quotes.", "// Return result.", "line", "=",...
// ParseGoEnvLine parses a "go env" line into a key value pair.
[ "ParseGoEnvLine", "parses", "a", "go", "env", "line", "into", "a", "key", "value", "pair", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/internal/pathos/path.go#L121-L137
train
kardianos/govendor
internal/pathos/path.go
GoEnv
func GoEnv(name, line string) (value string, ok bool) { // Remove any leading "set " found on windows. // Match the name to the env var + "=". // Remove any quotes. // Return result. line = strings.TrimPrefix(line, "set ") if len(line) < len(name)+1 { return "", false } if name != line[:len(name)] || line[len(name)] != '=' { return "", false } line = line[len(name)+1:] if un, err := strconv.Unquote(line); err == nil { line = un } return line, true }
go
func GoEnv(name, line string) (value string, ok bool) { // Remove any leading "set " found on windows. // Match the name to the env var + "=". // Remove any quotes. // Return result. line = strings.TrimPrefix(line, "set ") if len(line) < len(name)+1 { return "", false } if name != line[:len(name)] || line[len(name)] != '=' { return "", false } line = line[len(name)+1:] if un, err := strconv.Unquote(line); err == nil { line = un } return line, true }
[ "func", "GoEnv", "(", "name", ",", "line", "string", ")", "(", "value", "string", ",", "ok", "bool", ")", "{", "// Remove any leading \"set \" found on windows.", "// Match the name to the env var + \"=\".", "// Remove any quotes.", "// Return result.", "line", "=", "stri...
// GoEnv parses a "go env" line and checks for a specific // variable name.
[ "GoEnv", "parses", "a", "go", "env", "line", "and", "checks", "for", "a", "specific", "variable", "name", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/internal/pathos/path.go#L141-L158
train
kardianos/govendor
context/modify.go
ModifyStatus
func (ctx *Context) ModifyStatus(sg StatusGroup, mod Modify, mops ...ModifyOption) error { if ctx.added == nil { ctx.added = make(map[string]bool, 10) } list, err := ctx.Status() if err != nil { return err } // Add packages from status. statusLoop: for _, item := range list { if !item.Status.MatchGroup(sg) { continue } if ctx.added[item.Pkg.PathOrigin()] { continue } // Do not add excluded packages if item.Status.Presence == PresenceExcluded { continue } // Do not attempt to add any existing status items that are // already present in vendor folder. if mod == Add { if ctx.VendorFilePackagePath(item.Pkg.Path) != nil { continue } for _, pkg := range ctx.Package { if pkg.Status.Location == LocationVendor && item.Pkg.Path == pkg.Path { continue statusLoop } } } err = ctx.modify(item.Pkg, mod, mops) if err != nil { // Skip these errors if from status. if _, is := err.(ErrTreeChildren); is { continue } if _, is := err.(ErrTreeParents); is { continue } return err } } return nil }
go
func (ctx *Context) ModifyStatus(sg StatusGroup, mod Modify, mops ...ModifyOption) error { if ctx.added == nil { ctx.added = make(map[string]bool, 10) } list, err := ctx.Status() if err != nil { return err } // Add packages from status. statusLoop: for _, item := range list { if !item.Status.MatchGroup(sg) { continue } if ctx.added[item.Pkg.PathOrigin()] { continue } // Do not add excluded packages if item.Status.Presence == PresenceExcluded { continue } // Do not attempt to add any existing status items that are // already present in vendor folder. if mod == Add { if ctx.VendorFilePackagePath(item.Pkg.Path) != nil { continue } for _, pkg := range ctx.Package { if pkg.Status.Location == LocationVendor && item.Pkg.Path == pkg.Path { continue statusLoop } } } err = ctx.modify(item.Pkg, mod, mops) if err != nil { // Skip these errors if from status. if _, is := err.(ErrTreeChildren); is { continue } if _, is := err.(ErrTreeParents); is { continue } return err } } return nil }
[ "func", "(", "ctx", "*", "Context", ")", "ModifyStatus", "(", "sg", "StatusGroup", ",", "mod", "Modify", ",", "mops", "...", "ModifyOption", ")", "error", "{", "if", "ctx", ".", "added", "==", "nil", "{", "ctx", ".", "added", "=", "make", "(", "map",...
// ModifyStatus adds packages to the context by status.
[ "ModifyStatus", "adds", "packages", "to", "the", "context", "by", "status", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/modify.go#L113-L162
train
kardianos/govendor
context/modify.go
ModifyImport
func (ctx *Context) ModifyImport(imp *pkgspec.Pkg, mod Modify, mops ...ModifyOption) error { var err error if ctx.added == nil { ctx.added = make(map[string]bool, 10) } // Grap the origin of the pkg spec from the vendor file as needed. if len(imp.Origin) == 0 { for _, vpkg := range ctx.VendorFile.Package { if vpkg.Remove { continue } if vpkg.Path == imp.Path { imp.Origin = vpkg.Origin } } } if !imp.MatchTree { if !ctx.added[imp.PathOrigin()] { err = ctx.modify(imp, mod, mops) if err != nil { return err } } return nil } list, err := ctx.Status() if err != nil { return err } // If add any matched from "...". match := imp.Path + "/" for _, item := range list { if ctx.added[item.Pkg.PathOrigin()] { continue } if item.Pkg.Path != imp.Path && !strings.HasPrefix(item.Pkg.Path, match) { continue } if imp.HasVersion { item.Pkg.HasVersion = true item.Pkg.Version = imp.Version } item.Pkg.HasOrigin = imp.HasOrigin item.Pkg.Origin = path.Join(imp.PathOrigin(), strings.TrimPrefix(item.Pkg.Path, imp.Path)) err = ctx.modify(item.Pkg, mod, mops) if err != nil { return err } } // cache for later use ctx.TreeImport = append(ctx.TreeImport, imp) return nil }
go
func (ctx *Context) ModifyImport(imp *pkgspec.Pkg, mod Modify, mops ...ModifyOption) error { var err error if ctx.added == nil { ctx.added = make(map[string]bool, 10) } // Grap the origin of the pkg spec from the vendor file as needed. if len(imp.Origin) == 0 { for _, vpkg := range ctx.VendorFile.Package { if vpkg.Remove { continue } if vpkg.Path == imp.Path { imp.Origin = vpkg.Origin } } } if !imp.MatchTree { if !ctx.added[imp.PathOrigin()] { err = ctx.modify(imp, mod, mops) if err != nil { return err } } return nil } list, err := ctx.Status() if err != nil { return err } // If add any matched from "...". match := imp.Path + "/" for _, item := range list { if ctx.added[item.Pkg.PathOrigin()] { continue } if item.Pkg.Path != imp.Path && !strings.HasPrefix(item.Pkg.Path, match) { continue } if imp.HasVersion { item.Pkg.HasVersion = true item.Pkg.Version = imp.Version } item.Pkg.HasOrigin = imp.HasOrigin item.Pkg.Origin = path.Join(imp.PathOrigin(), strings.TrimPrefix(item.Pkg.Path, imp.Path)) err = ctx.modify(item.Pkg, mod, mops) if err != nil { return err } } // cache for later use ctx.TreeImport = append(ctx.TreeImport, imp) return nil }
[ "func", "(", "ctx", "*", "Context", ")", "ModifyImport", "(", "imp", "*", "pkgspec", ".", "Pkg", ",", "mod", "Modify", ",", "mops", "...", "ModifyOption", ")", "error", "{", "var", "err", "error", "\n", "if", "ctx", ".", "added", "==", "nil", "{", ...
// ModifyImport adds the package to the context.
[ "ModifyImport", "adds", "the", "package", "to", "the", "context", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/modify.go#L165-L217
train
kardianos/govendor
context/modify.go
modifyFetch
func (ctx *Context) modifyFetch(pkg *Package, uncommitted, hasVersion bool, version string) error { vp := ctx.VendorFilePackagePath(pkg.Path) if vp == nil { vp = &vendorfile.Package{ Add: true, Path: pkg.Path, } ctx.VendorFile.Package = append(ctx.VendorFile.Package, vp) } if hasVersion { vp.Version = version pkg.Version = version pkg.HasVersion = true } if pkg.IncludeTree { vp.Tree = pkg.IncludeTree } pkg.Origin = strings.TrimPrefix(pkg.Origin, ctx.RootImportPath+"/"+ctx.VendorFolder+"/") vp.Origin = pkg.Origin origin := vp.Origin if len(vp.Origin) == 0 { origin = vp.Path } ps := &pkgspec.Pkg{ Path: pkg.Path, Origin: origin, HasVersion: hasVersion, Version: version, } dest := filepath.Join(ctx.RootDir, ctx.VendorFolder, pathos.SlashToFilepath(pkg.Path)) ctx.Operation = append(ctx.Operation, &Operation{ Type: OpFetch, Pkg: pkg, Src: ps.String(), Dest: dest, }) return nil }
go
func (ctx *Context) modifyFetch(pkg *Package, uncommitted, hasVersion bool, version string) error { vp := ctx.VendorFilePackagePath(pkg.Path) if vp == nil { vp = &vendorfile.Package{ Add: true, Path: pkg.Path, } ctx.VendorFile.Package = append(ctx.VendorFile.Package, vp) } if hasVersion { vp.Version = version pkg.Version = version pkg.HasVersion = true } if pkg.IncludeTree { vp.Tree = pkg.IncludeTree } pkg.Origin = strings.TrimPrefix(pkg.Origin, ctx.RootImportPath+"/"+ctx.VendorFolder+"/") vp.Origin = pkg.Origin origin := vp.Origin if len(vp.Origin) == 0 { origin = vp.Path } ps := &pkgspec.Pkg{ Path: pkg.Path, Origin: origin, HasVersion: hasVersion, Version: version, } dest := filepath.Join(ctx.RootDir, ctx.VendorFolder, pathos.SlashToFilepath(pkg.Path)) ctx.Operation = append(ctx.Operation, &Operation{ Type: OpFetch, Pkg: pkg, Src: ps.String(), Dest: dest, }) return nil }
[ "func", "(", "ctx", "*", "Context", ")", "modifyFetch", "(", "pkg", "*", "Package", ",", "uncommitted", ",", "hasVersion", "bool", ",", "version", "string", ")", "error", "{", "vp", ":=", "ctx", ".", "VendorFilePackagePath", "(", "pkg", ".", "Path", ")",...
// modify function to fetch given package.
[ "modify", "function", "to", "fetch", "given", "package", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/modify.go#L502-L539
train
kardianos/govendor
context/modify.go
Check
func (ctx *Context) Check() []*Conflict { // Find duplicate packages that have been marked for moving. findDups := make(map[string][]*Operation, 3) // map[canonical][]local for _, op := range ctx.Operation { if op.State != OpReady { continue } findDups[op.Pkg.Path] = append(findDups[op.Pkg.Path], op) } var ret []*Conflict for canonical, lop := range findDups { if len(lop) == 1 { continue } destDir := path.Join(ctx.RootImportPath, ctx.VendorFolder, canonical) ret = append(ret, &Conflict{ Canonical: canonical, Local: destDir, Operation: lop, }) } return ret }
go
func (ctx *Context) Check() []*Conflict { // Find duplicate packages that have been marked for moving. findDups := make(map[string][]*Operation, 3) // map[canonical][]local for _, op := range ctx.Operation { if op.State != OpReady { continue } findDups[op.Pkg.Path] = append(findDups[op.Pkg.Path], op) } var ret []*Conflict for canonical, lop := range findDups { if len(lop) == 1 { continue } destDir := path.Join(ctx.RootImportPath, ctx.VendorFolder, canonical) ret = append(ret, &Conflict{ Canonical: canonical, Local: destDir, Operation: lop, }) } return ret }
[ "func", "(", "ctx", "*", "Context", ")", "Check", "(", ")", "[", "]", "*", "Conflict", "{", "// Find duplicate packages that have been marked for moving.", "findDups", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "*", "Operation", ",", "3", ")", ...
// Check returns any conflicts when more than one package can be moved into // the same path.
[ "Check", "returns", "any", "conflicts", "when", "more", "than", "one", "package", "can", "be", "moved", "into", "the", "same", "path", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/modify.go#L543-L566
train
kardianos/govendor
context/modify.go
ResloveApply
func (ctx *Context) ResloveApply(cc []*Conflict) { for _, c := range cc { if !c.Resolved { continue } for i, op := range c.Operation { if op.State != OpReady { continue } if i == c.OpIndex { if vp := ctx.VendorFilePackagePath(c.Canonical); vp != nil { vp.Origin = c.Local } continue } op.State = OpIgnore } } }
go
func (ctx *Context) ResloveApply(cc []*Conflict) { for _, c := range cc { if !c.Resolved { continue } for i, op := range c.Operation { if op.State != OpReady { continue } if i == c.OpIndex { if vp := ctx.VendorFilePackagePath(c.Canonical); vp != nil { vp.Origin = c.Local } continue } op.State = OpIgnore } } }
[ "func", "(", "ctx", "*", "Context", ")", "ResloveApply", "(", "cc", "[", "]", "*", "Conflict", ")", "{", "for", "_", ",", "c", ":=", "range", "cc", "{", "if", "!", "c", ".", "Resolved", "{", "continue", "\n", "}", "\n", "for", "i", ",", "op", ...
// ResolveApply applies the conflict resolution selected. It chooses the // Operation listed in the OpIndex field.
[ "ResolveApply", "applies", "the", "conflict", "resolution", "selected", ".", "It", "chooses", "the", "Operation", "listed", "in", "the", "OpIndex", "field", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/modify.go#L570-L588
train
kardianos/govendor
context/modify.go
ResolveAutoLongestPath
func ResolveAutoLongestPath(cc []*Conflict) []*Conflict { for _, c := range cc { if c.Resolved { continue } longestLen := 0 longestIndex := 0 for i, op := range c.Operation { if op.State != OpReady { continue } if len(op.Pkg.Local) > longestLen { longestLen = len(op.Pkg.Local) longestIndex = i } } c.OpIndex = longestIndex c.Resolved = true } return cc }
go
func ResolveAutoLongestPath(cc []*Conflict) []*Conflict { for _, c := range cc { if c.Resolved { continue } longestLen := 0 longestIndex := 0 for i, op := range c.Operation { if op.State != OpReady { continue } if len(op.Pkg.Local) > longestLen { longestLen = len(op.Pkg.Local) longestIndex = i } } c.OpIndex = longestIndex c.Resolved = true } return cc }
[ "func", "ResolveAutoLongestPath", "(", "cc", "[", "]", "*", "Conflict", ")", "[", "]", "*", "Conflict", "{", "for", "_", ",", "c", ":=", "range", "cc", "{", "if", "c", ".", "Resolved", "{", "continue", "\n", "}", "\n", "longestLen", ":=", "0", "\n"...
// ResolveAutoLongestPath finds the longest local path in each conflict // and set it to be used.
[ "ResolveAutoLongestPath", "finds", "the", "longest", "local", "path", "in", "each", "conflict", "and", "set", "it", "to", "be", "used", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/modify.go#L592-L613
train
kardianos/govendor
context/modify.go
ResolveAutoVendorFileOrigin
func (ctx *Context) ResolveAutoVendorFileOrigin(cc []*Conflict) []*Conflict { for _, c := range cc { if c.Resolved { continue } vp := ctx.VendorFilePackagePath(c.Canonical) if vp == nil { continue } // If this was just added, we still can't rely on it. // We still need to ask user. if vp.Add { continue } lookFor := vp.Path if len(vp.Origin) != 0 { lookFor = vp.Origin } for i, op := range c.Operation { if op.State != OpReady { continue } if op.Pkg.Local == lookFor { c.OpIndex = i c.Resolved = true break } } } return cc }
go
func (ctx *Context) ResolveAutoVendorFileOrigin(cc []*Conflict) []*Conflict { for _, c := range cc { if c.Resolved { continue } vp := ctx.VendorFilePackagePath(c.Canonical) if vp == nil { continue } // If this was just added, we still can't rely on it. // We still need to ask user. if vp.Add { continue } lookFor := vp.Path if len(vp.Origin) != 0 { lookFor = vp.Origin } for i, op := range c.Operation { if op.State != OpReady { continue } if op.Pkg.Local == lookFor { c.OpIndex = i c.Resolved = true break } } } return cc }
[ "func", "(", "ctx", "*", "Context", ")", "ResolveAutoVendorFileOrigin", "(", "cc", "[", "]", "*", "Conflict", ")", "[", "]", "*", "Conflict", "{", "for", "_", ",", "c", ":=", "range", "cc", "{", "if", "c", ".", "Resolved", "{", "continue", "\n", "}...
// ResolveAutoVendorFileOrigin resolves conflicts based on the vendor file // if possible.
[ "ResolveAutoVendorFileOrigin", "resolves", "conflicts", "based", "on", "the", "vendor", "file", "if", "possible", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/modify.go#L642-L673
train
kardianos/govendor
context/modify.go
Alter
func (ctx *Context) Alter() error { ctx.added = nil // Ensure there are no conflicts at this time. buf := &bytes.Buffer{} for _, conflict := range ctx.Check() { buf.WriteString(fmt.Sprintf("Different Canonical Packages for %s\n", conflict.Canonical)) for _, op := range conflict.Operation { buf.WriteString(fmt.Sprintf("\t%s\n", op.Pkg.Local)) } } if buf.Len() != 0 { return errors.New(buf.String()) } var err error fetch, err := newFetcher(ctx) if err != nil { return err } for { var nextOps []*Operation for _, op := range ctx.Operation { if op.State != OpReady { continue } switch op.Type { case OpFetch: var ops []*Operation // Download packages, transform fetch op into a copy op. ops, err = fetch.op(op) if len(ops) > 0 { nextOps = append(nextOps, ops...) } } if err != nil { return errors.Wrapf(err, "Failed to fetch package %q", op.Pkg.Path) } } if len(nextOps) == 0 { break } ctx.Operation = append(ctx.Operation, nextOps...) } // Move and possibly rewrite packages. for _, op := range ctx.Operation { if op.State != OpReady { continue } pkg := op.Pkg if pathos.FileStringEquals(op.Dest, op.Src) { panic("For package " + pkg.Local + " attempt to copy to same location: " + op.Src) } dprintf("MV: %s (%q -> %q)\n", pkg.Local, op.Src, op.Dest) // Copy the package or remove. switch op.Type { default: panic("unknown operation type") case OpRemove: ctx.dirty = true err = RemovePackage(op.Src, filepath.Join(ctx.RootDir, ctx.VendorFolder), pkg.IncludeTree) op.State = OpDone case OpCopy: err = ctx.copyOperation(op, nil) if os.IsNotExist(errors.Cause(err)) { // Ignore packages that don't exist, like appengine. err = nil } } if err != nil { return errors.Wrapf(err, "Failed to %v package %q -> %q", op.Type, op.Src, op.Dest) } } if ctx.rewriteImports { return ctx.rewrite() } return nil }
go
func (ctx *Context) Alter() error { ctx.added = nil // Ensure there are no conflicts at this time. buf := &bytes.Buffer{} for _, conflict := range ctx.Check() { buf.WriteString(fmt.Sprintf("Different Canonical Packages for %s\n", conflict.Canonical)) for _, op := range conflict.Operation { buf.WriteString(fmt.Sprintf("\t%s\n", op.Pkg.Local)) } } if buf.Len() != 0 { return errors.New(buf.String()) } var err error fetch, err := newFetcher(ctx) if err != nil { return err } for { var nextOps []*Operation for _, op := range ctx.Operation { if op.State != OpReady { continue } switch op.Type { case OpFetch: var ops []*Operation // Download packages, transform fetch op into a copy op. ops, err = fetch.op(op) if len(ops) > 0 { nextOps = append(nextOps, ops...) } } if err != nil { return errors.Wrapf(err, "Failed to fetch package %q", op.Pkg.Path) } } if len(nextOps) == 0 { break } ctx.Operation = append(ctx.Operation, nextOps...) } // Move and possibly rewrite packages. for _, op := range ctx.Operation { if op.State != OpReady { continue } pkg := op.Pkg if pathos.FileStringEquals(op.Dest, op.Src) { panic("For package " + pkg.Local + " attempt to copy to same location: " + op.Src) } dprintf("MV: %s (%q -> %q)\n", pkg.Local, op.Src, op.Dest) // Copy the package or remove. switch op.Type { default: panic("unknown operation type") case OpRemove: ctx.dirty = true err = RemovePackage(op.Src, filepath.Join(ctx.RootDir, ctx.VendorFolder), pkg.IncludeTree) op.State = OpDone case OpCopy: err = ctx.copyOperation(op, nil) if os.IsNotExist(errors.Cause(err)) { // Ignore packages that don't exist, like appengine. err = nil } } if err != nil { return errors.Wrapf(err, "Failed to %v package %q -> %q", op.Type, op.Src, op.Dest) } } if ctx.rewriteImports { return ctx.rewrite() } return nil }
[ "func", "(", "ctx", "*", "Context", ")", "Alter", "(", ")", "error", "{", "ctx", ".", "added", "=", "nil", "\n", "// Ensure there are no conflicts at this time.", "buf", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "for", "_", ",", "conflict", ":="...
// Alter runs any requested package alterations.
[ "Alter", "runs", "any", "requested", "package", "alterations", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/modify.go#L676-L754
train
kardianos/govendor
internal/gt/gopath.go
In
func (g *GopathTest) In(pkg string) { g.pkg = pkg p := g.Path(pkg) err := os.Chdir(p) if err != nil { g.Fatal(err) } g.current = p }
go
func (g *GopathTest) In(pkg string) { g.pkg = pkg p := g.Path(pkg) err := os.Chdir(p) if err != nil { g.Fatal(err) } g.current = p }
[ "func", "(", "g", "*", "GopathTest", ")", "In", "(", "pkg", "string", ")", "{", "g", ".", "pkg", "=", "pkg", "\n", "p", ":=", "g", ".", "Path", "(", "pkg", ")", "\n", "err", ":=", "os", ".", "Chdir", "(", "p", ")", "\n", "if", "err", "!=", ...
// In sets the current directory as an import path.
[ "In", "sets", "the", "current", "directory", "as", "an", "import", "path", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/internal/gt/gopath.go#L75-L83
train
kardianos/govendor
internal/gt/gopath.go
Path
func (g *GopathTest) Path(pkg string) string { return filepath.Join(g.base, "src", pkg) }
go
func (g *GopathTest) Path(pkg string) string { return filepath.Join(g.base, "src", pkg) }
[ "func", "(", "g", "*", "GopathTest", ")", "Path", "(", "pkg", "string", ")", "string", "{", "return", "filepath", ".", "Join", "(", "g", ".", "base", ",", "\"", "\"", ",", "pkg", ")", "\n", "}" ]
// Get path from package import path pkg.
[ "Get", "path", "from", "package", "import", "path", "pkg", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/internal/gt/gopath.go#L86-L88
train
kardianos/govendor
internal/gt/gopath.go
Check
func (g *GopathTest) Check(err error) { if err == nil { return } g.Fatal(err) }
go
func (g *GopathTest) Check(err error) { if err == nil { return } g.Fatal(err) }
[ "func", "(", "g", "*", "GopathTest", ")", "Check", "(", "err", "error", ")", "{", "if", "err", "==", "nil", "{", "return", "\n", "}", "\n", "g", ".", "Fatal", "(", "err", ")", "\n", "}" ]
// Check is fatal to the test if err is not nil.
[ "Check", "is", "fatal", "to", "the", "test", "if", "err", "is", "not", "nil", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/internal/gt/gopath.go#L114-L119
train
kardianos/govendor
context/context.go
NewContextWD
func NewContextWD(rt RootType) (*Context, error) { wd, err := os.Getwd() if err != nil { return nil, err } rootIndicator := "vendor" root := wd switch rt { case RootVendor: tryRoot, err := findRoot(wd, rootIndicator) if err != nil { return nil, err } root = tryRoot case RootVendorOrWD: tryRoot, err := findRoot(wd, rootIndicator) if err == nil { root = tryRoot } case RootVendorOrWDOrFirstGOPATH: root, err = findRoot(wd, rootIndicator) if err != nil { env, err := NewEnv() if err != nil { return nil, err } allgopath := env["GOPATH"] if len(allgopath) == 0 { return nil, ErrMissingGOPATH } gopathList := filepath.SplitList(allgopath) root = filepath.Join(gopathList[0], "src") } } // Check for old vendor file location. oldLocation := filepath.Join(root, vendorFilename) if _, err := os.Stat(oldLocation); err == nil { return nil, ErrOldVersion{`Use the "migrate" command to update.`} } return NewContextRoot(root) }
go
func NewContextWD(rt RootType) (*Context, error) { wd, err := os.Getwd() if err != nil { return nil, err } rootIndicator := "vendor" root := wd switch rt { case RootVendor: tryRoot, err := findRoot(wd, rootIndicator) if err != nil { return nil, err } root = tryRoot case RootVendorOrWD: tryRoot, err := findRoot(wd, rootIndicator) if err == nil { root = tryRoot } case RootVendorOrWDOrFirstGOPATH: root, err = findRoot(wd, rootIndicator) if err != nil { env, err := NewEnv() if err != nil { return nil, err } allgopath := env["GOPATH"] if len(allgopath) == 0 { return nil, ErrMissingGOPATH } gopathList := filepath.SplitList(allgopath) root = filepath.Join(gopathList[0], "src") } } // Check for old vendor file location. oldLocation := filepath.Join(root, vendorFilename) if _, err := os.Stat(oldLocation); err == nil { return nil, ErrOldVersion{`Use the "migrate" command to update.`} } return NewContextRoot(root) }
[ "func", "NewContextWD", "(", "rt", "RootType", ")", "(", "*", "Context", ",", "error", ")", "{", "wd", ",", "err", ":=", "os", ".", "Getwd", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "rootIndicat...
// NewContextWD creates a new context. It looks for a root folder by finding // a vendor file.
[ "NewContextWD", "creates", "a", "new", "context", ".", "It", "looks", "for", "a", "root", "folder", "by", "finding", "a", "vendor", "file", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/context.go#L154-L198
train
kardianos/govendor
context/context.go
NewContextRoot
func NewContextRoot(root string) (*Context, error) { pathToVendorFile := filepath.Join("vendor", vendorFilename) vendorFolder := "vendor" return NewContext(root, pathToVendorFile, vendorFolder, false) }
go
func NewContextRoot(root string) (*Context, error) { pathToVendorFile := filepath.Join("vendor", vendorFilename) vendorFolder := "vendor" return NewContext(root, pathToVendorFile, vendorFolder, false) }
[ "func", "NewContextRoot", "(", "root", "string", ")", "(", "*", "Context", ",", "error", ")", "{", "pathToVendorFile", ":=", "filepath", ".", "Join", "(", "\"", "\"", ",", "vendorFilename", ")", "\n", "vendorFolder", ":=", "\"", "\"", "\n\n", "return", "...
// NewContextRoot creates a new context for the given root folder.
[ "NewContextRoot", "creates", "a", "new", "context", "for", "the", "given", "root", "folder", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/context.go#L201-L206
train
kardianos/govendor
context/context.go
NewContext
func NewContext(root, vendorFilePathRel, vendorFolder string, rewriteImports bool) (*Context, error) { dprintf("CTX: %s\n", root) var err error env, err := NewEnv() if err != nil { return nil, err } goroot := env["GOROOT"] all := env["GOPATH"] if goroot == "" { return nil, ErrMissingGOROOT } goroot = filepath.Join(goroot, "src") // Get the GOPATHs. Prepend the GOROOT to the list. if len(all) == 0 { return nil, ErrMissingGOPATH } gopathList := filepath.SplitList(all) gopathGoroot := make([]string, 0, len(gopathList)+1) gopathGoroot = append(gopathGoroot, goroot) for _, gopath := range gopathList { srcPath := filepath.Join(gopath, "src") + string(filepath.Separator) srcPathEvaled, err := filepath.EvalSymlinks(srcPath) if err != nil { return nil, err } gopathGoroot = append(gopathGoroot, srcPath, srcPathEvaled+string(filepath.Separator)) } rootToVendorFile, _ := filepath.Split(vendorFilePathRel) vendorFilePath := filepath.Join(root, vendorFilePathRel) ctx := &Context{ RootDir: root, GopathList: gopathGoroot, Goroot: goroot, VendorFilePath: vendorFilePath, VendorFolder: vendorFolder, RootToVendorFile: pathos.SlashToImportPath(rootToVendorFile), VendorDiscoverFolder: "vendor", Package: make(map[string]*Package), RewriteRule: make(map[string]string, 3), rewriteImports: rewriteImports, } ctx.RootImportPath, ctx.RootGopath, err = ctx.findImportPath(root) if err != nil { return nil, err } vf, err := readVendorFile(path.Join(ctx.RootImportPath, vendorFolder)+"/", vendorFilePath) if err != nil { if !os.IsNotExist(err) { return nil, err } vf = &vendorfile.File{} } ctx.VendorFile = vf ctx.IgnoreBuildAndPackage(vf.Ignore) return ctx, nil }
go
func NewContext(root, vendorFilePathRel, vendorFolder string, rewriteImports bool) (*Context, error) { dprintf("CTX: %s\n", root) var err error env, err := NewEnv() if err != nil { return nil, err } goroot := env["GOROOT"] all := env["GOPATH"] if goroot == "" { return nil, ErrMissingGOROOT } goroot = filepath.Join(goroot, "src") // Get the GOPATHs. Prepend the GOROOT to the list. if len(all) == 0 { return nil, ErrMissingGOPATH } gopathList := filepath.SplitList(all) gopathGoroot := make([]string, 0, len(gopathList)+1) gopathGoroot = append(gopathGoroot, goroot) for _, gopath := range gopathList { srcPath := filepath.Join(gopath, "src") + string(filepath.Separator) srcPathEvaled, err := filepath.EvalSymlinks(srcPath) if err != nil { return nil, err } gopathGoroot = append(gopathGoroot, srcPath, srcPathEvaled+string(filepath.Separator)) } rootToVendorFile, _ := filepath.Split(vendorFilePathRel) vendorFilePath := filepath.Join(root, vendorFilePathRel) ctx := &Context{ RootDir: root, GopathList: gopathGoroot, Goroot: goroot, VendorFilePath: vendorFilePath, VendorFolder: vendorFolder, RootToVendorFile: pathos.SlashToImportPath(rootToVendorFile), VendorDiscoverFolder: "vendor", Package: make(map[string]*Package), RewriteRule: make(map[string]string, 3), rewriteImports: rewriteImports, } ctx.RootImportPath, ctx.RootGopath, err = ctx.findImportPath(root) if err != nil { return nil, err } vf, err := readVendorFile(path.Join(ctx.RootImportPath, vendorFolder)+"/", vendorFilePath) if err != nil { if !os.IsNotExist(err) { return nil, err } vf = &vendorfile.File{} } ctx.VendorFile = vf ctx.IgnoreBuildAndPackage(vf.Ignore) return ctx, nil }
[ "func", "NewContext", "(", "root", ",", "vendorFilePathRel", ",", "vendorFolder", "string", ",", "rewriteImports", "bool", ")", "(", "*", "Context", ",", "error", ")", "{", "dprintf", "(", "\"", "\\n", "\"", ",", "root", ")", "\n", "var", "err", "error",...
// NewContext creates new context from a given root folder and vendor file path. // The vendorFolder is where vendor packages should be placed.
[ "NewContext", "creates", "new", "context", "from", "a", "given", "root", "folder", "and", "vendor", "file", "path", ".", "The", "vendorFolder", "is", "where", "vendor", "packages", "should", "be", "placed", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/context.go#L210-L281
train
kardianos/govendor
context/context.go
Write
func (ctx *Context) Write(s []byte) (int, error) { if ctx.Logger != nil { return ctx.Logger.Write(s) } return len(s), nil }
go
func (ctx *Context) Write(s []byte) (int, error) { if ctx.Logger != nil { return ctx.Logger.Write(s) } return len(s), nil }
[ "func", "(", "ctx", "*", "Context", ")", "Write", "(", "s", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "ctx", ".", "Logger", "!=", "nil", "{", "return", "ctx", ".", "Logger", ".", "Write", "(", "s", ")", "\n", "}", "\n",...
// Write to the set io.Writer for logging.
[ "Write", "to", "the", "set", "io", ".", "Writer", "for", "logging", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/context.go#L308-L313
train
kardianos/govendor
context/context.go
VendorFilePackagePath
func (ctx *Context) VendorFilePackagePath(path string) *vendorfile.Package { for _, pkg := range ctx.VendorFile.Package { if pkg.Remove { continue } if pkg.Path == path { return pkg } } return nil }
go
func (ctx *Context) VendorFilePackagePath(path string) *vendorfile.Package { for _, pkg := range ctx.VendorFile.Package { if pkg.Remove { continue } if pkg.Path == path { return pkg } } return nil }
[ "func", "(", "ctx", "*", "Context", ")", "VendorFilePackagePath", "(", "path", "string", ")", "*", "vendorfile", ".", "Package", "{", "for", "_", ",", "pkg", ":=", "range", "ctx", ".", "VendorFile", ".", "Package", "{", "if", "pkg", ".", "Remove", "{",...
// VendorFilePackagePath finds a given vendor file package give the import path.
[ "VendorFilePackagePath", "finds", "a", "given", "vendor", "file", "package", "give", "the", "import", "path", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/context.go#L316-L326
train
kardianos/govendor
context/context.go
findPackageChild
func (ctx *Context) findPackageChild(ck *Package) []*Package { out := make([]*Package, 0, 3) for _, pkg := range ctx.Package { if pkg == ck { continue } if !pkg.inVendor { continue } if pkg.Status.Presence == PresenceTree { continue } if strings.HasPrefix(pkg.Path, ck.Path+"/") { out = append(out, pkg) } } return out }
go
func (ctx *Context) findPackageChild(ck *Package) []*Package { out := make([]*Package, 0, 3) for _, pkg := range ctx.Package { if pkg == ck { continue } if !pkg.inVendor { continue } if pkg.Status.Presence == PresenceTree { continue } if strings.HasPrefix(pkg.Path, ck.Path+"/") { out = append(out, pkg) } } return out }
[ "func", "(", "ctx", "*", "Context", ")", "findPackageChild", "(", "ck", "*", "Package", ")", "[", "]", "*", "Package", "{", "out", ":=", "make", "(", "[", "]", "*", "Package", ",", "0", ",", "3", ")", "\n", "for", "_", ",", "pkg", ":=", "range"...
// findPackageChild finds any package under the current package. // Used for finding tree overlaps.
[ "findPackageChild", "finds", "any", "package", "under", "the", "current", "package", ".", "Used", "for", "finding", "tree", "overlaps", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/context.go#L330-L347
train
kardianos/govendor
context/context.go
findPackageParentTree
func (ctx *Context) findPackageParentTree(ck *Package) []string { out := make([]string, 0, 1) for _, pkg := range ctx.Package { if !pkg.inVendor { continue } if !pkg.IncludeTree || pkg == ck { continue } // pkg.Path = github.com/usera/pkg, tree = true // ck.Path = github.com/usera/pkg/dance if strings.HasPrefix(ck.Path, pkg.Path+"/") { out = append(out, pkg.Local) } } return out }
go
func (ctx *Context) findPackageParentTree(ck *Package) []string { out := make([]string, 0, 1) for _, pkg := range ctx.Package { if !pkg.inVendor { continue } if !pkg.IncludeTree || pkg == ck { continue } // pkg.Path = github.com/usera/pkg, tree = true // ck.Path = github.com/usera/pkg/dance if strings.HasPrefix(ck.Path, pkg.Path+"/") { out = append(out, pkg.Local) } } return out }
[ "func", "(", "ctx", "*", "Context", ")", "findPackageParentTree", "(", "ck", "*", "Package", ")", "[", "]", "string", "{", "out", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "1", ")", "\n", "for", "_", ",", "pkg", ":=", "range", "ctx", ...
// findPackageParentTree finds any parent tree package that would // include the given canonical path.
[ "findPackageParentTree", "finds", "any", "parent", "tree", "package", "that", "would", "include", "the", "given", "canonical", "path", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/context.go#L351-L367
train
kardianos/govendor
context/context.go
updatePackageReferences
func (ctx *Context) updatePackageReferences() { pathUnderDirLookup := make(map[string]map[string]*Package) findCanonicalUnderDir := func(dir, path string) *Package { if importMap, found := pathUnderDirLookup[dir]; found { if pkg, found2 := importMap[path]; found2 { return pkg } } else { pathUnderDirLookup[dir] = make(map[string]*Package) } for _, pkg := range ctx.Package { if !pkg.inVendor { continue } removeFromEnd := len(pkg.Path) + len(ctx.VendorDiscoverFolder) + 2 nextLen := len(pkg.Dir) - removeFromEnd if nextLen < 0 { continue } checkDir := pkg.Dir[:nextLen] if !pathos.FileHasPrefix(dir, checkDir) { continue } if pkg.Path != path { continue } pathUnderDirLookup[dir][path] = pkg return pkg } pathUnderDirLookup[dir][path] = nil return nil } for _, pkg := range ctx.Package { pkg.referenced = make(map[string]*Package, len(pkg.referenced)) } for _, pkg := range ctx.Package { for _, f := range pkg.Files { for _, imp := range f.Imports { if vpkg := findCanonicalUnderDir(pkg.Dir, imp); vpkg != nil { vpkg.referenced[pkg.Local] = pkg continue } if other, found := ctx.Package[imp]; found { other.referenced[pkg.Local] = pkg continue } } } } // Transfer all references from the child to the top parent. for _, pkg := range ctx.Package { if parentTrees := ctx.findPackageParentTree(pkg); len(parentTrees) > 0 { if parentPkg := ctx.Package[parentTrees[0]]; parentPkg != nil { for opath, opkg := range pkg.referenced { // Do not transfer internal references. if strings.HasPrefix(opkg.Path, parentPkg.Path+"/") { continue } parentPkg.referenced[opath] = opkg } pkg.referenced = make(map[string]*Package, 0) } } } }
go
func (ctx *Context) updatePackageReferences() { pathUnderDirLookup := make(map[string]map[string]*Package) findCanonicalUnderDir := func(dir, path string) *Package { if importMap, found := pathUnderDirLookup[dir]; found { if pkg, found2 := importMap[path]; found2 { return pkg } } else { pathUnderDirLookup[dir] = make(map[string]*Package) } for _, pkg := range ctx.Package { if !pkg.inVendor { continue } removeFromEnd := len(pkg.Path) + len(ctx.VendorDiscoverFolder) + 2 nextLen := len(pkg.Dir) - removeFromEnd if nextLen < 0 { continue } checkDir := pkg.Dir[:nextLen] if !pathos.FileHasPrefix(dir, checkDir) { continue } if pkg.Path != path { continue } pathUnderDirLookup[dir][path] = pkg return pkg } pathUnderDirLookup[dir][path] = nil return nil } for _, pkg := range ctx.Package { pkg.referenced = make(map[string]*Package, len(pkg.referenced)) } for _, pkg := range ctx.Package { for _, f := range pkg.Files { for _, imp := range f.Imports { if vpkg := findCanonicalUnderDir(pkg.Dir, imp); vpkg != nil { vpkg.referenced[pkg.Local] = pkg continue } if other, found := ctx.Package[imp]; found { other.referenced[pkg.Local] = pkg continue } } } } // Transfer all references from the child to the top parent. for _, pkg := range ctx.Package { if parentTrees := ctx.findPackageParentTree(pkg); len(parentTrees) > 0 { if parentPkg := ctx.Package[parentTrees[0]]; parentPkg != nil { for opath, opkg := range pkg.referenced { // Do not transfer internal references. if strings.HasPrefix(opkg.Path, parentPkg.Path+"/") { continue } parentPkg.referenced[opath] = opkg } pkg.referenced = make(map[string]*Package, 0) } } } }
[ "func", "(", "ctx", "*", "Context", ")", "updatePackageReferences", "(", ")", "{", "pathUnderDirLookup", ":=", "make", "(", "map", "[", "string", "]", "map", "[", "string", "]", "*", "Package", ")", "\n", "findCanonicalUnderDir", ":=", "func", "(", "dir", ...
// updatePackageReferences populates the referenced field in each Package.
[ "updatePackageReferences", "populates", "the", "referenced", "field", "in", "each", "Package", "." ]
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/context.go#L370-L436
train
go-ini/ini
file.go
newFile
func newFile(dataSources []dataSource, opts LoadOptions) *File { if len(opts.KeyValueDelimiters) == 0 { opts.KeyValueDelimiters = "=:" } return &File{ BlockMode: true, dataSources: dataSources, sections: make(map[string]*Section), sectionList: make([]string, 0, 10), options: opts, } }
go
func newFile(dataSources []dataSource, opts LoadOptions) *File { if len(opts.KeyValueDelimiters) == 0 { opts.KeyValueDelimiters = "=:" } return &File{ BlockMode: true, dataSources: dataSources, sections: make(map[string]*Section), sectionList: make([]string, 0, 10), options: opts, } }
[ "func", "newFile", "(", "dataSources", "[", "]", "dataSource", ",", "opts", "LoadOptions", ")", "*", "File", "{", "if", "len", "(", "opts", ".", "KeyValueDelimiters", ")", "==", "0", "{", "opts", ".", "KeyValueDelimiters", "=", "\"", "\"", "\n", "}", "...
// newFile initializes File object with given data sources.
[ "newFile", "initializes", "File", "object", "with", "given", "data", "sources", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L47-L58
train
go-ini/ini
file.go
NewRawSection
func (f *File) NewRawSection(name, body string) (*Section, error) { section, err := f.NewSection(name) if err != nil { return nil, err } section.isRawSection = true section.rawBody = body return section, nil }
go
func (f *File) NewRawSection(name, body string) (*Section, error) { section, err := f.NewSection(name) if err != nil { return nil, err } section.isRawSection = true section.rawBody = body return section, nil }
[ "func", "(", "f", "*", "File", ")", "NewRawSection", "(", "name", ",", "body", "string", ")", "(", "*", "Section", ",", "error", ")", "{", "section", ",", "err", ":=", "f", ".", "NewSection", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{",...
// NewRawSection creates a new section with an unparseable body.
[ "NewRawSection", "creates", "a", "new", "section", "with", "an", "unparseable", "body", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L90-L99
train
go-ini/ini
file.go
NewSections
func (f *File) NewSections(names ...string) (err error) { for _, name := range names { if _, err = f.NewSection(name); err != nil { return err } } return nil }
go
func (f *File) NewSections(names ...string) (err error) { for _, name := range names { if _, err = f.NewSection(name); err != nil { return err } } return nil }
[ "func", "(", "f", "*", "File", ")", "NewSections", "(", "names", "...", "string", ")", "(", "err", "error", ")", "{", "for", "_", ",", "name", ":=", "range", "names", "{", "if", "_", ",", "err", "=", "f", ".", "NewSection", "(", "name", ")", ";...
// NewSections creates a list of sections.
[ "NewSections", "creates", "a", "list", "of", "sections", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L102-L109
train
go-ini/ini
file.go
GetSection
func (f *File) GetSection(name string) (*Section, error) { if len(name) == 0 { name = DefaultSection } if f.options.Insensitive { name = strings.ToLower(name) } if f.BlockMode { f.lock.RLock() defer f.lock.RUnlock() } sec := f.sections[name] if sec == nil { return nil, fmt.Errorf("section '%s' does not exist", name) } return sec, nil }
go
func (f *File) GetSection(name string) (*Section, error) { if len(name) == 0 { name = DefaultSection } if f.options.Insensitive { name = strings.ToLower(name) } if f.BlockMode { f.lock.RLock() defer f.lock.RUnlock() } sec := f.sections[name] if sec == nil { return nil, fmt.Errorf("section '%s' does not exist", name) } return sec, nil }
[ "func", "(", "f", "*", "File", ")", "GetSection", "(", "name", "string", ")", "(", "*", "Section", ",", "error", ")", "{", "if", "len", "(", "name", ")", "==", "0", "{", "name", "=", "DefaultSection", "\n", "}", "\n", "if", "f", ".", "options", ...
// GetSection returns section by given name.
[ "GetSection", "returns", "section", "by", "given", "name", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L112-L130
train
go-ini/ini
file.go
Section
func (f *File) Section(name string) *Section { sec, err := f.GetSection(name) if err != nil { // Note: It's OK here because the only possible error is empty section name, // but if it's empty, this piece of code won't be executed. sec, _ = f.NewSection(name) return sec } return sec }
go
func (f *File) Section(name string) *Section { sec, err := f.GetSection(name) if err != nil { // Note: It's OK here because the only possible error is empty section name, // but if it's empty, this piece of code won't be executed. sec, _ = f.NewSection(name) return sec } return sec }
[ "func", "(", "f", "*", "File", ")", "Section", "(", "name", "string", ")", "*", "Section", "{", "sec", ",", "err", ":=", "f", ".", "GetSection", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "// Note: It's OK here because the only possible error i...
// Section assumes named section exists and returns a zero-value when not.
[ "Section", "assumes", "named", "section", "exists", "and", "returns", "a", "zero", "-", "value", "when", "not", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L133-L142
train
go-ini/ini
file.go
Sections
func (f *File) Sections() []*Section { if f.BlockMode { f.lock.RLock() defer f.lock.RUnlock() } sections := make([]*Section, len(f.sectionList)) for i, name := range f.sectionList { sections[i] = f.sections[name] } return sections }
go
func (f *File) Sections() []*Section { if f.BlockMode { f.lock.RLock() defer f.lock.RUnlock() } sections := make([]*Section, len(f.sectionList)) for i, name := range f.sectionList { sections[i] = f.sections[name] } return sections }
[ "func", "(", "f", "*", "File", ")", "Sections", "(", ")", "[", "]", "*", "Section", "{", "if", "f", ".", "BlockMode", "{", "f", ".", "lock", ".", "RLock", "(", ")", "\n", "defer", "f", ".", "lock", ".", "RUnlock", "(", ")", "\n", "}", "\n\n",...
// Sections returns a list of Section stored in the current instance.
[ "Sections", "returns", "a", "list", "of", "Section", "stored", "in", "the", "current", "instance", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L145-L156
train
go-ini/ini
file.go
ChildSections
func (f *File) ChildSections(name string) []*Section { return f.Section(name).ChildSections() }
go
func (f *File) ChildSections(name string) []*Section { return f.Section(name).ChildSections() }
[ "func", "(", "f", "*", "File", ")", "ChildSections", "(", "name", "string", ")", "[", "]", "*", "Section", "{", "return", "f", ".", "Section", "(", "name", ")", ".", "ChildSections", "(", ")", "\n", "}" ]
// ChildSections returns a list of child sections of given section name.
[ "ChildSections", "returns", "a", "list", "of", "child", "sections", "of", "given", "section", "name", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L159-L161
train
go-ini/ini
file.go
SectionStrings
func (f *File) SectionStrings() []string { list := make([]string, len(f.sectionList)) copy(list, f.sectionList) return list }
go
func (f *File) SectionStrings() []string { list := make([]string, len(f.sectionList)) copy(list, f.sectionList) return list }
[ "func", "(", "f", "*", "File", ")", "SectionStrings", "(", ")", "[", "]", "string", "{", "list", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "f", ".", "sectionList", ")", ")", "\n", "copy", "(", "list", ",", "f", ".", "sectionList", ...
// SectionStrings returns list of section names.
[ "SectionStrings", "returns", "list", "of", "section", "names", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L164-L168
train
go-ini/ini
file.go
DeleteSection
func (f *File) DeleteSection(name string) { if f.BlockMode { f.lock.Lock() defer f.lock.Unlock() } if len(name) == 0 { name = DefaultSection } for i, s := range f.sectionList { if s == name { f.sectionList = append(f.sectionList[:i], f.sectionList[i+1:]...) delete(f.sections, name) return } } }
go
func (f *File) DeleteSection(name string) { if f.BlockMode { f.lock.Lock() defer f.lock.Unlock() } if len(name) == 0 { name = DefaultSection } for i, s := range f.sectionList { if s == name { f.sectionList = append(f.sectionList[:i], f.sectionList[i+1:]...) delete(f.sections, name) return } } }
[ "func", "(", "f", "*", "File", ")", "DeleteSection", "(", "name", "string", ")", "{", "if", "f", ".", "BlockMode", "{", "f", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "lock", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "if", ...
// DeleteSection deletes a section.
[ "DeleteSection", "deletes", "a", "section", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L171-L188
train
go-ini/ini
file.go
Reload
func (f *File) Reload() (err error) { for _, s := range f.dataSources { if err = f.reload(s); err != nil { // In loose mode, we create an empty default section for nonexistent files. if os.IsNotExist(err) && f.options.Loose { f.parse(bytes.NewBuffer(nil)) continue } return err } } return nil }
go
func (f *File) Reload() (err error) { for _, s := range f.dataSources { if err = f.reload(s); err != nil { // In loose mode, we create an empty default section for nonexistent files. if os.IsNotExist(err) && f.options.Loose { f.parse(bytes.NewBuffer(nil)) continue } return err } } return nil }
[ "func", "(", "f", "*", "File", ")", "Reload", "(", ")", "(", "err", "error", ")", "{", "for", "_", ",", "s", ":=", "range", "f", ".", "dataSources", "{", "if", "err", "=", "f", ".", "reload", "(", "s", ")", ";", "err", "!=", "nil", "{", "//...
// Reload reloads and parses all data sources.
[ "Reload", "reloads", "and", "parses", "all", "data", "sources", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L201-L213
train
go-ini/ini
file.go
Append
func (f *File) Append(source interface{}, others ...interface{}) error { ds, err := parseDataSource(source) if err != nil { return err } f.dataSources = append(f.dataSources, ds) for _, s := range others { ds, err = parseDataSource(s) if err != nil { return err } f.dataSources = append(f.dataSources, ds) } return f.Reload() }
go
func (f *File) Append(source interface{}, others ...interface{}) error { ds, err := parseDataSource(source) if err != nil { return err } f.dataSources = append(f.dataSources, ds) for _, s := range others { ds, err = parseDataSource(s) if err != nil { return err } f.dataSources = append(f.dataSources, ds) } return f.Reload() }
[ "func", "(", "f", "*", "File", ")", "Append", "(", "source", "interface", "{", "}", ",", "others", "...", "interface", "{", "}", ")", "error", "{", "ds", ",", "err", ":=", "parseDataSource", "(", "source", ")", "\n", "if", "err", "!=", "nil", "{", ...
// Append appends one or more data sources and reloads automatically.
[ "Append", "appends", "one", "or", "more", "data", "sources", "and", "reloads", "automatically", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L216-L230
train
go-ini/ini
file.go
WriteToIndent
func (f *File) WriteToIndent(w io.Writer, indent string) (int64, error) { buf, err := f.writeToBuffer(indent) if err != nil { return 0, err } return buf.WriteTo(w) }
go
func (f *File) WriteToIndent(w io.Writer, indent string) (int64, error) { buf, err := f.writeToBuffer(indent) if err != nil { return 0, err } return buf.WriteTo(w) }
[ "func", "(", "f", "*", "File", ")", "WriteToIndent", "(", "w", "io", ".", "Writer", ",", "indent", "string", ")", "(", "int64", ",", "error", ")", "{", "buf", ",", "err", ":=", "f", ".", "writeToBuffer", "(", "indent", ")", "\n", "if", "err", "!=...
// WriteToIndent writes content into io.Writer with given indention. // If PrettyFormat has been set to be true, // it will align "=" sign with spaces under each section.
[ "WriteToIndent", "writes", "content", "into", "io", ".", "Writer", "with", "given", "indention", ".", "If", "PrettyFormat", "has", "been", "set", "to", "be", "true", "it", "will", "align", "=", "sign", "with", "spaces", "under", "each", "section", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L390-L396
train
go-ini/ini
file.go
WriteTo
func (f *File) WriteTo(w io.Writer) (int64, error) { return f.WriteToIndent(w, "") }
go
func (f *File) WriteTo(w io.Writer) (int64, error) { return f.WriteToIndent(w, "") }
[ "func", "(", "f", "*", "File", ")", "WriteTo", "(", "w", "io", ".", "Writer", ")", "(", "int64", ",", "error", ")", "{", "return", "f", ".", "WriteToIndent", "(", "w", ",", "\"", "\"", ")", "\n", "}" ]
// WriteTo writes file content into io.Writer.
[ "WriteTo", "writes", "file", "content", "into", "io", ".", "Writer", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L399-L401
train
go-ini/ini
file.go
SaveToIndent
func (f *File) SaveToIndent(filename, indent string) error { // Note: Because we are truncating with os.Create, // so it's safer to save to a temporary file location and rename afte done. buf, err := f.writeToBuffer(indent) if err != nil { return err } return ioutil.WriteFile(filename, buf.Bytes(), 0666) }
go
func (f *File) SaveToIndent(filename, indent string) error { // Note: Because we are truncating with os.Create, // so it's safer to save to a temporary file location and rename afte done. buf, err := f.writeToBuffer(indent) if err != nil { return err } return ioutil.WriteFile(filename, buf.Bytes(), 0666) }
[ "func", "(", "f", "*", "File", ")", "SaveToIndent", "(", "filename", ",", "indent", "string", ")", "error", "{", "// Note: Because we are truncating with os.Create,", "// \tso it's safer to save to a temporary file location and rename afte done.", "buf", ",", "err", ":=", "...
// SaveToIndent writes content to file system with given value indention.
[ "SaveToIndent", "writes", "content", "to", "file", "system", "with", "given", "value", "indention", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L404-L413
train
go-ini/ini
ini.go
LooseLoad
func LooseLoad(source interface{}, others ...interface{}) (*File, error) { return LoadSources(LoadOptions{Loose: true}, source, others...) }
go
func LooseLoad(source interface{}, others ...interface{}) (*File, error) { return LoadSources(LoadOptions{Loose: true}, source, others...) }
[ "func", "LooseLoad", "(", "source", "interface", "{", "}", ",", "others", "...", "interface", "{", "}", ")", "(", "*", "File", ",", "error", ")", "{", "return", "LoadSources", "(", "LoadOptions", "{", "Loose", ":", "true", "}", ",", "source", ",", "o...
// LooseLoad has exactly same functionality as Load function // except it ignores nonexistent files instead of returning error.
[ "LooseLoad", "has", "exactly", "same", "functionality", "as", "Load", "function", "except", "it", "ignores", "nonexistent", "files", "instead", "of", "returning", "error", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/ini.go#L209-L211
train
go-ini/ini
ini.go
InsensitiveLoad
func InsensitiveLoad(source interface{}, others ...interface{}) (*File, error) { return LoadSources(LoadOptions{Insensitive: true}, source, others...) }
go
func InsensitiveLoad(source interface{}, others ...interface{}) (*File, error) { return LoadSources(LoadOptions{Insensitive: true}, source, others...) }
[ "func", "InsensitiveLoad", "(", "source", "interface", "{", "}", ",", "others", "...", "interface", "{", "}", ")", "(", "*", "File", ",", "error", ")", "{", "return", "LoadSources", "(", "LoadOptions", "{", "Insensitive", ":", "true", "}", ",", "source",...
// InsensitiveLoad has exactly same functionality as Load function // except it forces all section and key names to be lowercased.
[ "InsensitiveLoad", "has", "exactly", "same", "functionality", "as", "Load", "function", "except", "it", "forces", "all", "section", "and", "key", "names", "to", "be", "lowercased", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/ini.go#L215-L217
train
go-ini/ini
ini.go
ShadowLoad
func ShadowLoad(source interface{}, others ...interface{}) (*File, error) { return LoadSources(LoadOptions{AllowShadows: true}, source, others...) }
go
func ShadowLoad(source interface{}, others ...interface{}) (*File, error) { return LoadSources(LoadOptions{AllowShadows: true}, source, others...) }
[ "func", "ShadowLoad", "(", "source", "interface", "{", "}", ",", "others", "...", "interface", "{", "}", ")", "(", "*", "File", ",", "error", ")", "{", "return", "LoadSources", "(", "LoadOptions", "{", "AllowShadows", ":", "true", "}", ",", "source", "...
// ShadowLoad has exactly same functionality as Load function // except it allows have shadow keys.
[ "ShadowLoad", "has", "exactly", "same", "functionality", "as", "Load", "function", "except", "it", "allows", "have", "shadow", "keys", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/ini.go#L221-L223
train
go-ini/ini
key.go
newKey
func newKey(s *Section, name, val string) *Key { return &Key{ s: s, name: name, value: val, } }
go
func newKey(s *Section, name, val string) *Key { return &Key{ s: s, name: name, value: val, } }
[ "func", "newKey", "(", "s", "*", "Section", ",", "name", ",", "val", "string", ")", "*", "Key", "{", "return", "&", "Key", "{", "s", ":", "s", ",", "name", ":", "name", ",", "value", ":", "val", ",", "}", "\n", "}" ]
// newKey simply return a key object with given values.
[ "newKey", "simply", "return", "a", "key", "object", "with", "given", "values", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L42-L48
train
go-ini/ini
key.go
AddShadow
func (k *Key) AddShadow(val string) error { if !k.s.f.options.AllowShadows { return errors.New("shadow key is not allowed") } return k.addShadow(val) }
go
func (k *Key) AddShadow(val string) error { if !k.s.f.options.AllowShadows { return errors.New("shadow key is not allowed") } return k.addShadow(val) }
[ "func", "(", "k", "*", "Key", ")", "AddShadow", "(", "val", "string", ")", "error", "{", "if", "!", "k", ".", "s", ".", "f", ".", "options", ".", "AllowShadows", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "retur...
// AddShadow adds a new shadow key to itself.
[ "AddShadow", "adds", "a", "new", "shadow", "key", "to", "itself", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L64-L69
train
go-ini/ini
key.go
AddNestedValue
func (k *Key) AddNestedValue(val string) error { if !k.s.f.options.AllowNestedValues { return errors.New("nested value is not allowed") } return k.addNestedValue(val) }
go
func (k *Key) AddNestedValue(val string) error { if !k.s.f.options.AllowNestedValues { return errors.New("nested value is not allowed") } return k.addNestedValue(val) }
[ "func", "(", "k", "*", "Key", ")", "AddNestedValue", "(", "val", "string", ")", "error", "{", "if", "!", "k", ".", "s", ".", "f", ".", "options", ".", "AllowNestedValues", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n"...
// AddNestedValue adds a nested value to the key.
[ "AddNestedValue", "adds", "a", "nested", "value", "to", "the", "key", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L81-L86
train
go-ini/ini
key.go
ValueWithShadows
func (k *Key) ValueWithShadows() []string { if len(k.shadows) == 0 { return []string{k.value} } vals := make([]string, len(k.shadows)+1) vals[0] = k.value for i := range k.shadows { vals[i+1] = k.shadows[i].value } return vals }
go
func (k *Key) ValueWithShadows() []string { if len(k.shadows) == 0 { return []string{k.value} } vals := make([]string, len(k.shadows)+1) vals[0] = k.value for i := range k.shadows { vals[i+1] = k.shadows[i].value } return vals }
[ "func", "(", "k", "*", "Key", ")", "ValueWithShadows", "(", ")", "[", "]", "string", "{", "if", "len", "(", "k", ".", "shadows", ")", "==", "0", "{", "return", "[", "]", "string", "{", "k", ".", "value", "}", "\n", "}", "\n", "vals", ":=", "m...
// ValueWithShadows returns raw values of key and its shadows if any.
[ "ValueWithShadows", "returns", "raw", "values", "of", "key", "and", "its", "shadows", "if", "any", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L102-L112
train
go-ini/ini
key.go
transformValue
func (k *Key) transformValue(val string) string { if k.s.f.ValueMapper != nil { val = k.s.f.ValueMapper(val) } // Fail-fast if no indicate char found for recursive value if !strings.Contains(val, "%") { return val } for i := 0; i < depthValues; i++ { vr := varPattern.FindString(val) if len(vr) == 0 { break } // Take off leading '%(' and trailing ')s'. noption := vr[2 : len(vr)-2] // Search in the same section. nk, err := k.s.GetKey(noption) if err != nil || k == nk { // Search again in default section. nk, _ = k.s.f.Section("").GetKey(noption) } // Substitute by new value and take off leading '%(' and trailing ')s'. val = strings.Replace(val, vr, nk.value, -1) } return val }
go
func (k *Key) transformValue(val string) string { if k.s.f.ValueMapper != nil { val = k.s.f.ValueMapper(val) } // Fail-fast if no indicate char found for recursive value if !strings.Contains(val, "%") { return val } for i := 0; i < depthValues; i++ { vr := varPattern.FindString(val) if len(vr) == 0 { break } // Take off leading '%(' and trailing ')s'. noption := vr[2 : len(vr)-2] // Search in the same section. nk, err := k.s.GetKey(noption) if err != nil || k == nk { // Search again in default section. nk, _ = k.s.f.Section("").GetKey(noption) } // Substitute by new value and take off leading '%(' and trailing ')s'. val = strings.Replace(val, vr, nk.value, -1) } return val }
[ "func", "(", "k", "*", "Key", ")", "transformValue", "(", "val", "string", ")", "string", "{", "if", "k", ".", "s", ".", "f", ".", "ValueMapper", "!=", "nil", "{", "val", "=", "k", ".", "s", ".", "f", ".", "ValueMapper", "(", "val", ")", "\n", ...
// transformValue takes a raw value and transforms to its final string.
[ "transformValue", "takes", "a", "raw", "value", "and", "transforms", "to", "its", "final", "string", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L121-L150
train
go-ini/ini
key.go
Validate
func (k *Key) Validate(fn func(string) string) string { return fn(k.String()) }
go
func (k *Key) Validate(fn func(string) string) string { return fn(k.String()) }
[ "func", "(", "k", "*", "Key", ")", "Validate", "(", "fn", "func", "(", "string", ")", "string", ")", "string", "{", "return", "fn", "(", "k", ".", "String", "(", ")", ")", "\n", "}" ]
// Validate accepts a validate function which can // return modifed result as key value.
[ "Validate", "accepts", "a", "validate", "function", "which", "can", "return", "modifed", "result", "as", "key", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L159-L161
train
go-ini/ini
key.go
parseBool
func parseBool(str string) (value bool, err error) { switch str { case "1", "t", "T", "true", "TRUE", "True", "YES", "yes", "Yes", "y", "ON", "on", "On": return true, nil case "0", "f", "F", "false", "FALSE", "False", "NO", "no", "No", "n", "OFF", "off", "Off": return false, nil } return false, fmt.Errorf("parsing \"%s\": invalid syntax", str) }
go
func parseBool(str string) (value bool, err error) { switch str { case "1", "t", "T", "true", "TRUE", "True", "YES", "yes", "Yes", "y", "ON", "on", "On": return true, nil case "0", "f", "F", "false", "FALSE", "False", "NO", "no", "No", "n", "OFF", "off", "Off": return false, nil } return false, fmt.Errorf("parsing \"%s\": invalid syntax", str) }
[ "func", "parseBool", "(", "str", "string", ")", "(", "value", "bool", ",", "err", "error", ")", "{", "switch", "str", "{", "case", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"...
// parseBool returns the boolean value represented by the string. // // It accepts 1, t, T, TRUE, true, True, YES, yes, Yes, y, ON, on, On, // 0, f, F, FALSE, false, False, NO, no, No, n, OFF, off, Off. // Any other value returns an error.
[ "parseBool", "returns", "the", "boolean", "value", "represented", "by", "the", "string", ".", "It", "accepts", "1", "t", "T", "TRUE", "true", "True", "YES", "yes", "Yes", "y", "ON", "on", "On", "0", "f", "F", "FALSE", "false", "False", "NO", "no", "N...
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L168-L176
train
go-ini/ini
key.go
Uint
func (k *Key) Uint() (uint, error) { u, e := strconv.ParseUint(k.String(), 0, 64) return uint(u), e }
go
func (k *Key) Uint() (uint, error) { u, e := strconv.ParseUint(k.String(), 0, 64) return uint(u), e }
[ "func", "(", "k", "*", "Key", ")", "Uint", "(", ")", "(", "uint", ",", "error", ")", "{", "u", ",", "e", ":=", "strconv", ".", "ParseUint", "(", "k", ".", "String", "(", ")", ",", "0", ",", "64", ")", "\n", "return", "uint", "(", "u", ")", ...
// Uint returns uint type valued.
[ "Uint", "returns", "uint", "type", "valued", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L200-L203
train
go-ini/ini
key.go
Duration
func (k *Key) Duration() (time.Duration, error) { return time.ParseDuration(k.String()) }
go
func (k *Key) Duration() (time.Duration, error) { return time.ParseDuration(k.String()) }
[ "func", "(", "k", "*", "Key", ")", "Duration", "(", ")", "(", "time", ".", "Duration", ",", "error", ")", "{", "return", "time", ".", "ParseDuration", "(", "k", ".", "String", "(", ")", ")", "\n", "}" ]
// Duration returns time.Duration type value.
[ "Duration", "returns", "time", ".", "Duration", "type", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L211-L213
train
go-ini/ini
key.go
TimeFormat
func (k *Key) TimeFormat(format string) (time.Time, error) { return time.Parse(format, k.String()) }
go
func (k *Key) TimeFormat(format string) (time.Time, error) { return time.Parse(format, k.String()) }
[ "func", "(", "k", "*", "Key", ")", "TimeFormat", "(", "format", "string", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "time", ".", "Parse", "(", "format", ",", "k", ".", "String", "(", ")", ")", "\n", "}" ]
// TimeFormat parses with given format and returns time.Time type value.
[ "TimeFormat", "parses", "with", "given", "format", "and", "returns", "time", ".", "Time", "type", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L216-L218
train
go-ini/ini
key.go
Time
func (k *Key) Time() (time.Time, error) { return k.TimeFormat(time.RFC3339) }
go
func (k *Key) Time() (time.Time, error) { return k.TimeFormat(time.RFC3339) }
[ "func", "(", "k", "*", "Key", ")", "Time", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "k", ".", "TimeFormat", "(", "time", ".", "RFC3339", ")", "\n", "}" ]
// Time parses with RFC3339 format and returns time.Time type value.
[ "Time", "parses", "with", "RFC3339", "format", "and", "returns", "time", ".", "Time", "type", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L221-L223
train
go-ini/ini
key.go
MustString
func (k *Key) MustString(defaultVal string) string { val := k.String() if len(val) == 0 { k.value = defaultVal return defaultVal } return val }
go
func (k *Key) MustString(defaultVal string) string { val := k.String() if len(val) == 0 { k.value = defaultVal return defaultVal } return val }
[ "func", "(", "k", "*", "Key", ")", "MustString", "(", "defaultVal", "string", ")", "string", "{", "val", ":=", "k", ".", "String", "(", ")", "\n", "if", "len", "(", "val", ")", "==", "0", "{", "k", ".", "value", "=", "defaultVal", "\n", "return",...
// MustString returns default value if key value is empty.
[ "MustString", "returns", "default", "value", "if", "key", "value", "is", "empty", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L226-L233
train
go-ini/ini
key.go
MustUint
func (k *Key) MustUint(defaultVal ...uint) uint { val, err := k.Uint() if len(defaultVal) > 0 && err != nil { k.value = strconv.FormatUint(uint64(defaultVal[0]), 10) return defaultVal[0] } return val }
go
func (k *Key) MustUint(defaultVal ...uint) uint { val, err := k.Uint() if len(defaultVal) > 0 && err != nil { k.value = strconv.FormatUint(uint64(defaultVal[0]), 10) return defaultVal[0] } return val }
[ "func", "(", "k", "*", "Key", ")", "MustUint", "(", "defaultVal", "...", "uint", ")", "uint", "{", "val", ",", "err", ":=", "k", ".", "Uint", "(", ")", "\n", "if", "len", "(", "defaultVal", ")", ">", "0", "&&", "err", "!=", "nil", "{", "k", "...
// MustUint always returns value without error, // it returns 0 if error occurs.
[ "MustUint", "always", "returns", "value", "without", "error", "it", "returns", "0", "if", "error", "occurs", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L281-L288
train
go-ini/ini
key.go
MustUint64
func (k *Key) MustUint64(defaultVal ...uint64) uint64 { val, err := k.Uint64() if len(defaultVal) > 0 && err != nil { k.value = strconv.FormatUint(defaultVal[0], 10) return defaultVal[0] } return val }
go
func (k *Key) MustUint64(defaultVal ...uint64) uint64 { val, err := k.Uint64() if len(defaultVal) > 0 && err != nil { k.value = strconv.FormatUint(defaultVal[0], 10) return defaultVal[0] } return val }
[ "func", "(", "k", "*", "Key", ")", "MustUint64", "(", "defaultVal", "...", "uint64", ")", "uint64", "{", "val", ",", "err", ":=", "k", ".", "Uint64", "(", ")", "\n", "if", "len", "(", "defaultVal", ")", ">", "0", "&&", "err", "!=", "nil", "{", ...
// MustUint64 always returns value without error, // it returns 0 if error occurs.
[ "MustUint64", "always", "returns", "value", "without", "error", "it", "returns", "0", "if", "error", "occurs", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L292-L299
train
go-ini/ini
key.go
MustDuration
func (k *Key) MustDuration(defaultVal ...time.Duration) time.Duration { val, err := k.Duration() if len(defaultVal) > 0 && err != nil { k.value = defaultVal[0].String() return defaultVal[0] } return val }
go
func (k *Key) MustDuration(defaultVal ...time.Duration) time.Duration { val, err := k.Duration() if len(defaultVal) > 0 && err != nil { k.value = defaultVal[0].String() return defaultVal[0] } return val }
[ "func", "(", "k", "*", "Key", ")", "MustDuration", "(", "defaultVal", "...", "time", ".", "Duration", ")", "time", ".", "Duration", "{", "val", ",", "err", ":=", "k", ".", "Duration", "(", ")", "\n", "if", "len", "(", "defaultVal", ")", ">", "0", ...
// MustDuration always returns value without error, // it returns zero value if error occurs.
[ "MustDuration", "always", "returns", "value", "without", "error", "it", "returns", "zero", "value", "if", "error", "occurs", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L303-L310
train
go-ini/ini
key.go
MustTimeFormat
func (k *Key) MustTimeFormat(format string, defaultVal ...time.Time) time.Time { val, err := k.TimeFormat(format) if len(defaultVal) > 0 && err != nil { k.value = defaultVal[0].Format(format) return defaultVal[0] } return val }
go
func (k *Key) MustTimeFormat(format string, defaultVal ...time.Time) time.Time { val, err := k.TimeFormat(format) if len(defaultVal) > 0 && err != nil { k.value = defaultVal[0].Format(format) return defaultVal[0] } return val }
[ "func", "(", "k", "*", "Key", ")", "MustTimeFormat", "(", "format", "string", ",", "defaultVal", "...", "time", ".", "Time", ")", "time", ".", "Time", "{", "val", ",", "err", ":=", "k", ".", "TimeFormat", "(", "format", ")", "\n", "if", "len", "(",...
// MustTimeFormat always parses with given format and returns value without error, // it returns zero value if error occurs.
[ "MustTimeFormat", "always", "parses", "with", "given", "format", "and", "returns", "value", "without", "error", "it", "returns", "zero", "value", "if", "error", "occurs", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L314-L321
train
go-ini/ini
key.go
MustTime
func (k *Key) MustTime(defaultVal ...time.Time) time.Time { return k.MustTimeFormat(time.RFC3339, defaultVal...) }
go
func (k *Key) MustTime(defaultVal ...time.Time) time.Time { return k.MustTimeFormat(time.RFC3339, defaultVal...) }
[ "func", "(", "k", "*", "Key", ")", "MustTime", "(", "defaultVal", "...", "time", ".", "Time", ")", "time", ".", "Time", "{", "return", "k", ".", "MustTimeFormat", "(", "time", ".", "RFC3339", ",", "defaultVal", "...", ")", "\n", "}" ]
// MustTime always parses with RFC3339 format and returns value without error, // it returns zero value if error occurs.
[ "MustTime", "always", "parses", "with", "RFC3339", "format", "and", "returns", "value", "without", "error", "it", "returns", "zero", "value", "if", "error", "occurs", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L325-L327
train
go-ini/ini
key.go
In
func (k *Key) In(defaultVal string, candidates []string) string { val := k.String() for _, cand := range candidates { if val == cand { return val } } return defaultVal }
go
func (k *Key) In(defaultVal string, candidates []string) string { val := k.String() for _, cand := range candidates { if val == cand { return val } } return defaultVal }
[ "func", "(", "k", "*", "Key", ")", "In", "(", "defaultVal", "string", ",", "candidates", "[", "]", "string", ")", "string", "{", "val", ":=", "k", ".", "String", "(", ")", "\n", "for", "_", ",", "cand", ":=", "range", "candidates", "{", "if", "va...
// In always returns value without error, // it returns default value if error occurs or doesn't fit into candidates.
[ "In", "always", "returns", "value", "without", "error", "it", "returns", "default", "value", "if", "error", "occurs", "or", "doesn", "t", "fit", "into", "candidates", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L331-L339
train
go-ini/ini
key.go
InFloat64
func (k *Key) InFloat64(defaultVal float64, candidates []float64) float64 { val := k.MustFloat64() for _, cand := range candidates { if val == cand { return val } } return defaultVal }
go
func (k *Key) InFloat64(defaultVal float64, candidates []float64) float64 { val := k.MustFloat64() for _, cand := range candidates { if val == cand { return val } } return defaultVal }
[ "func", "(", "k", "*", "Key", ")", "InFloat64", "(", "defaultVal", "float64", ",", "candidates", "[", "]", "float64", ")", "float64", "{", "val", ":=", "k", ".", "MustFloat64", "(", ")", "\n", "for", "_", ",", "cand", ":=", "range", "candidates", "{"...
// InFloat64 always returns value without error, // it returns default value if error occurs or doesn't fit into candidates.
[ "InFloat64", "always", "returns", "value", "without", "error", "it", "returns", "default", "value", "if", "error", "occurs", "or", "doesn", "t", "fit", "into", "candidates", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L343-L351
train
go-ini/ini
key.go
InInt
func (k *Key) InInt(defaultVal int, candidates []int) int { val := k.MustInt() for _, cand := range candidates { if val == cand { return val } } return defaultVal }
go
func (k *Key) InInt(defaultVal int, candidates []int) int { val := k.MustInt() for _, cand := range candidates { if val == cand { return val } } return defaultVal }
[ "func", "(", "k", "*", "Key", ")", "InInt", "(", "defaultVal", "int", ",", "candidates", "[", "]", "int", ")", "int", "{", "val", ":=", "k", ".", "MustInt", "(", ")", "\n", "for", "_", ",", "cand", ":=", "range", "candidates", "{", "if", "val", ...
// InInt always returns value without error, // it returns default value if error occurs or doesn't fit into candidates.
[ "InInt", "always", "returns", "value", "without", "error", "it", "returns", "default", "value", "if", "error", "occurs", "or", "doesn", "t", "fit", "into", "candidates", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L355-L363
train
go-ini/ini
key.go
InInt64
func (k *Key) InInt64(defaultVal int64, candidates []int64) int64 { val := k.MustInt64() for _, cand := range candidates { if val == cand { return val } } return defaultVal }
go
func (k *Key) InInt64(defaultVal int64, candidates []int64) int64 { val := k.MustInt64() for _, cand := range candidates { if val == cand { return val } } return defaultVal }
[ "func", "(", "k", "*", "Key", ")", "InInt64", "(", "defaultVal", "int64", ",", "candidates", "[", "]", "int64", ")", "int64", "{", "val", ":=", "k", ".", "MustInt64", "(", ")", "\n", "for", "_", ",", "cand", ":=", "range", "candidates", "{", "if", ...
// InInt64 always returns value without error, // it returns default value if error occurs or doesn't fit into candidates.
[ "InInt64", "always", "returns", "value", "without", "error", "it", "returns", "default", "value", "if", "error", "occurs", "or", "doesn", "t", "fit", "into", "candidates", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L367-L375
train
go-ini/ini
key.go
InUint
func (k *Key) InUint(defaultVal uint, candidates []uint) uint { val := k.MustUint() for _, cand := range candidates { if val == cand { return val } } return defaultVal }
go
func (k *Key) InUint(defaultVal uint, candidates []uint) uint { val := k.MustUint() for _, cand := range candidates { if val == cand { return val } } return defaultVal }
[ "func", "(", "k", "*", "Key", ")", "InUint", "(", "defaultVal", "uint", ",", "candidates", "[", "]", "uint", ")", "uint", "{", "val", ":=", "k", ".", "MustUint", "(", ")", "\n", "for", "_", ",", "cand", ":=", "range", "candidates", "{", "if", "va...
// InUint always returns value without error, // it returns default value if error occurs or doesn't fit into candidates.
[ "InUint", "always", "returns", "value", "without", "error", "it", "returns", "default", "value", "if", "error", "occurs", "or", "doesn", "t", "fit", "into", "candidates", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L379-L387
train
go-ini/ini
key.go
InUint64
func (k *Key) InUint64(defaultVal uint64, candidates []uint64) uint64 { val := k.MustUint64() for _, cand := range candidates { if val == cand { return val } } return defaultVal }
go
func (k *Key) InUint64(defaultVal uint64, candidates []uint64) uint64 { val := k.MustUint64() for _, cand := range candidates { if val == cand { return val } } return defaultVal }
[ "func", "(", "k", "*", "Key", ")", "InUint64", "(", "defaultVal", "uint64", ",", "candidates", "[", "]", "uint64", ")", "uint64", "{", "val", ":=", "k", ".", "MustUint64", "(", ")", "\n", "for", "_", ",", "cand", ":=", "range", "candidates", "{", "...
// InUint64 always returns value without error, // it returns default value if error occurs or doesn't fit into candidates.
[ "InUint64", "always", "returns", "value", "without", "error", "it", "returns", "default", "value", "if", "error", "occurs", "or", "doesn", "t", "fit", "into", "candidates", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L391-L399
train
go-ini/ini
key.go
InTimeFormat
func (k *Key) InTimeFormat(format string, defaultVal time.Time, candidates []time.Time) time.Time { val := k.MustTimeFormat(format) for _, cand := range candidates { if val == cand { return val } } return defaultVal }
go
func (k *Key) InTimeFormat(format string, defaultVal time.Time, candidates []time.Time) time.Time { val := k.MustTimeFormat(format) for _, cand := range candidates { if val == cand { return val } } return defaultVal }
[ "func", "(", "k", "*", "Key", ")", "InTimeFormat", "(", "format", "string", ",", "defaultVal", "time", ".", "Time", ",", "candidates", "[", "]", "time", ".", "Time", ")", "time", ".", "Time", "{", "val", ":=", "k", ".", "MustTimeFormat", "(", "format...
// InTimeFormat always parses with given format and returns value without error, // it returns default value if error occurs or doesn't fit into candidates.
[ "InTimeFormat", "always", "parses", "with", "given", "format", "and", "returns", "value", "without", "error", "it", "returns", "default", "value", "if", "error", "occurs", "or", "doesn", "t", "fit", "into", "candidates", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L403-L411
train
go-ini/ini
key.go
InTime
func (k *Key) InTime(defaultVal time.Time, candidates []time.Time) time.Time { return k.InTimeFormat(time.RFC3339, defaultVal, candidates) }
go
func (k *Key) InTime(defaultVal time.Time, candidates []time.Time) time.Time { return k.InTimeFormat(time.RFC3339, defaultVal, candidates) }
[ "func", "(", "k", "*", "Key", ")", "InTime", "(", "defaultVal", "time", ".", "Time", ",", "candidates", "[", "]", "time", ".", "Time", ")", "time", ".", "Time", "{", "return", "k", ".", "InTimeFormat", "(", "time", ".", "RFC3339", ",", "defaultVal", ...
// InTime always parses with RFC3339 format and returns value without error, // it returns default value if error occurs or doesn't fit into candidates.
[ "InTime", "always", "parses", "with", "RFC3339", "format", "and", "returns", "value", "without", "error", "it", "returns", "default", "value", "if", "error", "occurs", "or", "doesn", "t", "fit", "into", "candidates", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L415-L417
train
go-ini/ini
key.go
RangeFloat64
func (k *Key) RangeFloat64(defaultVal, min, max float64) float64 { val := k.MustFloat64() if val < min || val > max { return defaultVal } return val }
go
func (k *Key) RangeFloat64(defaultVal, min, max float64) float64 { val := k.MustFloat64() if val < min || val > max { return defaultVal } return val }
[ "func", "(", "k", "*", "Key", ")", "RangeFloat64", "(", "defaultVal", ",", "min", ",", "max", "float64", ")", "float64", "{", "val", ":=", "k", ".", "MustFloat64", "(", ")", "\n", "if", "val", "<", "min", "||", "val", ">", "max", "{", "return", "...
// RangeFloat64 checks if value is in given range inclusively, // and returns default value if it's not.
[ "RangeFloat64", "checks", "if", "value", "is", "in", "given", "range", "inclusively", "and", "returns", "default", "value", "if", "it", "s", "not", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L421-L427
train
go-ini/ini
key.go
RangeInt
func (k *Key) RangeInt(defaultVal, min, max int) int { val := k.MustInt() if val < min || val > max { return defaultVal } return val }
go
func (k *Key) RangeInt(defaultVal, min, max int) int { val := k.MustInt() if val < min || val > max { return defaultVal } return val }
[ "func", "(", "k", "*", "Key", ")", "RangeInt", "(", "defaultVal", ",", "min", ",", "max", "int", ")", "int", "{", "val", ":=", "k", ".", "MustInt", "(", ")", "\n", "if", "val", "<", "min", "||", "val", ">", "max", "{", "return", "defaultVal", "...
// RangeInt checks if value is in given range inclusively, // and returns default value if it's not.
[ "RangeInt", "checks", "if", "value", "is", "in", "given", "range", "inclusively", "and", "returns", "default", "value", "if", "it", "s", "not", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L431-L437
train
go-ini/ini
key.go
RangeInt64
func (k *Key) RangeInt64(defaultVal, min, max int64) int64 { val := k.MustInt64() if val < min || val > max { return defaultVal } return val }
go
func (k *Key) RangeInt64(defaultVal, min, max int64) int64 { val := k.MustInt64() if val < min || val > max { return defaultVal } return val }
[ "func", "(", "k", "*", "Key", ")", "RangeInt64", "(", "defaultVal", ",", "min", ",", "max", "int64", ")", "int64", "{", "val", ":=", "k", ".", "MustInt64", "(", ")", "\n", "if", "val", "<", "min", "||", "val", ">", "max", "{", "return", "defaultV...
// RangeInt64 checks if value is in given range inclusively, // and returns default value if it's not.
[ "RangeInt64", "checks", "if", "value", "is", "in", "given", "range", "inclusively", "and", "returns", "default", "value", "if", "it", "s", "not", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L441-L447
train
go-ini/ini
key.go
RangeTimeFormat
func (k *Key) RangeTimeFormat(format string, defaultVal, min, max time.Time) time.Time { val := k.MustTimeFormat(format) if val.Unix() < min.Unix() || val.Unix() > max.Unix() { return defaultVal } return val }
go
func (k *Key) RangeTimeFormat(format string, defaultVal, min, max time.Time) time.Time { val := k.MustTimeFormat(format) if val.Unix() < min.Unix() || val.Unix() > max.Unix() { return defaultVal } return val }
[ "func", "(", "k", "*", "Key", ")", "RangeTimeFormat", "(", "format", "string", ",", "defaultVal", ",", "min", ",", "max", "time", ".", "Time", ")", "time", ".", "Time", "{", "val", ":=", "k", ".", "MustTimeFormat", "(", "format", ")", "\n", "if", "...
// RangeTimeFormat checks if value with given format is in given range inclusively, // and returns default value if it's not.
[ "RangeTimeFormat", "checks", "if", "value", "with", "given", "format", "is", "in", "given", "range", "inclusively", "and", "returns", "default", "value", "if", "it", "s", "not", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L451-L457
train
go-ini/ini
key.go
RangeTime
func (k *Key) RangeTime(defaultVal, min, max time.Time) time.Time { return k.RangeTimeFormat(time.RFC3339, defaultVal, min, max) }
go
func (k *Key) RangeTime(defaultVal, min, max time.Time) time.Time { return k.RangeTimeFormat(time.RFC3339, defaultVal, min, max) }
[ "func", "(", "k", "*", "Key", ")", "RangeTime", "(", "defaultVal", ",", "min", ",", "max", "time", ".", "Time", ")", "time", ".", "Time", "{", "return", "k", ".", "RangeTimeFormat", "(", "time", ".", "RFC3339", ",", "defaultVal", ",", "min", ",", "...
// RangeTime checks if value with RFC3339 format is in given range inclusively, // and returns default value if it's not.
[ "RangeTime", "checks", "if", "value", "with", "RFC3339", "format", "is", "in", "given", "range", "inclusively", "and", "returns", "default", "value", "if", "it", "s", "not", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L461-L463
train
go-ini/ini
key.go
Strings
func (k *Key) Strings(delim string) []string { str := k.String() if len(str) == 0 { return []string{} } runes := []rune(str) vals := make([]string, 0, 2) var buf bytes.Buffer escape := false idx := 0 for { if escape { escape = false if runes[idx] != '\\' && !strings.HasPrefix(string(runes[idx:]), delim) { buf.WriteRune('\\') } buf.WriteRune(runes[idx]) } else { if runes[idx] == '\\' { escape = true } else if strings.HasPrefix(string(runes[idx:]), delim) { idx += len(delim) - 1 vals = append(vals, strings.TrimSpace(buf.String())) buf.Reset() } else { buf.WriteRune(runes[idx]) } } idx++ if idx == len(runes) { break } } if buf.Len() > 0 { vals = append(vals, strings.TrimSpace(buf.String())) } return vals }
go
func (k *Key) Strings(delim string) []string { str := k.String() if len(str) == 0 { return []string{} } runes := []rune(str) vals := make([]string, 0, 2) var buf bytes.Buffer escape := false idx := 0 for { if escape { escape = false if runes[idx] != '\\' && !strings.HasPrefix(string(runes[idx:]), delim) { buf.WriteRune('\\') } buf.WriteRune(runes[idx]) } else { if runes[idx] == '\\' { escape = true } else if strings.HasPrefix(string(runes[idx:]), delim) { idx += len(delim) - 1 vals = append(vals, strings.TrimSpace(buf.String())) buf.Reset() } else { buf.WriteRune(runes[idx]) } } idx++ if idx == len(runes) { break } } if buf.Len() > 0 { vals = append(vals, strings.TrimSpace(buf.String())) } return vals }
[ "func", "(", "k", "*", "Key", ")", "Strings", "(", "delim", "string", ")", "[", "]", "string", "{", "str", ":=", "k", ".", "String", "(", ")", "\n", "if", "len", "(", "str", ")", "==", "0", "{", "return", "[", "]", "string", "{", "}", "\n", ...
// Strings returns list of string divided by given delimiter.
[ "Strings", "returns", "list", "of", "string", "divided", "by", "given", "delimiter", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L466-L506
train