當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。