當前位置: 首頁>>代碼示例>>Golang>>正文


Golang MungeObject.GetFileContents方法代碼示例

本文整理匯總了Golang中k8s/io/contrib/mungegithub/github.MungeObject.GetFileContents方法的典型用法代碼示例。如果您正苦於以下問題:Golang MungeObject.GetFileContents方法的具體用法?Golang MungeObject.GetFileContents怎麽用?Golang MungeObject.GetFileContents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在k8s/io/contrib/mungegithub/github.MungeObject的用法示例。


在下文中一共展示了MungeObject.GetFileContents方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getGeneratedFiles

// getGeneratedFiles returns a list of all automatically generated files in the repo. These include
// docs, deep_copy, and conversions
//
// It would be 'better' to call this for every commit but that takes
// a whole lot of time for almost always the same information, and if
// our results are slightly wrong, who cares? Instead look for the
// generated files once and if someone changed what files are generated
// we'll size slightly wrong. No biggie.
func (s *SizeMunger) getGeneratedFiles(obj *github.MungeObject) {
	if s.genFiles != nil {
		return
	}
	files := sets.NewString()
	prefixes := []string{}
	s.genFiles = &files
	s.genPrefixes = &prefixes

	file := s.generatedFilesFile
	if len(file) == 0 {
		glog.Infof("No --generated-files-config= supplied, applying no labels")
		return
	}
	fp, err := os.Open(file)
	if err != nil {
		glog.Errorf("Unable to open %q: %v", file, err)
		return
	}

	defer fp.Close()
	scanner := bufio.NewScanner(fp)
	for scanner.Scan() {
		line := scanner.Text()
		if strings.HasPrefix(line, "#") || line == "" {
			continue
		}
		fields := strings.Fields(line)
		if len(fields) != 2 {
			glog.Errorf("Invalid line in generated docs config %s: %q", file, line)
			continue
		}
		eType := fields[0]
		file := fields[1]
		if eType == "prefix" {
			prefixes = append(prefixes, file)
		} else if eType == "path" {
			files.Insert(file)
		} else if eType == "paths-from-repo" {
			docs, err := obj.GetFileContents(file, "")
			if err != nil {
				continue
			}
			docSlice := strings.Split(docs, "\n")
			files.Insert(docSlice...)
		} else {
			glog.Errorf("Invalid line in generated docs config, unknown type: %s, %q", eType, line)
			continue
		}
	}
	if scanner.Err() != nil {
		glog.Errorf("Error scanning %s: %v", file, err)
		return
	}
	s.genFiles = &files
	s.genPrefixes = &prefixes

	return
}
開發者ID:qinguoan,項目名稱:vulcan,代碼行數:67,代碼來源:size.go

示例2: getGeneratedFiles

// getGeneratedFiles returns a list of all automatically generated files in the repo. These include
// docs, deep_copy, and conversions
//
// It would be 'better' to call this for every commit but that takes
// a whole lot of time for almost always the same information, and if
// our results are slightly wrong, who cares? Instead look for the
// generated files once and if someone changed what files are generated
// we'll size slightly wrong. No biggie.
func (s *SizeMunger) getGeneratedFiles(obj *github.MungeObject) {
	if s.genFilePaths != nil {
		return
	}
	if s.genFilePrefixes != nil {
		return
	}
	if s.genFileNames != nil {
		return
	}
	if s.genPathPrefixes != nil {
		return
	}

	// Don't write into s yet, since this might fail, and these are indicators
	// to not repeat this function.
	paths := sets.NewString()
	filePrefixes := sets.NewString()
	fileNames := sets.NewString()
	pathPrefixes := sets.NewString()

	file := s.GeneratedFilesFile
	if len(file) == 0 {
		glog.Infof("No --generated-files-config= supplied, applying no labels")
		return
	}

	contents, err := obj.GetFileContents(file, "")
	if err != nil {
		glog.Errorf("Failed to read generated-files-config %q: %v", file, err)
	}

	lines := strings.Split(contents, "\n")
	for i, line := range lines {
		line := strings.TrimSpace(line)
		if strings.HasPrefix(line, "#") || line == "" {
			continue
		}
		fields := strings.Fields(line)
		if len(fields) != 2 {
			glog.Errorf("Invalid line %d in generated docs config %s: %q", i, file, line)
			continue
		}
		key := fields[0]
		val := fields[1]
		if key == "prefix" || key == "path-prefix" {
			pathPrefixes.Insert(val)
		} else if key == "file-prefix" {
			filePrefixes.Insert(val)
		} else if key == "file-name" {
			fileNames.Insert(val)
		} else if key == "path" {
			paths.Insert(val)
		} else if key == "paths-from-repo" {
			docs, err := obj.GetFileContents(val, "")
			if err != nil {
				continue
			}
			docSlice := strings.Split(docs, "\n")
			paths.Insert(docSlice...)
		} else {
			glog.Errorf("Invalid line %d in generated docs config, unknown key: %s, %q", i, key, line)
			continue
		}
	}

	// Save the results so we don't repeat this function.
	s.genFilePaths = paths
	s.genFilePrefixes = filePrefixes
	s.genFileNames = fileNames
	s.genPathPrefixes = pathPrefixes

	return
}
開發者ID:kubernetes,項目名稱:contrib,代碼行數:82,代碼來源:size.go


注:本文中的k8s/io/contrib/mungegithub/github.MungeObject.GetFileContents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。