_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q33000 | FprintZipData | train | func FprintZipData(dest *bytes.Buffer, zipData []byte) {
for _, b := range zipData {
if b == '\n' {
dest.WriteString(`\n`)
continue
}
if b == '\\' {
dest.WriteString(`\\`)
continue
}
if b == '"' {
dest.WriteString(`\"`)
continue
}
if (b >= 32 && b <= 126) || b == '\t' {
dest.WriteByt... | go | {
"resource": ""
} |
q33001 | New | train | func New() (http.FileSystem, error) {
if zipData == "" {
return nil, errors.New("statik/fs: no zip data registered")
}
zipReader, err := zip.NewReader(strings.NewReader(zipData), int64(len(zipData)))
if err != nil {
return nil, err
}
files := make(map[string]file, len(zipReader.File))
dirs := make(map[string... | go | {
"resource": ""
} |
q33002 | Open | train | func (fs *statikFS) Open(name string) (http.File, error) {
name = strings.Replace(name, "//", "/", -1)
if f, ok := fs.files[name]; ok {
return newHTTPFile(f), nil
}
return nil, os.ErrNotExist
} | go | {
"resource": ""
} |
q33003 | Read | train | func (f *httpFile) Read(p []byte) (n int, err error) {
if f.reader == nil && f.isDir {
return 0, io.EOF
}
return f.reader.Read(p)
} | go | {
"resource": ""
} |
q33004 | Seek | train | func (f *httpFile) Seek(offset int64, whence int) (ret int64, err error) {
return f.reader.Seek(offset, whence)
} | go | {
"resource": ""
} |
q33005 | Readdir | train | func (f *httpFile) Readdir(count int) ([]os.FileInfo, error) {
var fis []os.FileInfo
if !f.isDir {
return fis, nil
}
di, ok := f.FileInfo.(dirInfo)
if !ok {
return nil, fmt.Errorf("failed to read directory: %q", f.Name())
}
// If count is positive, the specified number of files will be returned,
// and if ... | go | {
"resource": ""
} |
q33006 | NewSource | train | func NewSource(opts ...source.Option) source.Source {
options := source.NewOptions(opts...)
// create the client
client, _ := api.NewClient(api.DefaultConfig())
// get and set options
if address := getAddress(options); address != "" {
_ = client.SetAddress(address)
}
if nameSpace := getNameSpace(options); n... | go | {
"resource": ""
} |
q33007 | Context | train | func Context(c *cli.Context) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, contextKey{}, c)
}
} | go | {
"resource": ""
} |
q33008 | WithNamespace | train | func WithNamespace(s string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, namespaceKey{}, s)
}
} | go | {
"resource": ""
} |
q33009 | WithName | train | func WithName(s string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, nameKey{}, s)
}
} | go | {
"resource": ""
} |
q33010 | WithConfigPath | train | func WithConfigPath(s string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, configPathKey{}, s)
}
} | go | {
"resource": ""
} |
q33011 | WithAddress | train | func WithAddress(a string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, addressKey{}, a)
}
} | go | {
"resource": ""
} |
q33012 | WithPath | train | func WithPath(p string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, pathKey{}, p)
}
} | go | {
"resource": ""
} |
q33013 | WithTLS | train | func WithTLS(t *tls.Config) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, tls.Config{}, t)
}
} | go | {
"resource": ""
} |
q33014 | WithChangeSet | train | func WithChangeSet(cs *source.ChangeSet) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, changeSetKey{}, cs)
}
} | go | {
"resource": ""
} |
q33015 | WithData | train | func WithData(d []byte) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, changeSetKey{}, &source.ChangeSet{
Data: d,
Format: "json",
})
}
} | go | {
"resource": ""
} |
q33016 | NewReader | train | func NewReader(opts ...reader.Option) reader.Reader {
options := reader.NewOptions(opts...)
return &jsonReader{
json: json.NewEncoder(),
opts: options,
}
} | go | {
"resource": ""
} |
q33017 | NewSource | train | func NewSource(opts ...source.Option) source.Source {
var (
options = source.NewOptions(opts...)
name = DefaultName
configPath = DefaultConfigPath
namespace = DefaultNamespace
)
prefix, ok := options.Context.Value(prefixKey{}).(string)
if ok {
name = prefix
}
cfg, ok := options.Context.Value... | go | {
"resource": ""
} |
q33018 | WithPrefix | train | func WithPrefix(p string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, prefixKey{}, p)
}
} | go | {
"resource": ""
} |
q33019 | StripPrefix | train | func StripPrefix(strip bool) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, stripPrefixKey{}, strip)
}
} | go | {
"resource": ""
} |
q33020 | WithStrippedPrefix | train | func WithStrippedPrefix(p ...string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, strippedPrefixKey{}, appendUnderscore(p))
}
} | go | {
"resource": ""
} |
q33021 | WithVariable | train | func WithVariable(v *runtimevar.Variable) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, variableKey{}, v)
}
} | go | {
"resource": ""
} |
q33022 | LoadFile | train | func LoadFile(path string) error {
return Load(file.NewSource(
file.WithPath(path),
))
} | go | {
"resource": ""
} |
q33023 | WithToken | train | func WithToken(p string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, tokenKey{}, p)
}
} | go | {
"resource": ""
} |
q33024 | reload | train | func (m *memory) reload() error {
m.Lock()
// merge sets
set, err := m.opts.Reader.Merge(m.sets...)
if err != nil {
m.Unlock()
return err
}
// set values
m.vals, _ = m.opts.Reader.Values(set)
m.snap = &loader.Snapshot{
ChangeSet: set,
Version: fmt.Sprintf("%d", time.Now().Unix()),
}
m.Unlock()
... | go | {
"resource": ""
} |
q33025 | Snapshot | train | func (m *memory) Snapshot() (*loader.Snapshot, error) {
if m.loaded() {
m.RLock()
snap := loader.Copy(m.snap)
m.RUnlock()
return snap, nil
}
// not loaded, sync
if err := m.Sync(); err != nil {
return nil, err
}
// make copy
m.RLock()
snap := loader.Copy(m.snap)
m.RUnlock()
return snap, nil
} | go | {
"resource": ""
} |
q33026 | Sync | train | func (m *memory) Sync() error {
var sets []*source.ChangeSet
m.Lock()
// read the source
var gerr []string
for _, source := range m.sources {
ch, err := source.Read()
if err != nil {
gerr = append(gerr, err.Error())
continue
}
sets = append(sets, ch)
}
// merge sets
set, err := m.opts.Reader.M... | go | {
"resource": ""
} |
q33027 | Sum | train | func (c *ChangeSet) Sum() string {
h := md5.New()
h.Write(c.Data)
return fmt.Sprintf("%x", h.Sum(nil))
} | go | {
"resource": ""
} |
q33028 | WithEncoder | train | func WithEncoder(e encoder.Encoder) Option {
return func(o *Options) {
o.Encoder = e
}
} | go | {
"resource": ""
} |
q33029 | WithLoader | train | func WithLoader(l loader.Loader) Option {
return func(o *Options) {
o.Loader = l
}
} | go | {
"resource": ""
} |
q33030 | WithContext | train | func WithContext(ctx *cli.Context, opts ...source.Option) source.Source {
return &cliSource{
ctx: ctx,
opts: source.NewOptions(opts...),
}
} | go | {
"resource": ""
} |
q33031 | WithSource | train | func WithSource(s source.Source) loader.Option {
return func(o *loader.Options) {
o.Source = append(o.Source, s)
}
} | go | {
"resource": ""
} |
q33032 | WithReader | train | func WithReader(r reader.Reader) loader.Option {
return func(o *loader.Options) {
o.Reader = r
}
} | go | {
"resource": ""
} |
q33033 | NewSource | train | func NewSource(opts ...source.Option) source.Source {
options := source.NewOptions(opts...)
// use default config
config := api.DefaultConfig()
// check if there are any addrs
a, ok := options.Context.Value(addressKey{}).(string)
if ok {
addr, port, err := net.SplitHostPort(a)
if ae, ok := err.(*net.AddrErr... | go | {
"resource": ""
} |
q33034 | WithResourcePath | train | func WithResourcePath(p string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, resourcePath{}, p)
}
} | go | {
"resource": ""
} |
q33035 | WithNameSpace | train | func WithNameSpace(n string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, nameSpace{}, n)
}
} | go | {
"resource": ""
} |
q33036 | WithSecretName | train | func WithSecretName(t string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, secretName{}, t)
}
} | go | {
"resource": ""
} |
q33037 | IncludeUnset | train | func IncludeUnset(b bool) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, includeUnsetKey{}, true)
}
} | go | {
"resource": ""
} |
q33038 | WithMaxResults | train | func WithMaxResults(maxResults int) userSearchF {
return func(s userSearch) userSearch {
s = append(s, userSearchParam{name: "maxResults", value: fmt.Sprintf("%d", maxResults)})
return s
}
} | go | {
"resource": ""
} |
q33039 | WithStartAt | train | func WithStartAt(startAt int) userSearchF {
return func(s userSearch) userSearch {
s = append(s, userSearchParam{name: "startAt", value: fmt.Sprintf("%d", startAt)})
return s
}
} | go | {
"resource": ""
} |
q33040 | WithActive | train | func WithActive(active bool) userSearchF {
return func(s userSearch) userSearch {
s = append(s, userSearchParam{name: "includeActive", value: fmt.Sprintf("%t", active)})
return s
}
} | go | {
"resource": ""
} |
q33041 | WithInactive | train | func WithInactive(inactive bool) userSearchF {
return func(s userSearch) userSearch {
s = append(s, userSearchParam{name: "includeInactive", value: fmt.Sprintf("%t", inactive)})
return s
}
} | go | {
"resource": ""
} |
q33042 | GetCreateMeta | train | func (s *IssueService) GetCreateMeta(projectkeys string) (*CreateMetaInfo, *Response, error) {
return s.GetCreateMetaWithOptions(&GetQueryOptions{ProjectKeys: projectkeys, Expand: "projects.issuetypes.fields"})
} | go | {
"resource": ""
} |
q33043 | GetCreateMetaWithOptions | train | func (s *IssueService) GetCreateMetaWithOptions(options *GetQueryOptions) (*CreateMetaInfo, *Response, error) {
apiEndpoint := "rest/api/2/issue/createmeta"
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
if options != nil {
q, err := query.Values(options)
if ... | go | {
"resource": ""
} |
q33044 | GetProjectWithName | train | func (m *CreateMetaInfo) GetProjectWithName(name string) *MetaProject {
for _, m := range m.Projects {
if strings.ToLower(m.Name) == strings.ToLower(name) {
return m
}
}
return nil
} | go | {
"resource": ""
} |
q33045 | GetProjectWithKey | train | func (m *CreateMetaInfo) GetProjectWithKey(key string) *MetaProject {
for _, m := range m.Projects {
if strings.ToLower(m.Key) == strings.ToLower(key) {
return m
}
}
return nil
} | go | {
"resource": ""
} |
q33046 | GetIssueTypeWithName | train | func (p *MetaProject) GetIssueTypeWithName(name string) *MetaIssueType {
for _, m := range p.IssueTypes {
if strings.ToLower(m.Name) == strings.ToLower(name) {
return m
}
}
return nil
} | go | {
"resource": ""
} |
q33047 | GetAllFields | train | func (t *MetaIssueType) GetAllFields() (map[string]string, error) {
ret := make(map[string]string)
for key := range t.Fields {
name, err := t.Fields.String(key + "/name")
if err != nil {
return nil, err
}
ret[name] = key
}
return ret, nil
} | go | {
"resource": ""
} |
q33048 | CheckCompleteAndAvailable | train | func (t *MetaIssueType) CheckCompleteAndAvailable(config map[string]string) (bool, error) {
mandatory, err := t.GetMandatoryFields()
if err != nil {
return false, err
}
all, err := t.GetAllFields()
if err != nil {
return false, err
}
// check templateconfig against mandatory fields
for key := range mandato... | go | {
"resource": ""
} |
q33049 | Create | train | func (s *ComponentService) Create(options *CreateComponentOptions) (*ProjectComponent, *Response, error) {
apiEndpoint := "rest/api/2/component"
req, err := s.client.NewRequest("POST", apiEndpoint, options)
if err != nil {
return nil, nil, err
}
component := new(ProjectComponent)
resp, err := s.client.Do(req, ... | go | {
"resource": ""
} |
q33050 | DownloadAttachment | train | func (s *IssueService) DownloadAttachment(attachmentID string) (*Response, error) {
apiEndpoint := fmt.Sprintf("secure/attachment/%s/", attachmentID)
req, err := s.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
jerr := NewJiraEr... | go | {
"resource": ""
} |
q33051 | Delete | train | func (s *IssueService) Delete(issueID string) (*Response, error) {
apiEndpoint := fmt.Sprintf("rest/api/2/issue/%s", issueID)
// to enable deletion of subtasks; without this, the request will fail if the issue has subtasks
deletePayload := make(map[string]interface{})
deletePayload["deleteSubtasks"] = "true"
cont... | go | {
"resource": ""
} |
q33052 | Authenticated | train | func (s *AuthenticationService) Authenticated() bool {
if s != nil {
if s.authType == authTypeSession {
return s.client.session != nil
} else if s.authType == authTypeBasic {
return s.username != ""
}
}
return false
} | go | {
"resource": ""
} |
q33053 | GetList | train | func (fs *FilterService) GetList() ([]*Filter, *Response, error) {
options := &GetQueryOptions{}
apiEndpoint := "rest/api/2/filter"
req, err := fs.client.NewRequest("GET", apiEndpoint, nil)
if err != nil {
return nil, nil, err
}
if options != nil {
q, err := query.Values(options)
if err != nil {
return... | go | {
"resource": ""
} |
q33054 | GetFavouriteList | train | 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 := New... | go | {
"resource": ""
} |
q33055 | Get | train | 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 {
j... | go | {
"resource": ""
} |
q33056 | NewJiraError | train | 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 := ... | go | {
"resource": ""
} |
q33057 | Error | train | 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.HTTPEr... | go | {
"resource": ""
} |
q33058 | LongError | train | 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.Wr... | go | {
"resource": ""
} |
q33059 | NewRequest | train | 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 :=... | go | {
"resource": ""
} |
q33060 | RoundTrip | train | 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 | {
"resource": ""
} |
q33061 | RoundTrip | train | 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 :... | go | {
"resource": ""
} |
q33062 | buildAuthRequest | train | 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 != ... | go | {
"resource": ""
} |
q33063 | IsDir | train | func IsDir(dir string) bool {
f, e := os.Stat(dir)
if e != nil {
return false
}
return f.IsDir()
} | go | {
"resource": ""
} |
q33064 | Copy | train | 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 reco... | go | {
"resource": ""
} |
q33065 | CopyDir | train | 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 in... | go | {
"resource": ""
} |
q33066 | ExecCmdDirBytes | train | 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 | {
"resource": ""
} |
q33067 | ExecCmdBytes | train | func ExecCmdBytes(cmdName string, args ...string) ([]byte, []byte, error) {
return ExecCmdDirBytes("", cmdName, args...)
} | go | {
"resource": ""
} |
q33068 | ExecCmdDir | train | func ExecCmdDir(dir, cmdName string, args ...string) (string, string, error) {
bufOut, bufErr, err := ExecCmdDirBytes(dir, cmdName, args...)
return string(bufOut), string(bufErr), err
} | go | {
"resource": ""
} |
q33069 | ExecCmd | train | func ExecCmd(cmdName string, args ...string) (string, string, error) {
return ExecCmdDir("", cmdName, args...)
} | go | {
"resource": ""
} |
q33070 | IsSliceContainsStr | train | 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 | {
"resource": ""
} |
q33071 | ToStr | train | 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).G... | go | {
"resource": ""
} |
q33072 | GetTempDir | train | func GetTempDir() string {
return path.Join(os.TempDir(), ToStr(time.Now().Nanosecond()))
} | go | {
"resource": ""
} |
q33073 | HttpGetBytes | train | 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 | {
"resource": ""
} |
q33074 | newConfigFile | train | 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 | {
"resource": ""
} |
q33075 | DeleteKey | train | 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 {
del... | go | {
"resource": ""
} |
q33076 | Bool | train | 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 | {
"resource": ""
} |
q33077 | Float64 | train | 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 | {
"resource": ""
} |
q33078 | Int64 | train | 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 | {
"resource": ""
} |
q33079 | MustValue | train | 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 | {
"resource": ""
} |
q33080 | MustValueSet | train | 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 | {
"resource": ""
} |
q33081 | MustValueRange | train | 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 | {
"resource": ""
} |
q33082 | MustValueArray | train | 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 | {
"resource": ""
} |
q33083 | GetSectionList | train | func (c *ConfigFile) GetSectionList() []string {
list := make([]string, len(c.sectionList))
copy(list, c.sectionList)
return list
} | go | {
"resource": ""
} |
q33084 | GetKeyList | train | 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
... | go | {
"resource": ""
} |
q33085 | DeleteSection | train | 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.SetSectionC... | go | {
"resource": ""
} |
q33086 | GetSection | train | 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,... | go | {
"resource": ""
} |
q33087 | IsFixed | train | func (pkg *Pkg) IsFixed() bool {
if pkg.Type == BRANCH || len(pkg.Value) == 0 {
return false
}
return true
} | go | {
"resource": ""
} |
q33088 | NewNode | train | 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.Ins... | go | {
"resource": ""
} |
q33089 | UpdateByVcs | train | 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(... | go | {
"resource": ""
} |
q33090 | Download | train | 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 giv... | go | {
"resource": ""
} |
q33091 | ParseTarget | train | 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
}... | go | {
"resource": ""
} |
q33092 | GetRootPath | train | 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
... | go | {
"resource": ""
} |
q33093 | ListImports | train | 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 settin... | go | {
"resource": ""
} |
q33094 | GetVcsName | train | 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 | {
"resource": ""
} |
q33095 | getDepList | train | 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) ... | go | {
"resource": ""
} |
q33096 | HasName | train | func (c Command) HasName(name string) bool {
return c.Name == name || c.ShortName == name
} | go | {
"resource": ""
} |
q33097 | IsEntry | train | func IsEntry(name string, entries []string) bool {
for _, e := range entries {
if e == name {
return true
}
}
return false
} | go | {
"resource": ""
} |
q33098 | DefaultAppComplete | train | func DefaultAppComplete(c *Context) {
for _, command := range c.App.Commands {
fmt.Println(command.Name)
if command.ShortName != "" {
fmt.Println(command.ShortName)
}
}
} | go | {
"resource": ""
} |
q33099 | ShowCommandHelp | train | 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 | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.