当前位置: 首页>>代码示例>>Golang>>正文


Golang fileutil.ReadBytesFromFile函数代码示例

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


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

示例1: loadBitriseConfig

func loadBitriseConfig() (ConfigModel, error) {
	if err := EnsureBitriseConfigDirExists(); err != nil {
		return ConfigModel{}, err
	}

	configPth := getBitriseConfigFilePath()
	if exist, err := pathutil.IsPathExists(configPth); err != nil {
		return ConfigModel{}, err
	} else if !exist {
		return ConfigModel{}, nil
	}

	bytes, err := fileutil.ReadBytesFromFile(configPth)
	if err != nil {
		return ConfigModel{}, err
	}

	if len(bytes) == 0 {
		return ConfigModel{}, errors.New("empty config file")
	}

	config := ConfigModel{}
	if err := json.Unmarshal(bytes, &config); err != nil {
		return ConfigModel{}, fmt.Errorf("failed to marshal config (%s), error: %s", string(bytes), err)
	}

	return config, nil
}
开发者ID:viktorbenei,项目名称:bitrise,代码行数:28,代码来源:configs.go

示例2: ReadSpecStep

// ReadSpecStep ...
func ReadSpecStep(pth string) (stepmanModels.StepModel, error) {
	if isExists, err := pathutil.IsPathExists(pth); err != nil {
		return stepmanModels.StepModel{}, err
	} else if !isExists {
		return stepmanModels.StepModel{}, errors.New(fmt.Sprint("No file found at path", pth))
	}

	bytes, err := fileutil.ReadBytesFromFile(pth)
	if err != nil {
		return stepmanModels.StepModel{}, err
	}

	var stepModel stepmanModels.StepModel
	if err := yaml.Unmarshal(bytes, &stepModel); err != nil {
		return stepmanModels.StepModel{}, err
	}

	if err := stepModel.Normalize(); err != nil {
		return stepmanModels.StepModel{}, err
	}

	if err := stepModel.Validate(false); err != nil {
		return stepmanModels.StepModel{}, err
	}

	if err := stepModel.FillMissingDefaults(); err != nil {
		return stepmanModels.StepModel{}, err
	}

	return stepModel, nil
}
开发者ID:bitrise-io,项目名称:bitrise-yml-converter,代码行数:32,代码来源:util.go

示例3: NewConfigFromFile

// NewConfigFromFile ...
func NewConfigFromFile(pth string) (Config, error) {
	bytes, err := fileutil.ReadBytesFromFile(pth)
	if err != nil {
		return Config{}, err
	}
	return NewConfigFromBytes(bytes)
}
开发者ID:bitrise-tools,项目名称:releaseman,代码行数:8,代码来源:configs.go

示例4: GetConfigs

// GetConfigs ...
func GetConfigs() (ConfigsModel, error) {
	configPth := getEnvmanConfigsFilePath()
	defaultConfigs := createDefaultConfigsModel()

	if isExist, err := pathutil.IsPathExists(configPth); err != nil {
		return ConfigsModel{}, err
	} else if !isExist {
		return defaultConfigs, nil
	}

	bytes, err := fileutil.ReadBytesFromFile(configPth)
	if err != nil {
		return ConfigsModel{}, err
	}

	type ConfigsFileMode struct {
		EnvBytesLimitInKB     *int `json:"env_bytes_limit_in_kb,omitempty"`
		EnvListBytesLimitInKB *int `json:"env_list_bytes_limit_in_kb,omitempty"`
	}

	var userConfigs ConfigsFileMode
	if err := json.Unmarshal(bytes, &userConfigs); err != nil {
		return ConfigsModel{}, err
	}

	if userConfigs.EnvBytesLimitInKB != nil {
		defaultConfigs.EnvBytesLimitInKB = *userConfigs.EnvBytesLimitInKB
	}
	if userConfigs.EnvListBytesLimitInKB != nil {
		defaultConfigs.EnvListBytesLimitInKB = *userConfigs.EnvListBytesLimitInKB
	}

	return defaultConfigs, nil
}
开发者ID:fbernardo,项目名称:envman,代码行数:35,代码来源:configs.go

示例5: readRouteMap

func readRouteMap() (SteplibRoutes, error) {
	exist, err := pathutil.IsPathExists(getRoutingFilePath())
	if err != nil {
		return SteplibRoutes{}, err
	} else if !exist {
		return SteplibRoutes{}, nil
	}

	bytes, err := fileutil.ReadBytesFromFile(getRoutingFilePath())
	if err != nil {
		return SteplibRoutes{}, err
	}
	var routeMap map[string]string
	if err := json.Unmarshal(bytes, &routeMap); err != nil {
		return SteplibRoutes{}, err
	}

	routes := []SteplibRoute{}
	for key, value := range routeMap {
		routes = append(routes, SteplibRoute{
			SteplibURI:  key,
			FolderAlias: value,
		})
	}

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

示例6: ParseStepYml

// ParseStepYml ...
func ParseStepYml(pth string, validate bool) (models.StepModel, error) {
	bytes, err := fileutil.ReadBytesFromFile(pth)
	if err != nil {
		return models.StepModel{}, err
	}

	var stepModel models.StepModel
	if err := yaml.Unmarshal(bytes, &stepModel); err != nil {
		return models.StepModel{}, err
	}

	if err := stepModel.Normalize(); err != nil {
		return models.StepModel{}, err
	}

	if validate {
		if err := stepModel.Audit(); err != nil {
			return models.StepModel{}, err
		}
	}

	if err := stepModel.FillMissingDefaults(); err != nil {
		return models.StepModel{}, err
	}

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

示例7: CollectEnvironmentsFromFile

// CollectEnvironmentsFromFile ...
func CollectEnvironmentsFromFile(pth string) ([]envmanModels.EnvironmentItemModel, error) {
	bytes, err := fileutil.ReadBytesFromFile(pth)
	if err != nil {
		return []envmanModels.EnvironmentItemModel{}, err
	}

	var envstore envmanModels.EnvsYMLModel
	if err := yaml.Unmarshal(bytes, &envstore); err != nil {
		return []envmanModels.EnvironmentItemModel{}, err
	}

	for _, env := range envstore.Envs {
		if err := env.Normalize(); err != nil {
			return []envmanModels.EnvironmentItemModel{}, err
		}
		if err := env.FillMissingDefaults(); err != nil {
			return []envmanModels.EnvironmentItemModel{}, err
		}
		if err := env.Validate(); err != nil {
			return []envmanModels.EnvironmentItemModel{}, err
		}
	}

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

示例8: ReadSSHConfigFileFromDir

// ReadSSHConfigFileFromDir ...
func ReadSSHConfigFileFromDir(workdirPth string) (SSHConfigModel, error) {
	configBytes, err := fileutil.ReadBytesFromFile(fullSSHConfigFilePath(workdirPth))
	if err != nil {
		return SSHConfigModel{}, err
	}

	return readSSHConfigFromBytes(configBytes)
}
开发者ID:bitrise-tools,项目名称:bitrise-machine,代码行数:9,代码来源:ssh_config.go

示例9: ReadEnvs

// ReadEnvs ...
func ReadEnvs(pth string) ([]models.EnvironmentItemModel, error) {
	bytes, err := fileutil.ReadBytesFromFile(pth)
	if err != nil {
		return []models.EnvironmentItemModel{}, err
	}

	return ParseEnvsYML(bytes)
}
开发者ID:fbernardo,项目名称:envman,代码行数:9,代码来源:util.go

示例10: ParseStepCollection

// ParseStepCollection ...
func ParseStepCollection(pth string) (models.StepCollectionModel, error) {
	bytes, err := fileutil.ReadBytesFromFile(pth)
	if err != nil {
		return models.StepCollectionModel{}, err
	}

	var stepCollection models.StepCollectionModel
	if err := yaml.Unmarshal(bytes, &stepCollection); err != nil {
		return models.StepCollectionModel{}, err
	}
	return stepCollection, nil
}
开发者ID:bitrise-io,项目名称:stepman,代码行数:13,代码来源:util.go

示例11: ParseStepGroupInfo

// ParseStepGroupInfo ...
func ParseStepGroupInfo(pth string) (models.StepGroupInfoModel, error) {
	bytes, err := fileutil.ReadBytesFromFile(pth)
	if err != nil {
		return models.StepGroupInfoModel{}, err
	}

	var stepGroupInfo models.StepGroupInfoModel
	if err := yaml.Unmarshal(bytes, &stepGroupInfo); err != nil {
		return models.StepGroupInfoModel{}, err
	}

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

示例12: LoadConfigFromFile

// LoadConfigFromFile ...
func LoadConfigFromFile(pth string) (Model, error) {
	bytes, err := fileutil.ReadBytesFromFile(pth)
	if err != nil {
		return Model{}, err
	}

	var m Model
	if err := json.Unmarshal(bytes, &m); err != nil {
		return Model{}, err
	}

	return m, nil
}
开发者ID:bitrise-tools,项目名称:bitrise-bridge,代码行数:14,代码来源:config.go

示例13: jwtConfigFromJSONKeyFile

func jwtConfigFromJSONKeyFile(pth string) (*jwt.Config, error) {
	jsonKeyBytes, err := fileutil.ReadBytesFromFile(pth)
	if err != nil {
		return nil, err
	}

	config, err := google.JWTConfigFromJSON(jsonKeyBytes, androidpublisher.AndroidpublisherScope)
	if err != nil {
		return nil, err
	}

	return config, nil
}
开发者ID:bitrise-steplib,项目名称:steps-google-play-deploy,代码行数:13,代码来源:main.go

示例14: ReadMachineConfigFileFromDir

// ReadMachineConfigFileFromDir ...
func ReadMachineConfigFileFromDir(workdirPth string, appendEnvs EnvItemsModel) (MachineConfigModel, error) {
	configBytes, err := fileutil.ReadBytesFromFile(path.Join(workdirPth, machineConfigFileName))
	if err != nil {
		return MachineConfigModel{}, fmt.Errorf("ReadMachineConfigFileFromDir: failed to read file: %s", err)
	}

	machineConfig, err := readMachineConfigFromBytes(configBytes, appendEnvs)
	if err != nil {
		return MachineConfigModel{}, fmt.Errorf("ReadMachineConfigFileFromDir: failed to parse configuration: %s", err)
	}

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

示例15: NewPluginFromYML

// NewPluginFromYML ...
func NewPluginFromYML(ymlPth string) (Plugin, error) {
	if isExists, err := pathutil.IsPathExists(ymlPth); err != nil {
		return Plugin{}, err
	} else if !isExists {
		return Plugin{}, fmt.Errorf("Plugin yml path (%s) doesn't exist", ymlPth)
	}

	bytes, err := fileutil.ReadBytesFromFile(ymlPth)
	if err != nil {
		return Plugin{}, err
	}

	return NewPluginFromBytes(bytes)
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:15,代码来源:models_methods.go


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