repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
andygrunwald/go-jira
filter.go
GetFavouriteList
func (fs *FilterService) GetFavouriteList() ([]*Filter, *Response, error) { apiEndpoint := "rest/api/2/filter/favourite" req, err := fs.client.NewRequest("GET", apiEndpoint, nil) if err != nil { return nil, nil, err } filters := []*Filter{} resp, err := fs.client.Do(req, &filters) if err != nil { jerr := NewJiraError(resp, err) return nil, resp, jerr } return filters, resp, err }
go
func (fs *FilterService) GetFavouriteList() ([]*Filter, *Response, error) { apiEndpoint := "rest/api/2/filter/favourite" req, err := fs.client.NewRequest("GET", apiEndpoint, nil) if err != nil { return nil, nil, err } filters := []*Filter{} resp, err := fs.client.Do(req, &filters) if err != nil { jerr := NewJiraError(resp, err) return nil, resp, jerr } return filters, resp, err }
[ "func", "(", "fs", "*", "FilterService", ")", "GetFavouriteList", "(", ")", "(", "[", "]", "*", "Filter", ",", "*", "Response", ",", "error", ")", "{", "apiEndpoint", ":=", "\"rest/api/2/filter/favourite\"", "\n", "req", ",", "err", ":=", "fs", ".", "cli...
// GetFavouriteList retrieves the user's favourited filters from Jira
[ "GetFavouriteList", "retrieves", "the", "user", "s", "favourited", "filters", "from", "Jira" ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/filter.go#L63-L76
train
andygrunwald/go-jira
filter.go
Get
func (fs *FilterService) Get(filterID int) (*Filter, *Response, error) { apiEndpoint := fmt.Sprintf("rest/api/2/filter/%d", filterID) req, err := fs.client.NewRequest("GET", apiEndpoint, nil) if err != nil { return nil, nil, err } filter := new(Filter) resp, err := fs.client.Do(req, filter) if err != nil { jerr := NewJiraError(resp, err) return nil, resp, jerr } return filter, resp, err }
go
func (fs *FilterService) Get(filterID int) (*Filter, *Response, error) { apiEndpoint := fmt.Sprintf("rest/api/2/filter/%d", filterID) req, err := fs.client.NewRequest("GET", apiEndpoint, nil) if err != nil { return nil, nil, err } filter := new(Filter) resp, err := fs.client.Do(req, filter) if err != nil { jerr := NewJiraError(resp, err) return nil, resp, jerr } return filter, resp, err }
[ "func", "(", "fs", "*", "FilterService", ")", "Get", "(", "filterID", "int", ")", "(", "*", "Filter", ",", "*", "Response", ",", "error", ")", "{", "apiEndpoint", ":=", "fmt", ".", "Sprintf", "(", "\"rest/api/2/filter/%d\"", ",", "filterID", ")", "\n", ...
// Get retrieves a single Filter from Jira
[ "Get", "retrieves", "a", "single", "Filter", "from", "Jira" ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/filter.go#L79-L93
train
andygrunwald/go-jira
error.go
NewJiraError
func NewJiraError(resp *Response, httpError error) error { if resp == nil { return errors.Wrap(httpError, "No response returned") } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return errors.Wrap(err, httpError.Error()) } jerr := Error{HTTPError: httpError} contentType := resp.Header.Get("Content-Type") if strings.HasPrefix(contentType, "application/json") { err = json.Unmarshal(body, &jerr) if err != nil { httpError = errors.Wrap(errors.New("Could not parse JSON"), httpError.Error()) return errors.Wrap(err, httpError.Error()) } } else { if httpError == nil { return fmt.Errorf("Got Response Status %s:%s", resp.Status, string(body)) } return errors.Wrap(httpError, fmt.Sprintf("%s: %s", resp.Status, string(body))) } return &jerr }
go
func NewJiraError(resp *Response, httpError error) error { if resp == nil { return errors.Wrap(httpError, "No response returned") } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return errors.Wrap(err, httpError.Error()) } jerr := Error{HTTPError: httpError} contentType := resp.Header.Get("Content-Type") if strings.HasPrefix(contentType, "application/json") { err = json.Unmarshal(body, &jerr) if err != nil { httpError = errors.Wrap(errors.New("Could not parse JSON"), httpError.Error()) return errors.Wrap(err, httpError.Error()) } } else { if httpError == nil { return fmt.Errorf("Got Response Status %s:%s", resp.Status, string(body)) } return errors.Wrap(httpError, fmt.Sprintf("%s: %s", resp.Status, string(body))) } return &jerr }
[ "func", "NewJiraError", "(", "resp", "*", "Response", ",", "httpError", "error", ")", "error", "{", "if", "resp", "==", "nil", "{", "return", "errors", ".", "Wrap", "(", "httpError", ",", "\"No response returned\"", ")", "\n", "}", "\n", "defer", "resp", ...
// NewJiraError creates a new jira Error
[ "NewJiraError", "creates", "a", "new", "jira", "Error" ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/error.go#L22-L48
train
andygrunwald/go-jira
error.go
Error
func (e *Error) Error() string { if len(e.ErrorMessages) > 0 { // return fmt.Sprintf("%v", e.HTTPError) return fmt.Sprintf("%s: %v", e.ErrorMessages[0], e.HTTPError) } if len(e.Errors) > 0 { for key, value := range e.Errors { return fmt.Sprintf("%s - %s: %v", key, value, e.HTTPError) } } return e.HTTPError.Error() }
go
func (e *Error) Error() string { if len(e.ErrorMessages) > 0 { // return fmt.Sprintf("%v", e.HTTPError) return fmt.Sprintf("%s: %v", e.ErrorMessages[0], e.HTTPError) } if len(e.Errors) > 0 { for key, value := range e.Errors { return fmt.Sprintf("%s - %s: %v", key, value, e.HTTPError) } } return e.HTTPError.Error() }
[ "func", "(", "e", "*", "Error", ")", "Error", "(", ")", "string", "{", "if", "len", "(", "e", ".", "ErrorMessages", ")", ">", "0", "{", "return", "fmt", ".", "Sprintf", "(", "\"%s: %v\"", ",", "e", ".", "ErrorMessages", "[", "0", "]", ",", "e", ...
// Error is a short string representing the error
[ "Error", "is", "a", "short", "string", "representing", "the", "error" ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/error.go#L51-L62
train
andygrunwald/go-jira
error.go
LongError
func (e *Error) LongError() string { var msg bytes.Buffer if e.HTTPError != nil { msg.WriteString("Original:\n") msg.WriteString(e.HTTPError.Error()) msg.WriteString("\n") } if len(e.ErrorMessages) > 0 { msg.WriteString("Messages:\n") for _, v := range e.ErrorMessages { msg.WriteString(" - ") msg.WriteString(v) msg.WriteString("\n") } } if len(e.Errors) > 0 { for key, value := range e.Errors { msg.WriteString(" - ") msg.WriteString(key) msg.WriteString(" - ") msg.WriteString(value) msg.WriteString("\n") } } return msg.String() }
go
func (e *Error) LongError() string { var msg bytes.Buffer if e.HTTPError != nil { msg.WriteString("Original:\n") msg.WriteString(e.HTTPError.Error()) msg.WriteString("\n") } if len(e.ErrorMessages) > 0 { msg.WriteString("Messages:\n") for _, v := range e.ErrorMessages { msg.WriteString(" - ") msg.WriteString(v) msg.WriteString("\n") } } if len(e.Errors) > 0 { for key, value := range e.Errors { msg.WriteString(" - ") msg.WriteString(key) msg.WriteString(" - ") msg.WriteString(value) msg.WriteString("\n") } } return msg.String() }
[ "func", "(", "e", "*", "Error", ")", "LongError", "(", ")", "string", "{", "var", "msg", "bytes", ".", "Buffer", "\n", "if", "e", ".", "HTTPError", "!=", "nil", "{", "msg", ".", "WriteString", "(", "\"Original:\\n\"", ")", "\n", "\\n", "\n", "msg", ...
// LongError is a full representation of the error as a string
[ "LongError", "is", "a", "full", "representation", "of", "the", "error", "as", "a", "string" ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/error.go#L65-L90
train
andygrunwald/go-jira
jira.go
NewRequest
func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error) { rel, err := url.Parse(urlStr) if err != nil { return nil, err } // Relative URLs should be specified without a preceding slash since baseURL will have the trailing slash rel.Path = strings.TrimLeft(rel.Path, "/") u := c.baseURL.ResolveReference(rel) var buf io.ReadWriter if body != nil { buf = new(bytes.Buffer) err = json.NewEncoder(buf).Encode(body) if err != nil { return nil, err } } req, err := http.NewRequest(method, u.String(), buf) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") // Set authentication information if c.Authentication.authType == authTypeSession { // Set session cookie if there is one if c.session != nil { for _, cookie := range c.session.Cookies { req.AddCookie(cookie) } } } else if c.Authentication.authType == authTypeBasic { // Set basic auth information if c.Authentication.username != "" { req.SetBasicAuth(c.Authentication.username, c.Authentication.password) } } return req, nil }
go
func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error) { rel, err := url.Parse(urlStr) if err != nil { return nil, err } // Relative URLs should be specified without a preceding slash since baseURL will have the trailing slash rel.Path = strings.TrimLeft(rel.Path, "/") u := c.baseURL.ResolveReference(rel) var buf io.ReadWriter if body != nil { buf = new(bytes.Buffer) err = json.NewEncoder(buf).Encode(body) if err != nil { return nil, err } } req, err := http.NewRequest(method, u.String(), buf) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") // Set authentication information if c.Authentication.authType == authTypeSession { // Set session cookie if there is one if c.session != nil { for _, cookie := range c.session.Cookies { req.AddCookie(cookie) } } } else if c.Authentication.authType == authTypeBasic { // Set basic auth information if c.Authentication.username != "" { req.SetBasicAuth(c.Authentication.username, c.Authentication.password) } } return req, nil }
[ "func", "(", "c", "*", "Client", ")", "NewRequest", "(", "method", ",", "urlStr", "string", ",", "body", "interface", "{", "}", ")", "(", "*", "http", ".", "Request", ",", "error", ")", "{", "rel", ",", "err", ":=", "url", ".", "Parse", "(", "url...
// NewRequest creates an API request. // A relative URL can be provided in urlStr, in which case it is resolved relative to the baseURL of the Client. // If specified, the value pointed to by body is JSON encoded and included as the request body.
[ "NewRequest", "creates", "an", "API", "request", ".", "A", "relative", "URL", "can", "be", "provided", "in", "urlStr", "in", "which", "case", "it", "is", "resolved", "relative", "to", "the", "baseURL", "of", "the", "Client", ".", "If", "specified", "the", ...
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/jira.go#L131-L173
train
andygrunwald/go-jira
jira.go
RoundTrip
func (t *BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) { req2 := cloneRequest(req) // per RoundTripper contract req2.SetBasicAuth(t.Username, t.Password) return t.transport().RoundTrip(req2) }
go
func (t *BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) { req2 := cloneRequest(req) // per RoundTripper contract req2.SetBasicAuth(t.Username, t.Password) return t.transport().RoundTrip(req2) }
[ "func", "(", "t", "*", "BasicAuthTransport", ")", "RoundTrip", "(", "req", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "req2", ":=", "cloneRequest", "(", "req", ")", "\n", "req2", ".", "SetBasicAuth", ...
// RoundTrip implements the RoundTripper interface. We just add the // basic auth and return the RoundTripper for this transport type.
[ "RoundTrip", "implements", "the", "RoundTripper", "interface", ".", "We", "just", "add", "the", "basic", "auth", "and", "return", "the", "RoundTripper", "for", "this", "transport", "type", "." ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/jira.go#L325-L330
train
andygrunwald/go-jira
jira.go
RoundTrip
func (t *CookieAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) { if t.SessionObject == nil { err := t.setSessionObject() if err != nil { return nil, errors.Wrap(err, "cookieauth: no session object has been set") } } req2 := cloneRequest(req) // per RoundTripper contract for _, cookie := range t.SessionObject { // Don't add an empty value cookie to the request if cookie.Value != "" { req2.AddCookie(cookie) } } return t.transport().RoundTrip(req2) }
go
func (t *CookieAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) { if t.SessionObject == nil { err := t.setSessionObject() if err != nil { return nil, errors.Wrap(err, "cookieauth: no session object has been set") } } req2 := cloneRequest(req) // per RoundTripper contract for _, cookie := range t.SessionObject { // Don't add an empty value cookie to the request if cookie.Value != "" { req2.AddCookie(cookie) } } return t.transport().RoundTrip(req2) }
[ "func", "(", "t", "*", "CookieAuthTransport", ")", "RoundTrip", "(", "req", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "if", "t", ".", "SessionObject", "==", "nil", "{", "err", ":=", "t", ".", "setS...
// RoundTrip adds the session object to the request.
[ "RoundTrip", "adds", "the", "session", "object", "to", "the", "request", "." ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/jira.go#L370-L387
train
andygrunwald/go-jira
jira.go
buildAuthRequest
func (t *CookieAuthTransport) buildAuthRequest() (*http.Request, error) { body := struct { Username string `json:"username"` Password string `json:"password"` }{ t.Username, t.Password, } b := new(bytes.Buffer) json.NewEncoder(b).Encode(body) req, err := http.NewRequest("POST", t.AuthURL, b) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") return req, nil }
go
func (t *CookieAuthTransport) buildAuthRequest() (*http.Request, error) { body := struct { Username string `json:"username"` Password string `json:"password"` }{ t.Username, t.Password, } b := new(bytes.Buffer) json.NewEncoder(b).Encode(body) req, err := http.NewRequest("POST", t.AuthURL, b) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") return req, nil }
[ "func", "(", "t", "*", "CookieAuthTransport", ")", "buildAuthRequest", "(", ")", "(", "*", "http", ".", "Request", ",", "error", ")", "{", "body", ":=", "struct", "{", "Username", "string", "`json:\"username\"`", "\n", "Password", "string", "`json:\"password\"...
// getAuthRequest assembles the request to get the authenticated cookie
[ "getAuthRequest", "assembles", "the", "request", "to", "get", "the", "authenticated", "cookie" ]
15b3b5364390d5c1d72f2b065f01c778cb0ccd18
https://github.com/andygrunwald/go-jira/blob/15b3b5364390d5c1d72f2b065f01c778cb0ccd18/jira.go#L416-L435
train
gpmgo/gopm
modules/base/tool.go
IsDir
func IsDir(dir string) bool { f, e := os.Stat(dir) if e != nil { return false } return f.IsDir() }
go
func IsDir(dir string) bool { f, e := os.Stat(dir) if e != nil { return false } return f.IsDir() }
[ "func", "IsDir", "(", "dir", "string", ")", "bool", "{", "f", ",", "e", ":=", "os", ".", "Stat", "(", "dir", ")", "\n", "if", "e", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "return", "f", ".", "IsDir", "(", ")", "\n", "}" ]
// IsDir returns true if given path is a directory, // or returns false when it's a file or does not exist.
[ "IsDir", "returns", "true", "if", "given", "path", "is", "a", "directory", "or", "returns", "false", "when", "it", "s", "a", "file", "or", "does", "not", "exist", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L54-L60
train
gpmgo/gopm
modules/base/tool.go
Copy
func Copy(src, dest string) error { // Gather file information to set back later. si, err := os.Lstat(src) if err != nil { return err } // Handle symbolic link. if si.Mode()&os.ModeSymlink != 0 { target, err := os.Readlink(src) if err != nil { return err } // NOTE: os.Chmod and os.Chtimes don't recoganize symbolic link, // which will lead "no such file or directory" error. return os.Symlink(target, dest) } sr, err := os.Open(src) if err != nil { return err } defer sr.Close() dw, err := os.Create(dest) if err != nil { return err } defer dw.Close() if _, err = io.Copy(dw, sr); err != nil { return err } // Set back file information. if err = os.Chtimes(dest, si.ModTime(), si.ModTime()); err != nil { return err } return os.Chmod(dest, si.Mode()) }
go
func Copy(src, dest string) error { // Gather file information to set back later. si, err := os.Lstat(src) if err != nil { return err } // Handle symbolic link. if si.Mode()&os.ModeSymlink != 0 { target, err := os.Readlink(src) if err != nil { return err } // NOTE: os.Chmod and os.Chtimes don't recoganize symbolic link, // which will lead "no such file or directory" error. return os.Symlink(target, dest) } sr, err := os.Open(src) if err != nil { return err } defer sr.Close() dw, err := os.Create(dest) if err != nil { return err } defer dw.Close() if _, err = io.Copy(dw, sr); err != nil { return err } // Set back file information. if err = os.Chtimes(dest, si.ModTime(), si.ModTime()); err != nil { return err } return os.Chmod(dest, si.Mode()) }
[ "func", "Copy", "(", "src", ",", "dest", "string", ")", "error", "{", "si", ",", "err", ":=", "os", ".", "Lstat", "(", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "si", ".", "Mode", "(", ")", "&", ...
// Copy copies file from source to target path.
[ "Copy", "copies", "file", "from", "source", "to", "target", "path", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L118-L157
train
gpmgo/gopm
modules/base/tool.go
CopyDir
func CopyDir(srcPath, destPath string, filters ...func(filePath string) bool) error { // Check if target directory exists. if IsExist(destPath) { return errors.New("file or directory alreay exists: " + destPath) } err := os.MkdirAll(destPath, os.ModePerm) if err != nil { return err } // Gather directory info. infos, err := StatDir(srcPath, true) if err != nil { return err } var filter func(filePath string) bool if len(filters) > 0 { filter = filters[0] } for _, info := range infos { if filter != nil && filter(info) { continue } curPath := path.Join(destPath, info) if strings.HasSuffix(info, "/") { err = os.MkdirAll(curPath, os.ModePerm) } else { err = Copy(path.Join(srcPath, info), curPath) } if err != nil { return err } } return nil }
go
func CopyDir(srcPath, destPath string, filters ...func(filePath string) bool) error { // Check if target directory exists. if IsExist(destPath) { return errors.New("file or directory alreay exists: " + destPath) } err := os.MkdirAll(destPath, os.ModePerm) if err != nil { return err } // Gather directory info. infos, err := StatDir(srcPath, true) if err != nil { return err } var filter func(filePath string) bool if len(filters) > 0 { filter = filters[0] } for _, info := range infos { if filter != nil && filter(info) { continue } curPath := path.Join(destPath, info) if strings.HasSuffix(info, "/") { err = os.MkdirAll(curPath, os.ModePerm) } else { err = Copy(path.Join(srcPath, info), curPath) } if err != nil { return err } } return nil }
[ "func", "CopyDir", "(", "srcPath", ",", "destPath", "string", ",", "filters", "...", "func", "(", "filePath", "string", ")", "bool", ")", "error", "{", "if", "IsExist", "(", "destPath", ")", "{", "return", "errors", ".", "New", "(", "\"file or directory al...
// CopyDir copy files recursively from source to target directory. // // The filter accepts a function that process the path info. // and should return true for need to filter. // // It returns error when error occurs in underlying functions.
[ "CopyDir", "copy", "files", "recursively", "from", "source", "to", "target", "directory", ".", "The", "filter", "accepts", "a", "function", "that", "process", "the", "path", "info", ".", "and", "should", "return", "true", "for", "need", "to", "filter", ".", ...
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L165-L203
train
gpmgo/gopm
modules/base/tool.go
ExecCmdDirBytes
func ExecCmdDirBytes(dir, cmdName string, args ...string) ([]byte, []byte, error) { bufOut := new(bytes.Buffer) bufErr := new(bytes.Buffer) cmd := exec.Command(cmdName, args...) cmd.Dir = dir cmd.Stdout = bufOut cmd.Stderr = bufErr err := cmd.Run() return bufOut.Bytes(), bufErr.Bytes(), err }
go
func ExecCmdDirBytes(dir, cmdName string, args ...string) ([]byte, []byte, error) { bufOut := new(bytes.Buffer) bufErr := new(bytes.Buffer) cmd := exec.Command(cmdName, args...) cmd.Dir = dir cmd.Stdout = bufOut cmd.Stderr = bufErr err := cmd.Run() return bufOut.Bytes(), bufErr.Bytes(), err }
[ "func", "ExecCmdDirBytes", "(", "dir", ",", "cmdName", "string", ",", "args", "...", "string", ")", "(", "[", "]", "byte", ",", "[", "]", "byte", ",", "error", ")", "{", "bufOut", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "bufErr", ":=",...
// ExecCmdDirBytes executes system command in given directory // and return stdout, stderr in bytes type, along with possible error.
[ "ExecCmdDirBytes", "executes", "system", "command", "in", "given", "directory", "and", "return", "stdout", "stderr", "in", "bytes", "type", "along", "with", "possible", "error", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L207-L218
train
gpmgo/gopm
modules/base/tool.go
ExecCmdBytes
func ExecCmdBytes(cmdName string, args ...string) ([]byte, []byte, error) { return ExecCmdDirBytes("", cmdName, args...) }
go
func ExecCmdBytes(cmdName string, args ...string) ([]byte, []byte, error) { return ExecCmdDirBytes("", cmdName, args...) }
[ "func", "ExecCmdBytes", "(", "cmdName", "string", ",", "args", "...", "string", ")", "(", "[", "]", "byte", ",", "[", "]", "byte", ",", "error", ")", "{", "return", "ExecCmdDirBytes", "(", "\"\"", ",", "cmdName", ",", "args", "...", ")", "\n", "}" ]
// ExecCmdBytes executes system command // and return stdout, stderr in bytes type, along with possible error.
[ "ExecCmdBytes", "executes", "system", "command", "and", "return", "stdout", "stderr", "in", "bytes", "type", "along", "with", "possible", "error", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L222-L224
train
gpmgo/gopm
modules/base/tool.go
ExecCmdDir
func ExecCmdDir(dir, cmdName string, args ...string) (string, string, error) { bufOut, bufErr, err := ExecCmdDirBytes(dir, cmdName, args...) return string(bufOut), string(bufErr), err }
go
func ExecCmdDir(dir, cmdName string, args ...string) (string, string, error) { bufOut, bufErr, err := ExecCmdDirBytes(dir, cmdName, args...) return string(bufOut), string(bufErr), err }
[ "func", "ExecCmdDir", "(", "dir", ",", "cmdName", "string", ",", "args", "...", "string", ")", "(", "string", ",", "string", ",", "error", ")", "{", "bufOut", ",", "bufErr", ",", "err", ":=", "ExecCmdDirBytes", "(", "dir", ",", "cmdName", ",", "args", ...
// ExecCmdDir executes system command in given directory // and return stdout, stderr in string type, along with possible error.
[ "ExecCmdDir", "executes", "system", "command", "in", "given", "directory", "and", "return", "stdout", "stderr", "in", "string", "type", "along", "with", "possible", "error", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L228-L231
train
gpmgo/gopm
modules/base/tool.go
ExecCmd
func ExecCmd(cmdName string, args ...string) (string, string, error) { return ExecCmdDir("", cmdName, args...) }
go
func ExecCmd(cmdName string, args ...string) (string, string, error) { return ExecCmdDir("", cmdName, args...) }
[ "func", "ExecCmd", "(", "cmdName", "string", ",", "args", "...", "string", ")", "(", "string", ",", "string", ",", "error", ")", "{", "return", "ExecCmdDir", "(", "\"\"", ",", "cmdName", ",", "args", "...", ")", "\n", "}" ]
// ExecCmd executes system command // and return stdout, stderr in string type, along with possible error.
[ "ExecCmd", "executes", "system", "command", "and", "return", "stdout", "stderr", "in", "string", "type", "along", "with", "possible", "error", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L235-L237
train
gpmgo/gopm
modules/base/tool.go
IsSliceContainsStr
func IsSliceContainsStr(sl []string, str string) bool { str = strings.ToLower(str) for _, s := range sl { if strings.ToLower(s) == str { return true } } return false }
go
func IsSliceContainsStr(sl []string, str string) bool { str = strings.ToLower(str) for _, s := range sl { if strings.ToLower(s) == str { return true } } return false }
[ "func", "IsSliceContainsStr", "(", "sl", "[", "]", "string", ",", "str", "string", ")", "bool", "{", "str", "=", "strings", ".", "ToLower", "(", "str", ")", "\n", "for", "_", ",", "s", ":=", "range", "sl", "{", "if", "strings", ".", "ToLower", "(",...
// IsSliceContainsStr returns true if the string exists in given slice.
[ "IsSliceContainsStr", "returns", "true", "if", "the", "string", "exists", "in", "given", "slice", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L300-L308
train
gpmgo/gopm
modules/base/tool.go
ToStr
func ToStr(value interface{}, args ...int) (s string) { switch v := value.(type) { case bool: s = strconv.FormatBool(v) case float32: s = strconv.FormatFloat(float64(v), 'f', argInt(args).Get(0, -1), argInt(args).Get(1, 32)) case float64: s = strconv.FormatFloat(v, 'f', argInt(args).Get(0, -1), argInt(args).Get(1, 64)) case int: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int8: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int16: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int32: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int64: s = strconv.FormatInt(v, argInt(args).Get(0, 10)) case uint: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint8: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint16: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint32: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint64: s = strconv.FormatUint(v, argInt(args).Get(0, 10)) case string: s = v case []byte: s = string(v) default: s = fmt.Sprintf("%v", v) } return s }
go
func ToStr(value interface{}, args ...int) (s string) { switch v := value.(type) { case bool: s = strconv.FormatBool(v) case float32: s = strconv.FormatFloat(float64(v), 'f', argInt(args).Get(0, -1), argInt(args).Get(1, 32)) case float64: s = strconv.FormatFloat(v, 'f', argInt(args).Get(0, -1), argInt(args).Get(1, 64)) case int: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int8: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int16: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int32: s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) case int64: s = strconv.FormatInt(v, argInt(args).Get(0, 10)) case uint: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint8: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint16: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint32: s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) case uint64: s = strconv.FormatUint(v, argInt(args).Get(0, 10)) case string: s = v case []byte: s = string(v) default: s = fmt.Sprintf("%v", v) } return s }
[ "func", "ToStr", "(", "value", "interface", "{", "}", ",", "args", "...", "int", ")", "(", "s", "string", ")", "{", "switch", "v", ":=", "value", ".", "(", "type", ")", "{", "case", "bool", ":", "s", "=", "strconv", ".", "FormatBool", "(", "v", ...
// Convert any type to string.
[ "Convert", "any", "type", "to", "string", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L711-L747
train
gpmgo/gopm
modules/base/tool.go
GetTempDir
func GetTempDir() string { return path.Join(os.TempDir(), ToStr(time.Now().Nanosecond())) }
go
func GetTempDir() string { return path.Join(os.TempDir(), ToStr(time.Now().Nanosecond())) }
[ "func", "GetTempDir", "(", ")", "string", "{", "return", "path", ".", "Join", "(", "os", ".", "TempDir", "(", ")", ",", "ToStr", "(", "time", ".", "Now", "(", ")", ".", "Nanosecond", "(", ")", ")", ")", "\n", "}" ]
//GetTempDir generates and returns time-based unique temporary path.
[ "GetTempDir", "generates", "and", "returns", "time", "-", "based", "unique", "temporary", "path", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L761-L763
train
gpmgo/gopm
modules/base/tool.go
HttpGetBytes
func HttpGetBytes(client *http.Client, url string, header http.Header) ([]byte, error) { rc, err := HttpGet(client, url, header) if err != nil { return nil, err } defer rc.Close() return ioutil.ReadAll(rc) }
go
func HttpGetBytes(client *http.Client, url string, header http.Header) ([]byte, error) { rc, err := HttpGet(client, url, header) if err != nil { return nil, err } defer rc.Close() return ioutil.ReadAll(rc) }
[ "func", "HttpGetBytes", "(", "client", "*", "http", ".", "Client", ",", "url", "string", ",", "header", "http", ".", "Header", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "rc", ",", "err", ":=", "HttpGet", "(", "client", ",", "url", ",", ...
// HttpGetBytes gets the specified resource. ErrNotFound is returned if the server // responds with status 404.
[ "HttpGetBytes", "gets", "the", "specified", "resource", ".", "ErrNotFound", "is", "returned", "if", "the", "server", "responds", "with", "status", "404", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/base/tool.go#L796-L803
train
gpmgo/gopm
modules/goconfig/conf.go
newConfigFile
func newConfigFile(fileNames []string) *ConfigFile { c := new(ConfigFile) c.fileNames = fileNames c.data = make(map[string]map[string]string) c.keyList = make(map[string][]string) c.sectionComments = make(map[string]string) c.keyComments = make(map[string]map[string]string) c.BlockMode = true return c }
go
func newConfigFile(fileNames []string) *ConfigFile { c := new(ConfigFile) c.fileNames = fileNames c.data = make(map[string]map[string]string) c.keyList = make(map[string][]string) c.sectionComments = make(map[string]string) c.keyComments = make(map[string]map[string]string) c.BlockMode = true return c }
[ "func", "newConfigFile", "(", "fileNames", "[", "]", "string", ")", "*", "ConfigFile", "{", "c", ":=", "new", "(", "ConfigFile", ")", "\n", "c", ".", "fileNames", "=", "fileNames", "\n", "c", ".", "data", "=", "make", "(", "map", "[", "string", "]", ...
// newConfigFile creates an empty configuration representation.
[ "newConfigFile", "creates", "an", "empty", "configuration", "representation", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L69-L78
train
gpmgo/gopm
modules/goconfig/conf.go
DeleteKey
func (c *ConfigFile) DeleteKey(section, key 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 } // Check if key exists. if _, ok := c.data[section][key]; ok { delete(c.data[section], key) // Remove comments of key. c.SetKeyComments(section, key, "") // Get index of key. i := 0 for _, keyName := range c.keyList[section] { if keyName == key { break } i++ } // Remove from key list. c.keyList[section] = append(c.keyList[section][:i], c.keyList[section][i+1:]...) return true } return false }
go
func (c *ConfigFile) DeleteKey(section, key 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 } // Check if key exists. if _, ok := c.data[section][key]; ok { delete(c.data[section], key) // Remove comments of key. c.SetKeyComments(section, key, "") // Get index of key. i := 0 for _, keyName := range c.keyList[section] { if keyName == key { break } i++ } // Remove from key list. c.keyList[section] = append(c.keyList[section][:i], c.keyList[section][i+1:]...) return true } return false }
[ "func", "(", "c", "*", "ConfigFile", ")", "DeleteKey", "(", "section", ",", "key", "string", ")", "bool", "{", "if", "len", "(", "section", ")", "==", "0", "{", "section", "=", "DEFAULT_SECTION", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "c", ...
// DeleteKey deletes the key in given section. // It returns true if the key was deleted, // or returns false if the section or key didn't exist.
[ "DeleteKey", "deletes", "the", "key", "in", "given", "section", ".", "It", "returns", "true", "if", "the", "key", "was", "deleted", "or", "returns", "false", "if", "the", "section", "or", "key", "didn", "t", "exist", "." ]
7edb73a0f439c016ee40b6608bc271c7fc4462e9
https://github.com/gpmgo/gopm/blob/7edb73a0f439c016ee40b6608bc271c7fc4462e9/modules/goconfig/conf.go#L116-L145
train
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", ...
// 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", "!=", "ni...
// 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", ...
// 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", ...
// 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", ...
// 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", ...
// 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", "!=", ...
// 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", ".", "sectionLi...
// 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", "{", "if", "len", "(", "section", ")", "==", "0", "{", "section", "=", "DEFAULT_SECTION", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "c", ...
// 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", "{", "if", "len", "(", "section", ")", "==", "0", "{", "section", "=", "DEFAULT_SECTION", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "c", ".", "data...
// 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", ")", "{", "if", "len", "(", "section", ")", "==", "0", "{", "section", "=", "DEFAULT_SECTION", "\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", ":"...
// 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", "\"git\"", ":", "branch", ",", "stderr", ",", "err", ":=", "base", ".", "ExecCmdDir", "(", "n", ".", "InstallGopath", ",", "\"gi...
// 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"...
// 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", "for", "_", ",", "gopath", ":=", "range", "base", ".", "GetGOPATHs", "(", ")", "{", "if", "stri...
// 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"...
// 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", "(", "\"GOPATH\"", ...
// 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", ",", "\".git\"", ")", ")", ":", "return", "\"git\"", "\n", "case", "base", ".", "IsExist", "(",...
// 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", ",", "\"src\"", ")", ...
// 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", "\...
// 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", "!="...
// 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", "(", "CommandHelp...
// 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"...
// 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", "for", "_", ",", "f", ":...
// 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", "f", ",", "err", ":=", "os", ".", "Open", ...
// 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", ",", "glob...
// 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", "....
// 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", ")", "{", "log", ".", "Info", "(", "\"Downloading package: %s\"", ",", "...
// 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", ")", "{", "var", "f", "*", "os", ".", "File", "\n", "if", "f", ",", "err", "=", "os", ".", "Create", "(", "filename", ")", ";", "err", "!=...
// 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", "(",...
// 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", "...
// 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", "_...
// 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...
// 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", ...
// 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", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "PkgNameListFile", ")", "\n", "if", "err"...
// 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", "(", "\"no match packa...
// 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", "...
// 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", ":", "\"A new cli application\"", ",", "Version", ":", "\"0.0.0\"", ",", "BashComplete", ":", "DefaultAppComplete", ",", ...
// 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", "(", "er...
// 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", "(", "\"debug\"", ")", "\n", "log", ".", "NonColor", "=", "ctx", ".", "GlobalBool", "(", "\"noterm\""...
// 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", ")", "{", "fileNames", ":=", "make", "(", "[", "]", "string", ",", "1", ",", "len", "(", "moreFiles", ")", ...
// 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", ...
// 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", ...
// 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", ...
// 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", ".", "NewW...
// 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", "{", "r...
// 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", "if", "len", ...
// 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", "}", "...
// 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", "if", "strings", ".", "TrimSpace", "(...
// 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", ":=", "\"gorp - undefined\"", "\n", "if", "d", ".", "Engine", "==", "\"\"...
// 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", "=="...
// 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", ...
// 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", "tableName", ":=", "\"\"", "\n", "if", "dyn", ",", "ok", ":=", "table", ".", "...
// 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", "tableName", ":=", "\"\"", "\n", "if", "dyn", ",", "ok", ":=", "table", ...
// 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", ",", "addIfExi...
// 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", "==", ...
// 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",...
// 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", "(", "&", "...
// 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", ",", "ar...
// 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", "(", "&",...
// 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"...
// 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", "(", "&", ...
// 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", ...
// 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", ",",...
// Begin starts a gorp Transaction
[ "Begin", "starts", "a", "gorp", "Transaction" ]
f3677d4a0a8838c846ed41bf41927f2c8713bd60
https://github.com/go-gorp/gorp/blob/f3677d4a0a8838c846ed41bf41927f2c8713bd60/db.go#L744-L758
train