• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang fileutil.WriteBytesToFile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/bitrise-io/go-utils/fileutil.WriteBytesToFile函数的典型用法代码示例。如果您正苦于以下问题:Golang WriteBytesToFile函数的具体用法?Golang WriteBytesToFile怎么用?Golang WriteBytesToFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了WriteBytesToFile函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: WriteStepSpecToFile

// WriteStepSpecToFile ...
func WriteStepSpecToFile(templateCollection models.StepCollectionModel, route SteplibRoute) error {
	pth := GetStepSpecPath(route)

	if exist, err := pathutil.IsPathExists(pth); err != nil {
		log.Error("Failed to check path:", err)
		return err
	} else if !exist {
		dir, _ := path.Split(pth)
		err := os.MkdirAll(dir, 0777)
		if err != nil {
			return err
		}
	} else {
		err := os.Remove(pth)
		if err != nil {
			return err
		}
	}

	collection, err := generateStepLib(route, templateCollection)
	if err != nil {
		return err
	}

	bytes, err := json.MarshalIndent(collection, "", "\t")
	if err != nil {
		return err
	}
	return fileutil.WriteBytesToFile(pth, bytes)
}
开发者ID:bitrise-io,项目名称:stepman,代码行数:31,代码来源:util.go


示例2: ExportFromKeychain

// ExportFromKeychain ...
func ExportFromKeychain(itemRefsToExport []C.CFTypeRef, outputFilePath string, isAskForPassword bool) error {
	passphraseCString := C.CString("")
	defer C.free(unsafe.Pointer(passphraseCString))

	var exportedData C.CFDataRef
	var exportParams C.SecItemImportExportKeyParameters
	exportParams.keyUsage = nil
	exportParams.keyAttributes = nil
	exportParams.version = C.SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION
	if isAskForPassword {
		exportParams.flags = C.kSecKeySecurePassphrase
		exportParams.passphrase = nil
		exportParams.alertTitle = nil

		promptText := C.CString("Enter a password which will be used to protect the exported items")
		defer C.free(unsafe.Pointer(promptText))
		exportParams.alertPrompt = convertCStringToCFString(promptText)
	} else {
		exportParams.flags = 0
		exportParams.passphrase = (C.CFTypeRef)(convertCStringToCFString(passphraseCString))
		exportParams.alertTitle = nil
		exportParams.alertPrompt = nil
	}

	// create a C array from the input
	ptr := (*unsafe.Pointer)(&itemRefsToExport[0])
	cfArrayForExport := C.CFArrayCreate(
		C.kCFAllocatorDefault,
		ptr,
		C.CFIndex(len(itemRefsToExport)),
		&C.kCFTypeArrayCallBacks)

	// do the export!
	status := C.SecItemExport(C.CFTypeRef(cfArrayForExport),
		C.kSecFormatPKCS12,
		0, //C.kSecItemPemArmour, // Use kSecItemPemArmour to add PEM armour - the .p12 generated by Keychain Access.app does NOT have PEM armour
		&exportParams,
		&exportedData)

	if status != C.errSecSuccess {
		return fmt.Errorf("SecItemExport: error (OSStatus): %d", status)
	}
	// exportedData now contains your PKCS12 data
	//  make sure it'll be released properly!
	defer C.CFRelease(C.CFTypeRef(exportedData))

	dataBytes := convertCFDataRefToGoBytes(exportedData)
	if dataBytes == nil || len(dataBytes) < 1 {
		return errors.New("ExportFromKeychain: failed to convert export data - nil or empty")
	}

	if err := fileutil.WriteBytesToFile(outputFilePath, dataBytes); err != nil {
		return fmt.Errorf("ExportFromKeychain: failed to write into file: %s", err)
	}

	log.Debug("Export - success")

	return nil
}
开发者ID:bitrise-tools,项目名称:codesigndoc,代码行数:60,代码来源:osxkeychain.go


示例3: saveBitriseConfig

func saveBitriseConfig(config ConfigModel) error {
	bytes, err := json.Marshal(config)
	if err != nil {
		return err
	}

	configPth := getBitriseConfigFilePath()
	return fileutil.WriteBytesToFile(configPth, bytes)
}
开发者ID:viktorbenei,项目名称:bitrise,代码行数:9,代码来源:configs.go


示例4: WriteNewWorkflowModel

// WriteNewWorkflowModel ...
func WriteNewWorkflowModel(pth string, newWorkflow bitriseModels.BitriseDataModel) error {
	bytes, err := yaml.Marshal(newWorkflow)
	if err != nil {
		return err
	}
	if err := fileutil.WriteBytesToFile(pth, bytes); err != nil {
		return err
	}
	return nil
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:11,代码来源:util.go


示例5: SaveConfigToFile

// SaveConfigToFile ...
func SaveConfigToFile(pth string, bitriseConf models.BitriseDataModel) error {
	contBytes, err := generateYAML(bitriseConf)
	if err != nil {
		return err
	}
	if err := fileutil.WriteBytesToFile(pth, contBytes); err != nil {
		return err
	}
	return nil
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:11,代码来源:util.go


示例6: WriteShareSteplibToFile

// WriteShareSteplibToFile ...
func WriteShareSteplibToFile(share ShareModel) error {
	var bytes []byte
	bytes, err := json.MarshalIndent(share, "", "\t")
	if err != nil {
		log.Error("[STEPMAN] - Failed to parse json:", err)
		return err
	}

	return fileutil.WriteBytesToFile(getShareFilePath(), bytes)
}
开发者ID:godrei,项目名称:stepman,代码行数:11,代码来源:share.go


示例7: WritePlistToFile

// WritePlistToFile ...
func WritePlistToFile(options map[string]interface{}, pth string) error {
	plistBytes, err := plist.MarshalIndent(options, plist.XMLFormat, "\t")
	if err != nil {
		return fmt.Errorf("failed to marshal export options model, error: %s", err)
	}
	if err := fileutil.WriteBytesToFile(pth, plistBytes); err != nil {
		return fmt.Errorf("failed to write export options, error: %s", err)
	}

	return nil
}
开发者ID:bitrise-io,项目名称:steps-xcode-archive,代码行数:12,代码来源:exportoptions.go


示例8: writeToFile

func (routes SteplibRoutes) writeToFile() error {
	routeMap := map[string]string{}
	for _, route := range routes {
		routeMap[route.SteplibURI] = route.FolderAlias
	}
	bytes, err := json.MarshalIndent(routeMap, "", "\t")
	if err != nil {
		return err
	}
	return fileutil.WriteBytesToFile(getRoutingFilePath(), bytes)
}
开发者ID:godrei,项目名称:stepman,代码行数:11,代码来源:paths.go


示例9: saveConfigs

// saveConfigs ...
//  only used for unit testing at the moment
func saveConfigs(configModel ConfigsModel) error {
	if err := ensureEnvmanConfigDirExists(); err != nil {
		return err
	}

	bytes, err := json.Marshal(configModel)
	if err != nil {
		return err
	}
	configsPth := getEnvmanConfigsFilePath()
	return fileutil.WriteBytesToFile(configsPth, bytes)
}
开发者ID:fbernardo,项目名称:envman,代码行数:14,代码来源:configs.go


示例10: WriteEnvMapToFile

// WriteEnvMapToFile ...
func WriteEnvMapToFile(pth string, envs []models.EnvironmentItemModel) error {
	if pth == "" {
		return errors.New("No path provided")
	}

	envYML, err := generateFormattedYMLForEnvModels(envs)
	if err != nil {
		return err
	}
	bytes, err := yaml.Marshal(envYML)
	if err != nil {
		return err
	}
	return fileutil.WriteBytesToFile(pth, bytes)
}
开发者ID:bazscsa,项目名称:envman,代码行数:16,代码来源:util.go


示例11: WriteIntoFileInDir

// WriteIntoFileInDir ...
func (model SSHConfigModel) WriteIntoFileInDir(workdirPth string) error {
	if err := model.normalizeAndValidate(); err != nil {
		return err
	}

	configBytes, err := model.serializeIntoJSONBytes()
	if err != nil {
		return err
	}

	if err := fileutil.WriteBytesToFile(fullSSHConfigFilePath(workdirPth), configBytes); err != nil {
		return err
	}

	return nil
}
开发者ID:bitrise-tools,项目名称:bitrise-machine,代码行数:17,代码来源:ssh_config.go


示例12: export

func export(c *cli.Context) {
	PrintBitriseHeaderASCIIArt(c.App.Version)

	outfilePth := c.String(OuputPathKey)
	if outfilePth == "" {
		log.Fatalln("No output file path specified!")
	}
	outFormat := c.String(OuputFormatKey)
	if outFormat == "" {
		log.Fatalln("No output file format specified!")
	}

	// Config validation
	bitriseConfig, err := CreateBitriseConfigFromCLIParams(c)
	if err != nil {
		log.Fatalf("Failed to create bitrise cofing, err: %s", err)
	}

	// serialize
	configBytes := []byte{}
	if outFormat == OutputFormatJSON {
		if c.Bool(PrettyFormatKey) {
			configBytes, err = json.MarshalIndent(bitriseConfig, "", "\t")
		} else {
			configBytes, err = json.Marshal(bitriseConfig)
		}
		if err != nil {
			log.Fatalln("Failed to generate JSON: ", err)
		}
	} else if outFormat == OutputFormatYML {
		configBytes, err = yaml.Marshal(bitriseConfig)
		if err != nil {
			log.Fatalln("Failed to generate YAML: ", err)
		}
	} else {
		log.Fatalln("Invalid output format: ", outFormat)
	}

	// write to file
	if err := fileutil.WriteBytesToFile(outfilePth, configBytes); err != nil {
		log.Fatalf("Failed to write to file (%s), error: ", err)
	}

	log.Infoln("Done, saved to path: ", outfilePth)
}
开发者ID:andrewhavens,项目名称:bitrise,代码行数:45,代码来源:export.go


示例13: initRelease

func initRelease(c *cli.Context) {
	//
	// Fail if git is not clean
	if exist, err := pathutil.IsPathExists(releaseman.DefaultConfigPth); err != nil {
		log.Fatalf("Failed to check path (%s), error: %#v", releaseman.DefaultConfigPth, err)
	} else if exist {
		if releaseman.IsCIMode {
			log.Fatalf("Release config already exist at (%s)", releaseman.DefaultConfigPth)
		} else {
			ok, err := goinp.AskForBoolWithDefault(fmt.Sprintf("Release config already exist at (%s), would you like to overwrite it?", releaseman.DefaultConfigPth), true)
			if err != nil {
				log.Fatalf("Failed to ask for bool, error: %#v", err)
			} else if !ok {
				log.Fatalln("Create release config aborted")
			}
		}
	}

	releaseConfig, err := collectInitConfigParams(releaseman.Config{}, c)
	if err != nil {
		log.Fatalf("Failed to collect config params, error: %#v", err)
	}
	releaseConfig.Changelog.ContentTemplate = releaseman.ChangelogContentTemplate
	releaseConfig.Changelog.HeaderTemplate = releaseman.ChangelogHeaderTemplate
	releaseConfig.Changelog.FooterTemplate = releaseman.ChangelogFooterTemplate

	//
	// Print config
	releaseConfig.Print(releaseman.FullMode)

	bytes, err := yaml.Marshal(releaseConfig)
	if err != nil {
		log.Fatalf("Failed to marshal config, error: %#v", err)
	}

	if err := fileutil.WriteBytesToFile(releaseman.DefaultConfigPth, bytes); err != nil {
		log.Fatalf("Failed to write config to file, error: %#v", err)
	}
}
开发者ID:bitrise-tools,项目名称:releaseman,代码行数:39,代码来源:command_init.go


示例14: create


//.........这里部分代码省略.........
	// Clone Step to tmp dir
	tmp, err := pathutil.NormalizedOSTempDirPath("")
	if err != nil {
		log.Fatalf("Failed to get temp directory, err: %s", err)
	}

	log.Infof("Cloning Step from (%s) with tag (%s) to temporary path (%s)", gitURI, tag, tmp)
	if err := cmdex.GitCloneTag(gitURI, tmp, tag); err != nil {
		log.Fatalf("Git clone failed, err: %s", err)
	}

	// Update step.yml
	tmpStepYMLPath := path.Join(tmp, "step.yml")
	bytes, err := fileutil.ReadBytesFromFile(tmpStepYMLPath)
	if err != nil {
		log.Fatalf("Failed to read Step from file, err: %s", err)
	}
	var stepModel models.StepModel
	if err := yaml.Unmarshal(bytes, &stepModel); err != nil {
		log.Fatalf("Failed to unmarchal Step, err: %s", err)
	}

	commit, err := cmdex.GitGetCommitHashOfHEAD(tmp)
	if err != nil {
		log.Fatalf("Failed to get commit hash, err: %s", err)
	}
	stepModel.Source = &models.StepSourceModel{
		Git:    gitURI,
		Commit: commit,
	}
	stepModel.PublishedAt = pointers.NewTimePtr(time.Now())

	// Validate step-yml
	if err := stepModel.Audit(); err != nil {
		log.Fatalf("Failed to validate Step, err: %s", err)
	}
	for _, input := range stepModel.Inputs {
		key, value, err := input.GetKeyValuePair()
		if err != nil {
			log.Fatalf("Failed to get Step input key-value pair, err: %s", err)
		}

		options, err := input.GetOptions()
		if err != nil {
			log.Fatalf("Failed to get Step input (%s) options, err: %s", key, err)
		}

		if len(options.ValueOptions) > 0 && value == "" {
			log.Warn("Step input with 'value_options', should contain default value!")
			log.Fatalf("Missing default value for Step input (%s).", key)
		}
	}
	if strings.Contains(*stepModel.Summary, "\n") {
		log.Warningln("Step summary should be one line!")
	}
	if utf8.RuneCountInString(*stepModel.Summary) > maxSummaryLength {
		log.Warningf("Step summary should contains maximum (%d) characters, actual: (%d)!", maxSummaryLength, utf8.RuneCountInString(*stepModel.Summary))
	}

	// Copy step.yml to steplib
	share.StepID = stepID
	share.StepTag = tag
	if err := WriteShareSteplibToFile(share); err != nil {
		log.Fatalf("Failed to save share steplib to file, err: %s", err)
	}

	log.Info("Step dir in collection:", stepDirInSteplib)
	if exist, err := pathutil.IsPathExists(stepDirInSteplib); err != nil {
		log.Fatalf("Failed to check path (%s), err: %s", stepDirInSteplib, err)
	} else if !exist {
		if err := os.MkdirAll(stepDirInSteplib, 0777); err != nil {
			log.Fatalf("Failed to create path (%s), err: %s", stepDirInSteplib, err)
		}
	}

	log.Infof("Checkout branch: %s", share.ShareBranchName())
	collectionDir := stepman.GetCollectionBaseDirPath(route)
	if err := cmdex.GitCheckout(collectionDir, share.ShareBranchName()); err != nil {
		if err := cmdex.GitCreateAndCheckoutBranch(collectionDir, share.ShareBranchName()); err != nil {
			log.Fatalf("Git failed to create and checkout branch, err: %s", err)
		}
	}

	stepBytes, err := yaml.Marshal(stepModel)
	if err != nil {
		log.Fatalf("Failed to marcshal Step model, err: %s", err)
	}
	if err := fileutil.WriteBytesToFile(stepYMLPathInSteplib, stepBytes); err != nil {
		log.Fatalf("Failed to write Step to file, err: %s", err)
	}

	// Update spec.json
	if err := stepman.ReGenerateStepSpec(route); err != nil {
		log.Fatalf("Failed to re-create steplib, err: %s", err)
	}

	printFinishCreate(share, stepDirInSteplib, toolMode)

	return nil
}
开发者ID:bitrise-io,项目名称:stepman,代码行数:101,代码来源:share_create.go


示例15: export

func export(c *cli.Context) error {
	// Expand cli.Context
	bitriseConfigBase64Data := c.String(ConfigBase64Key)

	bitriseConfigPath := c.String(ConfigKey)
	deprecatedBitriseConfigPath := c.String(PathKey)
	if bitriseConfigPath == "" && deprecatedBitriseConfigPath != "" {
		log.Warn("'path' key is deprecated, use 'config' instead!")
		bitriseConfigPath = deprecatedBitriseConfigPath
	}

	outfilePth := c.String(OuputPathKey)
	outFormat := c.String(OuputFormatKey)
	prettyFormat := c.Bool(PrettyFormatKey)
	//

	if outfilePth == "" {
		log.Fatal("No output file path specified!")
	}
	if outFormat == "" {
		log.Fatal("No output file format specified!")
	}

	// Config validation
	bitriseConfig, warnings, err := CreateBitriseConfigFromCLIParams(bitriseConfigBase64Data, bitriseConfigPath)
	for _, warning := range warnings {
		log.Warnf("warning: %s", warning)
	}
	if err != nil {
		log.Fatalf("Failed to create bitrise config, error: %s", err)
	}

	// serialize
	configBytes := []byte{}
	if outFormat == output.FormatJSON {
		if prettyFormat {
			configBytes, err = json.MarshalIndent(bitriseConfig, "", "\t")
		} else {
			configBytes, err = json.Marshal(bitriseConfig)
		}
		if err != nil {
			log.Fatalf("Failed to generate config JSON, error: %s", err)
		}
	} else if outFormat == output.FormatYML {
		configBytes, err = yaml.Marshal(bitriseConfig)
		if err != nil {
			log.Fatalf("Failed to generate config YML, error: %s", err)
		}
	} else {
		log.Fatalf("Invalid output format: %s", outFormat)
	}

	// write to file
	if err := fileutil.WriteBytesToFile(outfilePth, configBytes); err != nil {
		log.Fatalf("Failed to write file (%s), error: %s", outfilePth, err)
	}

	log.Infof("Done, saved to path: %s", outfilePth)

	return nil
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:61,代码来源:export.go


示例16: export

func export(c *cli.Context) error {
	// Input validation
	steplibURI := c.String("steplib")
	outputPth := c.String("output")
	exportTypeStr := c.String("export-type")

	if steplibURI == "" {
		return fmt.Errorf("Missing required input: steplib")
	}

	if outputPth == "" {
		return fmt.Errorf("Missing required input: output")
	}

	exportType := exportTypeFull
	if exportTypeStr != "" {
		var err error
		exportType, err = parseExportType(exportTypeStr)
		if err != nil {
			return err
		}
	}

	log.Infof("Exporting StepLib (%s) spec, export-type: %s, output: %s", steplibURI, exportTypeStr, outputPth)

	// Setup StepLib
	if exist, err := stepman.RootExistForCollection(steplibURI); err != nil {
		return fmt.Errorf("Failed to check if setup was done for StepLib, error: %s", err)
	} else if !exist {
		log.Infof("StepLib does not exist, setup...")
		if err := setupSteplib(steplibURI, false); err != nil {
			return fmt.Errorf("Failed to setup StepLib, error: %s", err)
		}
	}

	// Prepare spec
	stepLibSpec, err := stepman.ReadStepSpec(steplibURI)
	if err != nil {
		log.Fatalln("Failed to read StepLib spec, error: %s", err)
	}

	switch exportType {
	case exportTypeMinimal:
		stepLibSpec = convertToMinimalSpec(stepLibSpec)
	case exportTypeLatest:
		stepLibSpec = convertToLatestSpec(stepLibSpec)
	}

	stepLibSpecBytes, err := json.Marshal(stepLibSpec)
	if err != nil {
		return fmt.Errorf("Failed to marshal StepLib, error: %s", err)
	}

	// Export spec
	outputDir := filepath.Dir(outputPth)

	exist, err := pathutil.IsDirExists(outputDir)
	if err != nil {
		return fmt.Errorf("Failed to check if dir (%s) exist, error: %s", outputDir, err)
	}
	if !exist {
		if err := os.MkdirAll(outputDir, 0777); err != nil {
			return fmt.Errorf("Failed to create dir (%s), error: %s", outputDir, err)
		}
	}

	if err := fileutil.WriteBytesToFile(outputPth, stepLibSpecBytes); err != nil {
		return fmt.Errorf("Failed to write StepLib spec to: %s, error: %s", outputPth, err)
	}

	log.Infof("StepLib spec exported to: %s", outputPth)

	return nil
}
开发者ID:godrei,项目名称:stepman,代码行数:74,代码来源:export.go



注:本文中的github.com/bitrise-io/go-utils/fileutil.WriteBytesToFile函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang log.Detail函数代码示例发布时间:2022-05-24
下一篇:
Golang fileutil.ReadBytesFromFile函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap