id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
146,600
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", ")", "\n", "startIn", "=", "filepath", ".", "Clean", "(", "filepath", ".", "Join", "(", "startIn", ",", "\"", "\"", ")", ")", "\n", "return", "licenseWalk", "(", "root", ",", "startIn", ",", "func", "(", "folder", ",", "name", "string", ")", "error", "{", "srcPath", ":=", "filepath", ".", "Join", "(", "folder", ",", "name", ")", "\n", "trimTo", ":=", "pathos", ".", "FileTrimPrefix", "(", "getLastVendorRoot", "(", "folder", ")", ",", "root", ")", "\n\n", "/*\n\t\t\tPath: \"golang.org/x/tools/go/vcs\"\n\t\t\tRoot: \"/tmp/govendor-cache280388238/1\"\n\t\t\tStartIn: \"/tmp/govendor-cache280388238/1/go/vcs\"\n\t\t\taddTo: \"golang.org/x/tools\"\n\t\t\t$PROJ/vendor + addTo + pathos.FileTrimPrefix(folder, root) + \"LICENSE\"\n\t\t*/", "destPath", ":=", "filepath", ".", "Join", "(", "vendorRoot", ",", "addTo", ",", "trimTo", ",", "name", ")", "\n\n", "// Only copy if file does not exist.", "_", ",", "err", ":=", "os", ".", "Stat", "(", "srcPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "srcPath", ")", "\n", "}", "\n", "destDir", ",", "_", ":=", "filepath", ".", "Split", "(", "destPath", ")", "\n", "if", "err", "=", "os", ".", "MkdirAll", "(", "destDir", ",", "0777", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "destDir", ")", "\n", "}", "\n", "return", "errors", ".", "Wrapf", "(", "copyFile", "(", "destPath", ",", "srcPath", ",", "nil", ")", ",", "\"", "\"", ",", "destPath", ",", "srcPath", ")", "\n", "}", ")", "\n", "}" ]
// 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
146,601
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", "string", ")", "error", "{", "ipath", ":=", "pathos", ".", "SlashToImportPath", "(", "strings", ".", "TrimPrefix", "(", "folder", ",", "root", ")", ")", "\n", "if", "len", "(", "overridePath", ")", ">", "0", "{", "ipath", "=", "overridePath", "\n", "}", "\n", "if", "_", ",", "found", ":=", "list", "[", "ipath", "]", ";", "found", "{", "return", "nil", "\n", "}", "\n", "p", ":=", "filepath", ".", "Join", "(", "folder", ",", "name", ")", "\n", "text", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "p", ",", "err", ")", "\n", "}", "\n", "key", ":=", "path", ".", "Join", "(", "ipath", ",", "name", ")", "\n", "list", "[", "key", "]", "=", "License", "{", "Path", ":", "ipath", ",", "Filename", ":", "name", ",", "Text", ":", "string", "(", "text", ")", ",", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// 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
146,602
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", "m", ":=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "keyval", ")", ";", "i", "+=", "2", "{", "m", "[", "keyval", "[", "i", "]", "]", "=", "keyval", "[", "i", "+", "1", "]", "\n", "}", "\n", "args", ":=", "strings", ".", "Fields", "(", "cmdline", ")", "\n", "for", "i", ",", "arg", ":=", "range", "args", "{", "args", "[", "i", "]", "=", "expand", "(", "m", ",", "arg", ")", "\n", "}", "\n\n", "_", ",", "err", ":=", "exec", ".", "LookPath", "(", "v", ".", "Cmd", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\"", ",", "v", ".", "Name", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "cmd", ":=", "exec", ".", "Command", "(", "v", ".", "Cmd", ",", "args", "...", ")", "\n", "cmd", ".", "Dir", "=", "dir", "\n", "cmd", ".", "Env", "=", "envForDir", "(", "cmd", ".", "Dir", ")", "\n", "if", "vcs", ".", "ShowCmd", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "dir", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "v", ".", "Cmd", ",", "strings", ".", "Join", "(", "args", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "var", "buf", "bytes", ".", "Buffer", "\n", "cmd", ".", "Stdout", "=", "&", "buf", "\n", "cmd", ".", "Stderr", "=", "&", "buf", "\n", "err", "=", "cmd", ".", "Run", "(", ")", "\n", "out", ":=", "buf", ".", "Bytes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "verbose", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\"", ",", "dir", ",", "v", ".", "Cmd", ",", "strings", ".", "Join", "(", "args", ",", "\"", "\"", ")", ")", "\n", "os", ".", "Stderr", ".", "Write", "(", "out", ")", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "return", "out", ",", "nil", "\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
146,603
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", ")", "[", "0", "]", "\n", "for", "i", ",", "outkv", ":=", "range", "out", "{", "if", "strings", ".", "HasPrefix", "(", "outkv", ",", "k", ")", "{", "out", "[", "i", "]", "=", "inkv", "\n", "continue", "NextVar", "\n", "}", "\n", "}", "\n", "out", "=", "append", "(", "out", ",", "inkv", ")", "\n", "}", "\n", "return", "out", "\n", "}" ]
// 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
146,604
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", "=", "strings", ".", "TrimPrefix", "(", "line", ",", "\"", "\"", ")", "\n", "parts", ":=", "strings", ".", "SplitN", "(", "line", ",", "\"", "\"", ",", "2", ")", "\n", "if", "len", "(", "parts", ")", "<", "2", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "false", "\n", "}", "\n\n", "un", ",", "err", ":=", "strconv", ".", "Unquote", "(", "parts", "[", "1", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "parts", "[", "0", "]", ",", "parts", "[", "1", "]", ",", "true", "\n", "}", "\n", "return", "parts", "[", "0", "]", ",", "un", ",", "true", "\n", "}" ]
// 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
146,605
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", "=", "strings", ".", "TrimPrefix", "(", "line", ",", "\"", "\"", ")", "\n", "if", "len", "(", "line", ")", "<", "len", "(", "name", ")", "+", "1", "{", "return", "\"", "\"", ",", "false", "\n", "}", "\n", "if", "name", "!=", "line", "[", ":", "len", "(", "name", ")", "]", "||", "line", "[", "len", "(", "name", ")", "]", "!=", "'='", "{", "return", "\"", "\"", ",", "false", "\n", "}", "\n", "line", "=", "line", "[", "len", "(", "name", ")", "+", "1", ":", "]", "\n", "if", "un", ",", "err", ":=", "strconv", ".", "Unquote", "(", "line", ")", ";", "err", "==", "nil", "{", "line", "=", "un", "\n", "}", "\n", "return", "line", ",", "true", "\n", "}" ]
// 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
146,606
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", "[", "string", "]", "bool", ",", "10", ")", "\n", "}", "\n\n", "list", ",", "err", ":=", "ctx", ".", "Status", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Add packages from status.", "statusLoop", ":", "for", "_", ",", "item", ":=", "range", "list", "{", "if", "!", "item", ".", "Status", ".", "MatchGroup", "(", "sg", ")", "{", "continue", "\n", "}", "\n", "if", "ctx", ".", "added", "[", "item", ".", "Pkg", ".", "PathOrigin", "(", ")", "]", "{", "continue", "\n", "}", "\n", "// Do not add excluded packages", "if", "item", ".", "Status", ".", "Presence", "==", "PresenceExcluded", "{", "continue", "\n", "}", "\n", "// 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", "\n", "}", "\n", "for", "_", ",", "pkg", ":=", "range", "ctx", ".", "Package", "{", "if", "pkg", ".", "Status", ".", "Location", "==", "LocationVendor", "&&", "item", ".", "Pkg", ".", "Path", "==", "pkg", ".", "Path", "{", "continue", "statusLoop", "\n", "}", "\n", "}", "\n", "}", "\n\n", "err", "=", "ctx", ".", "modify", "(", "item", ".", "Pkg", ",", "mod", ",", "mops", ")", "\n", "if", "err", "!=", "nil", "{", "// Skip these errors if from status.", "if", "_", ",", "is", ":=", "err", ".", "(", "ErrTreeChildren", ")", ";", "is", "{", "continue", "\n", "}", "\n", "if", "_", ",", "is", ":=", "err", ".", "(", "ErrTreeParents", ")", ";", "is", "{", "continue", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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
146,607
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", "{", "ctx", ".", "added", "=", "make", "(", "map", "[", "string", "]", "bool", ",", "10", ")", "\n", "}", "\n", "// 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", "\n", "}", "\n", "if", "vpkg", ".", "Path", "==", "imp", ".", "Path", "{", "imp", ".", "Origin", "=", "vpkg", ".", "Origin", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "!", "imp", ".", "MatchTree", "{", "if", "!", "ctx", ".", "added", "[", "imp", ".", "PathOrigin", "(", ")", "]", "{", "err", "=", "ctx", ".", "modify", "(", "imp", ",", "mod", ",", "mops", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "list", ",", "err", ":=", "ctx", ".", "Status", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// If add any matched from \"...\".", "match", ":=", "imp", ".", "Path", "+", "\"", "\"", "\n", "for", "_", ",", "item", ":=", "range", "list", "{", "if", "ctx", ".", "added", "[", "item", ".", "Pkg", ".", "PathOrigin", "(", ")", "]", "{", "continue", "\n", "}", "\n", "if", "item", ".", "Pkg", ".", "Path", "!=", "imp", ".", "Path", "&&", "!", "strings", ".", "HasPrefix", "(", "item", ".", "Pkg", ".", "Path", ",", "match", ")", "{", "continue", "\n", "}", "\n", "if", "imp", ".", "HasVersion", "{", "item", ".", "Pkg", ".", "HasVersion", "=", "true", "\n", "item", ".", "Pkg", ".", "Version", "=", "imp", ".", "Version", "\n", "}", "\n", "item", ".", "Pkg", ".", "HasOrigin", "=", "imp", ".", "HasOrigin", "\n", "item", ".", "Pkg", ".", "Origin", "=", "path", ".", "Join", "(", "imp", ".", "PathOrigin", "(", ")", ",", "strings", ".", "TrimPrefix", "(", "item", ".", "Pkg", ".", "Path", ",", "imp", ".", "Path", ")", ")", "\n", "err", "=", "ctx", ".", "modify", "(", "item", ".", "Pkg", ",", "mod", ",", "mops", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "// cache for later use", "ctx", ".", "TreeImport", "=", "append", "(", "ctx", ".", "TreeImport", ",", "imp", ")", "\n", "return", "nil", "\n", "}" ]
// 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
146,608
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", ")", "\n", "if", "vp", "==", "nil", "{", "vp", "=", "&", "vendorfile", ".", "Package", "{", "Add", ":", "true", ",", "Path", ":", "pkg", ".", "Path", ",", "}", "\n", "ctx", ".", "VendorFile", ".", "Package", "=", "append", "(", "ctx", ".", "VendorFile", ".", "Package", ",", "vp", ")", "\n", "}", "\n", "if", "hasVersion", "{", "vp", ".", "Version", "=", "version", "\n", "pkg", ".", "Version", "=", "version", "\n", "pkg", ".", "HasVersion", "=", "true", "\n", "}", "\n", "if", "pkg", ".", "IncludeTree", "{", "vp", ".", "Tree", "=", "pkg", ".", "IncludeTree", "\n", "}", "\n", "pkg", ".", "Origin", "=", "strings", ".", "TrimPrefix", "(", "pkg", ".", "Origin", ",", "ctx", ".", "RootImportPath", "+", "\"", "\"", "+", "ctx", ".", "VendorFolder", "+", "\"", "\"", ")", "\n", "vp", ".", "Origin", "=", "pkg", ".", "Origin", "\n", "origin", ":=", "vp", ".", "Origin", "\n", "if", "len", "(", "vp", ".", "Origin", ")", "==", "0", "{", "origin", "=", "vp", ".", "Path", "\n", "}", "\n", "ps", ":=", "&", "pkgspec", ".", "Pkg", "{", "Path", ":", "pkg", ".", "Path", ",", "Origin", ":", "origin", ",", "HasVersion", ":", "hasVersion", ",", "Version", ":", "version", ",", "}", "\n", "dest", ":=", "filepath", ".", "Join", "(", "ctx", ".", "RootDir", ",", "ctx", ".", "VendorFolder", ",", "pathos", ".", "SlashToFilepath", "(", "pkg", ".", "Path", ")", ")", "\n", "ctx", ".", "Operation", "=", "append", "(", "ctx", ".", "Operation", ",", "&", "Operation", "{", "Type", ":", "OpFetch", ",", "Pkg", ":", "pkg", ",", "Src", ":", "ps", ".", "String", "(", ")", ",", "Dest", ":", "dest", ",", "}", ")", "\n", "return", "nil", "\n", "}" ]
// 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
146,609
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", ")", "// map[canonical][]local", "\n", "for", "_", ",", "op", ":=", "range", "ctx", ".", "Operation", "{", "if", "op", ".", "State", "!=", "OpReady", "{", "continue", "\n", "}", "\n", "findDups", "[", "op", ".", "Pkg", ".", "Path", "]", "=", "append", "(", "findDups", "[", "op", ".", "Pkg", ".", "Path", "]", ",", "op", ")", "\n", "}", "\n\n", "var", "ret", "[", "]", "*", "Conflict", "\n", "for", "canonical", ",", "lop", ":=", "range", "findDups", "{", "if", "len", "(", "lop", ")", "==", "1", "{", "continue", "\n", "}", "\n", "destDir", ":=", "path", ".", "Join", "(", "ctx", ".", "RootImportPath", ",", "ctx", ".", "VendorFolder", ",", "canonical", ")", "\n", "ret", "=", "append", "(", "ret", ",", "&", "Conflict", "{", "Canonical", ":", "canonical", ",", "Local", ":", "destDir", ",", "Operation", ":", "lop", ",", "}", ")", "\n", "}", "\n", "return", "ret", "\n", "}" ]
// 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
146,610
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", ":=", "range", "c", ".", "Operation", "{", "if", "op", ".", "State", "!=", "OpReady", "{", "continue", "\n", "}", "\n", "if", "i", "==", "c", ".", "OpIndex", "{", "if", "vp", ":=", "ctx", ".", "VendorFilePackagePath", "(", "c", ".", "Canonical", ")", ";", "vp", "!=", "nil", "{", "vp", ".", "Origin", "=", "c", ".", "Local", "\n", "}", "\n", "continue", "\n", "}", "\n", "op", ".", "State", "=", "OpIgnore", "\n", "}", "\n", "}", "\n", "}" ]
// 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
146,611
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", "longestIndex", ":=", "0", "\n", "for", "i", ",", "op", ":=", "range", "c", ".", "Operation", "{", "if", "op", ".", "State", "!=", "OpReady", "{", "continue", "\n", "}", "\n\n", "if", "len", "(", "op", ".", "Pkg", ".", "Local", ")", ">", "longestLen", "{", "longestLen", "=", "len", "(", "op", ".", "Pkg", ".", "Local", ")", "\n", "longestIndex", "=", "i", "\n", "}", "\n", "}", "\n", "c", ".", "OpIndex", "=", "longestIndex", "\n", "c", ".", "Resolved", "=", "true", "\n", "}", "\n", "return", "cc", "\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
146,612
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", "}", "\n", "vp", ":=", "ctx", ".", "VendorFilePackagePath", "(", "c", ".", "Canonical", ")", "\n", "if", "vp", "==", "nil", "{", "continue", "\n", "}", "\n", "// If this was just added, we still can't rely on it.", "// We still need to ask user.", "if", "vp", ".", "Add", "{", "continue", "\n", "}", "\n", "lookFor", ":=", "vp", ".", "Path", "\n", "if", "len", "(", "vp", ".", "Origin", ")", "!=", "0", "{", "lookFor", "=", "vp", ".", "Origin", "\n", "}", "\n", "for", "i", ",", "op", ":=", "range", "c", ".", "Operation", "{", "if", "op", ".", "State", "!=", "OpReady", "{", "continue", "\n", "}", "\n\n", "if", "op", ".", "Pkg", ".", "Local", "==", "lookFor", "{", "c", ".", "OpIndex", "=", "i", "\n", "c", ".", "Resolved", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "cc", "\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
146,613
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", ":=", "range", "ctx", ".", "Check", "(", ")", "{", "buf", ".", "WriteString", "(", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "conflict", ".", "Canonical", ")", ")", "\n", "for", "_", ",", "op", ":=", "range", "conflict", ".", "Operation", "{", "buf", ".", "WriteString", "(", "fmt", ".", "Sprintf", "(", "\"", "\\t", "\\n", "\"", ",", "op", ".", "Pkg", ".", "Local", ")", ")", "\n", "}", "\n", "}", "\n", "if", "buf", ".", "Len", "(", ")", "!=", "0", "{", "return", "errors", ".", "New", "(", "buf", ".", "String", "(", ")", ")", "\n", "}", "\n\n", "var", "err", "error", "\n", "fetch", ",", "err", ":=", "newFetcher", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "{", "var", "nextOps", "[", "]", "*", "Operation", "\n", "for", "_", ",", "op", ":=", "range", "ctx", ".", "Operation", "{", "if", "op", ".", "State", "!=", "OpReady", "{", "continue", "\n", "}", "\n\n", "switch", "op", ".", "Type", "{", "case", "OpFetch", ":", "var", "ops", "[", "]", "*", "Operation", "\n", "// Download packages, transform fetch op into a copy op.", "ops", ",", "err", "=", "fetch", ".", "op", "(", "op", ")", "\n", "if", "len", "(", "ops", ")", ">", "0", "{", "nextOps", "=", "append", "(", "nextOps", ",", "ops", "...", ")", "\n", "}", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "op", ".", "Pkg", ".", "Path", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "nextOps", ")", "==", "0", "{", "break", "\n", "}", "\n", "ctx", ".", "Operation", "=", "append", "(", "ctx", ".", "Operation", ",", "nextOps", "...", ")", "\n", "}", "\n", "// Move and possibly rewrite packages.", "for", "_", ",", "op", ":=", "range", "ctx", ".", "Operation", "{", "if", "op", ".", "State", "!=", "OpReady", "{", "continue", "\n", "}", "\n", "pkg", ":=", "op", ".", "Pkg", "\n\n", "if", "pathos", ".", "FileStringEquals", "(", "op", ".", "Dest", ",", "op", ".", "Src", ")", "{", "panic", "(", "\"", "\"", "+", "pkg", ".", "Local", "+", "\"", "\"", "+", "op", ".", "Src", ")", "\n", "}", "\n", "dprintf", "(", "\"", "\\n", "\"", ",", "pkg", ".", "Local", ",", "op", ".", "Src", ",", "op", ".", "Dest", ")", "\n", "// Copy the package or remove.", "switch", "op", ".", "Type", "{", "default", ":", "panic", "(", "\"", "\"", ")", "\n", "case", "OpRemove", ":", "ctx", ".", "dirty", "=", "true", "\n", "err", "=", "RemovePackage", "(", "op", ".", "Src", ",", "filepath", ".", "Join", "(", "ctx", ".", "RootDir", ",", "ctx", ".", "VendorFolder", ")", ",", "pkg", ".", "IncludeTree", ")", "\n", "op", ".", "State", "=", "OpDone", "\n", "case", "OpCopy", ":", "err", "=", "ctx", ".", "copyOperation", "(", "op", ",", "nil", ")", "\n", "if", "os", ".", "IsNotExist", "(", "errors", ".", "Cause", "(", "err", ")", ")", "{", "// Ignore packages that don't exist, like appengine.", "err", "=", "nil", "\n", "}", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "op", ".", "Type", ",", "op", ".", "Src", ",", "op", ".", "Dest", ")", "\n", "}", "\n", "}", "\n", "if", "ctx", ".", "rewriteImports", "{", "return", "ctx", ".", "rewrite", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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
146,614
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", "!=", "nil", "{", "g", ".", "Fatal", "(", "err", ")", "\n", "}", "\n", "g", ".", "current", "=", "p", "\n", "}" ]
// 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
146,615
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
146,616
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
146,617
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", "rootIndicator", ":=", "\"", "\"", "\n\n", "root", ":=", "wd", "\n", "switch", "rt", "{", "case", "RootVendor", ":", "tryRoot", ",", "err", ":=", "findRoot", "(", "wd", ",", "rootIndicator", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "root", "=", "tryRoot", "\n", "case", "RootVendorOrWD", ":", "tryRoot", ",", "err", ":=", "findRoot", "(", "wd", ",", "rootIndicator", ")", "\n", "if", "err", "==", "nil", "{", "root", "=", "tryRoot", "\n", "}", "\n", "case", "RootVendorOrWDOrFirstGOPATH", ":", "root", ",", "err", "=", "findRoot", "(", "wd", ",", "rootIndicator", ")", "\n", "if", "err", "!=", "nil", "{", "env", ",", "err", ":=", "NewEnv", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "allgopath", ":=", "env", "[", "\"", "\"", "]", "\n\n", "if", "len", "(", "allgopath", ")", "==", "0", "{", "return", "nil", ",", "ErrMissingGOPATH", "\n", "}", "\n", "gopathList", ":=", "filepath", ".", "SplitList", "(", "allgopath", ")", "\n", "root", "=", "filepath", ".", "Join", "(", "gopathList", "[", "0", "]", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "// Check for old vendor file location.", "oldLocation", ":=", "filepath", ".", "Join", "(", "root", ",", "vendorFilename", ")", "\n", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "oldLocation", ")", ";", "err", "==", "nil", "{", "return", "nil", ",", "ErrOldVersion", "{", "`Use the \"migrate\" command to update.`", "}", "\n", "}", "\n\n", "return", "NewContextRoot", "(", "root", ")", "\n", "}" ]
// 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
146,618
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", "NewContext", "(", "root", ",", "pathToVendorFile", ",", "vendorFolder", ",", "false", ")", "\n", "}" ]
// 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
146,619
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", "\n\n", "env", ",", "err", ":=", "NewEnv", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "goroot", ":=", "env", "[", "\"", "\"", "]", "\n", "all", ":=", "env", "[", "\"", "\"", "]", "\n\n", "if", "goroot", "==", "\"", "\"", "{", "return", "nil", ",", "ErrMissingGOROOT", "\n", "}", "\n", "goroot", "=", "filepath", ".", "Join", "(", "goroot", ",", "\"", "\"", ")", "\n\n", "// Get the GOPATHs. Prepend the GOROOT to the list.", "if", "len", "(", "all", ")", "==", "0", "{", "return", "nil", ",", "ErrMissingGOPATH", "\n", "}", "\n", "gopathList", ":=", "filepath", ".", "SplitList", "(", "all", ")", "\n", "gopathGoroot", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "gopathList", ")", "+", "1", ")", "\n", "gopathGoroot", "=", "append", "(", "gopathGoroot", ",", "goroot", ")", "\n", "for", "_", ",", "gopath", ":=", "range", "gopathList", "{", "srcPath", ":=", "filepath", ".", "Join", "(", "gopath", ",", "\"", "\"", ")", "+", "string", "(", "filepath", ".", "Separator", ")", "\n", "srcPathEvaled", ",", "err", ":=", "filepath", ".", "EvalSymlinks", "(", "srcPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "gopathGoroot", "=", "append", "(", "gopathGoroot", ",", "srcPath", ",", "srcPathEvaled", "+", "string", "(", "filepath", ".", "Separator", ")", ")", "\n", "}", "\n\n", "rootToVendorFile", ",", "_", ":=", "filepath", ".", "Split", "(", "vendorFilePathRel", ")", "\n\n", "vendorFilePath", ":=", "filepath", ".", "Join", "(", "root", ",", "vendorFilePathRel", ")", "\n\n", "ctx", ":=", "&", "Context", "{", "RootDir", ":", "root", ",", "GopathList", ":", "gopathGoroot", ",", "Goroot", ":", "goroot", ",", "VendorFilePath", ":", "vendorFilePath", ",", "VendorFolder", ":", "vendorFolder", ",", "RootToVendorFile", ":", "pathos", ".", "SlashToImportPath", "(", "rootToVendorFile", ")", ",", "VendorDiscoverFolder", ":", "\"", "\"", ",", "Package", ":", "make", "(", "map", "[", "string", "]", "*", "Package", ")", ",", "RewriteRule", ":", "make", "(", "map", "[", "string", "]", "string", ",", "3", ")", ",", "rewriteImports", ":", "rewriteImports", ",", "}", "\n\n", "ctx", ".", "RootImportPath", ",", "ctx", ".", "RootGopath", ",", "err", "=", "ctx", ".", "findImportPath", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "vf", ",", "err", ":=", "readVendorFile", "(", "path", ".", "Join", "(", "ctx", ".", "RootImportPath", ",", "vendorFolder", ")", "+", "\"", "\"", ",", "vendorFilePath", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vf", "=", "&", "vendorfile", ".", "File", "{", "}", "\n", "}", "\n", "ctx", ".", "VendorFile", "=", "vf", "\n\n", "ctx", ".", "IgnoreBuildAndPackage", "(", "vf", ".", "Ignore", ")", "\n\n", "return", "ctx", ",", "nil", "\n", "}" ]
// 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
146,620
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", "return", "len", "(", "s", ")", ",", "nil", "\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
146,621
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", "{", "continue", "\n", "}", "\n", "if", "pkg", ".", "Path", "==", "path", "{", "return", "pkg", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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
146,622
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", "ctx", ".", "Package", "{", "if", "pkg", "==", "ck", "{", "continue", "\n", "}", "\n", "if", "!", "pkg", ".", "inVendor", "{", "continue", "\n", "}", "\n", "if", "pkg", ".", "Status", ".", "Presence", "==", "PresenceTree", "{", "continue", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "pkg", ".", "Path", ",", "ck", ".", "Path", "+", "\"", "\"", ")", "{", "out", "=", "append", "(", "out", ",", "pkg", ")", "\n", "}", "\n", "}", "\n", "return", "out", "\n", "}" ]
// 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
146,623
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", ".", "Package", "{", "if", "!", "pkg", ".", "inVendor", "{", "continue", "\n", "}", "\n", "if", "!", "pkg", ".", "IncludeTree", "||", "pkg", "==", "ck", "{", "continue", "\n", "}", "\n", "// 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", ")", "\n", "}", "\n", "}", "\n", "return", "out", "\n", "}" ]
// 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
146,624
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", ",", "path", "string", ")", "*", "Package", "{", "if", "importMap", ",", "found", ":=", "pathUnderDirLookup", "[", "dir", "]", ";", "found", "{", "if", "pkg", ",", "found2", ":=", "importMap", "[", "path", "]", ";", "found2", "{", "return", "pkg", "\n", "}", "\n", "}", "else", "{", "pathUnderDirLookup", "[", "dir", "]", "=", "make", "(", "map", "[", "string", "]", "*", "Package", ")", "\n", "}", "\n", "for", "_", ",", "pkg", ":=", "range", "ctx", ".", "Package", "{", "if", "!", "pkg", ".", "inVendor", "{", "continue", "\n", "}", "\n\n", "removeFromEnd", ":=", "len", "(", "pkg", ".", "Path", ")", "+", "len", "(", "ctx", ".", "VendorDiscoverFolder", ")", "+", "2", "\n", "nextLen", ":=", "len", "(", "pkg", ".", "Dir", ")", "-", "removeFromEnd", "\n", "if", "nextLen", "<", "0", "{", "continue", "\n", "}", "\n", "checkDir", ":=", "pkg", ".", "Dir", "[", ":", "nextLen", "]", "\n", "if", "!", "pathos", ".", "FileHasPrefix", "(", "dir", ",", "checkDir", ")", "{", "continue", "\n", "}", "\n", "if", "pkg", ".", "Path", "!=", "path", "{", "continue", "\n", "}", "\n", "pathUnderDirLookup", "[", "dir", "]", "[", "path", "]", "=", "pkg", "\n", "return", "pkg", "\n", "}", "\n", "pathUnderDirLookup", "[", "dir", "]", "[", "path", "]", "=", "nil", "\n", "return", "nil", "\n", "}", "\n", "for", "_", ",", "pkg", ":=", "range", "ctx", ".", "Package", "{", "pkg", ".", "referenced", "=", "make", "(", "map", "[", "string", "]", "*", "Package", ",", "len", "(", "pkg", ".", "referenced", ")", ")", "\n", "}", "\n", "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", "\n", "continue", "\n", "}", "\n", "if", "other", ",", "found", ":=", "ctx", ".", "Package", "[", "imp", "]", ";", "found", "{", "other", ".", "referenced", "[", "pkg", ".", "Local", "]", "=", "pkg", "\n", "continue", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// 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", "\n", "}", "\n", "parentPkg", ".", "referenced", "[", "opath", "]", "=", "opkg", "\n", "}", "\n", "pkg", ".", "referenced", "=", "make", "(", "map", "[", "string", "]", "*", "Package", ",", "0", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// 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
146,625
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", "}", "\n", "return", "&", "File", "{", "BlockMode", ":", "true", ",", "dataSources", ":", "dataSources", ",", "sections", ":", "make", "(", "map", "[", "string", "]", "*", "Section", ")", ",", "sectionList", ":", "make", "(", "[", "]", "string", ",", "0", ",", "10", ")", ",", "options", ":", "opts", ",", "}", "\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
146,626
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", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "section", ".", "isRawSection", "=", "true", "\n", "section", ".", "rawBody", "=", "body", "\n", "return", "section", ",", "nil", "\n", "}" ]
// 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
146,627
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", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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
146,628
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", ".", "Insensitive", "{", "name", "=", "strings", ".", "ToLower", "(", "name", ")", "\n", "}", "\n\n", "if", "f", ".", "BlockMode", "{", "f", ".", "lock", ".", "RLock", "(", ")", "\n", "defer", "f", ".", "lock", ".", "RUnlock", "(", ")", "\n", "}", "\n\n", "sec", ":=", "f", ".", "sections", "[", "name", "]", "\n", "if", "sec", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "return", "sec", ",", "nil", "\n", "}" ]
// 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
146,629
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 is empty section name,", "// but if it's empty, this piece of code won't be executed.", "sec", ",", "_", "=", "f", ".", "NewSection", "(", "name", ")", "\n", "return", "sec", "\n", "}", "\n", "return", "sec", "\n", "}" ]
// 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
146,630
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", ":=", "make", "(", "[", "]", "*", "Section", ",", "len", "(", "f", ".", "sectionList", ")", ")", "\n", "for", "i", ",", "name", ":=", "range", "f", ".", "sectionList", "{", "sections", "[", "i", "]", "=", "f", ".", "sections", "[", "name", "]", "\n", "}", "\n", "return", "sections", "\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
146,631
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
146,632
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", ")", "\n", "return", "list", "\n", "}" ]
// 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
146,633
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", "len", "(", "name", ")", "==", "0", "{", "name", "=", "DefaultSection", "\n", "}", "\n\n", "for", "i", ",", "s", ":=", "range", "f", ".", "sectionList", "{", "if", "s", "==", "name", "{", "f", ".", "sectionList", "=", "append", "(", "f", ".", "sectionList", "[", ":", "i", "]", ",", "f", ".", "sectionList", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "delete", "(", "f", ".", "sections", ",", "name", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
// DeleteSection deletes a section.
[ "DeleteSection", "deletes", "a", "section", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/file.go#L171-L188
146,634
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", "{", "// In loose mode, we create an empty default section for nonexistent files.", "if", "os", ".", "IsNotExist", "(", "err", ")", "&&", "f", ".", "options", ".", "Loose", "{", "f", ".", "parse", "(", "bytes", ".", "NewBuffer", "(", "nil", ")", ")", "\n", "continue", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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
146,635
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", "{", "return", "err", "\n", "}", "\n", "f", ".", "dataSources", "=", "append", "(", "f", ".", "dataSources", ",", "ds", ")", "\n", "for", "_", ",", "s", ":=", "range", "others", "{", "ds", ",", "err", "=", "parseDataSource", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "f", ".", "dataSources", "=", "append", "(", "f", ".", "dataSources", ",", "ds", ")", "\n", "}", "\n", "return", "f", ".", "Reload", "(", ")", "\n", "}" ]
// 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
146,636
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", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "buf", ".", "WriteTo", "(", "w", ")", "\n", "}" ]
// 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
146,637
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
146,638
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", ":=", "f", ".", "writeToBuffer", "(", "indent", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "ioutil", ".", "WriteFile", "(", "filename", ",", "buf", ".", "Bytes", "(", ")", ",", "0666", ")", "\n", "}" ]
// 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
146,639
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", ",", "others", "...", ")", "\n", "}" ]
// 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
146,640
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", ",", "others", "...", ")", "\n", "}" ]
// 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
146,641
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", ",", "others", "...", ")", "\n", "}" ]
// 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
146,642
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
146,643
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", "return", "k", ".", "addShadow", "(", "val", ")", "\n", "}" ]
// 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
146,644
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", "return", "k", ".", "addNestedValue", "(", "val", ")", "\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
146,645
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", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "k", ".", "shadows", ")", "+", "1", ")", "\n", "vals", "[", "0", "]", "=", "k", ".", "value", "\n", "for", "i", ":=", "range", "k", ".", "shadows", "{", "vals", "[", "i", "+", "1", "]", "=", "k", ".", "shadows", "[", "i", "]", ".", "value", "\n", "}", "\n", "return", "vals", "\n", "}" ]
// 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
146,646
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", "}", "\n\n", "// Fail-fast if no indicate char found for recursive value", "if", "!", "strings", ".", "Contains", "(", "val", ",", "\"", "\"", ")", "{", "return", "val", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "depthValues", ";", "i", "++", "{", "vr", ":=", "varPattern", ".", "FindString", "(", "val", ")", "\n", "if", "len", "(", "vr", ")", "==", "0", "{", "break", "\n", "}", "\n\n", "// Take off leading '%(' and trailing ')s'.", "noption", ":=", "vr", "[", "2", ":", "len", "(", "vr", ")", "-", "2", "]", "\n\n", "// Search in the same section.", "nk", ",", "err", ":=", "k", ".", "s", ".", "GetKey", "(", "noption", ")", "\n", "if", "err", "!=", "nil", "||", "k", "==", "nk", "{", "// Search again in default section.", "nk", ",", "_", "=", "k", ".", "s", ".", "f", ".", "Section", "(", "\"", "\"", ")", ".", "GetKey", "(", "noption", ")", "\n", "}", "\n\n", "// Substitute by new value and take off leading '%(' and trailing ')s'.", "val", "=", "strings", ".", "Replace", "(", "val", ",", "vr", ",", "nk", ".", "value", ",", "-", "1", ")", "\n", "}", "\n", "return", "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
146,647
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
146,648
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", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ":", "return", "true", ",", "nil", "\n", "case", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ":", "return", "false", ",", "nil", "\n", "}", "\n", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\\\"", "\\\"", "\"", ",", "str", ")", "\n", "}" ]
// 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", "No", "n", "OFF", "off", "Off", ".", "Any", "other", "value", "returns", "an", "error", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L168-L176
146,649
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", ")", ",", "e", "\n", "}" ]
// Uint returns uint type valued.
[ "Uint", "returns", "uint", "type", "valued", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L200-L203
146,650
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
146,651
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
146,652
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
146,653
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", "defaultVal", "\n", "}", "\n", "return", "val", "\n", "}" ]
// 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
146,654
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", ".", "value", "=", "strconv", ".", "FormatUint", "(", "uint64", "(", "defaultVal", "[", "0", "]", ")", ",", "10", ")", "\n", "return", "defaultVal", "[", "0", "]", "\n", "}", "\n", "return", "val", "\n", "}" ]
// 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
146,655
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", "{", "k", ".", "value", "=", "strconv", ".", "FormatUint", "(", "defaultVal", "[", "0", "]", ",", "10", ")", "\n", "return", "defaultVal", "[", "0", "]", "\n", "}", "\n", "return", "val", "\n", "}" ]
// 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
146,656
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", "&&", "err", "!=", "nil", "{", "k", ".", "value", "=", "defaultVal", "[", "0", "]", ".", "String", "(", ")", "\n", "return", "defaultVal", "[", "0", "]", "\n", "}", "\n", "return", "val", "\n", "}" ]
// 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
146,657
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", "(", "defaultVal", ")", ">", "0", "&&", "err", "!=", "nil", "{", "k", ".", "value", "=", "defaultVal", "[", "0", "]", ".", "Format", "(", "format", ")", "\n", "return", "defaultVal", "[", "0", "]", "\n", "}", "\n", "return", "val", "\n", "}" ]
// 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
146,658
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
146,659
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", "val", "==", "cand", "{", "return", "val", "\n", "}", "\n", "}", "\n", "return", "defaultVal", "\n", "}" ]
// 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
146,660
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", "{", "if", "val", "==", "cand", "{", "return", "val", "\n", "}", "\n", "}", "\n", "return", "defaultVal", "\n", "}" ]
// 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
146,661
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", "==", "cand", "{", "return", "val", "\n", "}", "\n", "}", "\n", "return", "defaultVal", "\n", "}" ]
// 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
146,662
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", "val", "==", "cand", "{", "return", "val", "\n", "}", "\n", "}", "\n", "return", "defaultVal", "\n", "}" ]
// 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
146,663
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", "val", "==", "cand", "{", "return", "val", "\n", "}", "\n", "}", "\n", "return", "defaultVal", "\n", "}" ]
// 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
146,664
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", "{", "if", "val", "==", "cand", "{", "return", "val", "\n", "}", "\n", "}", "\n", "return", "defaultVal", "\n", "}" ]
// 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
146,665
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", ")", "\n", "for", "_", ",", "cand", ":=", "range", "candidates", "{", "if", "val", "==", "cand", "{", "return", "val", "\n", "}", "\n", "}", "\n", "return", "defaultVal", "\n", "}" ]
// 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
146,666
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", ",", "candidates", ")", "\n", "}" ]
// 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
146,667
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", "defaultVal", "\n", "}", "\n", "return", "val", "\n", "}" ]
// 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
146,668
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", "\n", "}", "\n", "return", "val", "\n", "}" ]
// 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
146,669
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", "defaultVal", "\n", "}", "\n", "return", "val", "\n", "}" ]
// 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
146,670
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", "val", ".", "Unix", "(", ")", "<", "min", ".", "Unix", "(", ")", "||", "val", ".", "Unix", "(", ")", ">", "max", ".", "Unix", "(", ")", "{", "return", "defaultVal", "\n", "}", "\n", "return", "val", "\n", "}" ]
// 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
146,671
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", ",", "max", ")", "\n", "}" ]
// 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
146,672
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", "}", "\n\n", "runes", ":=", "[", "]", "rune", "(", "str", ")", "\n", "vals", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "2", ")", "\n", "var", "buf", "bytes", ".", "Buffer", "\n", "escape", ":=", "false", "\n", "idx", ":=", "0", "\n", "for", "{", "if", "escape", "{", "escape", "=", "false", "\n", "if", "runes", "[", "idx", "]", "!=", "'\\\\'", "&&", "!", "strings", ".", "HasPrefix", "(", "string", "(", "runes", "[", "idx", ":", "]", ")", ",", "delim", ")", "{", "buf", ".", "WriteRune", "(", "'\\\\'", ")", "\n", "}", "\n", "buf", ".", "WriteRune", "(", "runes", "[", "idx", "]", ")", "\n", "}", "else", "{", "if", "runes", "[", "idx", "]", "==", "'\\\\'", "{", "escape", "=", "true", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "string", "(", "runes", "[", "idx", ":", "]", ")", ",", "delim", ")", "{", "idx", "+=", "len", "(", "delim", ")", "-", "1", "\n", "vals", "=", "append", "(", "vals", ",", "strings", ".", "TrimSpace", "(", "buf", ".", "String", "(", ")", ")", ")", "\n", "buf", ".", "Reset", "(", ")", "\n", "}", "else", "{", "buf", ".", "WriteRune", "(", "runes", "[", "idx", "]", ")", "\n", "}", "\n", "}", "\n", "idx", "++", "\n", "if", "idx", "==", "len", "(", "runes", ")", "{", "break", "\n", "}", "\n", "}", "\n\n", "if", "buf", ".", "Len", "(", ")", ">", "0", "{", "vals", "=", "append", "(", "vals", ",", "strings", ".", "TrimSpace", "(", "buf", ".", "String", "(", ")", ")", ")", "\n", "}", "\n\n", "return", "vals", "\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
146,673
go-ini/ini
key.go
StringsWithShadows
func (k *Key) StringsWithShadows(delim string) []string { vals := k.ValueWithShadows() results := make([]string, 0, len(vals)*2) for i := range vals { if len(vals) == 0 { continue } results = append(results, strings.Split(vals[i], delim)...) } for i := range results { results[i] = k.transformValue(strings.TrimSpace(results[i])) } return results }
go
func (k *Key) StringsWithShadows(delim string) []string { vals := k.ValueWithShadows() results := make([]string, 0, len(vals)*2) for i := range vals { if len(vals) == 0 { continue } results = append(results, strings.Split(vals[i], delim)...) } for i := range results { results[i] = k.transformValue(strings.TrimSpace(results[i])) } return results }
[ "func", "(", "k", "*", "Key", ")", "StringsWithShadows", "(", "delim", "string", ")", "[", "]", "string", "{", "vals", ":=", "k", ".", "ValueWithShadows", "(", ")", "\n", "results", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "vals", ")", "*", "2", ")", "\n", "for", "i", ":=", "range", "vals", "{", "if", "len", "(", "vals", ")", "==", "0", "{", "continue", "\n", "}", "\n\n", "results", "=", "append", "(", "results", ",", "strings", ".", "Split", "(", "vals", "[", "i", "]", ",", "delim", ")", "...", ")", "\n", "}", "\n\n", "for", "i", ":=", "range", "results", "{", "results", "[", "i", "]", "=", "k", ".", "transformValue", "(", "strings", ".", "TrimSpace", "(", "results", "[", "i", "]", ")", ")", "\n", "}", "\n", "return", "results", "\n", "}" ]
// StringsWithShadows returns list of string divided by given delimiter. // Shadows will also be appended if any.
[ "StringsWithShadows", "returns", "list", "of", "string", "divided", "by", "given", "delimiter", ".", "Shadows", "will", "also", "be", "appended", "if", "any", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L510-L525
146,674
go-ini/ini
key.go
Float64s
func (k *Key) Float64s(delim string) []float64 { vals, _ := k.parseFloat64s(k.Strings(delim), true, false) return vals }
go
func (k *Key) Float64s(delim string) []float64 { vals, _ := k.parseFloat64s(k.Strings(delim), true, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "Float64s", "(", "delim", "string", ")", "[", "]", "float64", "{", "vals", ",", "_", ":=", "k", ".", "parseFloat64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "true", ",", "false", ")", "\n", "return", "vals", "\n", "}" ]
// Float64s returns list of float64 divided by given delimiter. Any invalid input will be treated as zero value.
[ "Float64s", "returns", "list", "of", "float64", "divided", "by", "given", "delimiter", ".", "Any", "invalid", "input", "will", "be", "treated", "as", "zero", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L528-L531
146,675
go-ini/ini
key.go
Ints
func (k *Key) Ints(delim string) []int { vals, _ := k.parseInts(k.Strings(delim), true, false) return vals }
go
func (k *Key) Ints(delim string) []int { vals, _ := k.parseInts(k.Strings(delim), true, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "Ints", "(", "delim", "string", ")", "[", "]", "int", "{", "vals", ",", "_", ":=", "k", ".", "parseInts", "(", "k", ".", "Strings", "(", "delim", ")", ",", "true", ",", "false", ")", "\n", "return", "vals", "\n", "}" ]
// Ints returns list of int divided by given delimiter. Any invalid input will be treated as zero value.
[ "Ints", "returns", "list", "of", "int", "divided", "by", "given", "delimiter", ".", "Any", "invalid", "input", "will", "be", "treated", "as", "zero", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L534-L537
146,676
go-ini/ini
key.go
Int64s
func (k *Key) Int64s(delim string) []int64 { vals, _ := k.parseInt64s(k.Strings(delim), true, false) return vals }
go
func (k *Key) Int64s(delim string) []int64 { vals, _ := k.parseInt64s(k.Strings(delim), true, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "Int64s", "(", "delim", "string", ")", "[", "]", "int64", "{", "vals", ",", "_", ":=", "k", ".", "parseInt64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "true", ",", "false", ")", "\n", "return", "vals", "\n", "}" ]
// Int64s returns list of int64 divided by given delimiter. Any invalid input will be treated as zero value.
[ "Int64s", "returns", "list", "of", "int64", "divided", "by", "given", "delimiter", ".", "Any", "invalid", "input", "will", "be", "treated", "as", "zero", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L540-L543
146,677
go-ini/ini
key.go
Uints
func (k *Key) Uints(delim string) []uint { vals, _ := k.parseUints(k.Strings(delim), true, false) return vals }
go
func (k *Key) Uints(delim string) []uint { vals, _ := k.parseUints(k.Strings(delim), true, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "Uints", "(", "delim", "string", ")", "[", "]", "uint", "{", "vals", ",", "_", ":=", "k", ".", "parseUints", "(", "k", ".", "Strings", "(", "delim", ")", ",", "true", ",", "false", ")", "\n", "return", "vals", "\n", "}" ]
// Uints returns list of uint divided by given delimiter. Any invalid input will be treated as zero value.
[ "Uints", "returns", "list", "of", "uint", "divided", "by", "given", "delimiter", ".", "Any", "invalid", "input", "will", "be", "treated", "as", "zero", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L546-L549
146,678
go-ini/ini
key.go
Uint64s
func (k *Key) Uint64s(delim string) []uint64 { vals, _ := k.parseUint64s(k.Strings(delim), true, false) return vals }
go
func (k *Key) Uint64s(delim string) []uint64 { vals, _ := k.parseUint64s(k.Strings(delim), true, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "Uint64s", "(", "delim", "string", ")", "[", "]", "uint64", "{", "vals", ",", "_", ":=", "k", ".", "parseUint64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "true", ",", "false", ")", "\n", "return", "vals", "\n", "}" ]
// Uint64s returns list of uint64 divided by given delimiter. Any invalid input will be treated as zero value.
[ "Uint64s", "returns", "list", "of", "uint64", "divided", "by", "given", "delimiter", ".", "Any", "invalid", "input", "will", "be", "treated", "as", "zero", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L552-L555
146,679
go-ini/ini
key.go
ValidFloat64s
func (k *Key) ValidFloat64s(delim string) []float64 { vals, _ := k.parseFloat64s(k.Strings(delim), false, false) return vals }
go
func (k *Key) ValidFloat64s(delim string) []float64 { vals, _ := k.parseFloat64s(k.Strings(delim), false, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "ValidFloat64s", "(", "delim", "string", ")", "[", "]", "float64", "{", "vals", ",", "_", ":=", "k", ".", "parseFloat64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "false", ")", "\n", "return", "vals", "\n", "}" ]
// ValidFloat64s returns list of float64 divided by given delimiter. If some value is not float, then // it will not be included to result list.
[ "ValidFloat64s", "returns", "list", "of", "float64", "divided", "by", "given", "delimiter", ".", "If", "some", "value", "is", "not", "float", "then", "it", "will", "not", "be", "included", "to", "result", "list", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L572-L575
146,680
go-ini/ini
key.go
ValidInts
func (k *Key) ValidInts(delim string) []int { vals, _ := k.parseInts(k.Strings(delim), false, false) return vals }
go
func (k *Key) ValidInts(delim string) []int { vals, _ := k.parseInts(k.Strings(delim), false, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "ValidInts", "(", "delim", "string", ")", "[", "]", "int", "{", "vals", ",", "_", ":=", "k", ".", "parseInts", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "false", ")", "\n", "return", "vals", "\n", "}" ]
// ValidInts returns list of int divided by given delimiter. If some value is not integer, then it will // not be included to result list.
[ "ValidInts", "returns", "list", "of", "int", "divided", "by", "given", "delimiter", ".", "If", "some", "value", "is", "not", "integer", "then", "it", "will", "not", "be", "included", "to", "result", "list", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L579-L582
146,681
go-ini/ini
key.go
ValidInt64s
func (k *Key) ValidInt64s(delim string) []int64 { vals, _ := k.parseInt64s(k.Strings(delim), false, false) return vals }
go
func (k *Key) ValidInt64s(delim string) []int64 { vals, _ := k.parseInt64s(k.Strings(delim), false, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "ValidInt64s", "(", "delim", "string", ")", "[", "]", "int64", "{", "vals", ",", "_", ":=", "k", ".", "parseInt64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "false", ")", "\n", "return", "vals", "\n", "}" ]
// ValidInt64s returns list of int64 divided by given delimiter. If some value is not 64-bit integer, // then it will not be included to result list.
[ "ValidInt64s", "returns", "list", "of", "int64", "divided", "by", "given", "delimiter", ".", "If", "some", "value", "is", "not", "64", "-", "bit", "integer", "then", "it", "will", "not", "be", "included", "to", "result", "list", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L586-L589
146,682
go-ini/ini
key.go
ValidUints
func (k *Key) ValidUints(delim string) []uint { vals, _ := k.parseUints(k.Strings(delim), false, false) return vals }
go
func (k *Key) ValidUints(delim string) []uint { vals, _ := k.parseUints(k.Strings(delim), false, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "ValidUints", "(", "delim", "string", ")", "[", "]", "uint", "{", "vals", ",", "_", ":=", "k", ".", "parseUints", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "false", ")", "\n", "return", "vals", "\n", "}" ]
// ValidUints returns list of uint divided by given delimiter. If some value is not unsigned integer, // then it will not be included to result list.
[ "ValidUints", "returns", "list", "of", "uint", "divided", "by", "given", "delimiter", ".", "If", "some", "value", "is", "not", "unsigned", "integer", "then", "it", "will", "not", "be", "included", "to", "result", "list", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L593-L596
146,683
go-ini/ini
key.go
ValidUint64s
func (k *Key) ValidUint64s(delim string) []uint64 { vals, _ := k.parseUint64s(k.Strings(delim), false, false) return vals }
go
func (k *Key) ValidUint64s(delim string) []uint64 { vals, _ := k.parseUint64s(k.Strings(delim), false, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "ValidUint64s", "(", "delim", "string", ")", "[", "]", "uint64", "{", "vals", ",", "_", ":=", "k", ".", "parseUint64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "false", ")", "\n", "return", "vals", "\n", "}" ]
// ValidUint64s returns list of uint64 divided by given delimiter. If some value is not 64-bit unsigned // integer, then it will not be included to result list.
[ "ValidUint64s", "returns", "list", "of", "uint64", "divided", "by", "given", "delimiter", ".", "If", "some", "value", "is", "not", "64", "-", "bit", "unsigned", "integer", "then", "it", "will", "not", "be", "included", "to", "result", "list", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L600-L603
146,684
go-ini/ini
key.go
ValidTimesFormat
func (k *Key) ValidTimesFormat(format, delim string) []time.Time { vals, _ := k.parseTimesFormat(format, k.Strings(delim), false, false) return vals }
go
func (k *Key) ValidTimesFormat(format, delim string) []time.Time { vals, _ := k.parseTimesFormat(format, k.Strings(delim), false, false) return vals }
[ "func", "(", "k", "*", "Key", ")", "ValidTimesFormat", "(", "format", ",", "delim", "string", ")", "[", "]", "time", ".", "Time", "{", "vals", ",", "_", ":=", "k", ".", "parseTimesFormat", "(", "format", ",", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "false", ")", "\n", "return", "vals", "\n", "}" ]
// ValidTimesFormat parses with given format and returns list of time.Time divided by given delimiter.
[ "ValidTimesFormat", "parses", "with", "given", "format", "and", "returns", "list", "of", "time", ".", "Time", "divided", "by", "given", "delimiter", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L606-L609
146,685
go-ini/ini
key.go
ValidTimes
func (k *Key) ValidTimes(delim string) []time.Time { return k.ValidTimesFormat(time.RFC3339, delim) }
go
func (k *Key) ValidTimes(delim string) []time.Time { return k.ValidTimesFormat(time.RFC3339, delim) }
[ "func", "(", "k", "*", "Key", ")", "ValidTimes", "(", "delim", "string", ")", "[", "]", "time", ".", "Time", "{", "return", "k", ".", "ValidTimesFormat", "(", "time", ".", "RFC3339", ",", "delim", ")", "\n", "}" ]
// ValidTimes parses with RFC3339 format and returns list of time.Time divided by given delimiter.
[ "ValidTimes", "parses", "with", "RFC3339", "format", "and", "returns", "list", "of", "time", ".", "Time", "divided", "by", "given", "delimiter", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L612-L614
146,686
go-ini/ini
key.go
StrictFloat64s
func (k *Key) StrictFloat64s(delim string) ([]float64, error) { return k.parseFloat64s(k.Strings(delim), false, true) }
go
func (k *Key) StrictFloat64s(delim string) ([]float64, error) { return k.parseFloat64s(k.Strings(delim), false, true) }
[ "func", "(", "k", "*", "Key", ")", "StrictFloat64s", "(", "delim", "string", ")", "(", "[", "]", "float64", ",", "error", ")", "{", "return", "k", ".", "parseFloat64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "true", ")", "\n", "}" ]
// StrictFloat64s returns list of float64 divided by given delimiter or error on first invalid input.
[ "StrictFloat64s", "returns", "list", "of", "float64", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L617-L619
146,687
go-ini/ini
key.go
StrictInts
func (k *Key) StrictInts(delim string) ([]int, error) { return k.parseInts(k.Strings(delim), false, true) }
go
func (k *Key) StrictInts(delim string) ([]int, error) { return k.parseInts(k.Strings(delim), false, true) }
[ "func", "(", "k", "*", "Key", ")", "StrictInts", "(", "delim", "string", ")", "(", "[", "]", "int", ",", "error", ")", "{", "return", "k", ".", "parseInts", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "true", ")", "\n", "}" ]
// StrictInts returns list of int divided by given delimiter or error on first invalid input.
[ "StrictInts", "returns", "list", "of", "int", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L622-L624
146,688
go-ini/ini
key.go
StrictInt64s
func (k *Key) StrictInt64s(delim string) ([]int64, error) { return k.parseInt64s(k.Strings(delim), false, true) }
go
func (k *Key) StrictInt64s(delim string) ([]int64, error) { return k.parseInt64s(k.Strings(delim), false, true) }
[ "func", "(", "k", "*", "Key", ")", "StrictInt64s", "(", "delim", "string", ")", "(", "[", "]", "int64", ",", "error", ")", "{", "return", "k", ".", "parseInt64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "true", ")", "\n", "}" ]
// StrictInt64s returns list of int64 divided by given delimiter or error on first invalid input.
[ "StrictInt64s", "returns", "list", "of", "int64", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L627-L629
146,689
go-ini/ini
key.go
StrictUints
func (k *Key) StrictUints(delim string) ([]uint, error) { return k.parseUints(k.Strings(delim), false, true) }
go
func (k *Key) StrictUints(delim string) ([]uint, error) { return k.parseUints(k.Strings(delim), false, true) }
[ "func", "(", "k", "*", "Key", ")", "StrictUints", "(", "delim", "string", ")", "(", "[", "]", "uint", ",", "error", ")", "{", "return", "k", ".", "parseUints", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "true", ")", "\n", "}" ]
// StrictUints returns list of uint divided by given delimiter or error on first invalid input.
[ "StrictUints", "returns", "list", "of", "uint", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L632-L634
146,690
go-ini/ini
key.go
StrictUint64s
func (k *Key) StrictUint64s(delim string) ([]uint64, error) { return k.parseUint64s(k.Strings(delim), false, true) }
go
func (k *Key) StrictUint64s(delim string) ([]uint64, error) { return k.parseUint64s(k.Strings(delim), false, true) }
[ "func", "(", "k", "*", "Key", ")", "StrictUint64s", "(", "delim", "string", ")", "(", "[", "]", "uint64", ",", "error", ")", "{", "return", "k", ".", "parseUint64s", "(", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "true", ")", "\n", "}" ]
// StrictUint64s returns list of uint64 divided by given delimiter or error on first invalid input.
[ "StrictUint64s", "returns", "list", "of", "uint64", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L637-L639
146,691
go-ini/ini
key.go
StrictTimesFormat
func (k *Key) StrictTimesFormat(format, delim string) ([]time.Time, error) { return k.parseTimesFormat(format, k.Strings(delim), false, true) }
go
func (k *Key) StrictTimesFormat(format, delim string) ([]time.Time, error) { return k.parseTimesFormat(format, k.Strings(delim), false, true) }
[ "func", "(", "k", "*", "Key", ")", "StrictTimesFormat", "(", "format", ",", "delim", "string", ")", "(", "[", "]", "time", ".", "Time", ",", "error", ")", "{", "return", "k", ".", "parseTimesFormat", "(", "format", ",", "k", ".", "Strings", "(", "delim", ")", ",", "false", ",", "true", ")", "\n", "}" ]
// StrictTimesFormat parses with given format and returns list of time.Time divided by given delimiter // or error on first invalid input.
[ "StrictTimesFormat", "parses", "with", "given", "format", "and", "returns", "list", "of", "time", ".", "Time", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L643-L645
146,692
go-ini/ini
key.go
StrictTimes
func (k *Key) StrictTimes(delim string) ([]time.Time, error) { return k.StrictTimesFormat(time.RFC3339, delim) }
go
func (k *Key) StrictTimes(delim string) ([]time.Time, error) { return k.StrictTimesFormat(time.RFC3339, delim) }
[ "func", "(", "k", "*", "Key", ")", "StrictTimes", "(", "delim", "string", ")", "(", "[", "]", "time", ".", "Time", ",", "error", ")", "{", "return", "k", ".", "StrictTimesFormat", "(", "time", ".", "RFC3339", ",", "delim", ")", "\n", "}" ]
// StrictTimes parses with RFC3339 format and returns list of time.Time divided by given delimiter // or error on first invalid input.
[ "StrictTimes", "parses", "with", "RFC3339", "format", "and", "returns", "list", "of", "time", ".", "Time", "divided", "by", "given", "delimiter", "or", "error", "on", "first", "invalid", "input", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L649-L651
146,693
go-ini/ini
key.go
parseFloat64s
func (k *Key) parseFloat64s(strs []string, addInvalid, returnOnInvalid bool) ([]float64, error) { vals := make([]float64, 0, len(strs)) for _, str := range strs { val, err := strconv.ParseFloat(str, 64) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
go
func (k *Key) parseFloat64s(strs []string, addInvalid, returnOnInvalid bool) ([]float64, error) { vals := make([]float64, 0, len(strs)) for _, str := range strs { val, err := strconv.ParseFloat(str, 64) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
[ "func", "(", "k", "*", "Key", ")", "parseFloat64s", "(", "strs", "[", "]", "string", ",", "addInvalid", ",", "returnOnInvalid", "bool", ")", "(", "[", "]", "float64", ",", "error", ")", "{", "vals", ":=", "make", "(", "[", "]", "float64", ",", "0", ",", "len", "(", "strs", ")", ")", "\n", "for", "_", ",", "str", ":=", "range", "strs", "{", "val", ",", "err", ":=", "strconv", ".", "ParseFloat", "(", "str", ",", "64", ")", "\n", "if", "err", "!=", "nil", "&&", "returnOnInvalid", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", "==", "nil", "||", "addInvalid", "{", "vals", "=", "append", "(", "vals", ",", "val", ")", "\n", "}", "\n", "}", "\n", "return", "vals", ",", "nil", "\n", "}" ]
// parseFloat64s transforms strings to float64s.
[ "parseFloat64s", "transforms", "strings", "to", "float64s", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L654-L666
146,694
go-ini/ini
key.go
parseInts
func (k *Key) parseInts(strs []string, addInvalid, returnOnInvalid bool) ([]int, error) { vals := make([]int, 0, len(strs)) for _, str := range strs { valInt64, err := strconv.ParseInt(str, 0, 64) val := int(valInt64) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
go
func (k *Key) parseInts(strs []string, addInvalid, returnOnInvalid bool) ([]int, error) { vals := make([]int, 0, len(strs)) for _, str := range strs { valInt64, err := strconv.ParseInt(str, 0, 64) val := int(valInt64) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
[ "func", "(", "k", "*", "Key", ")", "parseInts", "(", "strs", "[", "]", "string", ",", "addInvalid", ",", "returnOnInvalid", "bool", ")", "(", "[", "]", "int", ",", "error", ")", "{", "vals", ":=", "make", "(", "[", "]", "int", ",", "0", ",", "len", "(", "strs", ")", ")", "\n", "for", "_", ",", "str", ":=", "range", "strs", "{", "valInt64", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "str", ",", "0", ",", "64", ")", "\n", "val", ":=", "int", "(", "valInt64", ")", "\n", "if", "err", "!=", "nil", "&&", "returnOnInvalid", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", "==", "nil", "||", "addInvalid", "{", "vals", "=", "append", "(", "vals", ",", "val", ")", "\n", "}", "\n", "}", "\n", "return", "vals", ",", "nil", "\n", "}" ]
// parseInts transforms strings to ints.
[ "parseInts", "transforms", "strings", "to", "ints", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L669-L682
146,695
go-ini/ini
key.go
parseInt64s
func (k *Key) parseInt64s(strs []string, addInvalid, returnOnInvalid bool) ([]int64, error) { vals := make([]int64, 0, len(strs)) for _, str := range strs { val, err := strconv.ParseInt(str, 0, 64) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
go
func (k *Key) parseInt64s(strs []string, addInvalid, returnOnInvalid bool) ([]int64, error) { vals := make([]int64, 0, len(strs)) for _, str := range strs { val, err := strconv.ParseInt(str, 0, 64) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
[ "func", "(", "k", "*", "Key", ")", "parseInt64s", "(", "strs", "[", "]", "string", ",", "addInvalid", ",", "returnOnInvalid", "bool", ")", "(", "[", "]", "int64", ",", "error", ")", "{", "vals", ":=", "make", "(", "[", "]", "int64", ",", "0", ",", "len", "(", "strs", ")", ")", "\n", "for", "_", ",", "str", ":=", "range", "strs", "{", "val", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "str", ",", "0", ",", "64", ")", "\n", "if", "err", "!=", "nil", "&&", "returnOnInvalid", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", "==", "nil", "||", "addInvalid", "{", "vals", "=", "append", "(", "vals", ",", "val", ")", "\n", "}", "\n", "}", "\n", "return", "vals", ",", "nil", "\n", "}" ]
// parseInt64s transforms strings to int64s.
[ "parseInt64s", "transforms", "strings", "to", "int64s", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L685-L697
146,696
go-ini/ini
key.go
parseUints
func (k *Key) parseUints(strs []string, addInvalid, returnOnInvalid bool) ([]uint, error) { vals := make([]uint, 0, len(strs)) for _, str := range strs { val, err := strconv.ParseUint(str, 0, 0) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, uint(val)) } } return vals, nil }
go
func (k *Key) parseUints(strs []string, addInvalid, returnOnInvalid bool) ([]uint, error) { vals := make([]uint, 0, len(strs)) for _, str := range strs { val, err := strconv.ParseUint(str, 0, 0) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, uint(val)) } } return vals, nil }
[ "func", "(", "k", "*", "Key", ")", "parseUints", "(", "strs", "[", "]", "string", ",", "addInvalid", ",", "returnOnInvalid", "bool", ")", "(", "[", "]", "uint", ",", "error", ")", "{", "vals", ":=", "make", "(", "[", "]", "uint", ",", "0", ",", "len", "(", "strs", ")", ")", "\n", "for", "_", ",", "str", ":=", "range", "strs", "{", "val", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "str", ",", "0", ",", "0", ")", "\n", "if", "err", "!=", "nil", "&&", "returnOnInvalid", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", "==", "nil", "||", "addInvalid", "{", "vals", "=", "append", "(", "vals", ",", "uint", "(", "val", ")", ")", "\n", "}", "\n", "}", "\n", "return", "vals", ",", "nil", "\n", "}" ]
// parseUints transforms strings to uints.
[ "parseUints", "transforms", "strings", "to", "uints", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L700-L712
146,697
go-ini/ini
key.go
parseTimesFormat
func (k *Key) parseTimesFormat(format string, strs []string, addInvalid, returnOnInvalid bool) ([]time.Time, error) { vals := make([]time.Time, 0, len(strs)) for _, str := range strs { val, err := time.Parse(format, str) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
go
func (k *Key) parseTimesFormat(format string, strs []string, addInvalid, returnOnInvalid bool) ([]time.Time, error) { vals := make([]time.Time, 0, len(strs)) for _, str := range strs { val, err := time.Parse(format, str) if err != nil && returnOnInvalid { return nil, err } if err == nil || addInvalid { vals = append(vals, val) } } return vals, nil }
[ "func", "(", "k", "*", "Key", ")", "parseTimesFormat", "(", "format", "string", ",", "strs", "[", "]", "string", ",", "addInvalid", ",", "returnOnInvalid", "bool", ")", "(", "[", "]", "time", ".", "Time", ",", "error", ")", "{", "vals", ":=", "make", "(", "[", "]", "time", ".", "Time", ",", "0", ",", "len", "(", "strs", ")", ")", "\n", "for", "_", ",", "str", ":=", "range", "strs", "{", "val", ",", "err", ":=", "time", ".", "Parse", "(", "format", ",", "str", ")", "\n", "if", "err", "!=", "nil", "&&", "returnOnInvalid", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", "==", "nil", "||", "addInvalid", "{", "vals", "=", "append", "(", "vals", ",", "val", ")", "\n", "}", "\n", "}", "\n", "return", "vals", ",", "nil", "\n", "}" ]
// parseTimesFormat transforms strings to times in given format.
[ "parseTimesFormat", "transforms", "strings", "to", "times", "in", "given", "format", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L730-L742
146,698
go-ini/ini
key.go
SetValue
func (k *Key) SetValue(v string) { if k.s.f.BlockMode { k.s.f.lock.Lock() defer k.s.f.lock.Unlock() } k.value = v k.s.keysHash[k.name] = v }
go
func (k *Key) SetValue(v string) { if k.s.f.BlockMode { k.s.f.lock.Lock() defer k.s.f.lock.Unlock() } k.value = v k.s.keysHash[k.name] = v }
[ "func", "(", "k", "*", "Key", ")", "SetValue", "(", "v", "string", ")", "{", "if", "k", ".", "s", ".", "f", ".", "BlockMode", "{", "k", ".", "s", ".", "f", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "k", ".", "s", ".", "f", ".", "lock", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "k", ".", "value", "=", "v", "\n", "k", ".", "s", ".", "keysHash", "[", "k", ".", "name", "]", "=", "v", "\n", "}" ]
// SetValue changes key value.
[ "SetValue", "changes", "key", "value", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/key.go#L745-L753
146,699
go-ini/ini
parser.go
hasSurroundedQuote
func hasSurroundedQuote(in string, quote byte) bool { return len(in) >= 2 && in[0] == quote && in[len(in)-1] == quote && strings.IndexByte(in[1:], quote) == len(in)-2 }
go
func hasSurroundedQuote(in string, quote byte) bool { return len(in) >= 2 && in[0] == quote && in[len(in)-1] == quote && strings.IndexByte(in[1:], quote) == len(in)-2 }
[ "func", "hasSurroundedQuote", "(", "in", "string", ",", "quote", "byte", ")", "bool", "{", "return", "len", "(", "in", ")", ">=", "2", "&&", "in", "[", "0", "]", "==", "quote", "&&", "in", "[", "len", "(", "in", ")", "-", "1", "]", "==", "quote", "&&", "strings", ".", "IndexByte", "(", "in", "[", "1", ":", "]", ",", "quote", ")", "==", "len", "(", "in", ")", "-", "2", "\n", "}" ]
// hasSurroundedQuote check if and only if the first and last characters // are quotes \" or \'. // It returns false if any other parts also contain same kind of quotes.
[ "hasSurroundedQuote", "check", "if", "and", "only", "if", "the", "first", "and", "last", "characters", "are", "quotes", "\\", "or", "\\", ".", "It", "returns", "false", "if", "any", "other", "parts", "also", "contain", "same", "kind", "of", "quotes", "." ]
3be5ad479f69d4e08d7fe25edf79bf3346bd658e
https://github.com/go-ini/ini/blob/3be5ad479f69d4e08d7fe25edf79bf3346bd658e/parser.go#L198-L201