repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
gpmgo/gopm
modules/goconfig/conf.go
Bool
func (c *ConfigFile) Bool(section, key string) (bool, error) { value, err := c.GetValue(section, key) if err != nil { return false, err } return strconv.ParseBool(value) }
go
func (c *ConfigFile) Bool(section, key string) (bool, error) { value, err := c.GetValue(section, key) if err != nil { return false, err } return strconv.ParseBool(value) }
[ "func", "(", "c", "*", "ConfigFile", ")", "Bool", "(", "section", ",", "key", "string", ")", "(", "bool", ",", "error", ")", "{", "value", ",", "err", ":=", "c", ".", "GetValue", "(", "section", ",", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "strconv", ".", "ParseBool", "(", "value", ")", "\n", "}" ]
// Bool returns bool type value.
[ "Bool", "returns", "bool", "type", "value", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L212-L218
train
gpmgo/gopm
modules/goconfig/conf.go
Float64
func (c *ConfigFile) Float64(section, key string) (float64, error) { value, err := c.GetValue(section, key) if err != nil { return 0.0, err } return strconv.ParseFloat(value, 64) }
go
func (c *ConfigFile) Float64(section, key string) (float64, error) { value, err := c.GetValue(section, key) if err != nil { return 0.0, err } return strconv.ParseFloat(value, 64) }
[ "func", "(", "c", "*", "ConfigFile", ")", "Float64", "(", "section", ",", "key", "string", ")", "(", "float64", ",", "error", ")", "{", "value", ",", "err", ":=", "c", ".", "GetValue", "(", "section", ",", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0.0", ",", "err", "\n", "}", "\n", "return", "strconv", ".", "ParseFloat", "(", "value", ",", "64", ")", "\n", "}" ]
// Float64 returns float64 type value.
[ "Float64", "returns", "float64", "type", "value", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L221-L227
train
gpmgo/gopm
modules/goconfig/conf.go
Int64
func (c *ConfigFile) Int64(section, key string) (int64, error) { value, err := c.GetValue(section, key) if err != nil { return 0, err } return strconv.ParseInt(value, 10, 64) }
go
func (c *ConfigFile) Int64(section, key string) (int64, error) { value, err := c.GetValue(section, key) if err != nil { return 0, err } return strconv.ParseInt(value, 10, 64) }
[ "func", "(", "c", "*", "ConfigFile", ")", "Int64", "(", "section", ",", "key", "string", ")", "(", "int64", ",", "error", ")", "{", "value", ",", "err", ":=", "c", ".", "GetValue", "(", "section", ",", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "strconv", ".", "ParseInt", "(", "value", ",", "10", ",", "64", ")", "\n", "}" ]
// Int64 returns int64 type value.
[ "Int64", "returns", "int64", "type", "value", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L239-L245
train
gpmgo/gopm
modules/goconfig/conf.go
MustValue
func (c *ConfigFile) MustValue(section, key string, defaultVal ...string) string { val, err := c.GetValue(section, key) if len(defaultVal) > 0 && (err != nil || len(val) == 0) { return defaultVal[0] } return val }
go
func (c *ConfigFile) MustValue(section, key string, defaultVal ...string) string { val, err := c.GetValue(section, key) if len(defaultVal) > 0 && (err != nil || len(val) == 0) { return defaultVal[0] } return val }
[ "func", "(", "c", "*", "ConfigFile", ")", "MustValue", "(", "section", ",", "key", "string", ",", "defaultVal", "...", "string", ")", "string", "{", "val", ",", "err", ":=", "c", ".", "GetValue", "(", "section", ",", "key", ")", "\n", "if", "len", "(", "defaultVal", ")", ">", "0", "&&", "(", "err", "!=", "nil", "||", "len", "(", "val", ")", "==", "0", ")", "{", "return", "defaultVal", "[", "0", "]", "\n", "}", "\n", "return", "val", "\n", "}" ]
// MustValue always returns value without error. // It returns empty string if error occurs, or the default value if given.
[ "MustValue", "always", "returns", "value", "without", "error", ".", "It", "returns", "empty", "string", "if", "error", "occurs", "or", "the", "default", "value", "if", "given", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L249-L255
train
gpmgo/gopm
modules/goconfig/conf.go
MustValueSet
func (c *ConfigFile) MustValueSet(section, key string, defaultVal ...string) (string, bool) { val, err := c.GetValue(section, key) if len(defaultVal) > 0 && (err != nil || len(val) == 0) { c.SetValue(section, key, defaultVal[0]) return defaultVal[0], true } return val, false }
go
func (c *ConfigFile) MustValueSet(section, key string, defaultVal ...string) (string, bool) { val, err := c.GetValue(section, key) if len(defaultVal) > 0 && (err != nil || len(val) == 0) { c.SetValue(section, key, defaultVal[0]) return defaultVal[0], true } return val, false }
[ "func", "(", "c", "*", "ConfigFile", ")", "MustValueSet", "(", "section", ",", "key", "string", ",", "defaultVal", "...", "string", ")", "(", "string", ",", "bool", ")", "{", "val", ",", "err", ":=", "c", ".", "GetValue", "(", "section", ",", "key", ")", "\n", "if", "len", "(", "defaultVal", ")", ">", "0", "&&", "(", "err", "!=", "nil", "||", "len", "(", "val", ")", "==", "0", ")", "{", "c", ".", "SetValue", "(", "section", ",", "key", ",", "defaultVal", "[", "0", "]", ")", "\n", "return", "defaultVal", "[", "0", "]", ",", "true", "\n", "}", "\n", "return", "val", ",", "false", "\n", "}" ]
// MustValue always returns value without error, // It returns empty string if error occurs, or the default value if given, // and a bool value indicates whether default value is returned.
[ "MustValue", "always", "returns", "value", "without", "error", "It", "returns", "empty", "string", "if", "error", "occurs", "or", "the", "default", "value", "if", "given", "and", "a", "bool", "value", "indicates", "whether", "default", "value", "is", "returned", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L260-L267
train
gpmgo/gopm
modules/goconfig/conf.go
MustValueRange
func (c *ConfigFile) MustValueRange(section, key, defaultVal string, candidates []string) string { val, err := c.GetValue(section, key) if err != nil || len(val) == 0 { return defaultVal } for _, cand := range candidates { if val == cand { return val } } return defaultVal }
go
func (c *ConfigFile) MustValueRange(section, key, defaultVal string, candidates []string) string { val, err := c.GetValue(section, key) if err != nil || len(val) == 0 { return defaultVal } for _, cand := range candidates { if val == cand { return val } } return defaultVal }
[ "func", "(", "c", "*", "ConfigFile", ")", "MustValueRange", "(", "section", ",", "key", ",", "defaultVal", "string", ",", "candidates", "[", "]", "string", ")", "string", "{", "val", ",", "err", ":=", "c", ".", "GetValue", "(", "section", ",", "key", ")", "\n", "if", "err", "!=", "nil", "||", "len", "(", "val", ")", "==", "0", "{", "return", "defaultVal", "\n", "}", "\n\n", "for", "_", ",", "cand", ":=", "range", "candidates", "{", "if", "val", "==", "cand", "{", "return", "val", "\n", "}", "\n", "}", "\n", "return", "defaultVal", "\n", "}" ]
// MustValueRange always returns value without error, // it returns default value if error occurs or doesn't fit into range.
[ "MustValueRange", "always", "returns", "value", "without", "error", "it", "returns", "default", "value", "if", "error", "occurs", "or", "doesn", "t", "fit", "into", "range", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L271-L283
train
gpmgo/gopm
modules/goconfig/conf.go
MustValueArray
func (c *ConfigFile) MustValueArray(section, key, delim string) []string { val, err := c.GetValue(section, key) if err != nil || len(val) == 0 { return []string{} } vals := strings.Split(val, delim) for i := range vals { vals[i] = strings.TrimSpace(vals[i]) } return vals }
go
func (c *ConfigFile) MustValueArray(section, key, delim string) []string { val, err := c.GetValue(section, key) if err != nil || len(val) == 0 { return []string{} } vals := strings.Split(val, delim) for i := range vals { vals[i] = strings.TrimSpace(vals[i]) } return vals }
[ "func", "(", "c", "*", "ConfigFile", ")", "MustValueArray", "(", "section", ",", "key", ",", "delim", "string", ")", "[", "]", "string", "{", "val", ",", "err", ":=", "c", ".", "GetValue", "(", "section", ",", "key", ")", "\n", "if", "err", "!=", "nil", "||", "len", "(", "val", ")", "==", "0", "{", "return", "[", "]", "string", "{", "}", "\n", "}", "\n\n", "vals", ":=", "strings", ".", "Split", "(", "val", ",", "delim", ")", "\n", "for", "i", ":=", "range", "vals", "{", "vals", "[", "i", "]", "=", "strings", ".", "TrimSpace", "(", "vals", "[", "i", "]", ")", "\n", "}", "\n", "return", "vals", "\n", "}" ]
// MustValueArray always returns value array without error, // it returns empty array if error occurs, split by delimiter otherwise.
[ "MustValueArray", "always", "returns", "value", "array", "without", "error", "it", "returns", "empty", "array", "if", "error", "occurs", "split", "by", "delimiter", "otherwise", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L287-L298
train
gpmgo/gopm
modules/goconfig/conf.go
GetSectionList
func (c *ConfigFile) GetSectionList() []string { list := make([]string, len(c.sectionList)) copy(list, c.sectionList) return list }
go
func (c *ConfigFile) GetSectionList() []string { list := make([]string, len(c.sectionList)) copy(list, c.sectionList) return list }
[ "func", "(", "c", "*", "ConfigFile", ")", "GetSectionList", "(", ")", "[", "]", "string", "{", "list", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "c", ".", "sectionList", ")", ")", "\n", "copy", "(", "list", ",", "c", ".", "sectionList", ")", "\n", "return", "list", "\n", "}" ]
// GetSectionList returns the list of all sections // in the same order in the file.
[ "GetSectionList", "returns", "the", "list", "of", "all", "sections", "in", "the", "same", "order", "in", "the", "file", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L342-L346
train
gpmgo/gopm
modules/goconfig/conf.go
GetKeyList
func (c *ConfigFile) GetKeyList(section string) []string { // Blank section name represents DEFAULT section. if len(section) == 0 { section = DEFAULT_SECTION } // Check if section exists. if _, ok := c.data[section]; !ok { return nil } // Non-default section has a blank key as section keeper. offset := 1 if section == DEFAULT_SECTION { offset = 0 } list := make([]string, len(c.keyList[section])-offset) copy(list, c.keyList[section][offset:]) return list }
go
func (c *ConfigFile) GetKeyList(section string) []string { // Blank section name represents DEFAULT section. if len(section) == 0 { section = DEFAULT_SECTION } // Check if section exists. if _, ok := c.data[section]; !ok { return nil } // Non-default section has a blank key as section keeper. offset := 1 if section == DEFAULT_SECTION { offset = 0 } list := make([]string, len(c.keyList[section])-offset) copy(list, c.keyList[section][offset:]) return list }
[ "func", "(", "c", "*", "ConfigFile", ")", "GetKeyList", "(", "section", "string", ")", "[", "]", "string", "{", "// Blank section name represents DEFAULT section.", "if", "len", "(", "section", ")", "==", "0", "{", "section", "=", "DEFAULT_SECTION", "\n", "}", "\n\n", "// Check if section exists.", "if", "_", ",", "ok", ":=", "c", ".", "data", "[", "section", "]", ";", "!", "ok", "{", "return", "nil", "\n", "}", "\n\n", "// Non-default section has a blank key as section keeper.", "offset", ":=", "1", "\n", "if", "section", "==", "DEFAULT_SECTION", "{", "offset", "=", "0", "\n", "}", "\n\n", "list", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "c", ".", "keyList", "[", "section", "]", ")", "-", "offset", ")", "\n", "copy", "(", "list", ",", "c", ".", "keyList", "[", "section", "]", "[", "offset", ":", "]", ")", "\n", "return", "list", "\n", "}" ]
// GetKeyList returns the list of all keys in give section // in the same order in the file. // It returns nil if given section does not exist.
[ "GetKeyList", "returns", "the", "list", "of", "all", "keys", "in", "give", "section", "in", "the", "same", "order", "in", "the", "file", ".", "It", "returns", "nil", "if", "given", "section", "does", "not", "exist", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L351-L371
train
gpmgo/gopm
modules/goconfig/conf.go
DeleteSection
func (c *ConfigFile) DeleteSection(section string) bool { // Blank section name represents DEFAULT section. if len(section) == 0 { section = DEFAULT_SECTION } // Check if section exists. if _, ok := c.data[section]; !ok { return false } delete(c.data, section) // Remove comments of section. c.SetSectionComments(section, "") // Get index of section. i := 0 for _, secName := range c.sectionList { if secName == section { break } i++ } // Remove from section list. c.sectionList = append(c.sectionList[:i], c.sectionList[i+1:]...) return true }
go
func (c *ConfigFile) DeleteSection(section string) bool { // Blank section name represents DEFAULT section. if len(section) == 0 { section = DEFAULT_SECTION } // Check if section exists. if _, ok := c.data[section]; !ok { return false } delete(c.data, section) // Remove comments of section. c.SetSectionComments(section, "") // Get index of section. i := 0 for _, secName := range c.sectionList { if secName == section { break } i++ } // Remove from section list. c.sectionList = append(c.sectionList[:i], c.sectionList[i+1:]...) return true }
[ "func", "(", "c", "*", "ConfigFile", ")", "DeleteSection", "(", "section", "string", ")", "bool", "{", "// Blank section name represents DEFAULT section.", "if", "len", "(", "section", ")", "==", "0", "{", "section", "=", "DEFAULT_SECTION", "\n", "}", "\n\n", "// Check if section exists.", "if", "_", ",", "ok", ":=", "c", ".", "data", "[", "section", "]", ";", "!", "ok", "{", "return", "false", "\n", "}", "\n\n", "delete", "(", "c", ".", "data", ",", "section", ")", "\n", "// Remove comments of section.", "c", ".", "SetSectionComments", "(", "section", ",", "\"", "\"", ")", "\n", "// Get index of section.", "i", ":=", "0", "\n", "for", "_", ",", "secName", ":=", "range", "c", ".", "sectionList", "{", "if", "secName", "==", "section", "{", "break", "\n", "}", "\n", "i", "++", "\n", "}", "\n", "// Remove from section list.", "c", ".", "sectionList", "=", "append", "(", "c", ".", "sectionList", "[", ":", "i", "]", ",", "c", ".", "sectionList", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "return", "true", "\n", "}" ]
// DeleteSection deletes the entire section by given name. // It returns true if the section was deleted, and false if the section didn't exist.
[ "DeleteSection", "deletes", "the", "entire", "section", "by", "given", "name", ".", "It", "returns", "true", "if", "the", "section", "was", "deleted", "and", "false", "if", "the", "section", "didn", "t", "exist", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L375-L400
train
gpmgo/gopm
modules/goconfig/conf.go
GetSection
func (c *ConfigFile) GetSection(section string) (map[string]string, error) { // Blank section name represents DEFAULT section. if len(section) == 0 { section = DEFAULT_SECTION } // Check if section exists. if _, ok := c.data[section]; !ok { // Section does not exist. return nil, getError{ErrSectionNotFound, section} } // Remove pre-defined key. secMap := c.data[section] delete(c.data[section], " ") // Section exists. return secMap, nil }
go
func (c *ConfigFile) GetSection(section string) (map[string]string, error) { // Blank section name represents DEFAULT section. if len(section) == 0 { section = DEFAULT_SECTION } // Check if section exists. if _, ok := c.data[section]; !ok { // Section does not exist. return nil, getError{ErrSectionNotFound, section} } // Remove pre-defined key. secMap := c.data[section] delete(c.data[section], " ") // Section exists. return secMap, nil }
[ "func", "(", "c", "*", "ConfigFile", ")", "GetSection", "(", "section", "string", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "// Blank section name represents DEFAULT section.", "if", "len", "(", "section", ")", "==", "0", "{", "section", "=", "DEFAULT_SECTION", "\n", "}", "\n\n", "// Check if section exists.", "if", "_", ",", "ok", ":=", "c", ".", "data", "[", "section", "]", ";", "!", "ok", "{", "// Section does not exist.", "return", "nil", ",", "getError", "{", "ErrSectionNotFound", ",", "section", "}", "\n", "}", "\n\n", "// Remove pre-defined key.", "secMap", ":=", "c", ".", "data", "[", "section", "]", "\n", "delete", "(", "c", ".", "data", "[", "section", "]", ",", "\"", "\"", ")", "\n\n", "// Section exists.", "return", "secMap", ",", "nil", "\n", "}" ]
// GetSection returns key-value pairs in given section. // It section does not exist, returns nil and error.
[ "GetSection", "returns", "key", "-", "value", "pairs", "in", "given", "section", ".", "It", "section", "does", "not", "exist", "returns", "nil", "and", "error", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L404-L422
train
gpmgo/gopm
modules/doc/struct.go
IsFixed
func (pkg *Pkg) IsFixed() bool { if pkg.Type == BRANCH || len(pkg.Value) == 0 { return false } return true }
go
func (pkg *Pkg) IsFixed() bool { if pkg.Type == BRANCH || len(pkg.Value) == 0 { return false } return true }
[ "func", "(", "pkg", "*", "Pkg", ")", "IsFixed", "(", ")", "bool", "{", "if", "pkg", ".", "Type", "==", "BRANCH", "||", "len", "(", "pkg", ".", "Value", ")", "==", "0", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// If the package is fixed and no need to updated. // For commit, tag and local, it's fixed.
[ "If", "the", "package", "is", "fixed", "and", "no", "need", "to", "updated", ".", "For", "commit", "tag", "and", "local", "it", "s", "fixed", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/doc/struct.go#L88-L93
train
gpmgo/gopm
modules/doc/struct.go
NewNode
func NewNode( importPath string, tp RevisionType, val string, isGetDeps bool) *Node { n := &Node{ Pkg: Pkg{ ImportPath: importPath, RootPath: GetRootPath(importPath), Type: tp, Value: val, }, DownloadURL: importPath, IsGetDeps: isGetDeps, } n.InstallPath = path.Join(setting.InstallRepoPath, n.RootPath) + n.ValSuffix() n.InstallGopath = path.Join(setting.InstallGopath, n.RootPath) return n }
go
func NewNode( importPath string, tp RevisionType, val string, isGetDeps bool) *Node { n := &Node{ Pkg: Pkg{ ImportPath: importPath, RootPath: GetRootPath(importPath), Type: tp, Value: val, }, DownloadURL: importPath, IsGetDeps: isGetDeps, } n.InstallPath = path.Join(setting.InstallRepoPath, n.RootPath) + n.ValSuffix() n.InstallGopath = path.Join(setting.InstallGopath, n.RootPath) return n }
[ "func", "NewNode", "(", "importPath", "string", ",", "tp", "RevisionType", ",", "val", "string", ",", "isGetDeps", "bool", ")", "*", "Node", "{", "n", ":=", "&", "Node", "{", "Pkg", ":", "Pkg", "{", "ImportPath", ":", "importPath", ",", "RootPath", ":", "GetRootPath", "(", "importPath", ")", ",", "Type", ":", "tp", ",", "Value", ":", "val", ",", "}", ",", "DownloadURL", ":", "importPath", ",", "IsGetDeps", ":", "isGetDeps", ",", "}", "\n", "n", ".", "InstallPath", "=", "path", ".", "Join", "(", "setting", ".", "InstallRepoPath", ",", "n", ".", "RootPath", ")", "+", "n", ".", "ValSuffix", "(", ")", "\n", "n", ".", "InstallGopath", "=", "path", ".", "Join", "(", "setting", ".", "InstallGopath", ",", "n", ".", "RootPath", ")", "\n", "return", "n", "\n", "}" ]
// NewNode initializes and returns a new Node representation.
[ "NewNode", "initializes", "and", "returns", "a", "new", "Node", "representation", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/doc/struct.go#L126-L144
train
gpmgo/gopm
modules/doc/struct.go
UpdateByVcs
func (n *Node) UpdateByVcs(vcs string) error { switch vcs { case "git": branch, stderr, err := base.ExecCmdDir(n.InstallGopath, "git", "rev-parse", "--abbrev-ref", "HEAD") if err != nil { log.Error("", "Error occurs when 'git rev-parse --abbrev-ref HEAD'") log.Error("", "\t"+stderr) return errors.New(stderr) } branch = strings.TrimSpace(branch) _, stderr, err = base.ExecCmdDir(n.InstallGopath, "git", "pull", "origin", branch) if err != nil { log.Error("", "Error occurs when 'git pull origin "+branch+"'") log.Error("", "\t"+stderr) return errors.New(stderr) } case "hg": _, stderr, err := base.ExecCmdDir(n.InstallGopath, "hg", "pull") if err != nil { log.Error("", "Error occurs when 'hg pull'") log.Error("", "\t"+stderr) return errors.New(stderr) } _, stderr, err = base.ExecCmdDir(n.InstallGopath, "hg", "up") if err != nil { log.Error("", "Error occurs when 'hg up'") log.Error("", "\t"+stderr) return errors.New(stderr) } case "svn": _, stderr, err := base.ExecCmdDir(n.InstallGopath, "svn", "update") if err != nil { log.Error("", "Error occurs when 'svn update'") log.Error("", "\t"+stderr) return errors.New(stderr) } } return nil }
go
func (n *Node) UpdateByVcs(vcs string) error { switch vcs { case "git": branch, stderr, err := base.ExecCmdDir(n.InstallGopath, "git", "rev-parse", "--abbrev-ref", "HEAD") if err != nil { log.Error("", "Error occurs when 'git rev-parse --abbrev-ref HEAD'") log.Error("", "\t"+stderr) return errors.New(stderr) } branch = strings.TrimSpace(branch) _, stderr, err = base.ExecCmdDir(n.InstallGopath, "git", "pull", "origin", branch) if err != nil { log.Error("", "Error occurs when 'git pull origin "+branch+"'") log.Error("", "\t"+stderr) return errors.New(stderr) } case "hg": _, stderr, err := base.ExecCmdDir(n.InstallGopath, "hg", "pull") if err != nil { log.Error("", "Error occurs when 'hg pull'") log.Error("", "\t"+stderr) return errors.New(stderr) } _, stderr, err = base.ExecCmdDir(n.InstallGopath, "hg", "up") if err != nil { log.Error("", "Error occurs when 'hg up'") log.Error("", "\t"+stderr) return errors.New(stderr) } case "svn": _, stderr, err := base.ExecCmdDir(n.InstallGopath, "svn", "update") if err != nil { log.Error("", "Error occurs when 'svn update'") log.Error("", "\t"+stderr) return errors.New(stderr) } } return nil }
[ "func", "(", "n", "*", "Node", ")", "UpdateByVcs", "(", "vcs", "string", ")", "error", "{", "switch", "vcs", "{", "case", "\"", "\"", ":", "branch", ",", "stderr", ",", "err", ":=", "base", ".", "ExecCmdDir", "(", "n", ".", "InstallGopath", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "log", ".", "Error", "(", "\"", "\"", ",", "\"", "\\t", "\"", "+", "stderr", ")", "\n", "return", "errors", ".", "New", "(", "stderr", ")", "\n", "}", "\n", "branch", "=", "strings", ".", "TrimSpace", "(", "branch", ")", "\n\n", "_", ",", "stderr", ",", "err", "=", "base", ".", "ExecCmdDir", "(", "n", ".", "InstallGopath", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "branch", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "\"", "\"", ",", "\"", "\"", "+", "branch", "+", "\"", "\"", ")", "\n", "log", ".", "Error", "(", "\"", "\"", ",", "\"", "\\t", "\"", "+", "stderr", ")", "\n", "return", "errors", ".", "New", "(", "stderr", ")", "\n", "}", "\n", "case", "\"", "\"", ":", "_", ",", "stderr", ",", "err", ":=", "base", ".", "ExecCmdDir", "(", "n", ".", "InstallGopath", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "log", ".", "Error", "(", "\"", "\"", ",", "\"", "\\t", "\"", "+", "stderr", ")", "\n", "return", "errors", ".", "New", "(", "stderr", ")", "\n", "}", "\n\n", "_", ",", "stderr", ",", "err", "=", "base", ".", "ExecCmdDir", "(", "n", ".", "InstallGopath", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "log", ".", "Error", "(", "\"", "\"", ",", "\"", "\\t", "\"", "+", "stderr", ")", "\n", "return", "errors", ".", "New", "(", "stderr", ")", "\n", "}", "\n", "case", "\"", "\"", ":", "_", ",", "stderr", ",", "err", ":=", "base", ".", "ExecCmdDir", "(", "n", ".", "InstallGopath", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Error", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "log", ".", "Error", "(", "\"", "\"", ",", "\"", "\\t", "\"", "+", "stderr", ")", "\n", "return", "errors", ".", "New", "(", "stderr", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// If vcs has been detected, use corresponding command to update package.
[ "If", "vcs", "has", "been", "detected", "use", "corresponding", "command", "to", "update", "package", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/doc/struct.go#L190-L235
train
gpmgo/gopm
modules/doc/struct.go
Download
func (n *Node) Download(ctx *cli.Context) ([]string, error) { for _, s := range services { if !strings.HasPrefix(n.DownloadURL, s.prefix) { continue } m := s.pattern.FindStringSubmatch(n.DownloadURL) if m == nil { if s.prefix != "" { return nil, errors.New("Cannot match package service prefix by given path") } continue } match := map[string]string{"downloadURL": n.DownloadURL} for i, n := range s.pattern.SubexpNames() { if n != "" { match[n] = m[i] } } return s.get(HttpClient, match, n, ctx) } if n.ImportPath != n.DownloadURL { return nil, errors.New("Didn't find any match service") } log.Info("Cannot match any service, getting dynamic...") return n.getDynamic(HttpClient, ctx) }
go
func (n *Node) Download(ctx *cli.Context) ([]string, error) { for _, s := range services { if !strings.HasPrefix(n.DownloadURL, s.prefix) { continue } m := s.pattern.FindStringSubmatch(n.DownloadURL) if m == nil { if s.prefix != "" { return nil, errors.New("Cannot match package service prefix by given path") } continue } match := map[string]string{"downloadURL": n.DownloadURL} for i, n := range s.pattern.SubexpNames() { if n != "" { match[n] = m[i] } } return s.get(HttpClient, match, n, ctx) } if n.ImportPath != n.DownloadURL { return nil, errors.New("Didn't find any match service") } log.Info("Cannot match any service, getting dynamic...") return n.getDynamic(HttpClient, ctx) }
[ "func", "(", "n", "*", "Node", ")", "Download", "(", "ctx", "*", "cli", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "for", "_", ",", "s", ":=", "range", "services", "{", "if", "!", "strings", ".", "HasPrefix", "(", "n", ".", "DownloadURL", ",", "s", ".", "prefix", ")", "{", "continue", "\n", "}", "\n\n", "m", ":=", "s", ".", "pattern", ".", "FindStringSubmatch", "(", "n", ".", "DownloadURL", ")", "\n", "if", "m", "==", "nil", "{", "if", "s", ".", "prefix", "!=", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "continue", "\n", "}", "\n\n", "match", ":=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "n", ".", "DownloadURL", "}", "\n", "for", "i", ",", "n", ":=", "range", "s", ".", "pattern", ".", "SubexpNames", "(", ")", "{", "if", "n", "!=", "\"", "\"", "{", "match", "[", "n", "]", "=", "m", "[", "i", "]", "\n", "}", "\n", "}", "\n", "return", "s", ".", "get", "(", "HttpClient", ",", "match", ",", "n", ",", "ctx", ")", "\n\n", "}", "\n\n", "if", "n", ".", "ImportPath", "!=", "n", ".", "DownloadURL", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "log", ".", "Info", "(", "\"", "\"", ")", "\n", "return", "n", ".", "getDynamic", "(", "HttpClient", ",", "ctx", ")", "\n", "}" ]
// Download downloads remote package without version control.
[ "Download", "downloads", "remote", "package", "without", "version", "control", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/doc/struct.go#L358-L388
train
gpmgo/gopm
modules/doc/utils.go
ParseTarget
func ParseTarget(target string) string { if len(target) > 0 { return target } for _, gopath := range base.GetGOPATHs() { if strings.HasPrefix(setting.WorkDir, gopath) { target = strings.TrimPrefix(setting.WorkDir, path.Join(gopath, "src")+"/") log.Info("Guess import path: %s", target) return target } } return "." }
go
func ParseTarget(target string) string { if len(target) > 0 { return target } for _, gopath := range base.GetGOPATHs() { if strings.HasPrefix(setting.WorkDir, gopath) { target = strings.TrimPrefix(setting.WorkDir, path.Join(gopath, "src")+"/") log.Info("Guess import path: %s", target) return target } } return "." }
[ "func", "ParseTarget", "(", "target", "string", ")", "string", "{", "if", "len", "(", "target", ")", ">", "0", "{", "return", "target", "\n", "}", "\n\n", "for", "_", ",", "gopath", ":=", "range", "base", ".", "GetGOPATHs", "(", ")", "{", "if", "strings", ".", "HasPrefix", "(", "setting", ".", "WorkDir", ",", "gopath", ")", "{", "target", "=", "strings", ".", "TrimPrefix", "(", "setting", ".", "WorkDir", ",", "path", ".", "Join", "(", "gopath", ",", "\"", "\"", ")", "+", "\"", "\"", ")", "\n", "log", ".", "Info", "(", "\"", "\"", ",", "target", ")", "\n", "return", "target", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// ParseTarget guesses import path of current package if target is empty, // otherwise simply returns the value it gets.
[ "ParseTarget", "guesses", "import", "path", "of", "current", "package", "if", "target", "is", "empty", "otherwise", "simply", "returns", "the", "value", "it", "gets", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/doc/utils.go#L33-L46
train
gpmgo/gopm
modules/doc/utils.go
GetRootPath
func GetRootPath(name string) string { for prefix, num := range setting.RootPathPairs { if strings.HasPrefix(name, prefix) { return joinPath(name, num) } } if strings.HasPrefix(name, "gopkg.in") { m := gopkgPathPattern.FindStringSubmatch(strings.TrimPrefix(name, "gopkg.in")) if m == nil { return name } user := m[1] repo := m[2] return path.Join("gopkg.in", user, repo+"."+m[3]) } return name }
go
func GetRootPath(name string) string { for prefix, num := range setting.RootPathPairs { if strings.HasPrefix(name, prefix) { return joinPath(name, num) } } if strings.HasPrefix(name, "gopkg.in") { m := gopkgPathPattern.FindStringSubmatch(strings.TrimPrefix(name, "gopkg.in")) if m == nil { return name } user := m[1] repo := m[2] return path.Join("gopkg.in", user, repo+"."+m[3]) } return name }
[ "func", "GetRootPath", "(", "name", "string", ")", "string", "{", "for", "prefix", ",", "num", ":=", "range", "setting", ".", "RootPathPairs", "{", "if", "strings", ".", "HasPrefix", "(", "name", ",", "prefix", ")", "{", "return", "joinPath", "(", "name", ",", "num", ")", "\n", "}", "\n", "}", "\n\n", "if", "strings", ".", "HasPrefix", "(", "name", ",", "\"", "\"", ")", "{", "m", ":=", "gopkgPathPattern", ".", "FindStringSubmatch", "(", "strings", ".", "TrimPrefix", "(", "name", ",", "\"", "\"", ")", ")", "\n", "if", "m", "==", "nil", "{", "return", "name", "\n", "}", "\n", "user", ":=", "m", "[", "1", "]", "\n", "repo", ":=", "m", "[", "2", "]", "\n", "return", "path", ".", "Join", "(", "\"", "\"", ",", "user", ",", "repo", "+", "\"", "\"", "+", "m", "[", "3", "]", ")", "\n", "}", "\n", "return", "name", "\n", "}" ]
// GetRootPath returns project root path.
[ "GetRootPath", "returns", "project", "root", "path", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/doc/utils.go#L59-L76
train
gpmgo/gopm
modules/doc/utils.go
ListImports
func ListImports(importPath, rootPath, vendorPath, srcPath, tags string, isTest bool) ([]string, error) { oldGOPATH := os.Getenv("GOPATH") sep := ":" if runtime.GOOS == "windows" { sep = ";" } ctxt := build.Default ctxt.BuildTags = strings.Split(tags, " ") ctxt.GOPATH = vendorPath + sep + oldGOPATH if setting.Debug { log.Debug("Import/root path: %s : %s", importPath, rootPath) log.Debug("Context GOPATH: %s", ctxt.GOPATH) log.Debug("Source path: %s", srcPath) } pkg, err := ctxt.Import(importPath, srcPath, build.AllowBinary) if err != nil { if _, ok := err.(*build.NoGoError); !ok { return nil, fmt.Errorf("fail to get imports(%s): %v", importPath, err) } log.Warn("Getting imports: %v", err) } rawImports := pkg.Imports numImports := len(rawImports) if isTest { rawImports = append(rawImports, pkg.TestImports...) numImports = len(rawImports) } imports := make([]string, 0, numImports) for _, name := range rawImports { if IsGoRepoPath(name) { continue } else if strings.HasPrefix(name, rootPath) { moreImports, err := ListImports(name, rootPath, vendorPath, srcPath, tags, isTest) if err != nil { return nil, err } imports = append(imports, moreImports...) continue } if setting.Debug { log.Debug("Found dependency: %s", name) } imports = append(imports, name) } return imports, nil }
go
func ListImports(importPath, rootPath, vendorPath, srcPath, tags string, isTest bool) ([]string, error) { oldGOPATH := os.Getenv("GOPATH") sep := ":" if runtime.GOOS == "windows" { sep = ";" } ctxt := build.Default ctxt.BuildTags = strings.Split(tags, " ") ctxt.GOPATH = vendorPath + sep + oldGOPATH if setting.Debug { log.Debug("Import/root path: %s : %s", importPath, rootPath) log.Debug("Context GOPATH: %s", ctxt.GOPATH) log.Debug("Source path: %s", srcPath) } pkg, err := ctxt.Import(importPath, srcPath, build.AllowBinary) if err != nil { if _, ok := err.(*build.NoGoError); !ok { return nil, fmt.Errorf("fail to get imports(%s): %v", importPath, err) } log.Warn("Getting imports: %v", err) } rawImports := pkg.Imports numImports := len(rawImports) if isTest { rawImports = append(rawImports, pkg.TestImports...) numImports = len(rawImports) } imports := make([]string, 0, numImports) for _, name := range rawImports { if IsGoRepoPath(name) { continue } else if strings.HasPrefix(name, rootPath) { moreImports, err := ListImports(name, rootPath, vendorPath, srcPath, tags, isTest) if err != nil { return nil, err } imports = append(imports, moreImports...) continue } if setting.Debug { log.Debug("Found dependency: %s", name) } imports = append(imports, name) } return imports, nil }
[ "func", "ListImports", "(", "importPath", ",", "rootPath", ",", "vendorPath", ",", "srcPath", ",", "tags", "string", ",", "isTest", "bool", ")", "(", "[", "]", "string", ",", "error", ")", "{", "oldGOPATH", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "sep", ":=", "\"", "\"", "\n", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "{", "sep", "=", "\"", "\"", "\n", "}", "\n\n", "ctxt", ":=", "build", ".", "Default", "\n", "ctxt", ".", "BuildTags", "=", "strings", ".", "Split", "(", "tags", ",", "\"", "\"", ")", "\n", "ctxt", ".", "GOPATH", "=", "vendorPath", "+", "sep", "+", "oldGOPATH", "\n", "if", "setting", ".", "Debug", "{", "log", ".", "Debug", "(", "\"", "\"", ",", "importPath", ",", "rootPath", ")", "\n", "log", ".", "Debug", "(", "\"", "\"", ",", "ctxt", ".", "GOPATH", ")", "\n", "log", ".", "Debug", "(", "\"", "\"", ",", "srcPath", ")", "\n", "}", "\n", "pkg", ",", "err", ":=", "ctxt", ".", "Import", "(", "importPath", ",", "srcPath", ",", "build", ".", "AllowBinary", ")", "\n", "if", "err", "!=", "nil", "{", "if", "_", ",", "ok", ":=", "err", ".", "(", "*", "build", ".", "NoGoError", ")", ";", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "importPath", ",", "err", ")", "\n", "}", "\n", "log", ".", "Warn", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "rawImports", ":=", "pkg", ".", "Imports", "\n", "numImports", ":=", "len", "(", "rawImports", ")", "\n", "if", "isTest", "{", "rawImports", "=", "append", "(", "rawImports", ",", "pkg", ".", "TestImports", "...", ")", "\n", "numImports", "=", "len", "(", "rawImports", ")", "\n", "}", "\n", "imports", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "numImports", ")", "\n", "for", "_", ",", "name", ":=", "range", "rawImports", "{", "if", "IsGoRepoPath", "(", "name", ")", "{", "continue", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "name", ",", "rootPath", ")", "{", "moreImports", ",", "err", ":=", "ListImports", "(", "name", ",", "rootPath", ",", "vendorPath", ",", "srcPath", ",", "tags", ",", "isTest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "imports", "=", "append", "(", "imports", ",", "moreImports", "...", ")", "\n", "continue", "\n", "}", "\n", "if", "setting", ".", "Debug", "{", "log", ".", "Debug", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "imports", "=", "append", "(", "imports", ",", "name", ")", "\n", "}", "\n", "return", "imports", ",", "nil", "\n", "}" ]
// ListImports checks and returns a list of imports of given import path and options.
[ "ListImports", "checks", "and", "returns", "a", "list", "of", "imports", "of", "given", "import", "path", "and", "options", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/doc/utils.go#L256-L303
train
gpmgo/gopm
modules/doc/utils.go
GetVcsName
func GetVcsName(dirPath string) string { switch { case base.IsExist(path.Join(dirPath, ".git")): return "git" case base.IsExist(path.Join(dirPath, ".hg")): return "hg" case base.IsExist(path.Join(dirPath, ".svn")): return "svn" } return "" }
go
func GetVcsName(dirPath string) string { switch { case base.IsExist(path.Join(dirPath, ".git")): return "git" case base.IsExist(path.Join(dirPath, ".hg")): return "hg" case base.IsExist(path.Join(dirPath, ".svn")): return "svn" } return "" }
[ "func", "GetVcsName", "(", "dirPath", "string", ")", "string", "{", "switch", "{", "case", "base", ".", "IsExist", "(", "path", ".", "Join", "(", "dirPath", ",", "\"", "\"", ")", ")", ":", "return", "\"", "\"", "\n", "case", "base", ".", "IsExist", "(", "path", ".", "Join", "(", "dirPath", ",", "\"", "\"", ")", ")", ":", "return", "\"", "\"", "\n", "case", "base", ".", "IsExist", "(", "path", ".", "Join", "(", "dirPath", ",", "\"", "\"", ")", ")", ":", "return", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// GetVcsName checks whether dirPath has .git .hg .svn else return ""
[ "GetVcsName", "checks", "whether", "dirPath", "has", ".", "git", ".", "hg", ".", "svn", "else", "return" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/doc/utils.go#L306-L316
train
gpmgo/gopm
cmd/list.go
getDepList
func getDepList(ctx *cli.Context, target, pkgPath, vendor string) ([]string, error) { vendorSrc := path.Join(vendor, "src") rootPath := doc.GetRootPath(target) // If work directory is not in GOPATH, then need to setup a vendor path. if !setting.HasGOPATHSetting || !strings.HasPrefix(pkgPath, setting.InstallGopath) { // Make link of self. log.Debug("Linking %s...", rootPath) from := pkgPath to := path.Join(vendorSrc, rootPath) if setting.Debug { log.Debug("Linking from %s to %s", from, to) } if err := autoLink(from, to); err != nil { return nil, err } } imports, err := doc.ListImports(target, rootPath, vendor, pkgPath, ctx.String("tags"), ctx.Bool("test")) if err != nil { return nil, err } list := make([]string, 0, len(imports)) for _, name := range imports { name = doc.GetRootPath(name) if !base.IsSliceContainsStr(list, name) { list = append(list, name) } } sort.Strings(list) return list, nil }
go
func getDepList(ctx *cli.Context, target, pkgPath, vendor string) ([]string, error) { vendorSrc := path.Join(vendor, "src") rootPath := doc.GetRootPath(target) // If work directory is not in GOPATH, then need to setup a vendor path. if !setting.HasGOPATHSetting || !strings.HasPrefix(pkgPath, setting.InstallGopath) { // Make link of self. log.Debug("Linking %s...", rootPath) from := pkgPath to := path.Join(vendorSrc, rootPath) if setting.Debug { log.Debug("Linking from %s to %s", from, to) } if err := autoLink(from, to); err != nil { return nil, err } } imports, err := doc.ListImports(target, rootPath, vendor, pkgPath, ctx.String("tags"), ctx.Bool("test")) if err != nil { return nil, err } list := make([]string, 0, len(imports)) for _, name := range imports { name = doc.GetRootPath(name) if !base.IsSliceContainsStr(list, name) { list = append(list, name) } } sort.Strings(list) return list, nil }
[ "func", "getDepList", "(", "ctx", "*", "cli", ".", "Context", ",", "target", ",", "pkgPath", ",", "vendor", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "vendorSrc", ":=", "path", ".", "Join", "(", "vendor", ",", "\"", "\"", ")", "\n", "rootPath", ":=", "doc", ".", "GetRootPath", "(", "target", ")", "\n", "// If work directory is not in GOPATH, then need to setup a vendor path.", "if", "!", "setting", ".", "HasGOPATHSetting", "||", "!", "strings", ".", "HasPrefix", "(", "pkgPath", ",", "setting", ".", "InstallGopath", ")", "{", "// Make link of self.", "log", ".", "Debug", "(", "\"", "\"", ",", "rootPath", ")", "\n", "from", ":=", "pkgPath", "\n", "to", ":=", "path", ".", "Join", "(", "vendorSrc", ",", "rootPath", ")", "\n", "if", "setting", ".", "Debug", "{", "log", ".", "Debug", "(", "\"", "\"", ",", "from", ",", "to", ")", "\n", "}", "\n", "if", "err", ":=", "autoLink", "(", "from", ",", "to", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "imports", ",", "err", ":=", "doc", ".", "ListImports", "(", "target", ",", "rootPath", ",", "vendor", ",", "pkgPath", ",", "ctx", ".", "String", "(", "\"", "\"", ")", ",", "ctx", ".", "Bool", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "list", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "imports", ")", ")", "\n", "for", "_", ",", "name", ":=", "range", "imports", "{", "name", "=", "doc", ".", "GetRootPath", "(", "name", ")", "\n", "if", "!", "base", ".", "IsSliceContainsStr", "(", "list", ",", "name", ")", "{", "list", "=", "append", "(", "list", ",", "name", ")", "\n", "}", "\n", "}", "\n", "sort", ".", "Strings", "(", "list", ")", "\n", "return", "list", ",", "nil", "\n", "}" ]
// getDepList gets list of dependencies in root path format and nature order.
[ "getDepList", "gets", "list", "of", "dependencies", "in", "root", "path", "format", "and", "nature", "order", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/cmd/list.go#L57-L88
train
gpmgo/gopm
modules/cli/command.go
HasName
func (c Command) HasName(name string) bool { return c.Name == name || c.ShortName == name }
go
func (c Command) HasName(name string) bool { return c.Name == name || c.ShortName == name }
[ "func", "(", "c", "Command", ")", "HasName", "(", "name", "string", ")", "bool", "{", "return", "c", ".", "Name", "==", "name", "||", "c", ".", "ShortName", "==", "name", "\n", "}" ]
// Returns true if Command.Name or Command.ShortName matches given name
[ "Returns", "true", "if", "Command", ".", "Name", "or", "Command", ".", "ShortName", "matches", "given", "name" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/command.go#L106-L108
train
gpmgo/gopm
modules/cae/cae.go
IsEntry
func IsEntry(name string, entries []string) bool { for _, e := range entries { if e == name { return true } } return false }
go
func IsEntry(name string, entries []string) bool { for _, e := range entries { if e == name { return true } } return false }
[ "func", "IsEntry", "(", "name", "string", ",", "entries", "[", "]", "string", ")", "bool", "{", "for", "_", ",", "e", ":=", "range", "entries", "{", "if", "e", "==", "name", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsEntry returns true if name equals to any string in given slice.
[ "IsEntry", "returns", "true", "if", "name", "equals", "to", "any", "string", "in", "given", "slice", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cae/cae.go#L45-L52
train
gpmgo/gopm
modules/cli/help.go
DefaultAppComplete
func DefaultAppComplete(c *Context) { for _, command := range c.App.Commands { fmt.Println(command.Name) if command.ShortName != "" { fmt.Println(command.ShortName) } } }
go
func DefaultAppComplete(c *Context) { for _, command := range c.App.Commands { fmt.Println(command.Name) if command.ShortName != "" { fmt.Println(command.ShortName) } } }
[ "func", "DefaultAppComplete", "(", "c", "*", "Context", ")", "{", "for", "_", ",", "command", ":=", "range", "c", ".", "App", ".", "Commands", "{", "fmt", ".", "Println", "(", "command", ".", "Name", ")", "\n", "if", "command", ".", "ShortName", "!=", "\"", "\"", "{", "fmt", ".", "Println", "(", "command", ".", "ShortName", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Prints the list of subcommands as the default app completion method
[ "Prints", "the", "list", "of", "subcommands", "as", "the", "default", "app", "completion", "method" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/help.go#L107-L114
train
gpmgo/gopm
modules/cli/help.go
ShowCommandHelp
func ShowCommandHelp(c *Context, command string) { for _, c := range c.App.Commands { if c.HasName(command) { HelpPrinter(CommandHelpTemplate, c) return } } if c.App.CommandNotFound != nil { c.App.CommandNotFound(c, command) } else { fmt.Printf("No help topic for '%v'\n", command) } }
go
func ShowCommandHelp(c *Context, command string) { for _, c := range c.App.Commands { if c.HasName(command) { HelpPrinter(CommandHelpTemplate, c) return } } if c.App.CommandNotFound != nil { c.App.CommandNotFound(c, command) } else { fmt.Printf("No help topic for '%v'\n", command) } }
[ "func", "ShowCommandHelp", "(", "c", "*", "Context", ",", "command", "string", ")", "{", "for", "_", ",", "c", ":=", "range", "c", ".", "App", ".", "Commands", "{", "if", "c", ".", "HasName", "(", "command", ")", "{", "HelpPrinter", "(", "CommandHelpTemplate", ",", "c", ")", "\n", "return", "\n", "}", "\n", "}", "\n\n", "if", "c", ".", "App", ".", "CommandNotFound", "!=", "nil", "{", "c", ".", "App", ".", "CommandNotFound", "(", "c", ",", "command", ")", "\n", "}", "else", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "command", ")", "\n", "}", "\n", "}" ]
// Prints help for the given command
[ "Prints", "help", "for", "the", "given", "command" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/help.go#L117-L130
train
gpmgo/gopm
modules/cae/zip/zip.go
List
func (z *ZipArchive) List(prefixes ...string) []string { isHasPrefix := len(prefixes) > 0 names := make([]string, 0, z.NumFiles) for _, f := range z.files { if isHasPrefix && !cae.HasPrefix(f.Name, prefixes) { continue } names = append(names, f.Name) } return names }
go
func (z *ZipArchive) List(prefixes ...string) []string { isHasPrefix := len(prefixes) > 0 names := make([]string, 0, z.NumFiles) for _, f := range z.files { if isHasPrefix && !cae.HasPrefix(f.Name, prefixes) { continue } names = append(names, f.Name) } return names }
[ "func", "(", "z", "*", "ZipArchive", ")", "List", "(", "prefixes", "...", "string", ")", "[", "]", "string", "{", "isHasPrefix", ":=", "len", "(", "prefixes", ")", ">", "0", "\n", "names", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "z", ".", "NumFiles", ")", "\n", "for", "_", ",", "f", ":=", "range", "z", ".", "files", "{", "if", "isHasPrefix", "&&", "!", "cae", ".", "HasPrefix", "(", "f", ".", "Name", ",", "prefixes", ")", "{", "continue", "\n", "}", "\n", "names", "=", "append", "(", "names", ",", "f", ".", "Name", ")", "\n", "}", "\n", "return", "names", "\n", "}" ]
// List returns a string slice of files' name in ZipArchive. // Specify prefixes will be used as filters.
[ "List", "returns", "a", "string", "slice", "of", "files", "name", "in", "ZipArchive", ".", "Specify", "prefixes", "will", "be", "used", "as", "filters", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cae/zip/zip.go#L96-L106
train
gpmgo/gopm
modules/cae/zip/zip.go
AddEmptyDir
func (z *ZipArchive) AddEmptyDir(dirPath string) bool { if !strings.HasSuffix(dirPath, "/") { dirPath += "/" } for _, f := range z.files { if dirPath == f.Name { return false } } dirPath = strings.TrimSuffix(dirPath, "/") if strings.Contains(dirPath, "/") { // Auto add all upper level directories. z.AddEmptyDir(path.Dir(dirPath)) } z.files = append(z.files, &File{ FileHeader: &zip.FileHeader{ Name: dirPath + "/", UncompressedSize: 0, }, }) z.updateStat() return true }
go
func (z *ZipArchive) AddEmptyDir(dirPath string) bool { if !strings.HasSuffix(dirPath, "/") { dirPath += "/" } for _, f := range z.files { if dirPath == f.Name { return false } } dirPath = strings.TrimSuffix(dirPath, "/") if strings.Contains(dirPath, "/") { // Auto add all upper level directories. z.AddEmptyDir(path.Dir(dirPath)) } z.files = append(z.files, &File{ FileHeader: &zip.FileHeader{ Name: dirPath + "/", UncompressedSize: 0, }, }) z.updateStat() return true }
[ "func", "(", "z", "*", "ZipArchive", ")", "AddEmptyDir", "(", "dirPath", "string", ")", "bool", "{", "if", "!", "strings", ".", "HasSuffix", "(", "dirPath", ",", "\"", "\"", ")", "{", "dirPath", "+=", "\"", "\"", "\n", "}", "\n\n", "for", "_", ",", "f", ":=", "range", "z", ".", "files", "{", "if", "dirPath", "==", "f", ".", "Name", "{", "return", "false", "\n", "}", "\n", "}", "\n\n", "dirPath", "=", "strings", ".", "TrimSuffix", "(", "dirPath", ",", "\"", "\"", ")", "\n", "if", "strings", ".", "Contains", "(", "dirPath", ",", "\"", "\"", ")", "{", "// Auto add all upper level directories.", "z", ".", "AddEmptyDir", "(", "path", ".", "Dir", "(", "dirPath", ")", ")", "\n", "}", "\n", "z", ".", "files", "=", "append", "(", "z", ".", "files", ",", "&", "File", "{", "FileHeader", ":", "&", "zip", ".", "FileHeader", "{", "Name", ":", "dirPath", "+", "\"", "\"", ",", "UncompressedSize", ":", "0", ",", "}", ",", "}", ")", "\n", "z", ".", "updateStat", "(", ")", "\n", "return", "true", "\n", "}" ]
// AddEmptyDir adds a raw directory entry to ZipArchive, // it returns false if same directory enry already existed.
[ "AddEmptyDir", "adds", "a", "raw", "directory", "entry", "to", "ZipArchive", "it", "returns", "false", "if", "same", "directory", "enry", "already", "existed", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cae/zip/zip.go#L110-L134
train
gpmgo/gopm
modules/cae/zip/zip.go
AddFile
func (z *ZipArchive) AddFile(fileName, absPath string) error { if cae.IsFilter(absPath) { return nil } f, err := os.Open(absPath) if err != nil { return err } defer f.Close() fi, err := f.Stat() if err != nil { return err } file := new(File) file.FileHeader, err = zip.FileInfoHeader(fi) if err != nil { return err } file.Name = fileName file.absPath = absPath z.AddEmptyDir(path.Dir(fileName)) isExist := false for _, f := range z.files { if fileName == f.Name { f = file isExist = true break } } if !isExist { z.files = append(z.files, file) } z.updateStat() return nil }
go
func (z *ZipArchive) AddFile(fileName, absPath string) error { if cae.IsFilter(absPath) { return nil } f, err := os.Open(absPath) if err != nil { return err } defer f.Close() fi, err := f.Stat() if err != nil { return err } file := new(File) file.FileHeader, err = zip.FileInfoHeader(fi) if err != nil { return err } file.Name = fileName file.absPath = absPath z.AddEmptyDir(path.Dir(fileName)) isExist := false for _, f := range z.files { if fileName == f.Name { f = file isExist = true break } } if !isExist { z.files = append(z.files, file) } z.updateStat() return nil }
[ "func", "(", "z", "*", "ZipArchive", ")", "AddFile", "(", "fileName", ",", "absPath", "string", ")", "error", "{", "if", "cae", ".", "IsFilter", "(", "absPath", ")", "{", "return", "nil", "\n", "}", "\n\n", "f", ",", "err", ":=", "os", ".", "Open", "(", "absPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "fi", ",", "err", ":=", "f", ".", "Stat", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "file", ":=", "new", "(", "File", ")", "\n", "file", ".", "FileHeader", ",", "err", "=", "zip", ".", "FileInfoHeader", "(", "fi", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "file", ".", "Name", "=", "fileName", "\n", "file", ".", "absPath", "=", "absPath", "\n\n", "z", ".", "AddEmptyDir", "(", "path", ".", "Dir", "(", "fileName", ")", ")", "\n\n", "isExist", ":=", "false", "\n", "for", "_", ",", "f", ":=", "range", "z", ".", "files", "{", "if", "fileName", "==", "f", ".", "Name", "{", "f", "=", "file", "\n", "isExist", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "isExist", "{", "z", ".", "files", "=", "append", "(", "z", ".", "files", ",", "file", ")", "\n", "}", "\n\n", "z", ".", "updateStat", "(", ")", "\n", "return", "nil", "\n", "}" ]
// AddFile adds a file entry to ZipArchive.
[ "AddFile", "adds", "a", "file", "entry", "to", "ZipArchive", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cae/zip/zip.go#L174-L214
train
gpmgo/gopm
modules/cli/context.go
NewContext
func NewContext(app *App, set *flag.FlagSet, globalSet *flag.FlagSet) *Context { return &Context{App: app, flagSet: set, globalSet: globalSet} }
go
func NewContext(app *App, set *flag.FlagSet, globalSet *flag.FlagSet) *Context { return &Context{App: app, flagSet: set, globalSet: globalSet} }
[ "func", "NewContext", "(", "app", "*", "App", ",", "set", "*", "flag", ".", "FlagSet", ",", "globalSet", "*", "flag", ".", "FlagSet", ")", "*", "Context", "{", "return", "&", "Context", "{", "App", ":", "app", ",", "flagSet", ":", "set", ",", "globalSet", ":", "globalSet", "}", "\n", "}" ]
// Creates a new context. For use in when invoking an App or Command action.
[ "Creates", "a", "new", "context", ".", "For", "use", "in", "when", "invoking", "an", "App", "or", "Command", "action", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/context.go#L24-L26
train
gpmgo/gopm
modules/cli/context.go
GlobalInt
func (c *Context) GlobalInt(name string) int { return lookupInt(name, c.globalSet) }
go
func (c *Context) GlobalInt(name string) int { return lookupInt(name, c.globalSet) }
[ "func", "(", "c", "*", "Context", ")", "GlobalInt", "(", "name", "string", ")", "int", "{", "return", "lookupInt", "(", "name", ",", "c", ".", "globalSet", ")", "\n", "}" ]
// Looks up the value of a global int flag, returns 0 if no int flag exists
[ "Looks", "up", "the", "value", "of", "a", "global", "int", "flag", "returns", "0", "if", "no", "int", "flag", "exists" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/context.go#L74-L76
train
gpmgo/gopm
modules/cli/context.go
GlobalDuration
func (c *Context) GlobalDuration(name string) time.Duration { return lookupDuration(name, c.globalSet) }
go
func (c *Context) GlobalDuration(name string) time.Duration { return lookupDuration(name, c.globalSet) }
[ "func", "(", "c", "*", "Context", ")", "GlobalDuration", "(", "name", "string", ")", "time", ".", "Duration", "{", "return", "lookupDuration", "(", "name", ",", "c", ".", "globalSet", ")", "\n", "}" ]
// Looks up the value of a global time.Duration flag, returns 0 if no time.Duration flag exists
[ "Looks", "up", "the", "value", "of", "a", "global", "time", ".", "Duration", "flag", "returns", "0", "if", "no", "time", ".", "Duration", "flag", "exists" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/context.go#L79-L81
train
gpmgo/gopm
modules/cli/context.go
GlobalBool
func (c *Context) GlobalBool(name string) bool { return lookupBool(name, c.globalSet) }
go
func (c *Context) GlobalBool(name string) bool { return lookupBool(name, c.globalSet) }
[ "func", "(", "c", "*", "Context", ")", "GlobalBool", "(", "name", "string", ")", "bool", "{", "return", "lookupBool", "(", "name", ",", "c", ".", "globalSet", ")", "\n", "}" ]
// Looks up the value of a global bool flag, returns false if no bool flag exists
[ "Looks", "up", "the", "value", "of", "a", "global", "bool", "flag", "returns", "false", "if", "no", "bool", "flag", "exists" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/context.go#L84-L86
train
gpmgo/gopm
modules/cli/context.go
GlobalString
func (c *Context) GlobalString(name string) string { return lookupString(name, c.globalSet) }
go
func (c *Context) GlobalString(name string) string { return lookupString(name, c.globalSet) }
[ "func", "(", "c", "*", "Context", ")", "GlobalString", "(", "name", "string", ")", "string", "{", "return", "lookupString", "(", "name", ",", "c", ".", "globalSet", ")", "\n", "}" ]
// Looks up the value of a global string flag, returns "" if no string flag exists
[ "Looks", "up", "the", "value", "of", "a", "global", "string", "flag", "returns", "if", "no", "string", "flag", "exists" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/context.go#L89-L91
train
gpmgo/gopm
modules/cli/context.go
GlobalStringSlice
func (c *Context) GlobalStringSlice(name string) []string { return lookupStringSlice(name, c.globalSet) }
go
func (c *Context) GlobalStringSlice(name string) []string { return lookupStringSlice(name, c.globalSet) }
[ "func", "(", "c", "*", "Context", ")", "GlobalStringSlice", "(", "name", "string", ")", "[", "]", "string", "{", "return", "lookupStringSlice", "(", "name", ",", "c", ".", "globalSet", ")", "\n", "}" ]
// Looks up the value of a global string slice flag, returns nil if no string slice flag exists
[ "Looks", "up", "the", "value", "of", "a", "global", "string", "slice", "flag", "returns", "nil", "if", "no", "string", "slice", "flag", "exists" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/context.go#L94-L96
train
gpmgo/gopm
modules/cli/context.go
GlobalIntSlice
func (c *Context) GlobalIntSlice(name string) []int { return lookupIntSlice(name, c.globalSet) }
go
func (c *Context) GlobalIntSlice(name string) []int { return lookupIntSlice(name, c.globalSet) }
[ "func", "(", "c", "*", "Context", ")", "GlobalIntSlice", "(", "name", "string", ")", "[", "]", "int", "{", "return", "lookupIntSlice", "(", "name", ",", "c", ".", "globalSet", ")", "\n", "}" ]
// Looks up the value of a global int slice flag, returns nil if no int slice flag exists
[ "Looks", "up", "the", "value", "of", "a", "global", "int", "slice", "flag", "returns", "nil", "if", "no", "int", "slice", "flag", "exists" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/context.go#L99-L101
train
gpmgo/gopm
modules/cli/context.go
IsSet
func (c *Context) IsSet(name string) bool { if c.setFlags == nil { c.setFlags = make(map[string]bool) c.flagSet.Visit(func(f *flag.Flag) { c.setFlags[f.Name] = true }) } return c.setFlags[name] == true }
go
func (c *Context) IsSet(name string) bool { if c.setFlags == nil { c.setFlags = make(map[string]bool) c.flagSet.Visit(func(f *flag.Flag) { c.setFlags[f.Name] = true }) } return c.setFlags[name] == true }
[ "func", "(", "c", "*", "Context", ")", "IsSet", "(", "name", "string", ")", "bool", "{", "if", "c", ".", "setFlags", "==", "nil", "{", "c", ".", "setFlags", "=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "c", ".", "flagSet", ".", "Visit", "(", "func", "(", "f", "*", "flag", ".", "Flag", ")", "{", "c", ".", "setFlags", "[", "f", ".", "Name", "]", "=", "true", "\n", "}", ")", "\n", "}", "\n", "return", "c", ".", "setFlags", "[", "name", "]", "==", "true", "\n", "}" ]
// Determines if the flag was actually set exists
[ "Determines", "if", "the", "flag", "was", "actually", "set", "exists" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/context.go#L109-L117
train
gpmgo/gopm
cmd/get.go
downloadPackage
func downloadPackage(ctx *cli.Context, n *doc.Node) (*doc.Node, []string, error) { // fmt.Println(n.VerString()) log.Info("Downloading package: %s", n.VerString()) downloadCache.Set(n.VerString()) vendor := base.GetTempDir() defer os.RemoveAll(vendor) var ( err error imports []string srcPath string ) // Check if only need to use VCS tools. vcs := doc.GetVcsName(n.InstallGopath) // If update, gopath and VCS tools set then use VCS tools to update the package. if ctx.Bool("update") && (ctx.Bool("gopath") || ctx.Bool("local")) && len(vcs) > 0 { if err = n.UpdateByVcs(vcs); err != nil { return nil, nil, fmt.Errorf("fail to update by VCS(%s): %v", n.ImportPath, err) } srcPath = n.InstallGopath } else { if !n.IsGetDepsOnly || !n.IsExist() { // Get revision value from local records. n.Revision = setting.LocalNodes.MustValue(n.RootPath, "value") if err = n.DownloadGopm(ctx); err != nil { errors.AppendError(errors.NewErrDownload(n.ImportPath + ": " + err.Error())) failCount++ os.RemoveAll(n.InstallPath) return nil, nil, nil } } srcPath = n.InstallPath } if n.IsGetDeps { imports, err = getDepList(ctx, n.ImportPath, srcPath, vendor) if err != nil { return nil, nil, fmt.Errorf("fail to list imports(%s): %v", n.ImportPath, err) } if setting.Debug { log.Debug("New imports: %v", imports) } } return n, imports, err }
go
func downloadPackage(ctx *cli.Context, n *doc.Node) (*doc.Node, []string, error) { // fmt.Println(n.VerString()) log.Info("Downloading package: %s", n.VerString()) downloadCache.Set(n.VerString()) vendor := base.GetTempDir() defer os.RemoveAll(vendor) var ( err error imports []string srcPath string ) // Check if only need to use VCS tools. vcs := doc.GetVcsName(n.InstallGopath) // If update, gopath and VCS tools set then use VCS tools to update the package. if ctx.Bool("update") && (ctx.Bool("gopath") || ctx.Bool("local")) && len(vcs) > 0 { if err = n.UpdateByVcs(vcs); err != nil { return nil, nil, fmt.Errorf("fail to update by VCS(%s): %v", n.ImportPath, err) } srcPath = n.InstallGopath } else { if !n.IsGetDepsOnly || !n.IsExist() { // Get revision value from local records. n.Revision = setting.LocalNodes.MustValue(n.RootPath, "value") if err = n.DownloadGopm(ctx); err != nil { errors.AppendError(errors.NewErrDownload(n.ImportPath + ": " + err.Error())) failCount++ os.RemoveAll(n.InstallPath) return nil, nil, nil } } srcPath = n.InstallPath } if n.IsGetDeps { imports, err = getDepList(ctx, n.ImportPath, srcPath, vendor) if err != nil { return nil, nil, fmt.Errorf("fail to list imports(%s): %v", n.ImportPath, err) } if setting.Debug { log.Debug("New imports: %v", imports) } } return n, imports, err }
[ "func", "downloadPackage", "(", "ctx", "*", "cli", ".", "Context", ",", "n", "*", "doc", ".", "Node", ")", "(", "*", "doc", ".", "Node", ",", "[", "]", "string", ",", "error", ")", "{", "// fmt.Println(n.VerString())", "log", ".", "Info", "(", "\"", "\"", ",", "n", ".", "VerString", "(", ")", ")", "\n", "downloadCache", ".", "Set", "(", "n", ".", "VerString", "(", ")", ")", "\n\n", "vendor", ":=", "base", ".", "GetTempDir", "(", ")", "\n", "defer", "os", ".", "RemoveAll", "(", "vendor", ")", "\n\n", "var", "(", "err", "error", "\n", "imports", "[", "]", "string", "\n", "srcPath", "string", "\n", ")", "\n\n", "// Check if only need to use VCS tools.", "vcs", ":=", "doc", ".", "GetVcsName", "(", "n", ".", "InstallGopath", ")", "\n", "// If update, gopath and VCS tools set then use VCS tools to update the package.", "if", "ctx", ".", "Bool", "(", "\"", "\"", ")", "&&", "(", "ctx", ".", "Bool", "(", "\"", "\"", ")", "||", "ctx", ".", "Bool", "(", "\"", "\"", ")", ")", "&&", "len", "(", "vcs", ")", ">", "0", "{", "if", "err", "=", "n", ".", "UpdateByVcs", "(", "vcs", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "n", ".", "ImportPath", ",", "err", ")", "\n", "}", "\n", "srcPath", "=", "n", ".", "InstallGopath", "\n", "}", "else", "{", "if", "!", "n", ".", "IsGetDepsOnly", "||", "!", "n", ".", "IsExist", "(", ")", "{", "// Get revision value from local records.", "n", ".", "Revision", "=", "setting", ".", "LocalNodes", ".", "MustValue", "(", "n", ".", "RootPath", ",", "\"", "\"", ")", "\n", "if", "err", "=", "n", ".", "DownloadGopm", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "errors", ".", "AppendError", "(", "errors", ".", "NewErrDownload", "(", "n", ".", "ImportPath", "+", "\"", "\"", "+", "err", ".", "Error", "(", ")", ")", ")", "\n", "failCount", "++", "\n", "os", ".", "RemoveAll", "(", "n", ".", "InstallPath", ")", "\n", "return", "nil", ",", "nil", ",", "nil", "\n", "}", "\n", "}", "\n", "srcPath", "=", "n", ".", "InstallPath", "\n", "}", "\n\n", "if", "n", ".", "IsGetDeps", "{", "imports", ",", "err", "=", "getDepList", "(", "ctx", ",", "n", ".", "ImportPath", ",", "srcPath", ",", "vendor", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "n", ".", "ImportPath", ",", "err", ")", "\n", "}", "\n", "if", "setting", ".", "Debug", "{", "log", ".", "Debug", "(", "\"", "\"", ",", "imports", ")", "\n", "}", "\n", "}", "\n", "return", "n", ",", "imports", ",", "err", "\n", "}" ]
// downloadPackage downloads package either use version control tools or not.
[ "downloadPackage", "downloads", "package", "either", "use", "version", "control", "tools", "or", "not", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/cmd/get.go#L71-L118
train
gpmgo/gopm
modules/goconfig/write.go
SaveConfigFile
func SaveConfigFile(c *ConfigFile, filename string) (err error) { // Write configuration file by filename. var f *os.File if f, err = os.Create(filename); err != nil { return err } equalSign := "=" if PrettyFormat { equalSign = " = " } buf := bytes.NewBuffer(nil) for _, section := range c.sectionList { // Write section comments. if len(c.GetSectionComments(section)) > 0 { if _, err = buf.WriteString(c.GetSectionComments(section) + LineBreak); err != nil { return err } } if section != DEFAULT_SECTION { // Write section name. if _, err = buf.WriteString("[" + section + "]" + LineBreak); err != nil { return err } } for _, key := range c.keyList[section] { if key != " " { // Write key comments. if len(c.GetKeyComments(section, key)) > 0 { if _, err = buf.WriteString(c.GetKeyComments(section, key) + LineBreak); err != nil { return err } } keyName := key // Check if it's auto increment. if keyName[0] == '#' { keyName = "-" } //[SWH|+]:支持键名包含等号和冒号 if strings.Contains(keyName, `=`) || strings.Contains(keyName, `:`) { if strings.Contains(keyName, "`") { if strings.Contains(keyName, `"`) { keyName = `"""` + keyName + `"""` } else { keyName = `"` + keyName + `"` } } else { keyName = "`" + keyName + "`" } } value := c.data[section][key] // In case key value contains "`" or "\"". if strings.Contains(value, "`") { if strings.Contains(value, `"`) { value = `"""` + value + `"""` } else { value = `"` + value + `"` } } // Write key and value. if _, err = buf.WriteString(keyName + equalSign + value + LineBreak); err != nil { return err } } } // Put a line between sections. if _, err = buf.WriteString(LineBreak); err != nil { return err } } if _, err = buf.WriteTo(f); err != nil { return err } return f.Close() }
go
func SaveConfigFile(c *ConfigFile, filename string) (err error) { // Write configuration file by filename. var f *os.File if f, err = os.Create(filename); err != nil { return err } equalSign := "=" if PrettyFormat { equalSign = " = " } buf := bytes.NewBuffer(nil) for _, section := range c.sectionList { // Write section comments. if len(c.GetSectionComments(section)) > 0 { if _, err = buf.WriteString(c.GetSectionComments(section) + LineBreak); err != nil { return err } } if section != DEFAULT_SECTION { // Write section name. if _, err = buf.WriteString("[" + section + "]" + LineBreak); err != nil { return err } } for _, key := range c.keyList[section] { if key != " " { // Write key comments. if len(c.GetKeyComments(section, key)) > 0 { if _, err = buf.WriteString(c.GetKeyComments(section, key) + LineBreak); err != nil { return err } } keyName := key // Check if it's auto increment. if keyName[0] == '#' { keyName = "-" } //[SWH|+]:支持键名包含等号和冒号 if strings.Contains(keyName, `=`) || strings.Contains(keyName, `:`) { if strings.Contains(keyName, "`") { if strings.Contains(keyName, `"`) { keyName = `"""` + keyName + `"""` } else { keyName = `"` + keyName + `"` } } else { keyName = "`" + keyName + "`" } } value := c.data[section][key] // In case key value contains "`" or "\"". if strings.Contains(value, "`") { if strings.Contains(value, `"`) { value = `"""` + value + `"""` } else { value = `"` + value + `"` } } // Write key and value. if _, err = buf.WriteString(keyName + equalSign + value + LineBreak); err != nil { return err } } } // Put a line between sections. if _, err = buf.WriteString(LineBreak); err != nil { return err } } if _, err = buf.WriteTo(f); err != nil { return err } return f.Close() }
[ "func", "SaveConfigFile", "(", "c", "*", "ConfigFile", ",", "filename", "string", ")", "(", "err", "error", ")", "{", "// Write configuration file by filename.", "var", "f", "*", "os", ".", "File", "\n", "if", "f", ",", "err", "=", "os", ".", "Create", "(", "filename", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "equalSign", ":=", "\"", "\"", "\n", "if", "PrettyFormat", "{", "equalSign", "=", "\"", "\"", "\n", "}", "\n\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "nil", ")", "\n", "for", "_", ",", "section", ":=", "range", "c", ".", "sectionList", "{", "// Write section comments.", "if", "len", "(", "c", ".", "GetSectionComments", "(", "section", ")", ")", ">", "0", "{", "if", "_", ",", "err", "=", "buf", ".", "WriteString", "(", "c", ".", "GetSectionComments", "(", "section", ")", "+", "LineBreak", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "section", "!=", "DEFAULT_SECTION", "{", "// Write section name.", "if", "_", ",", "err", "=", "buf", ".", "WriteString", "(", "\"", "\"", "+", "section", "+", "\"", "\"", "+", "LineBreak", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "key", ":=", "range", "c", ".", "keyList", "[", "section", "]", "{", "if", "key", "!=", "\"", "\"", "{", "// Write key comments.", "if", "len", "(", "c", ".", "GetKeyComments", "(", "section", ",", "key", ")", ")", ">", "0", "{", "if", "_", ",", "err", "=", "buf", ".", "WriteString", "(", "c", ".", "GetKeyComments", "(", "section", ",", "key", ")", "+", "LineBreak", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "keyName", ":=", "key", "\n", "// Check if it's auto increment.", "if", "keyName", "[", "0", "]", "==", "'#'", "{", "keyName", "=", "\"", "\"", "\n", "}", "\n", "//[SWH|+]:支持键名包含等号和冒号", "if", "strings", ".", "Contains", "(", "keyName", ",", "`=`", ")", "||", "strings", ".", "Contains", "(", "keyName", ",", "`:`", ")", "{", "if", "strings", ".", "Contains", "(", "keyName", ",", "\"", "\"", ")", "{", "if", "strings", ".", "Contains", "(", "keyName", ",", "`\"`", ")", "{", "keyName", "=", "`\"\"\"`", "+", "keyName", "+", "`\"\"\"`", "\n", "}", "else", "{", "keyName", "=", "`\"`", "+", "keyName", "+", "`\"`", "\n", "}", "\n", "}", "else", "{", "keyName", "=", "\"", "\"", "+", "keyName", "+", "\"", "\"", "\n", "}", "\n", "}", "\n", "value", ":=", "c", ".", "data", "[", "section", "]", "[", "key", "]", "\n", "// In case key value contains \"`\" or \"\\\"\".", "if", "strings", ".", "Contains", "(", "value", ",", "\"", "\"", ")", "{", "if", "strings", ".", "Contains", "(", "value", ",", "`\"`", ")", "{", "value", "=", "`\"\"\"`", "+", "value", "+", "`\"\"\"`", "\n", "}", "else", "{", "value", "=", "`\"`", "+", "value", "+", "`\"`", "\n", "}", "\n", "}", "\n\n", "// Write key and value.", "if", "_", ",", "err", "=", "buf", ".", "WriteString", "(", "keyName", "+", "equalSign", "+", "value", "+", "LineBreak", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Put a line between sections.", "if", "_", ",", "err", "=", "buf", ".", "WriteString", "(", "LineBreak", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "_", ",", "err", "=", "buf", ".", "WriteTo", "(", "f", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "f", ".", "Close", "(", ")", "\n", "}" ]
// SaveConfigFile writes configuration file to local file system
[ "SaveConfigFile", "writes", "configuration", "file", "to", "local", "file", "system" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/write.go#L27-L108
train
gpmgo/gopm
modules/setting/setting.go
LoadGopmfile
func LoadGopmfile(fileName string) (*goconfig.ConfigFile, error) { if !base.IsFile(fileName) { return goconfig.LoadFromData([]byte("")) } gf, err := goconfig.LoadConfigFile(fileName) if err != nil { return nil, fmt.Errorf("Fail to load gopmfile: %v", err) } return gf, nil }
go
func LoadGopmfile(fileName string) (*goconfig.ConfigFile, error) { if !base.IsFile(fileName) { return goconfig.LoadFromData([]byte("")) } gf, err := goconfig.LoadConfigFile(fileName) if err != nil { return nil, fmt.Errorf("Fail to load gopmfile: %v", err) } return gf, nil }
[ "func", "LoadGopmfile", "(", "fileName", "string", ")", "(", "*", "goconfig", ".", "ConfigFile", ",", "error", ")", "{", "if", "!", "base", ".", "IsFile", "(", "fileName", ")", "{", "return", "goconfig", ".", "LoadFromData", "(", "[", "]", "byte", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "gf", ",", "err", ":=", "goconfig", ".", "LoadConfigFile", "(", "fileName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "gf", ",", "nil", "\n", "}" ]
// LoadGopmfile loads and returns given gopmfile.
[ "LoadGopmfile", "loads", "and", "returns", "given", "gopmfile", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/setting/setting.go#L92-L102
train
gpmgo/gopm
modules/setting/setting.go
SaveGopmfile
func SaveGopmfile(gf *goconfig.ConfigFile, fileName string) error { if err := goconfig.SaveConfigFile(gf, fileName); err != nil { return fmt.Errorf("Fail to save gopmfile: %v", err) } return nil }
go
func SaveGopmfile(gf *goconfig.ConfigFile, fileName string) error { if err := goconfig.SaveConfigFile(gf, fileName); err != nil { return fmt.Errorf("Fail to save gopmfile: %v", err) } return nil }
[ "func", "SaveGopmfile", "(", "gf", "*", "goconfig", ".", "ConfigFile", ",", "fileName", "string", ")", "error", "{", "if", "err", ":=", "goconfig", ".", "SaveConfigFile", "(", "gf", ",", "fileName", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SaveGopmfile saves gopmfile to given path.
[ "SaveGopmfile", "saves", "gopmfile", "to", "given", "path", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/setting/setting.go#L105-L110
train
gpmgo/gopm
modules/setting/setting.go
LoadConfig
func LoadConfig() (err error) { if !base.IsExist(ConfigFile) { os.MkdirAll(path.Dir(ConfigFile), os.ModePerm) if _, err = os.Create(ConfigFile); err != nil { return fmt.Errorf("fail to create config file: %v", err) } } Cfg, err = goconfig.LoadConfigFile(ConfigFile) if err != nil { return fmt.Errorf("fail to load config file: %v", err) } HttpProxy = Cfg.MustValue("settings", "HTTP_PROXY") return nil }
go
func LoadConfig() (err error) { if !base.IsExist(ConfigFile) { os.MkdirAll(path.Dir(ConfigFile), os.ModePerm) if _, err = os.Create(ConfigFile); err != nil { return fmt.Errorf("fail to create config file: %v", err) } } Cfg, err = goconfig.LoadConfigFile(ConfigFile) if err != nil { return fmt.Errorf("fail to load config file: %v", err) } HttpProxy = Cfg.MustValue("settings", "HTTP_PROXY") return nil }
[ "func", "LoadConfig", "(", ")", "(", "err", "error", ")", "{", "if", "!", "base", ".", "IsExist", "(", "ConfigFile", ")", "{", "os", ".", "MkdirAll", "(", "path", ".", "Dir", "(", "ConfigFile", ")", ",", "os", ".", "ModePerm", ")", "\n", "if", "_", ",", "err", "=", "os", ".", "Create", "(", "ConfigFile", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "Cfg", ",", "err", "=", "goconfig", ".", "LoadConfigFile", "(", "ConfigFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "HttpProxy", "=", "Cfg", ".", "MustValue", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "return", "nil", "\n", "}" ]
// LoadConfig loads gopm global configuration.
[ "LoadConfig", "loads", "gopm", "global", "configuration", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/setting/setting.go#L113-L128
train
gpmgo/gopm
modules/setting/setting.go
SetConfigValue
func SetConfigValue(section, key, val string) error { Cfg.SetValue(section, key, val) if err := goconfig.SaveConfigFile(Cfg, ConfigFile); err != nil { return fmt.Errorf("fail to set config value(%s:%s=%s): %v", section, key, val, err) } return nil }
go
func SetConfigValue(section, key, val string) error { Cfg.SetValue(section, key, val) if err := goconfig.SaveConfigFile(Cfg, ConfigFile); err != nil { return fmt.Errorf("fail to set config value(%s:%s=%s): %v", section, key, val, err) } return nil }
[ "func", "SetConfigValue", "(", "section", ",", "key", ",", "val", "string", ")", "error", "{", "Cfg", ".", "SetValue", "(", "section", ",", "key", ",", "val", ")", "\n", "if", "err", ":=", "goconfig", ".", "SaveConfigFile", "(", "Cfg", ",", "ConfigFile", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "section", ",", "key", ",", "val", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// SetConfigValue sets and saves gopm configuration.
[ "SetConfigValue", "sets", "and", "saves", "gopm", "configuration", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/setting/setting.go#L131-L137
train
gpmgo/gopm
modules/setting/setting.go
DeleteConfigOption
func DeleteConfigOption(section, key string) error { Cfg.DeleteKey(section, key) if err := goconfig.SaveConfigFile(Cfg, ConfigFile); err != nil { return fmt.Errorf("fail to delete config key(%s:%s): %v", section, key, err) } return nil }
go
func DeleteConfigOption(section, key string) error { Cfg.DeleteKey(section, key) if err := goconfig.SaveConfigFile(Cfg, ConfigFile); err != nil { return fmt.Errorf("fail to delete config key(%s:%s): %v", section, key, err) } return nil }
[ "func", "DeleteConfigOption", "(", "section", ",", "key", "string", ")", "error", "{", "Cfg", ".", "DeleteKey", "(", "section", ",", "key", ")", "\n", "if", "err", ":=", "goconfig", ".", "SaveConfigFile", "(", "Cfg", ",", "ConfigFile", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "section", ",", "key", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DeleteConfigOption deletes and saves gopm configuration.
[ "DeleteConfigOption", "deletes", "and", "saves", "gopm", "configuration", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/setting/setting.go#L140-L146
train
gpmgo/gopm
modules/setting/setting.go
LoadPkgNameList
func LoadPkgNameList() error { if !base.IsFile(PkgNameListFile) { return nil } data, err := ioutil.ReadFile(PkgNameListFile) if err != nil { return fmt.Errorf("fail to load package name list: %v", err) } pkgs := strings.Split(string(data), "\n") for i, line := range pkgs { infos := strings.Split(line, "=") if len(infos) != 2 { // Last item might be empty line. if i == len(pkgs)-1 { continue } return fmt.Errorf("fail to parse package name: %v", line) } PackageNameList[strings.TrimSpace(infos[0])] = strings.TrimSpace(infos[1]) } return nil }
go
func LoadPkgNameList() error { if !base.IsFile(PkgNameListFile) { return nil } data, err := ioutil.ReadFile(PkgNameListFile) if err != nil { return fmt.Errorf("fail to load package name list: %v", err) } pkgs := strings.Split(string(data), "\n") for i, line := range pkgs { infos := strings.Split(line, "=") if len(infos) != 2 { // Last item might be empty line. if i == len(pkgs)-1 { continue } return fmt.Errorf("fail to parse package name: %v", line) } PackageNameList[strings.TrimSpace(infos[0])] = strings.TrimSpace(infos[1]) } return nil }
[ "func", "LoadPkgNameList", "(", ")", "error", "{", "if", "!", "base", ".", "IsFile", "(", "PkgNameListFile", ")", "{", "return", "nil", "\n", "}", "\n\n", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "PkgNameListFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "pkgs", ":=", "strings", ".", "Split", "(", "string", "(", "data", ")", ",", "\"", "\\n", "\"", ")", "\n", "for", "i", ",", "line", ":=", "range", "pkgs", "{", "infos", ":=", "strings", ".", "Split", "(", "line", ",", "\"", "\"", ")", "\n", "if", "len", "(", "infos", ")", "!=", "2", "{", "// Last item might be empty line.", "if", "i", "==", "len", "(", "pkgs", ")", "-", "1", "{", "continue", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "line", ")", "\n", "}", "\n", "PackageNameList", "[", "strings", ".", "TrimSpace", "(", "infos", "[", "0", "]", ")", "]", "=", "strings", ".", "TrimSpace", "(", "infos", "[", "1", "]", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// LoadPkgNameList loads package name pairs.
[ "LoadPkgNameList", "loads", "package", "name", "pairs", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/setting/setting.go#L149-L172
train
gpmgo/gopm
modules/setting/setting.go
GetPkgFullPath
func GetPkgFullPath(short string) (string, error) { name, ok := PackageNameList[short] if !ok { return "", fmt.Errorf("no match package import path with given short name: %s", short) } return name, nil }
go
func GetPkgFullPath(short string) (string, error) { name, ok := PackageNameList[short] if !ok { return "", fmt.Errorf("no match package import path with given short name: %s", short) } return name, nil }
[ "func", "GetPkgFullPath", "(", "short", "string", ")", "(", "string", ",", "error", ")", "{", "name", ",", "ok", ":=", "PackageNameList", "[", "short", "]", "\n", "if", "!", "ok", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "short", ")", "\n", "}", "\n", "return", "name", ",", "nil", "\n", "}" ]
// GetPkgFullPath attmpts to get full path by given package short name.
[ "GetPkgFullPath", "attmpts", "to", "get", "full", "path", "by", "given", "package", "short", "name", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/setting/setting.go#L175-L181
train
gpmgo/gopm
cmd/run.go
validPkgInfo
func validPkgInfo(info string) (doc.RevisionType, string, error) { if len(info) == 0 { return doc.BRANCH, "", nil } infos := strings.Split(info, ":") if len(infos) == 2 { tp := doc.RevisionType(infos[0]) val := infos[1] switch tp { case doc.BRANCH, doc.COMMIT, doc.TAG: default: return "", "", fmt.Errorf("invalid node type: %v", tp) } return tp, val, nil } return "", "", fmt.Errorf("cannot parse dependency version: %v", info) }
go
func validPkgInfo(info string) (doc.RevisionType, string, error) { if len(info) == 0 { return doc.BRANCH, "", nil } infos := strings.Split(info, ":") if len(infos) == 2 { tp := doc.RevisionType(infos[0]) val := infos[1] switch tp { case doc.BRANCH, doc.COMMIT, doc.TAG: default: return "", "", fmt.Errorf("invalid node type: %v", tp) } return tp, val, nil } return "", "", fmt.Errorf("cannot parse dependency version: %v", info) }
[ "func", "validPkgInfo", "(", "info", "string", ")", "(", "doc", ".", "RevisionType", ",", "string", ",", "error", ")", "{", "if", "len", "(", "info", ")", "==", "0", "{", "return", "doc", ".", "BRANCH", ",", "\"", "\"", ",", "nil", "\n", "}", "\n\n", "infos", ":=", "strings", ".", "Split", "(", "info", ",", "\"", "\"", ")", "\n\n", "if", "len", "(", "infos", ")", "==", "2", "{", "tp", ":=", "doc", ".", "RevisionType", "(", "infos", "[", "0", "]", ")", "\n", "val", ":=", "infos", "[", "1", "]", "\n", "switch", "tp", "{", "case", "doc", ".", "BRANCH", ",", "doc", ".", "COMMIT", ",", "doc", ".", "TAG", ":", "default", ":", "return", "\"", "\"", ",", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "tp", ")", "\n", "}", "\n", "return", "tp", ",", "val", ",", "nil", "\n", "}", "\n", "return", "\"", "\"", ",", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "info", ")", "\n", "}" ]
// validPkgInfo checks if the information of the package is valid.
[ "validPkgInfo", "checks", "if", "the", "information", "of", "the", "package", "is", "valid", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/cmd/run.go#L56-L74
train
gpmgo/gopm
modules/cli/app.go
NewApp
func NewApp() *App { return &App{ Name: os.Args[0], Usage: "A new cli application", Version: "0.0.0", BashComplete: DefaultAppComplete, Action: helpCommand.Action, Compiled: compileTime(), } }
go
func NewApp() *App { return &App{ Name: os.Args[0], Usage: "A new cli application", Version: "0.0.0", BashComplete: DefaultAppComplete, Action: helpCommand.Action, Compiled: compileTime(), } }
[ "func", "NewApp", "(", ")", "*", "App", "{", "return", "&", "App", "{", "Name", ":", "os", ".", "Args", "[", "0", "]", ",", "Usage", ":", "\"", "\"", ",", "Version", ":", "\"", "\"", ",", "BashComplete", ":", "DefaultAppComplete", ",", "Action", ":", "helpCommand", ".", "Action", ",", "Compiled", ":", "compileTime", "(", ")", ",", "}", "\n", "}" ]
// Creates a new cli Application with some reasonable defaults for Name, Usage, Version and Action.
[ "Creates", "a", "new", "cli", "Application", "with", "some", "reasonable", "defaults", "for", "Name", "Usage", "Version", "and", "Action", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/app.go#L55-L64
train
gpmgo/gopm
modules/cli/app.go
RunAndExitOnError
func (a *App) RunAndExitOnError() { if err := a.Run(os.Args); err != nil { os.Stderr.WriteString(fmt.Sprintln(err)) os.Exit(1) } }
go
func (a *App) RunAndExitOnError() { if err := a.Run(os.Args); err != nil { os.Stderr.WriteString(fmt.Sprintln(err)) os.Exit(1) } }
[ "func", "(", "a", "*", "App", ")", "RunAndExitOnError", "(", ")", "{", "if", "err", ":=", "a", ".", "Run", "(", "os", ".", "Args", ")", ";", "err", "!=", "nil", "{", "os", ".", "Stderr", ".", "WriteString", "(", "fmt", ".", "Sprintln", "(", "err", ")", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "}" ]
// Another entry point to the cli app, takes care of passing arguments and error handling
[ "Another", "entry", "point", "to", "the", "cli", "app", "takes", "care", "of", "passing", "arguments", "and", "error", "handling" ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cli/app.go#L135-L140
train
gpmgo/gopm
cmd/cmd.go
setup
func setup(ctx *cli.Context) (err error) { setting.Debug = ctx.GlobalBool("debug") log.NonColor = ctx.GlobalBool("noterm") log.Verbose = ctx.Bool("verbose") log.Info("App Version: %s", ctx.App.Version) setting.HomeDir, err = base.HomeDir() if err != nil { return fmt.Errorf("Fail to get home directory: %v", err) } setting.HomeDir = strings.Replace(setting.HomeDir, "\\", "/", -1) setting.InstallRepoPath = path.Join(setting.HomeDir, ".gopm/repos") if runtime.GOOS == "windows" { setting.IsWindows = true } os.MkdirAll(setting.InstallRepoPath, os.ModePerm) log.Info("Local repository path: %s", setting.InstallRepoPath) if !setting.LibraryMode || len(setting.WorkDir) == 0 { setting.WorkDir, err = os.Getwd() if err != nil { return fmt.Errorf("Fail to get work directory: %v", err) } setting.WorkDir = strings.Replace(setting.WorkDir, "\\", "/", -1) } setting.DefaultGopmfile = path.Join(setting.WorkDir, setting.GOPMFILE) setting.DefaultVendor = path.Join(setting.WorkDir, setting.VENDOR) setting.DefaultVendorSrc = path.Join(setting.DefaultVendor, "src") if !ctx.Bool("remote") { if ctx.Bool("local") { // gf, _, _, err := genGopmfile(ctx) // if err != nil { // return err // } // setting.InstallGopath = gf.MustValue("project", "local_gopath") // if ctx.Command.Name != "gen" { // if com.IsDir(setting.InstallGopath) { // log.Log("Indicated local GOPATH: %s", setting.InstallGopath) // setting.InstallGopath += "/src" // } else { // if setting.LibraryMode { // return fmt.Errorf("Local GOPATH does not exist or is not a directory: %s", // setting.InstallGopath) // } // log.Error("", "Invalid local GOPATH path") // log.Error("", "Local GOPATH does not exist or is not a directory:") // log.Error("", "\t"+setting.InstallGopath) // log.Help("Try 'go help gopath' to get more information") // } // } } else { // Get GOPATH. setting.InstallGopath = base.GetGOPATHs()[0] if base.IsDir(setting.InstallGopath) { log.Info("Indicated GOPATH: %s", setting.InstallGopath) setting.InstallGopath += "/src" setting.HasGOPATHSetting = true } else { if ctx.Bool("gopath") { return fmt.Errorf("Local GOPATH does not exist or is not a directory: %s", setting.InstallGopath) } else { // It's OK that no GOPATH setting // when user does not specify to use. log.Warn("No GOPATH setting available") } } } } setting.ConfigFile = path.Join(setting.HomeDir, ".gopm/data/gopm.ini") if err = setting.LoadConfig(); err != nil { return err } setting.PkgNameListFile = path.Join(setting.HomeDir, ".gopm/data/pkgname.list") if err = setting.LoadPkgNameList(); err != nil { return err } setting.LocalNodesFile = path.Join(setting.HomeDir, ".gopm/data/localnodes.list") if err = setting.LoadLocalNodes(); err != nil { return err } return nil }
go
func setup(ctx *cli.Context) (err error) { setting.Debug = ctx.GlobalBool("debug") log.NonColor = ctx.GlobalBool("noterm") log.Verbose = ctx.Bool("verbose") log.Info("App Version: %s", ctx.App.Version) setting.HomeDir, err = base.HomeDir() if err != nil { return fmt.Errorf("Fail to get home directory: %v", err) } setting.HomeDir = strings.Replace(setting.HomeDir, "\\", "/", -1) setting.InstallRepoPath = path.Join(setting.HomeDir, ".gopm/repos") if runtime.GOOS == "windows" { setting.IsWindows = true } os.MkdirAll(setting.InstallRepoPath, os.ModePerm) log.Info("Local repository path: %s", setting.InstallRepoPath) if !setting.LibraryMode || len(setting.WorkDir) == 0 { setting.WorkDir, err = os.Getwd() if err != nil { return fmt.Errorf("Fail to get work directory: %v", err) } setting.WorkDir = strings.Replace(setting.WorkDir, "\\", "/", -1) } setting.DefaultGopmfile = path.Join(setting.WorkDir, setting.GOPMFILE) setting.DefaultVendor = path.Join(setting.WorkDir, setting.VENDOR) setting.DefaultVendorSrc = path.Join(setting.DefaultVendor, "src") if !ctx.Bool("remote") { if ctx.Bool("local") { // gf, _, _, err := genGopmfile(ctx) // if err != nil { // return err // } // setting.InstallGopath = gf.MustValue("project", "local_gopath") // if ctx.Command.Name != "gen" { // if com.IsDir(setting.InstallGopath) { // log.Log("Indicated local GOPATH: %s", setting.InstallGopath) // setting.InstallGopath += "/src" // } else { // if setting.LibraryMode { // return fmt.Errorf("Local GOPATH does not exist or is not a directory: %s", // setting.InstallGopath) // } // log.Error("", "Invalid local GOPATH path") // log.Error("", "Local GOPATH does not exist or is not a directory:") // log.Error("", "\t"+setting.InstallGopath) // log.Help("Try 'go help gopath' to get more information") // } // } } else { // Get GOPATH. setting.InstallGopath = base.GetGOPATHs()[0] if base.IsDir(setting.InstallGopath) { log.Info("Indicated GOPATH: %s", setting.InstallGopath) setting.InstallGopath += "/src" setting.HasGOPATHSetting = true } else { if ctx.Bool("gopath") { return fmt.Errorf("Local GOPATH does not exist or is not a directory: %s", setting.InstallGopath) } else { // It's OK that no GOPATH setting // when user does not specify to use. log.Warn("No GOPATH setting available") } } } } setting.ConfigFile = path.Join(setting.HomeDir, ".gopm/data/gopm.ini") if err = setting.LoadConfig(); err != nil { return err } setting.PkgNameListFile = path.Join(setting.HomeDir, ".gopm/data/pkgname.list") if err = setting.LoadPkgNameList(); err != nil { return err } setting.LocalNodesFile = path.Join(setting.HomeDir, ".gopm/data/localnodes.list") if err = setting.LoadLocalNodes(); err != nil { return err } return nil }
[ "func", "setup", "(", "ctx", "*", "cli", ".", "Context", ")", "(", "err", "error", ")", "{", "setting", ".", "Debug", "=", "ctx", ".", "GlobalBool", "(", "\"", "\"", ")", "\n", "log", ".", "NonColor", "=", "ctx", ".", "GlobalBool", "(", "\"", "\"", ")", "\n", "log", ".", "Verbose", "=", "ctx", ".", "Bool", "(", "\"", "\"", ")", "\n\n", "log", ".", "Info", "(", "\"", "\"", ",", "ctx", ".", "App", ".", "Version", ")", "\n\n", "setting", ".", "HomeDir", ",", "err", "=", "base", ".", "HomeDir", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "setting", ".", "HomeDir", "=", "strings", ".", "Replace", "(", "setting", ".", "HomeDir", ",", "\"", "\\\\", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n\n", "setting", ".", "InstallRepoPath", "=", "path", ".", "Join", "(", "setting", ".", "HomeDir", ",", "\"", "\"", ")", "\n", "if", "runtime", ".", "GOOS", "==", "\"", "\"", "{", "setting", ".", "IsWindows", "=", "true", "\n", "}", "\n", "os", ".", "MkdirAll", "(", "setting", ".", "InstallRepoPath", ",", "os", ".", "ModePerm", ")", "\n", "log", ".", "Info", "(", "\"", "\"", ",", "setting", ".", "InstallRepoPath", ")", "\n\n", "if", "!", "setting", ".", "LibraryMode", "||", "len", "(", "setting", ".", "WorkDir", ")", "==", "0", "{", "setting", ".", "WorkDir", ",", "err", "=", "os", ".", "Getwd", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "setting", ".", "WorkDir", "=", "strings", ".", "Replace", "(", "setting", ".", "WorkDir", ",", "\"", "\\\\", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "}", "\n", "setting", ".", "DefaultGopmfile", "=", "path", ".", "Join", "(", "setting", ".", "WorkDir", ",", "setting", ".", "GOPMFILE", ")", "\n", "setting", ".", "DefaultVendor", "=", "path", ".", "Join", "(", "setting", ".", "WorkDir", ",", "setting", ".", "VENDOR", ")", "\n", "setting", ".", "DefaultVendorSrc", "=", "path", ".", "Join", "(", "setting", ".", "DefaultVendor", ",", "\"", "\"", ")", "\n\n", "if", "!", "ctx", ".", "Bool", "(", "\"", "\"", ")", "{", "if", "ctx", ".", "Bool", "(", "\"", "\"", ")", "{", "// gf, _, _, err := genGopmfile(ctx)", "// if err != nil {", "// \treturn err", "// }", "// setting.InstallGopath = gf.MustValue(\"project\", \"local_gopath\")", "// if ctx.Command.Name != \"gen\" {", "// \tif com.IsDir(setting.InstallGopath) {", "// \t\tlog.Log(\"Indicated local GOPATH: %s\", setting.InstallGopath)", "// \t\tsetting.InstallGopath += \"/src\"", "// \t} else {", "// \t\tif setting.LibraryMode {", "// \t\t\treturn fmt.Errorf(\"Local GOPATH does not exist or is not a directory: %s\",", "// \t\t\t\tsetting.InstallGopath)", "// \t\t}", "// \t\tlog.Error(\"\", \"Invalid local GOPATH path\")", "// \t\tlog.Error(\"\", \"Local GOPATH does not exist or is not a directory:\")", "// \t\tlog.Error(\"\", \"\\t\"+setting.InstallGopath)", "// \t\tlog.Help(\"Try 'go help gopath' to get more information\")", "// \t}", "// }", "}", "else", "{", "// Get GOPATH.", "setting", ".", "InstallGopath", "=", "base", ".", "GetGOPATHs", "(", ")", "[", "0", "]", "\n", "if", "base", ".", "IsDir", "(", "setting", ".", "InstallGopath", ")", "{", "log", ".", "Info", "(", "\"", "\"", ",", "setting", ".", "InstallGopath", ")", "\n", "setting", ".", "InstallGopath", "+=", "\"", "\"", "\n", "setting", ".", "HasGOPATHSetting", "=", "true", "\n", "}", "else", "{", "if", "ctx", ".", "Bool", "(", "\"", "\"", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "setting", ".", "InstallGopath", ")", "\n", "}", "else", "{", "// It's OK that no GOPATH setting", "// when user does not specify to use.", "log", ".", "Warn", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "setting", ".", "ConfigFile", "=", "path", ".", "Join", "(", "setting", ".", "HomeDir", ",", "\"", "\"", ")", "\n", "if", "err", "=", "setting", ".", "LoadConfig", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "setting", ".", "PkgNameListFile", "=", "path", ".", "Join", "(", "setting", ".", "HomeDir", ",", "\"", "\"", ")", "\n", "if", "err", "=", "setting", ".", "LoadPkgNameList", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "setting", ".", "LocalNodesFile", "=", "path", ".", "Join", "(", "setting", ".", "HomeDir", ",", "\"", "\"", ")", "\n", "if", "err", "=", "setting", ".", "LoadLocalNodes", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// setup initializes and checks common environment variables.
[ "setup", "initializes", "and", "checks", "common", "environment", "variables", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/cmd/cmd.go#L35-L124
train
gpmgo/gopm
cmd/cmd.go
isSubpackage
func isSubpackage(rootPath, target string) bool { return strings.HasSuffix(setting.WorkDir, rootPath) || strings.HasPrefix(rootPath, target) }
go
func isSubpackage(rootPath, target string) bool { return strings.HasSuffix(setting.WorkDir, rootPath) || strings.HasPrefix(rootPath, target) }
[ "func", "isSubpackage", "(", "rootPath", ",", "target", "string", ")", "bool", "{", "return", "strings", ".", "HasSuffix", "(", "setting", ".", "WorkDir", ",", "rootPath", ")", "||", "strings", ".", "HasPrefix", "(", "rootPath", ",", "target", ")", "\n", "}" ]
// isSubpackage returns true if given package belongs to current project.
[ "isSubpackage", "returns", "true", "if", "given", "package", "belongs", "to", "current", "project", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/cmd/cmd.go#L180-L183
train
gpmgo/gopm
modules/goconfig/read.go
LoadConfigFile
func LoadConfigFile(fileName string, moreFiles ...string) (c *ConfigFile, err error) { // Append files' name together. fileNames := make([]string, 1, len(moreFiles)+1) fileNames[0] = fileName if len(moreFiles) > 0 { fileNames = append(fileNames, moreFiles...) } c = newConfigFile(fileNames) for _, name := range fileNames { if err = c.loadFile(name); err != nil { return nil, err } } return c, nil }
go
func LoadConfigFile(fileName string, moreFiles ...string) (c *ConfigFile, err error) { // Append files' name together. fileNames := make([]string, 1, len(moreFiles)+1) fileNames[0] = fileName if len(moreFiles) > 0 { fileNames = append(fileNames, moreFiles...) } c = newConfigFile(fileNames) for _, name := range fileNames { if err = c.loadFile(name); err != nil { return nil, err } } return c, nil }
[ "func", "LoadConfigFile", "(", "fileName", "string", ",", "moreFiles", "...", "string", ")", "(", "c", "*", "ConfigFile", ",", "err", "error", ")", "{", "// Append files' name together.", "fileNames", ":=", "make", "(", "[", "]", "string", ",", "1", ",", "len", "(", "moreFiles", ")", "+", "1", ")", "\n", "fileNames", "[", "0", "]", "=", "fileName", "\n", "if", "len", "(", "moreFiles", ")", ">", "0", "{", "fileNames", "=", "append", "(", "fileNames", ",", "moreFiles", "...", ")", "\n", "}", "\n\n", "c", "=", "newConfigFile", "(", "fileNames", ")", "\n\n", "for", "_", ",", "name", ":=", "range", "fileNames", "{", "if", "err", "=", "c", ".", "loadFile", "(", "name", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "return", "c", ",", "nil", "\n", "}" ]
// LoadConfigFile reads a file and returns a new configuration representation. // This representation can be queried with GetValue.
[ "LoadConfigFile", "reads", "a", "file", "and", "returns", "a", "new", "configuration", "representation", ".", "This", "representation", "can", "be", "queried", "with", "GetValue", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/read.go#L196-L213
train
gpmgo/gopm
modules/goconfig/read.go
Reload
func (c *ConfigFile) Reload() (err error) { var cfg *ConfigFile if len(c.fileNames) == 1 { cfg, err = LoadConfigFile(c.fileNames[0]) } else { cfg, err = LoadConfigFile(c.fileNames[0], c.fileNames[1:]...) } if err == nil { *c = *cfg } return err }
go
func (c *ConfigFile) Reload() (err error) { var cfg *ConfigFile if len(c.fileNames) == 1 { cfg, err = LoadConfigFile(c.fileNames[0]) } else { cfg, err = LoadConfigFile(c.fileNames[0], c.fileNames[1:]...) } if err == nil { *c = *cfg } return err }
[ "func", "(", "c", "*", "ConfigFile", ")", "Reload", "(", ")", "(", "err", "error", ")", "{", "var", "cfg", "*", "ConfigFile", "\n", "if", "len", "(", "c", ".", "fileNames", ")", "==", "1", "{", "cfg", ",", "err", "=", "LoadConfigFile", "(", "c", ".", "fileNames", "[", "0", "]", ")", "\n", "}", "else", "{", "cfg", ",", "err", "=", "LoadConfigFile", "(", "c", ".", "fileNames", "[", "0", "]", ",", "c", ".", "fileNames", "[", "1", ":", "]", "...", ")", "\n", "}", "\n\n", "if", "err", "==", "nil", "{", "*", "c", "=", "*", "cfg", "\n", "}", "\n", "return", "err", "\n", "}" ]
// Reload reloads configuration file in case it has changes.
[ "Reload", "reloads", "configuration", "file", "in", "case", "it", "has", "changes", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/read.go#L216-L228
train
gpmgo/gopm
modules/goconfig/read.go
AppendFiles
func (c *ConfigFile) AppendFiles(files ...string) error { c.fileNames = append(c.fileNames, files...) return c.Reload() }
go
func (c *ConfigFile) AppendFiles(files ...string) error { c.fileNames = append(c.fileNames, files...) return c.Reload() }
[ "func", "(", "c", "*", "ConfigFile", ")", "AppendFiles", "(", "files", "...", "string", ")", "error", "{", "c", ".", "fileNames", "=", "append", "(", "c", ".", "fileNames", ",", "files", "...", ")", "\n", "return", "c", ".", "Reload", "(", ")", "\n", "}" ]
// AppendFiles appends more files to ConfigFile and reload automatically.
[ "AppendFiles", "appends", "more", "files", "to", "ConfigFile", "and", "reload", "automatically", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/read.go#L231-L234
train
gpmgo/gopm
modules/cae/zip/write.go
extractFile
func (z *ZipArchive) extractFile(f *File) error { if !z.isHasWriter { for _, zf := range z.ReadCloser.File { if f.Name == zf.Name { return extractFile(zf, path.Dir(f.tmpPath)) } } } return cae.Copy(f.tmpPath, f.absPath) }
go
func (z *ZipArchive) extractFile(f *File) error { if !z.isHasWriter { for _, zf := range z.ReadCloser.File { if f.Name == zf.Name { return extractFile(zf, path.Dir(f.tmpPath)) } } } return cae.Copy(f.tmpPath, f.absPath) }
[ "func", "(", "z", "*", "ZipArchive", ")", "extractFile", "(", "f", "*", "File", ")", "error", "{", "if", "!", "z", ".", "isHasWriter", "{", "for", "_", ",", "zf", ":=", "range", "z", ".", "ReadCloser", ".", "File", "{", "if", "f", ".", "Name", "==", "zf", ".", "Name", "{", "return", "extractFile", "(", "zf", ",", "path", ".", "Dir", "(", "f", ".", "tmpPath", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "cae", ".", "Copy", "(", "f", ".", "tmpPath", ",", "f", ".", "absPath", ")", "\n", "}" ]
// extractFile extracts file from ZipArchive to file system.
[ "extractFile", "extracts", "file", "from", "ZipArchive", "to", "file", "system", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cae/zip/write.go#L151-L160
train
gpmgo/gopm
modules/cae/zip/write.go
packDir
func packDir(srcPath string, recPath string, zw *zip.Writer, fn cae.HookFunc) error { dir, err := os.Open(srcPath) if err != nil { return err } defer dir.Close() fis, err := dir.Readdir(0) if err != nil { return err } for _, fi := range fis { if cae.IsFilter(fi.Name()) { continue } curPath := srcPath + "/" + fi.Name() tmpRecPath := filepath.Join(recPath, fi.Name()) if err = fn(curPath, fi); err != nil { continue } if fi.IsDir() { if err = packFile(srcPath, tmpRecPath, zw, fi); err != nil { return err } err = packDir(curPath, tmpRecPath, zw, fn) } else { err = packFile(curPath, tmpRecPath, zw, fi) } if err != nil { return err } } return nil }
go
func packDir(srcPath string, recPath string, zw *zip.Writer, fn cae.HookFunc) error { dir, err := os.Open(srcPath) if err != nil { return err } defer dir.Close() fis, err := dir.Readdir(0) if err != nil { return err } for _, fi := range fis { if cae.IsFilter(fi.Name()) { continue } curPath := srcPath + "/" + fi.Name() tmpRecPath := filepath.Join(recPath, fi.Name()) if err = fn(curPath, fi); err != nil { continue } if fi.IsDir() { if err = packFile(srcPath, tmpRecPath, zw, fi); err != nil { return err } err = packDir(curPath, tmpRecPath, zw, fn) } else { err = packFile(curPath, tmpRecPath, zw, fi) } if err != nil { return err } } return nil }
[ "func", "packDir", "(", "srcPath", "string", ",", "recPath", "string", ",", "zw", "*", "zip", ".", "Writer", ",", "fn", "cae", ".", "HookFunc", ")", "error", "{", "dir", ",", "err", ":=", "os", ".", "Open", "(", "srcPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "dir", ".", "Close", "(", ")", "\n\n", "fis", ",", "err", ":=", "dir", ".", "Readdir", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "fi", ":=", "range", "fis", "{", "if", "cae", ".", "IsFilter", "(", "fi", ".", "Name", "(", ")", ")", "{", "continue", "\n", "}", "\n", "curPath", ":=", "srcPath", "+", "\"", "\"", "+", "fi", ".", "Name", "(", ")", "\n", "tmpRecPath", ":=", "filepath", ".", "Join", "(", "recPath", ",", "fi", ".", "Name", "(", ")", ")", "\n", "if", "err", "=", "fn", "(", "curPath", ",", "fi", ")", ";", "err", "!=", "nil", "{", "continue", "\n", "}", "\n\n", "if", "fi", ".", "IsDir", "(", ")", "{", "if", "err", "=", "packFile", "(", "srcPath", ",", "tmpRecPath", ",", "zw", ",", "fi", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "packDir", "(", "curPath", ",", "tmpRecPath", ",", "zw", ",", "fn", ")", "\n", "}", "else", "{", "err", "=", "packFile", "(", "curPath", ",", "tmpRecPath", ",", "zw", ",", "fi", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// packDir packs a directory and its subdirectories and files // recursively to zip.Writer.
[ "packDir", "packs", "a", "directory", "and", "its", "subdirectories", "and", "files", "recursively", "to", "zip", ".", "Writer", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cae/zip/write.go#L243-L277
train
gpmgo/gopm
modules/cae/zip/write.go
packToWriter
func packToWriter(srcPath string, w io.Writer, fn func(fullName string, fi os.FileInfo) error, includeDir bool) error { zw := zip.NewWriter(w) defer zw.Close() f, err := os.Open(srcPath) if err != nil { return err } defer f.Close() fi, err := f.Stat() if err != nil { return err } basePath := path.Base(srcPath) if fi.IsDir() { if includeDir { if err = packFile(srcPath, basePath, zw, fi); err != nil { return err } } else { basePath = "" } return packDir(srcPath, basePath, zw, fn) } return packFile(srcPath, basePath, zw, fi) }
go
func packToWriter(srcPath string, w io.Writer, fn func(fullName string, fi os.FileInfo) error, includeDir bool) error { zw := zip.NewWriter(w) defer zw.Close() f, err := os.Open(srcPath) if err != nil { return err } defer f.Close() fi, err := f.Stat() if err != nil { return err } basePath := path.Base(srcPath) if fi.IsDir() { if includeDir { if err = packFile(srcPath, basePath, zw, fi); err != nil { return err } } else { basePath = "" } return packDir(srcPath, basePath, zw, fn) } return packFile(srcPath, basePath, zw, fi) }
[ "func", "packToWriter", "(", "srcPath", "string", ",", "w", "io", ".", "Writer", ",", "fn", "func", "(", "fullName", "string", ",", "fi", "os", ".", "FileInfo", ")", "error", ",", "includeDir", "bool", ")", "error", "{", "zw", ":=", "zip", ".", "NewWriter", "(", "w", ")", "\n", "defer", "zw", ".", "Close", "(", ")", "\n\n", "f", ",", "err", ":=", "os", ".", "Open", "(", "srcPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "fi", ",", "err", ":=", "f", ".", "Stat", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "basePath", ":=", "path", ".", "Base", "(", "srcPath", ")", "\n", "if", "fi", ".", "IsDir", "(", ")", "{", "if", "includeDir", "{", "if", "err", "=", "packFile", "(", "srcPath", ",", "basePath", ",", "zw", ",", "fi", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "else", "{", "basePath", "=", "\"", "\"", "\n", "}", "\n", "return", "packDir", "(", "srcPath", ",", "basePath", ",", "zw", ",", "fn", ")", "\n", "}", "\n", "return", "packFile", "(", "srcPath", ",", "basePath", ",", "zw", ",", "fi", ")", "\n", "}" ]
// packToWriter packs given path object to io.Writer.
[ "packToWriter", "packs", "given", "path", "object", "to", "io", ".", "Writer", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cae/zip/write.go#L280-L307
train
gpmgo/gopm
modules/cae/zip/write.go
packTo
func packTo(srcPath, destPath string, fn cae.HookFunc, includeDir bool) error { fw, err := os.Create(destPath) if err != nil { return err } defer fw.Close() return packToWriter(srcPath, fw, fn, includeDir) }
go
func packTo(srcPath, destPath string, fn cae.HookFunc, includeDir bool) error { fw, err := os.Create(destPath) if err != nil { return err } defer fw.Close() return packToWriter(srcPath, fw, fn, includeDir) }
[ "func", "packTo", "(", "srcPath", ",", "destPath", "string", ",", "fn", "cae", ".", "HookFunc", ",", "includeDir", "bool", ")", "error", "{", "fw", ",", "err", ":=", "os", ".", "Create", "(", "destPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "fw", ".", "Close", "(", ")", "\n\n", "return", "packToWriter", "(", "srcPath", ",", "fw", ",", "fn", ",", "includeDir", ")", "\n", "}" ]
// packTo packs given source path object to target path.
[ "packTo", "packs", "given", "source", "path", "object", "to", "target", "path", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/cae/zip/write.go#L310-L318
train
go-gorp/gorp
gorp.go
maybeExpandNamedQueryAndExec
func maybeExpandNamedQueryAndExec(e SqlExecutor, query string, args ...interface{}) (sql.Result, error) { dbMap := extractDbMap(e) if len(args) == 1 { query, args = maybeExpandNamedQuery(dbMap, query, args) } return exec(e, query, args...) }
go
func maybeExpandNamedQueryAndExec(e SqlExecutor, query string, args ...interface{}) (sql.Result, error) { dbMap := extractDbMap(e) if len(args) == 1 { query, args = maybeExpandNamedQuery(dbMap, query, args) } return exec(e, query, args...) }
[ "func", "maybeExpandNamedQueryAndExec", "(", "e", "SqlExecutor", ",", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "sql", ".", "Result", ",", "error", ")", "{", "dbMap", ":=", "extractDbMap", "(", "e", ")", "\n\n", "if", "len", "(", "args", ")", "==", "1", "{", "query", ",", "args", "=", "maybeExpandNamedQuery", "(", "dbMap", ",", "query", ",", "args", ")", "\n", "}", "\n\n", "return", "exec", "(", "e", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// Calls the Exec function on the executor, but attempts to expand any eligible named // query arguments first.
[ "Calls", "the", "Exec", "function", "on", "the", "executor", "but", "attempts", "to", "expand", "any", "eligible", "named", "query", "arguments", "first", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/gorp.go#L166-L174
train
go-gorp/gorp
column.go
SetTransient
func (c *ColumnMap) SetTransient(b bool) *ColumnMap { c.Transient = b return c }
go
func (c *ColumnMap) SetTransient(b bool) *ColumnMap { c.Transient = b return c }
[ "func", "(", "c", "*", "ColumnMap", ")", "SetTransient", "(", "b", "bool", ")", "*", "ColumnMap", "{", "c", ".", "Transient", "=", "b", "\n", "return", "c", "\n", "}" ]
// SetTransient allows you to mark the column as transient. If true // this column will be skipped when SQL statements are generated
[ "SetTransient", "allows", "you", "to", "mark", "the", "column", "as", "transient", ".", "If", "true", "this", "column", "will", "be", "skipped", "when", "SQL", "statements", "are", "generated" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/column.go#L58-L61
train
go-gorp/gorp
column.go
SetUnique
func (c *ColumnMap) SetUnique(b bool) *ColumnMap { c.Unique = b return c }
go
func (c *ColumnMap) SetUnique(b bool) *ColumnMap { c.Unique = b return c }
[ "func", "(", "c", "*", "ColumnMap", ")", "SetUnique", "(", "b", "bool", ")", "*", "ColumnMap", "{", "c", ".", "Unique", "=", "b", "\n", "return", "c", "\n", "}" ]
// SetUnique adds "unique" to the create table statements for this // column, if b is true.
[ "SetUnique", "adds", "unique", "to", "the", "create", "table", "statements", "for", "this", "column", "if", "b", "is", "true", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/column.go#L65-L68
train
go-gorp/gorp
column.go
SetNotNull
func (c *ColumnMap) SetNotNull(nn bool) *ColumnMap { c.isNotNull = nn return c }
go
func (c *ColumnMap) SetNotNull(nn bool) *ColumnMap { c.isNotNull = nn return c }
[ "func", "(", "c", "*", "ColumnMap", ")", "SetNotNull", "(", "nn", "bool", ")", "*", "ColumnMap", "{", "c", ".", "isNotNull", "=", "nn", "\n", "return", "c", "\n", "}" ]
// SetNotNull adds "not null" to the create table statements for this // column, if nn is true.
[ "SetNotNull", "adds", "not", "null", "to", "the", "create", "table", "statements", "for", "this", "column", "if", "nn", "is", "true", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/column.go#L72-L75
train
go-gorp/gorp
table.go
IdxMap
func (t *TableMap) IdxMap(field string) *IndexMap { for _, idx := range t.indexes { if idx.IndexName == field { return idx } } return nil }
go
func (t *TableMap) IdxMap(field string) *IndexMap { for _, idx := range t.indexes { if idx.IndexName == field { return idx } } return nil }
[ "func", "(", "t", "*", "TableMap", ")", "IdxMap", "(", "field", "string", ")", "*", "IndexMap", "{", "for", "_", ",", "idx", ":=", "range", "t", ".", "indexes", "{", "if", "idx", ".", "IndexName", "==", "field", "{", "return", "idx", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// IdxMap returns the IndexMap pointer matching the given index name.
[ "IdxMap", "returns", "the", "IndexMap", "pointer", "matching", "the", "given", "index", "name", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/table.go#L130-L137
train
go-gorp/gorp
table.go
SqlForCreate
func (t *TableMap) SqlForCreate(ifNotExists bool) string { s := bytes.Buffer{} dialect := t.dbmap.Dialect if strings.TrimSpace(t.SchemaName) != "" { schemaCreate := "create schema" if ifNotExists { s.WriteString(dialect.IfSchemaNotExists(schemaCreate, t.SchemaName)) } else { s.WriteString(schemaCreate) } s.WriteString(fmt.Sprintf(" %s;", t.SchemaName)) } tableCreate := "create table" if ifNotExists { s.WriteString(dialect.IfTableNotExists(tableCreate, t.SchemaName, t.TableName)) } else { s.WriteString(tableCreate) } s.WriteString(fmt.Sprintf(" %s (", dialect.QuotedTableForQuery(t.SchemaName, t.TableName))) x := 0 for _, col := range t.Columns { if !col.Transient { if x > 0 { s.WriteString(", ") } stype := dialect.ToSqlType(col.gotype, col.MaxSize, col.isAutoIncr) s.WriteString(fmt.Sprintf("%s %s", dialect.QuoteField(col.ColumnName), stype)) if col.isPK || col.isNotNull { s.WriteString(" not null") } if col.isPK && len(t.keys) == 1 { s.WriteString(" primary key") } if col.Unique { s.WriteString(" unique") } if col.isAutoIncr { s.WriteString(fmt.Sprintf(" %s", dialect.AutoIncrStr())) } x++ } } if len(t.keys) > 1 { s.WriteString(", primary key (") for x := range t.keys { if x > 0 { s.WriteString(", ") } s.WriteString(dialect.QuoteField(t.keys[x].ColumnName)) } s.WriteString(")") } if len(t.uniqueTogether) > 0 { for _, columns := range t.uniqueTogether { s.WriteString(", unique (") for i, column := range columns { if i > 0 { s.WriteString(", ") } s.WriteString(dialect.QuoteField(column)) } s.WriteString(")") } } s.WriteString(") ") s.WriteString(dialect.CreateTableSuffix()) s.WriteString(dialect.QuerySuffix()) return s.String() }
go
func (t *TableMap) SqlForCreate(ifNotExists bool) string { s := bytes.Buffer{} dialect := t.dbmap.Dialect if strings.TrimSpace(t.SchemaName) != "" { schemaCreate := "create schema" if ifNotExists { s.WriteString(dialect.IfSchemaNotExists(schemaCreate, t.SchemaName)) } else { s.WriteString(schemaCreate) } s.WriteString(fmt.Sprintf(" %s;", t.SchemaName)) } tableCreate := "create table" if ifNotExists { s.WriteString(dialect.IfTableNotExists(tableCreate, t.SchemaName, t.TableName)) } else { s.WriteString(tableCreate) } s.WriteString(fmt.Sprintf(" %s (", dialect.QuotedTableForQuery(t.SchemaName, t.TableName))) x := 0 for _, col := range t.Columns { if !col.Transient { if x > 0 { s.WriteString(", ") } stype := dialect.ToSqlType(col.gotype, col.MaxSize, col.isAutoIncr) s.WriteString(fmt.Sprintf("%s %s", dialect.QuoteField(col.ColumnName), stype)) if col.isPK || col.isNotNull { s.WriteString(" not null") } if col.isPK && len(t.keys) == 1 { s.WriteString(" primary key") } if col.Unique { s.WriteString(" unique") } if col.isAutoIncr { s.WriteString(fmt.Sprintf(" %s", dialect.AutoIncrStr())) } x++ } } if len(t.keys) > 1 { s.WriteString(", primary key (") for x := range t.keys { if x > 0 { s.WriteString(", ") } s.WriteString(dialect.QuoteField(t.keys[x].ColumnName)) } s.WriteString(")") } if len(t.uniqueTogether) > 0 { for _, columns := range t.uniqueTogether { s.WriteString(", unique (") for i, column := range columns { if i > 0 { s.WriteString(", ") } s.WriteString(dialect.QuoteField(column)) } s.WriteString(")") } } s.WriteString(") ") s.WriteString(dialect.CreateTableSuffix()) s.WriteString(dialect.QuerySuffix()) return s.String() }
[ "func", "(", "t", "*", "TableMap", ")", "SqlForCreate", "(", "ifNotExists", "bool", ")", "string", "{", "s", ":=", "bytes", ".", "Buffer", "{", "}", "\n", "dialect", ":=", "t", ".", "dbmap", ".", "Dialect", "\n\n", "if", "strings", ".", "TrimSpace", "(", "t", ".", "SchemaName", ")", "!=", "\"", "\"", "{", "schemaCreate", ":=", "\"", "\"", "\n", "if", "ifNotExists", "{", "s", ".", "WriteString", "(", "dialect", ".", "IfSchemaNotExists", "(", "schemaCreate", ",", "t", ".", "SchemaName", ")", ")", "\n", "}", "else", "{", "s", ".", "WriteString", "(", "schemaCreate", ")", "\n", "}", "\n", "s", ".", "WriteString", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "t", ".", "SchemaName", ")", ")", "\n", "}", "\n\n", "tableCreate", ":=", "\"", "\"", "\n", "if", "ifNotExists", "{", "s", ".", "WriteString", "(", "dialect", ".", "IfTableNotExists", "(", "tableCreate", ",", "t", ".", "SchemaName", ",", "t", ".", "TableName", ")", ")", "\n", "}", "else", "{", "s", ".", "WriteString", "(", "tableCreate", ")", "\n", "}", "\n", "s", ".", "WriteString", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dialect", ".", "QuotedTableForQuery", "(", "t", ".", "SchemaName", ",", "t", ".", "TableName", ")", ")", ")", "\n\n", "x", ":=", "0", "\n", "for", "_", ",", "col", ":=", "range", "t", ".", "Columns", "{", "if", "!", "col", ".", "Transient", "{", "if", "x", ">", "0", "{", "s", ".", "WriteString", "(", "\"", "\"", ")", "\n", "}", "\n", "stype", ":=", "dialect", ".", "ToSqlType", "(", "col", ".", "gotype", ",", "col", ".", "MaxSize", ",", "col", ".", "isAutoIncr", ")", "\n", "s", ".", "WriteString", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dialect", ".", "QuoteField", "(", "col", ".", "ColumnName", ")", ",", "stype", ")", ")", "\n\n", "if", "col", ".", "isPK", "||", "col", ".", "isNotNull", "{", "s", ".", "WriteString", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "col", ".", "isPK", "&&", "len", "(", "t", ".", "keys", ")", "==", "1", "{", "s", ".", "WriteString", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "col", ".", "Unique", "{", "s", ".", "WriteString", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "col", ".", "isAutoIncr", "{", "s", ".", "WriteString", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dialect", ".", "AutoIncrStr", "(", ")", ")", ")", "\n", "}", "\n\n", "x", "++", "\n", "}", "\n", "}", "\n", "if", "len", "(", "t", ".", "keys", ")", ">", "1", "{", "s", ".", "WriteString", "(", "\"", "\"", ")", "\n", "for", "x", ":=", "range", "t", ".", "keys", "{", "if", "x", ">", "0", "{", "s", ".", "WriteString", "(", "\"", "\"", ")", "\n", "}", "\n", "s", ".", "WriteString", "(", "dialect", ".", "QuoteField", "(", "t", ".", "keys", "[", "x", "]", ".", "ColumnName", ")", ")", "\n", "}", "\n", "s", ".", "WriteString", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "t", ".", "uniqueTogether", ")", ">", "0", "{", "for", "_", ",", "columns", ":=", "range", "t", ".", "uniqueTogether", "{", "s", ".", "WriteString", "(", "\"", "\"", ")", "\n", "for", "i", ",", "column", ":=", "range", "columns", "{", "if", "i", ">", "0", "{", "s", ".", "WriteString", "(", "\"", "\"", ")", "\n", "}", "\n", "s", ".", "WriteString", "(", "dialect", ".", "QuoteField", "(", "column", ")", ")", "\n", "}", "\n", "s", ".", "WriteString", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "s", ".", "WriteString", "(", "\"", "\"", ")", "\n", "s", ".", "WriteString", "(", "dialect", ".", "CreateTableSuffix", "(", ")", ")", "\n", "s", ".", "WriteString", "(", "dialect", ".", "QuerySuffix", "(", ")", ")", "\n", "return", "s", ".", "String", "(", ")", "\n", "}" ]
// SqlForCreateTable gets a sequence of SQL commands that will create // the specified table and any associated schema
[ "SqlForCreateTable", "gets", "a", "sequence", "of", "SQL", "commands", "that", "will", "create", "the", "specified", "table", "and", "any", "associated", "schema" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/table.go#L180-L253
train
go-gorp/gorp
dialect_mysql.go
CreateTableSuffix
func (d MySQLDialect) CreateTableSuffix() string { if d.Engine == "" || d.Encoding == "" { msg := "gorp - undefined" if d.Engine == "" { msg += " MySQLDialect.Engine" } if d.Engine == "" && d.Encoding == "" { msg += "," } if d.Encoding == "" { msg += " MySQLDialect.Encoding" } msg += ". Check that your MySQLDialect was correctly initialized when declared." panic(msg) } return fmt.Sprintf(" engine=%s charset=%s", d.Engine, d.Encoding) }
go
func (d MySQLDialect) CreateTableSuffix() string { if d.Engine == "" || d.Encoding == "" { msg := "gorp - undefined" if d.Engine == "" { msg += " MySQLDialect.Engine" } if d.Engine == "" && d.Encoding == "" { msg += "," } if d.Encoding == "" { msg += " MySQLDialect.Encoding" } msg += ". Check that your MySQLDialect was correctly initialized when declared." panic(msg) } return fmt.Sprintf(" engine=%s charset=%s", d.Engine, d.Encoding) }
[ "func", "(", "d", "MySQLDialect", ")", "CreateTableSuffix", "(", ")", "string", "{", "if", "d", ".", "Engine", "==", "\"", "\"", "||", "d", ".", "Encoding", "==", "\"", "\"", "{", "msg", ":=", "\"", "\"", "\n\n", "if", "d", ".", "Engine", "==", "\"", "\"", "{", "msg", "+=", "\"", "\"", "\n", "}", "\n", "if", "d", ".", "Engine", "==", "\"", "\"", "&&", "d", ".", "Encoding", "==", "\"", "\"", "{", "msg", "+=", "\"", "\"", "\n", "}", "\n", "if", "d", ".", "Encoding", "==", "\"", "\"", "{", "msg", "+=", "\"", "\"", "\n", "}", "\n", "msg", "+=", "\"", "\"", "\n", "panic", "(", "msg", ")", "\n", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "d", ".", "Engine", ",", "d", ".", "Encoding", ")", "\n", "}" ]
// Returns engine=%s charset=%s based on values stored on struct
[ "Returns", "engine", "=", "%s", "charset", "=", "%s", "based", "on", "values", "stored", "on", "struct" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/dialect_mysql.go#L109-L127
train
go-gorp/gorp
db.go
AddTableWithName
func (m *DbMap) AddTableWithName(i interface{}, name string) *TableMap { return m.AddTableWithNameAndSchema(i, "", name) }
go
func (m *DbMap) AddTableWithName(i interface{}, name string) *TableMap { return m.AddTableWithNameAndSchema(i, "", name) }
[ "func", "(", "m", "*", "DbMap", ")", "AddTableWithName", "(", "i", "interface", "{", "}", ",", "name", "string", ")", "*", "TableMap", "{", "return", "m", ".", "AddTableWithNameAndSchema", "(", "i", ",", "\"", "\"", ",", "name", ")", "\n", "}" ]
// AddTableWithName has the same behavior as AddTable, but sets // table.TableName to name.
[ "AddTableWithName", "has", "the", "same", "behavior", "as", "AddTable", "but", "sets", "table", ".", "TableName", "to", "name", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L225-L227
train
go-gorp/gorp
db.go
AddTableWithNameAndSchema
func (m *DbMap) AddTableWithNameAndSchema(i interface{}, schema string, name string) *TableMap { t := reflect.TypeOf(i) if name == "" { name = t.Name() } // check if we have a table for this type already // if so, update the name and return the existing pointer for i := range m.tables { table := m.tables[i] if table.gotype == t { table.TableName = name return table } } tmap := &TableMap{gotype: t, TableName: name, SchemaName: schema, dbmap: m} var primaryKey []*ColumnMap tmap.Columns, primaryKey = m.readStructColumns(t) m.tables = append(m.tables, tmap) if len(primaryKey) > 0 { tmap.keys = append(tmap.keys, primaryKey...) } return tmap }
go
func (m *DbMap) AddTableWithNameAndSchema(i interface{}, schema string, name string) *TableMap { t := reflect.TypeOf(i) if name == "" { name = t.Name() } // check if we have a table for this type already // if so, update the name and return the existing pointer for i := range m.tables { table := m.tables[i] if table.gotype == t { table.TableName = name return table } } tmap := &TableMap{gotype: t, TableName: name, SchemaName: schema, dbmap: m} var primaryKey []*ColumnMap tmap.Columns, primaryKey = m.readStructColumns(t) m.tables = append(m.tables, tmap) if len(primaryKey) > 0 { tmap.keys = append(tmap.keys, primaryKey...) } return tmap }
[ "func", "(", "m", "*", "DbMap", ")", "AddTableWithNameAndSchema", "(", "i", "interface", "{", "}", ",", "schema", "string", ",", "name", "string", ")", "*", "TableMap", "{", "t", ":=", "reflect", ".", "TypeOf", "(", "i", ")", "\n", "if", "name", "==", "\"", "\"", "{", "name", "=", "t", ".", "Name", "(", ")", "\n", "}", "\n\n", "// check if we have a table for this type already", "// if so, update the name and return the existing pointer", "for", "i", ":=", "range", "m", ".", "tables", "{", "table", ":=", "m", ".", "tables", "[", "i", "]", "\n", "if", "table", ".", "gotype", "==", "t", "{", "table", ".", "TableName", "=", "name", "\n", "return", "table", "\n", "}", "\n", "}", "\n\n", "tmap", ":=", "&", "TableMap", "{", "gotype", ":", "t", ",", "TableName", ":", "name", ",", "SchemaName", ":", "schema", ",", "dbmap", ":", "m", "}", "\n", "var", "primaryKey", "[", "]", "*", "ColumnMap", "\n", "tmap", ".", "Columns", ",", "primaryKey", "=", "m", ".", "readStructColumns", "(", "t", ")", "\n", "m", ".", "tables", "=", "append", "(", "m", ".", "tables", ",", "tmap", ")", "\n", "if", "len", "(", "primaryKey", ")", ">", "0", "{", "tmap", ".", "keys", "=", "append", "(", "tmap", ".", "keys", ",", "primaryKey", "...", ")", "\n", "}", "\n\n", "return", "tmap", "\n", "}" ]
// AddTableWithNameAndSchema has the same behavior as AddTable, but sets // table.TableName to name.
[ "AddTableWithNameAndSchema", "has", "the", "same", "behavior", "as", "AddTable", "but", "sets", "table", ".", "TableName", "to", "name", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L231-L256
train
go-gorp/gorp
db.go
AddTableDynamic
func (m *DbMap) AddTableDynamic(inp DynamicTable, schema string) *TableMap { val := reflect.ValueOf(inp) elm := val.Elem() t := elm.Type() name := inp.TableName() if name == "" { panic("Missing table name in DynamicTable instance") } // Check if there is another dynamic table with the same name if _, found := m.dynamicTableFind(name); found { panic(fmt.Sprintf("A table with the same name %v already exists", name)) } tmap := &TableMap{gotype: t, TableName: name, SchemaName: schema, dbmap: m} var primaryKey []*ColumnMap tmap.Columns, primaryKey = m.readStructColumns(t) if len(primaryKey) > 0 { tmap.keys = append(tmap.keys, primaryKey...) } m.dynamicTableAdd(name, tmap) return tmap }
go
func (m *DbMap) AddTableDynamic(inp DynamicTable, schema string) *TableMap { val := reflect.ValueOf(inp) elm := val.Elem() t := elm.Type() name := inp.TableName() if name == "" { panic("Missing table name in DynamicTable instance") } // Check if there is another dynamic table with the same name if _, found := m.dynamicTableFind(name); found { panic(fmt.Sprintf("A table with the same name %v already exists", name)) } tmap := &TableMap{gotype: t, TableName: name, SchemaName: schema, dbmap: m} var primaryKey []*ColumnMap tmap.Columns, primaryKey = m.readStructColumns(t) if len(primaryKey) > 0 { tmap.keys = append(tmap.keys, primaryKey...) } m.dynamicTableAdd(name, tmap) return tmap }
[ "func", "(", "m", "*", "DbMap", ")", "AddTableDynamic", "(", "inp", "DynamicTable", ",", "schema", "string", ")", "*", "TableMap", "{", "val", ":=", "reflect", ".", "ValueOf", "(", "inp", ")", "\n", "elm", ":=", "val", ".", "Elem", "(", ")", "\n", "t", ":=", "elm", ".", "Type", "(", ")", "\n", "name", ":=", "inp", ".", "TableName", "(", ")", "\n", "if", "name", "==", "\"", "\"", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Check if there is another dynamic table with the same name", "if", "_", ",", "found", ":=", "m", ".", "dynamicTableFind", "(", "name", ")", ";", "found", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ")", ")", "\n", "}", "\n\n", "tmap", ":=", "&", "TableMap", "{", "gotype", ":", "t", ",", "TableName", ":", "name", ",", "SchemaName", ":", "schema", ",", "dbmap", ":", "m", "}", "\n", "var", "primaryKey", "[", "]", "*", "ColumnMap", "\n", "tmap", ".", "Columns", ",", "primaryKey", "=", "m", ".", "readStructColumns", "(", "t", ")", "\n", "if", "len", "(", "primaryKey", ")", ">", "0", "{", "tmap", ".", "keys", "=", "append", "(", "tmap", ".", "keys", ",", "primaryKey", "...", ")", "\n", "}", "\n\n", "m", ".", "dynamicTableAdd", "(", "name", ",", "tmap", ")", "\n\n", "return", "tmap", "\n", "}" ]
// AddTableDynamic registers the given interface type with gorp. // The table name will be dynamically determined at runtime by // using the GetTableName method on DynamicTable interface
[ "AddTableDynamic", "registers", "the", "given", "interface", "type", "with", "gorp", ".", "The", "table", "name", "will", "be", "dynamically", "determined", "at", "runtime", "by", "using", "the", "GetTableName", "method", "on", "DynamicTable", "interface" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L261-L286
train
go-gorp/gorp
db.go
DropTable
func (m *DbMap) DropTable(table interface{}) error { t := reflect.TypeOf(table) tableName := "" if dyn, ok := table.(DynamicTable); ok { tableName = dyn.TableName() } return m.dropTable(t, tableName, false) }
go
func (m *DbMap) DropTable(table interface{}) error { t := reflect.TypeOf(table) tableName := "" if dyn, ok := table.(DynamicTable); ok { tableName = dyn.TableName() } return m.dropTable(t, tableName, false) }
[ "func", "(", "m", "*", "DbMap", ")", "DropTable", "(", "table", "interface", "{", "}", ")", "error", "{", "t", ":=", "reflect", ".", "TypeOf", "(", "table", ")", "\n\n", "tableName", ":=", "\"", "\"", "\n", "if", "dyn", ",", "ok", ":=", "table", ".", "(", "DynamicTable", ")", ";", "ok", "{", "tableName", "=", "dyn", ".", "TableName", "(", ")", "\n", "}", "\n\n", "return", "m", ".", "dropTable", "(", "t", ",", "tableName", ",", "false", ")", "\n", "}" ]
// DropTable drops an individual table. // Returns an error when the table does not exist.
[ "DropTable", "drops", "an", "individual", "table", ".", "Returns", "an", "error", "when", "the", "table", "does", "not", "exist", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L463-L472
train
go-gorp/gorp
db.go
DropTableIfExists
func (m *DbMap) DropTableIfExists(table interface{}) error { t := reflect.TypeOf(table) tableName := "" if dyn, ok := table.(DynamicTable); ok { tableName = dyn.TableName() } return m.dropTable(t, tableName, true) }
go
func (m *DbMap) DropTableIfExists(table interface{}) error { t := reflect.TypeOf(table) tableName := "" if dyn, ok := table.(DynamicTable); ok { tableName = dyn.TableName() } return m.dropTable(t, tableName, true) }
[ "func", "(", "m", "*", "DbMap", ")", "DropTableIfExists", "(", "table", "interface", "{", "}", ")", "error", "{", "t", ":=", "reflect", ".", "TypeOf", "(", "table", ")", "\n\n", "tableName", ":=", "\"", "\"", "\n", "if", "dyn", ",", "ok", ":=", "table", ".", "(", "DynamicTable", ")", ";", "ok", "{", "tableName", "=", "dyn", ".", "TableName", "(", ")", "\n", "}", "\n\n", "return", "m", ".", "dropTable", "(", "t", ",", "tableName", ",", "true", ")", "\n", "}" ]
// DropTableIfExists drops an individual table when the table exists.
[ "DropTableIfExists", "drops", "an", "individual", "table", "when", "the", "table", "exists", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L475-L484
train
go-gorp/gorp
db.go
dropTables
func (m *DbMap) dropTables(addIfExists bool) (err error) { for _, table := range m.tables { err = m.dropTableImpl(table, addIfExists) if err != nil { return err } } for _, table := range m.dynamicTableMap() { err = m.dropTableImpl(table, addIfExists) if err != nil { return err } } return err }
go
func (m *DbMap) dropTables(addIfExists bool) (err error) { for _, table := range m.tables { err = m.dropTableImpl(table, addIfExists) if err != nil { return err } } for _, table := range m.dynamicTableMap() { err = m.dropTableImpl(table, addIfExists) if err != nil { return err } } return err }
[ "func", "(", "m", "*", "DbMap", ")", "dropTables", "(", "addIfExists", "bool", ")", "(", "err", "error", ")", "{", "for", "_", ",", "table", ":=", "range", "m", ".", "tables", "{", "err", "=", "m", ".", "dropTableImpl", "(", "table", ",", "addIfExists", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "table", ":=", "range", "m", ".", "dynamicTableMap", "(", ")", "{", "err", "=", "m", ".", "dropTableImpl", "(", "table", ",", "addIfExists", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// Goes through all the registered tables, dropping them one by one. // If an error is encountered, then it is returned and the rest of // the tables are not dropped.
[ "Goes", "through", "all", "the", "registered", "tables", "dropping", "them", "one", "by", "one", ".", "If", "an", "error", "is", "encountered", "then", "it", "is", "returned", "and", "the", "rest", "of", "the", "tables", "are", "not", "dropped", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L501-L517
train
go-gorp/gorp
db.go
dropTable
func (m *DbMap) dropTable(t reflect.Type, name string, addIfExists bool) error { table := tableOrNil(m, t, name) if table == nil { return fmt.Errorf("table %s was not registered", table.TableName) } return m.dropTableImpl(table, addIfExists) }
go
func (m *DbMap) dropTable(t reflect.Type, name string, addIfExists bool) error { table := tableOrNil(m, t, name) if table == nil { return fmt.Errorf("table %s was not registered", table.TableName) } return m.dropTableImpl(table, addIfExists) }
[ "func", "(", "m", "*", "DbMap", ")", "dropTable", "(", "t", "reflect", ".", "Type", ",", "name", "string", ",", "addIfExists", "bool", ")", "error", "{", "table", ":=", "tableOrNil", "(", "m", ",", "t", ",", "name", ")", "\n", "if", "table", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "table", ".", "TableName", ")", "\n", "}", "\n\n", "return", "m", ".", "dropTableImpl", "(", "table", ",", "addIfExists", ")", "\n", "}" ]
// Implementation of dropping a single table.
[ "Implementation", "of", "dropping", "a", "single", "table", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L520-L527
train
go-gorp/gorp
db.go
SelectInt
func (m *DbMap) SelectInt(query string, args ...interface{}) (int64, error) { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectInt(m, query, args...) }
go
func (m *DbMap) SelectInt(query string, args ...interface{}) (int64, error) { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectInt(m, query, args...) }
[ "func", "(", "m", "*", "DbMap", ")", "SelectInt", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "int64", ",", "error", ")", "{", "if", "m", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectInt", "(", "m", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectInt is a convenience wrapper around the gorp.SelectInt function
[ "SelectInt", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectInt", "function" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L681-L687
train
go-gorp/gorp
db.go
SelectNullInt
func (m *DbMap) SelectNullInt(query string, args ...interface{}) (sql.NullInt64, error) { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectNullInt(m, query, args...) }
go
func (m *DbMap) SelectNullInt(query string, args ...interface{}) (sql.NullInt64, error) { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectNullInt(m, query, args...) }
[ "func", "(", "m", "*", "DbMap", ")", "SelectNullInt", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "sql", ".", "NullInt64", ",", "error", ")", "{", "if", "m", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectNullInt", "(", "m", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectNullInt is a convenience wrapper around the gorp.SelectNullInt function
[ "SelectNullInt", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectNullInt", "function" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L690-L696
train
go-gorp/gorp
db.go
SelectFloat
func (m *DbMap) SelectFloat(query string, args ...interface{}) (float64, error) { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectFloat(m, query, args...) }
go
func (m *DbMap) SelectFloat(query string, args ...interface{}) (float64, error) { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectFloat(m, query, args...) }
[ "func", "(", "m", "*", "DbMap", ")", "SelectFloat", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "float64", ",", "error", ")", "{", "if", "m", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectFloat", "(", "m", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectFloat is a convenience wrapper around the gorp.SelectFloat function
[ "SelectFloat", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectFloat", "function" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L699-L705
train
go-gorp/gorp
db.go
SelectNullFloat
func (m *DbMap) SelectNullFloat(query string, args ...interface{}) (sql.NullFloat64, error) { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectNullFloat(m, query, args...) }
go
func (m *DbMap) SelectNullFloat(query string, args ...interface{}) (sql.NullFloat64, error) { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectNullFloat(m, query, args...) }
[ "func", "(", "m", "*", "DbMap", ")", "SelectNullFloat", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "sql", ".", "NullFloat64", ",", "error", ")", "{", "if", "m", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectNullFloat", "(", "m", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectNullFloat is a convenience wrapper around the gorp.SelectNullFloat function
[ "SelectNullFloat", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectNullFloat", "function" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L708-L714
train
go-gorp/gorp
db.go
SelectStr
func (m *DbMap) SelectStr(query string, args ...interface{}) (string, error) { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectStr(m, query, args...) }
go
func (m *DbMap) SelectStr(query string, args ...interface{}) (string, error) { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectStr(m, query, args...) }
[ "func", "(", "m", "*", "DbMap", ")", "SelectStr", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "if", "m", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectStr", "(", "m", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectStr is a convenience wrapper around the gorp.SelectStr function
[ "SelectStr", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectStr", "function" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L717-L723
train
go-gorp/gorp
db.go
SelectNullStr
func (m *DbMap) SelectNullStr(query string, args ...interface{}) (sql.NullString, error) { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectNullStr(m, query, args...) }
go
func (m *DbMap) SelectNullStr(query string, args ...interface{}) (sql.NullString, error) { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectNullStr(m, query, args...) }
[ "func", "(", "m", "*", "DbMap", ")", "SelectNullStr", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "sql", ".", "NullString", ",", "error", ")", "{", "if", "m", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectNullStr", "(", "m", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectNullStr is a convenience wrapper around the gorp.SelectNullStr function
[ "SelectNullStr", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectNullStr", "function" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L726-L732
train
go-gorp/gorp
db.go
SelectOne
func (m *DbMap) SelectOne(holder interface{}, query string, args ...interface{}) error { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectOne(m, m, holder, query, args...) }
go
func (m *DbMap) SelectOne(holder interface{}, query string, args ...interface{}) error { if m.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectOne(m, m, holder, query, args...) }
[ "func", "(", "m", "*", "DbMap", ")", "SelectOne", "(", "holder", "interface", "{", "}", ",", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "error", "{", "if", "m", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectOne", "(", "m", ",", "m", ",", "holder", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectOne is a convenience wrapper around the gorp.SelectOne function
[ "SelectOne", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectOne", "function" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L735-L741
train
go-gorp/gorp
db.go
Begin
func (m *DbMap) Begin() (*Transaction, error) { if m.logger != nil { now := time.Now() defer m.trace(now, "begin;") } tx, err := begin(m) if err != nil { return nil, err } return &Transaction{ dbmap: m, tx: tx, closed: false, }, nil }
go
func (m *DbMap) Begin() (*Transaction, error) { if m.logger != nil { now := time.Now() defer m.trace(now, "begin;") } tx, err := begin(m) if err != nil { return nil, err } return &Transaction{ dbmap: m, tx: tx, closed: false, }, nil }
[ "func", "(", "m", "*", "DbMap", ")", "Begin", "(", ")", "(", "*", "Transaction", ",", "error", ")", "{", "if", "m", ".", "logger", "!=", "nil", "{", "now", ":=", "time", ".", "Now", "(", ")", "\n", "defer", "m", ".", "trace", "(", "now", ",", "\"", "\"", ")", "\n", "}", "\n", "tx", ",", "err", ":=", "begin", "(", "m", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "Transaction", "{", "dbmap", ":", "m", ",", "tx", ":", "tx", ",", "closed", ":", "false", ",", "}", ",", "nil", "\n", "}" ]
// Begin starts a gorp Transaction
[ "Begin", "starts", "a", "gorp", "Transaction" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L744-L758
train
go-gorp/gorp
index.go
SetUnique
func (idx *IndexMap) SetUnique(b bool) *IndexMap { idx.Unique = b return idx }
go
func (idx *IndexMap) SetUnique(b bool) *IndexMap { idx.Unique = b return idx }
[ "func", "(", "idx", "*", "IndexMap", ")", "SetUnique", "(", "b", "bool", ")", "*", "IndexMap", "{", "idx", ".", "Unique", "=", "b", "\n", "return", "idx", "\n", "}" ]
// SetUnique adds "unique" to the create index statements for this // index, if b is true.
[ "SetUnique", "adds", "unique", "to", "the", "create", "index", "statements", "for", "this", "index", "if", "b", "is", "true", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/index.go#L47-L50
train
go-gorp/gorp
index.go
SetIndexType
func (idx *IndexMap) SetIndexType(indtype string) *IndexMap { idx.IndexType = indtype return idx }
go
func (idx *IndexMap) SetIndexType(indtype string) *IndexMap { idx.IndexType = indtype return idx }
[ "func", "(", "idx", "*", "IndexMap", ")", "SetIndexType", "(", "indtype", "string", ")", "*", "IndexMap", "{", "idx", ".", "IndexType", "=", "indtype", "\n", "return", "idx", "\n", "}" ]
// SetIndexType specifies the index type supported by chousen SQL Dialect
[ "SetIndexType", "specifies", "the", "index", "type", "supported", "by", "chousen", "SQL", "Dialect" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/index.go#L53-L56
train
go-gorp/gorp
dialect_sqlite.go
QuotedTableForQuery
func (d SqliteDialect) QuotedTableForQuery(schema string, table string) string { return d.QuoteField(table) }
go
func (d SqliteDialect) QuotedTableForQuery(schema string, table string) string { return d.QuoteField(table) }
[ "func", "(", "d", "SqliteDialect", ")", "QuotedTableForQuery", "(", "schema", "string", ",", "table", "string", ")", "string", "{", "return", "d", ".", "QuoteField", "(", "table", ")", "\n", "}" ]
// sqlite does not have schemas like PostgreSQL does, so just escape it like normal
[ "sqlite", "does", "not", "have", "schemas", "like", "PostgreSQL", "does", "so", "just", "escape", "it", "like", "normal" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/dialect_sqlite.go#L105-L107
train
go-gorp/gorp
dialect_oracle.go
InsertQueryToTarget
func (d OracleDialect) InsertQueryToTarget(exec SqlExecutor, insertSql, idSql string, target interface{}, params ...interface{}) error { _, err := exec.Exec(insertSql, params...) if err != nil { return err } id, err := exec.SelectInt(idSql) if err != nil { return err } switch target.(type) { case *int64: *(target.(*int64)) = id case *int32: *(target.(*int32)) = int32(id) case int: *(target.(*int)) = int(id) default: return fmt.Errorf("Id field can be int, int32 or int64") } return nil }
go
func (d OracleDialect) InsertQueryToTarget(exec SqlExecutor, insertSql, idSql string, target interface{}, params ...interface{}) error { _, err := exec.Exec(insertSql, params...) if err != nil { return err } id, err := exec.SelectInt(idSql) if err != nil { return err } switch target.(type) { case *int64: *(target.(*int64)) = id case *int32: *(target.(*int32)) = int32(id) case int: *(target.(*int)) = int(id) default: return fmt.Errorf("Id field can be int, int32 or int64") } return nil }
[ "func", "(", "d", "OracleDialect", ")", "InsertQueryToTarget", "(", "exec", "SqlExecutor", ",", "insertSql", ",", "idSql", "string", ",", "target", "interface", "{", "}", ",", "params", "...", "interface", "{", "}", ")", "error", "{", "_", ",", "err", ":=", "exec", ".", "Exec", "(", "insertSql", ",", "params", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "id", ",", "err", ":=", "exec", ".", "SelectInt", "(", "idSql", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "switch", "target", ".", "(", "type", ")", "{", "case", "*", "int64", ":", "*", "(", "target", ".", "(", "*", "int64", ")", ")", "=", "id", "\n", "case", "*", "int32", ":", "*", "(", "target", ".", "(", "*", "int32", ")", ")", "=", "int32", "(", "id", ")", "\n", "case", "int", ":", "*", "(", "target", ".", "(", "*", "int", ")", ")", "=", "int", "(", "id", ")", "\n", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// After executing the insert uses the ColMap IdQuery to get the generated id
[ "After", "executing", "the", "insert", "uses", "the", "ColMap", "IdQuery", "to", "get", "the", "generated", "id" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/dialect_oracle.go#L102-L122
train
go-gorp/gorp
transaction.go
SelectInt
func (t *Transaction) SelectInt(query string, args ...interface{}) (int64, error) { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectInt(t, query, args...) }
go
func (t *Transaction) SelectInt(query string, args ...interface{}) (int64, error) { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectInt(t, query, args...) }
[ "func", "(", "t", "*", "Transaction", ")", "SelectInt", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "int64", ",", "error", ")", "{", "if", "t", ".", "dbmap", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectInt", "(", "t", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectInt is a convenience wrapper around the gorp.SelectInt function.
[ "SelectInt", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectInt", "function", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/transaction.go#L86-L92
train
go-gorp/gorp
transaction.go
SelectNullInt
func (t *Transaction) SelectNullInt(query string, args ...interface{}) (sql.NullInt64, error) { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectNullInt(t, query, args...) }
go
func (t *Transaction) SelectNullInt(query string, args ...interface{}) (sql.NullInt64, error) { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectNullInt(t, query, args...) }
[ "func", "(", "t", "*", "Transaction", ")", "SelectNullInt", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "sql", ".", "NullInt64", ",", "error", ")", "{", "if", "t", ".", "dbmap", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectNullInt", "(", "t", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectNullInt is a convenience wrapper around the gorp.SelectNullInt function.
[ "SelectNullInt", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectNullInt", "function", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/transaction.go#L95-L101
train
go-gorp/gorp
transaction.go
SelectFloat
func (t *Transaction) SelectFloat(query string, args ...interface{}) (float64, error) { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectFloat(t, query, args...) }
go
func (t *Transaction) SelectFloat(query string, args ...interface{}) (float64, error) { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectFloat(t, query, args...) }
[ "func", "(", "t", "*", "Transaction", ")", "SelectFloat", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "float64", ",", "error", ")", "{", "if", "t", ".", "dbmap", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectFloat", "(", "t", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectFloat is a convenience wrapper around the gorp.SelectFloat function.
[ "SelectFloat", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectFloat", "function", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/transaction.go#L104-L110
train
go-gorp/gorp
transaction.go
SelectNullFloat
func (t *Transaction) SelectNullFloat(query string, args ...interface{}) (sql.NullFloat64, error) { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectNullFloat(t, query, args...) }
go
func (t *Transaction) SelectNullFloat(query string, args ...interface{}) (sql.NullFloat64, error) { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectNullFloat(t, query, args...) }
[ "func", "(", "t", "*", "Transaction", ")", "SelectNullFloat", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "sql", ".", "NullFloat64", ",", "error", ")", "{", "if", "t", ".", "dbmap", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectNullFloat", "(", "t", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectNullFloat is a convenience wrapper around the gorp.SelectNullFloat function.
[ "SelectNullFloat", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectNullFloat", "function", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/transaction.go#L113-L119
train
go-gorp/gorp
transaction.go
SelectStr
func (t *Transaction) SelectStr(query string, args ...interface{}) (string, error) { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectStr(t, query, args...) }
go
func (t *Transaction) SelectStr(query string, args ...interface{}) (string, error) { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectStr(t, query, args...) }
[ "func", "(", "t", "*", "Transaction", ")", "SelectStr", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "if", "t", ".", "dbmap", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectStr", "(", "t", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectStr is a convenience wrapper around the gorp.SelectStr function.
[ "SelectStr", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectStr", "function", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/transaction.go#L122-L128
train
go-gorp/gorp
transaction.go
SelectNullStr
func (t *Transaction) SelectNullStr(query string, args ...interface{}) (sql.NullString, error) { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectNullStr(t, query, args...) }
go
func (t *Transaction) SelectNullStr(query string, args ...interface{}) (sql.NullString, error) { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectNullStr(t, query, args...) }
[ "func", "(", "t", "*", "Transaction", ")", "SelectNullStr", "(", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "sql", ".", "NullString", ",", "error", ")", "{", "if", "t", ".", "dbmap", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectNullStr", "(", "t", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectNullStr is a convenience wrapper around the gorp.SelectNullStr function.
[ "SelectNullStr", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectNullStr", "function", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/transaction.go#L131-L137
train
go-gorp/gorp
transaction.go
SelectOne
func (t *Transaction) SelectOne(holder interface{}, query string, args ...interface{}) error { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectOne(t.dbmap, t, holder, query, args...) }
go
func (t *Transaction) SelectOne(holder interface{}, query string, args ...interface{}) error { if t.dbmap.ExpandSliceArgs { expandSliceArgs(&query, args...) } return SelectOne(t.dbmap, t, holder, query, args...) }
[ "func", "(", "t", "*", "Transaction", ")", "SelectOne", "(", "holder", "interface", "{", "}", ",", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "error", "{", "if", "t", ".", "dbmap", ".", "ExpandSliceArgs", "{", "expandSliceArgs", "(", "&", "query", ",", "args", "...", ")", "\n", "}", "\n\n", "return", "SelectOne", "(", "t", ".", "dbmap", ",", "t", ",", "holder", ",", "query", ",", "args", "...", ")", "\n", "}" ]
// SelectOne is a convenience wrapper around the gorp.SelectOne function.
[ "SelectOne", "is", "a", "convenience", "wrapper", "around", "the", "gorp", ".", "SelectOne", "function", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/transaction.go#L140-L146
train
go-gorp/gorp
transaction.go
Savepoint
func (t *Transaction) Savepoint(name string) error { query := "savepoint " + t.dbmap.Dialect.QuoteField(name) if t.dbmap.logger != nil { now := time.Now() defer t.dbmap.trace(now, query, nil) } _, err := exec(t, query) return err }
go
func (t *Transaction) Savepoint(name string) error { query := "savepoint " + t.dbmap.Dialect.QuoteField(name) if t.dbmap.logger != nil { now := time.Now() defer t.dbmap.trace(now, query, nil) } _, err := exec(t, query) return err }
[ "func", "(", "t", "*", "Transaction", ")", "Savepoint", "(", "name", "string", ")", "error", "{", "query", ":=", "\"", "\"", "+", "t", ".", "dbmap", ".", "Dialect", ".", "QuoteField", "(", "name", ")", "\n", "if", "t", ".", "dbmap", ".", "logger", "!=", "nil", "{", "now", ":=", "time", ".", "Now", "(", ")", "\n", "defer", "t", ".", "dbmap", ".", "trace", "(", "now", ",", "query", ",", "nil", ")", "\n", "}", "\n", "_", ",", "err", ":=", "exec", "(", "t", ",", "query", ")", "\n", "return", "err", "\n", "}" ]
// Savepoint creates a savepoint with the given name. The name is interpolated // directly into the SQL SAVEPOINT statement, so you must sanitize it if it is // derived from user input.
[ "Savepoint", "creates", "a", "savepoint", "with", "the", "given", "name", ".", "The", "name", "is", "interpolated", "directly", "into", "the", "SQL", "SAVEPOINT", "statement", "so", "you", "must", "sanitize", "it", "if", "it", "is", "derived", "from", "user", "input", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/transaction.go#L179-L187
train
go-gorp/gorp
lockerror.go
Error
func (e OptimisticLockError) Error() string { if e.RowExists { return fmt.Sprintf("gorp: OptimisticLockError table=%s keys=%v out of date version=%d", e.TableName, e.Keys, e.LocalVersion) } return fmt.Sprintf("gorp: OptimisticLockError no row found for table=%s keys=%v", e.TableName, e.Keys) }
go
func (e OptimisticLockError) Error() string { if e.RowExists { return fmt.Sprintf("gorp: OptimisticLockError table=%s keys=%v out of date version=%d", e.TableName, e.Keys, e.LocalVersion) } return fmt.Sprintf("gorp: OptimisticLockError no row found for table=%s keys=%v", e.TableName, e.Keys) }
[ "func", "(", "e", "OptimisticLockError", ")", "Error", "(", ")", "string", "{", "if", "e", ".", "RowExists", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "TableName", ",", "e", ".", "Keys", ",", "e", ".", "LocalVersion", ")", "\n", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "TableName", ",", "e", ".", "Keys", ")", "\n", "}" ]
// Error returns a description of the cause of the lock error
[ "Error", "returns", "a", "description", "of", "the", "cause", "of", "the", "lock", "error" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/lockerror.go#L41-L47
train
go-gorp/gorp
select.go
SelectInt
func SelectInt(e SqlExecutor, query string, args ...interface{}) (int64, error) { var h int64 err := selectVal(e, &h, query, args...) if err != nil && err != sql.ErrNoRows { return 0, err } return h, nil }
go
func SelectInt(e SqlExecutor, query string, args ...interface{}) (int64, error) { var h int64 err := selectVal(e, &h, query, args...) if err != nil && err != sql.ErrNoRows { return 0, err } return h, nil }
[ "func", "SelectInt", "(", "e", "SqlExecutor", ",", "query", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "int64", ",", "error", ")", "{", "var", "h", "int64", "\n", "err", ":=", "selectVal", "(", "e", ",", "&", "h", ",", "query", ",", "args", "...", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "sql", ".", "ErrNoRows", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "h", ",", "nil", "\n", "}" ]
// SelectInt executes the given query, which should be a SELECT statement for a single // integer column, and returns the value of the first row returned. If no rows are // found, zero is returned.
[ "SelectInt", "executes", "the", "given", "query", "which", "should", "be", "a", "SELECT", "statement", "for", "a", "single", "integer", "column", "and", "returns", "the", "value", "of", "the", "first", "row", "returned", ".", "If", "no", "rows", "are", "found", "zero", "is", "returned", "." ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/select.go#L23-L30
train
hashicorp/go-version
constraint.go
NewConstraint
func NewConstraint(v string) (Constraints, error) { vs := strings.Split(v, ",") result := make([]*Constraint, len(vs)) for i, single := range vs { c, err := parseSingle(single) if err != nil { return nil, err } result[i] = c } return Constraints(result), nil }
go
func NewConstraint(v string) (Constraints, error) { vs := strings.Split(v, ",") result := make([]*Constraint, len(vs)) for i, single := range vs { c, err := parseSingle(single) if err != nil { return nil, err } result[i] = c } return Constraints(result), nil }
[ "func", "NewConstraint", "(", "v", "string", ")", "(", "Constraints", ",", "error", ")", "{", "vs", ":=", "strings", ".", "Split", "(", "v", ",", "\"", "\"", ")", "\n", "result", ":=", "make", "(", "[", "]", "*", "Constraint", ",", "len", "(", "vs", ")", ")", "\n", "for", "i", ",", "single", ":=", "range", "vs", "{", "c", ",", "err", ":=", "parseSingle", "(", "single", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "result", "[", "i", "]", "=", "c", "\n", "}", "\n\n", "return", "Constraints", "(", "result", ")", ",", "nil", "\n", "}" ]
// NewConstraint will parse one or more constraints from the given // constraint string. The string must be a comma-separated list of // constraints.
[ "NewConstraint", "will", "parse", "one", "or", "more", "constraints", "from", "the", "given", "constraint", "string", ".", "The", "string", "must", "be", "a", "comma", "-", "separated", "list", "of", "constraints", "." ]
192140e6f3e645d971b134d4e35b5191adb9dfd3
https://github.com/hashicorp/go-version/blob/192140e6f3e645d971b134d4e35b5191adb9dfd3/constraint.go#L54-L67
train
hashicorp/go-version
constraint.go
Check
func (cs Constraints) Check(v *Version) bool { for _, c := range cs { if !c.Check(v) { return false } } return true }
go
func (cs Constraints) Check(v *Version) bool { for _, c := range cs { if !c.Check(v) { return false } } return true }
[ "func", "(", "cs", "Constraints", ")", "Check", "(", "v", "*", "Version", ")", "bool", "{", "for", "_", ",", "c", ":=", "range", "cs", "{", "if", "!", "c", ".", "Check", "(", "v", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
// Check tests if a version satisfies all the constraints.
[ "Check", "tests", "if", "a", "version", "satisfies", "all", "the", "constraints", "." ]
192140e6f3e645d971b134d4e35b5191adb9dfd3
https://github.com/hashicorp/go-version/blob/192140e6f3e645d971b134d4e35b5191adb9dfd3/constraint.go#L70-L78
train
hashicorp/go-version
constraint.go
String
func (cs Constraints) String() string { csStr := make([]string, len(cs)) for i, c := range cs { csStr[i] = c.String() } return strings.Join(csStr, ",") }
go
func (cs Constraints) String() string { csStr := make([]string, len(cs)) for i, c := range cs { csStr[i] = c.String() } return strings.Join(csStr, ",") }
[ "func", "(", "cs", "Constraints", ")", "String", "(", ")", "string", "{", "csStr", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "cs", ")", ")", "\n", "for", "i", ",", "c", ":=", "range", "cs", "{", "csStr", "[", "i", "]", "=", "c", ".", "String", "(", ")", "\n", "}", "\n\n", "return", "strings", ".", "Join", "(", "csStr", ",", "\"", "\"", ")", "\n", "}" ]
// Returns the string format of the constraints
[ "Returns", "the", "string", "format", "of", "the", "constraints" ]
192140e6f3e645d971b134d4e35b5191adb9dfd3
https://github.com/hashicorp/go-version/blob/192140e6f3e645d971b134d4e35b5191adb9dfd3/constraint.go#L81-L88
train
hashicorp/go-version
constraint.go
Check
func (c *Constraint) Check(v *Version) bool { return c.f(v, c.check) }
go
func (c *Constraint) Check(v *Version) bool { return c.f(v, c.check) }
[ "func", "(", "c", "*", "Constraint", ")", "Check", "(", "v", "*", "Version", ")", "bool", "{", "return", "c", ".", "f", "(", "v", ",", "c", ".", "check", ")", "\n", "}" ]
// Check tests if a constraint is validated by the given version.
[ "Check", "tests", "if", "a", "constraint", "is", "validated", "by", "the", "given", "version", "." ]
192140e6f3e645d971b134d4e35b5191adb9dfd3
https://github.com/hashicorp/go-version/blob/192140e6f3e645d971b134d4e35b5191adb9dfd3/constraint.go#L91-L93
train
hashicorp/go-version
version.go
Compare
func (v *Version) Compare(other *Version) int { // A quick, efficient equality check if v.String() == other.String() { return 0 } segmentsSelf := v.Segments64() segmentsOther := other.Segments64() // If the segments are the same, we must compare on prerelease info if reflect.DeepEqual(segmentsSelf, segmentsOther) { preSelf := v.Prerelease() preOther := other.Prerelease() if preSelf == "" && preOther == "" { return 0 } if preSelf == "" { return 1 } if preOther == "" { return -1 } return comparePrereleases(preSelf, preOther) } // Get the highest specificity (hS), or if they're equal, just use segmentSelf length lenSelf := len(segmentsSelf) lenOther := len(segmentsOther) hS := lenSelf if lenSelf < lenOther { hS = lenOther } // Compare the segments // Because a constraint could have more/less specificity than the version it's // checking, we need to account for a lopsided or jagged comparison for i := 0; i < hS; i++ { if i > lenSelf-1 { // This means Self had the lower specificity // Check to see if the remaining segments in Other are all zeros if !allZero(segmentsOther[i:]) { // if not, it means that Other has to be greater than Self return -1 } break } else if i > lenOther-1 { // this means Other had the lower specificity // Check to see if the remaining segments in Self are all zeros - if !allZero(segmentsSelf[i:]) { //if not, it means that Self has to be greater than Other return 1 } break } lhs := segmentsSelf[i] rhs := segmentsOther[i] if lhs == rhs { continue } else if lhs < rhs { return -1 } // Otherwis, rhs was > lhs, they're not equal return 1 } // if we got this far, they're equal return 0 }
go
func (v *Version) Compare(other *Version) int { // A quick, efficient equality check if v.String() == other.String() { return 0 } segmentsSelf := v.Segments64() segmentsOther := other.Segments64() // If the segments are the same, we must compare on prerelease info if reflect.DeepEqual(segmentsSelf, segmentsOther) { preSelf := v.Prerelease() preOther := other.Prerelease() if preSelf == "" && preOther == "" { return 0 } if preSelf == "" { return 1 } if preOther == "" { return -1 } return comparePrereleases(preSelf, preOther) } // Get the highest specificity (hS), or if they're equal, just use segmentSelf length lenSelf := len(segmentsSelf) lenOther := len(segmentsOther) hS := lenSelf if lenSelf < lenOther { hS = lenOther } // Compare the segments // Because a constraint could have more/less specificity than the version it's // checking, we need to account for a lopsided or jagged comparison for i := 0; i < hS; i++ { if i > lenSelf-1 { // This means Self had the lower specificity // Check to see if the remaining segments in Other are all zeros if !allZero(segmentsOther[i:]) { // if not, it means that Other has to be greater than Self return -1 } break } else if i > lenOther-1 { // this means Other had the lower specificity // Check to see if the remaining segments in Self are all zeros - if !allZero(segmentsSelf[i:]) { //if not, it means that Self has to be greater than Other return 1 } break } lhs := segmentsSelf[i] rhs := segmentsOther[i] if lhs == rhs { continue } else if lhs < rhs { return -1 } // Otherwis, rhs was > lhs, they're not equal return 1 } // if we got this far, they're equal return 0 }
[ "func", "(", "v", "*", "Version", ")", "Compare", "(", "other", "*", "Version", ")", "int", "{", "// A quick, efficient equality check", "if", "v", ".", "String", "(", ")", "==", "other", ".", "String", "(", ")", "{", "return", "0", "\n", "}", "\n\n", "segmentsSelf", ":=", "v", ".", "Segments64", "(", ")", "\n", "segmentsOther", ":=", "other", ".", "Segments64", "(", ")", "\n\n", "// If the segments are the same, we must compare on prerelease info", "if", "reflect", ".", "DeepEqual", "(", "segmentsSelf", ",", "segmentsOther", ")", "{", "preSelf", ":=", "v", ".", "Prerelease", "(", ")", "\n", "preOther", ":=", "other", ".", "Prerelease", "(", ")", "\n", "if", "preSelf", "==", "\"", "\"", "&&", "preOther", "==", "\"", "\"", "{", "return", "0", "\n", "}", "\n", "if", "preSelf", "==", "\"", "\"", "{", "return", "1", "\n", "}", "\n", "if", "preOther", "==", "\"", "\"", "{", "return", "-", "1", "\n", "}", "\n\n", "return", "comparePrereleases", "(", "preSelf", ",", "preOther", ")", "\n", "}", "\n\n", "// Get the highest specificity (hS), or if they're equal, just use segmentSelf length", "lenSelf", ":=", "len", "(", "segmentsSelf", ")", "\n", "lenOther", ":=", "len", "(", "segmentsOther", ")", "\n", "hS", ":=", "lenSelf", "\n", "if", "lenSelf", "<", "lenOther", "{", "hS", "=", "lenOther", "\n", "}", "\n", "// Compare the segments", "// Because a constraint could have more/less specificity than the version it's", "// checking, we need to account for a lopsided or jagged comparison", "for", "i", ":=", "0", ";", "i", "<", "hS", ";", "i", "++", "{", "if", "i", ">", "lenSelf", "-", "1", "{", "// This means Self had the lower specificity", "// Check to see if the remaining segments in Other are all zeros", "if", "!", "allZero", "(", "segmentsOther", "[", "i", ":", "]", ")", "{", "// if not, it means that Other has to be greater than Self", "return", "-", "1", "\n", "}", "\n", "break", "\n", "}", "else", "if", "i", ">", "lenOther", "-", "1", "{", "// this means Other had the lower specificity", "// Check to see if the remaining segments in Self are all zeros -", "if", "!", "allZero", "(", "segmentsSelf", "[", "i", ":", "]", ")", "{", "//if not, it means that Self has to be greater than Other", "return", "1", "\n", "}", "\n", "break", "\n", "}", "\n", "lhs", ":=", "segmentsSelf", "[", "i", "]", "\n", "rhs", ":=", "segmentsOther", "[", "i", "]", "\n", "if", "lhs", "==", "rhs", "{", "continue", "\n", "}", "else", "if", "lhs", "<", "rhs", "{", "return", "-", "1", "\n", "}", "\n", "// Otherwis, rhs was > lhs, they're not equal", "return", "1", "\n", "}", "\n\n", "// if we got this far, they're equal", "return", "0", "\n", "}" ]
// Compare compares this version to another version. This // returns -1, 0, or 1 if this version is smaller, equal, // or larger than the other version, respectively. // // If you want boolean results, use the LessThan, Equal, // GreaterThan, GreaterThanOrEqual or LessThanOrEqual methods.
[ "Compare", "compares", "this", "version", "to", "another", "version", ".", "This", "returns", "-", "1", "0", "or", "1", "if", "this", "version", "is", "smaller", "equal", "or", "larger", "than", "the", "other", "version", "respectively", ".", "If", "you", "want", "boolean", "results", "use", "the", "LessThan", "Equal", "GreaterThan", "GreaterThanOrEqual", "or", "LessThanOrEqual", "methods", "." ]
192140e6f3e645d971b134d4e35b5191adb9dfd3
https://github.com/hashicorp/go-version/blob/192140e6f3e645d971b134d4e35b5191adb9dfd3/version.go#L116-L183
train
hashicorp/go-version
version.go
Segments
func (v *Version) Segments() []int { segmentSlice := make([]int, len(v.segments)) for i, v := range v.segments { segmentSlice[i] = int(v) } return segmentSlice }
go
func (v *Version) Segments() []int { segmentSlice := make([]int, len(v.segments)) for i, v := range v.segments { segmentSlice[i] = int(v) } return segmentSlice }
[ "func", "(", "v", "*", "Version", ")", "Segments", "(", ")", "[", "]", "int", "{", "segmentSlice", ":=", "make", "(", "[", "]", "int", ",", "len", "(", "v", ".", "segments", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "v", ".", "segments", "{", "segmentSlice", "[", "i", "]", "=", "int", "(", "v", ")", "\n", "}", "\n", "return", "segmentSlice", "\n", "}" ]
// Segments returns the numeric segments of the version as a slice of ints. // // This excludes any metadata or pre-release information. For example, // for a version "1.2.3-beta", segments will return a slice of // 1, 2, 3.
[ "Segments", "returns", "the", "numeric", "segments", "of", "the", "version", "as", "a", "slice", "of", "ints", ".", "This", "excludes", "any", "metadata", "or", "pre", "-", "release", "information", ".", "For", "example", "for", "a", "version", "1", ".", "2", ".", "3", "-", "beta", "segments", "will", "return", "a", "slice", "of", "1", "2", "3", "." ]
192140e6f3e645d971b134d4e35b5191adb9dfd3
https://github.com/hashicorp/go-version/blob/192140e6f3e645d971b134d4e35b5191adb9dfd3/version.go#L330-L336
train
hashicorp/go-version
version.go
Segments64
func (v *Version) Segments64() []int64 { result := make([]int64, len(v.segments)) copy(result, v.segments) return result }
go
func (v *Version) Segments64() []int64 { result := make([]int64, len(v.segments)) copy(result, v.segments) return result }
[ "func", "(", "v", "*", "Version", ")", "Segments64", "(", ")", "[", "]", "int64", "{", "result", ":=", "make", "(", "[", "]", "int64", ",", "len", "(", "v", ".", "segments", ")", ")", "\n", "copy", "(", "result", ",", "v", ".", "segments", ")", "\n", "return", "result", "\n", "}" ]
// Segments64 returns the numeric segments of the version as a slice of int64s. // // This excludes any metadata or pre-release information. For example, // for a version "1.2.3-beta", segments will return a slice of // 1, 2, 3.
[ "Segments64", "returns", "the", "numeric", "segments", "of", "the", "version", "as", "a", "slice", "of", "int64s", ".", "This", "excludes", "any", "metadata", "or", "pre", "-", "release", "information", ".", "For", "example", "for", "a", "version", "1", ".", "2", ".", "3", "-", "beta", "segments", "will", "return", "a", "slice", "of", "1", "2", "3", "." ]
192140e6f3e645d971b134d4e35b5191adb9dfd3
https://github.com/hashicorp/go-version/blob/192140e6f3e645d971b134d4e35b5191adb9dfd3/version.go#L343-L347
train
google/gops
main.go
elapsedTime
func elapsedTime(p *process.Process) (string, error) { crtTime, err := p.CreateTime() if err != nil { return "", err } etime := time.Since(time.Unix(int64(crtTime/1000), 0)) return fmtEtimeDuration(etime), nil }
go
func elapsedTime(p *process.Process) (string, error) { crtTime, err := p.CreateTime() if err != nil { return "", err } etime := time.Since(time.Unix(int64(crtTime/1000), 0)) return fmtEtimeDuration(etime), nil }
[ "func", "elapsedTime", "(", "p", "*", "process", ".", "Process", ")", "(", "string", ",", "error", ")", "{", "crtTime", ",", "err", ":=", "p", ".", "CreateTime", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "etime", ":=", "time", ".", "Since", "(", "time", ".", "Unix", "(", "int64", "(", "crtTime", "/", "1000", ")", ",", "0", ")", ")", "\n", "return", "fmtEtimeDuration", "(", "etime", ")", ",", "nil", "\n", "}" ]
// elapsedTime shows the elapsed time of the process indicating how long the // process has been running for.
[ "elapsedTime", "shows", "the", "elapsed", "time", "of", "the", "process", "indicating", "how", "long", "the", "process", "has", "been", "running", "for", "." ]
036f72c5be1f7a0970ffae4907e05dd11f49de35
https://github.com/google/gops/blob/036f72c5be1f7a0970ffae4907e05dd11f49de35/main.go#L170-L177
train