本文整理汇总了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
}
示例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
}
示例3: NewConfigFromFile
// NewConfigFromFile ...
func NewConfigFromFile(pth string) (Config, error) {
bytes, err := fileutil.ReadBytesFromFile(pth)
if err != nil {
return Config{}, err
}
return NewConfigFromBytes(bytes)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例8: ReadSSHConfigFileFromDir
// ReadSSHConfigFileFromDir ...
func ReadSSHConfigFileFromDir(workdirPth string) (SSHConfigModel, error) {
configBytes, err := fileutil.ReadBytesFromFile(fullSSHConfigFilePath(workdirPth))
if err != nil {
return SSHConfigModel{}, err
}
return readSSHConfigFromBytes(configBytes)
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}