(filename string)
| 933 | } |
| 934 | |
| 935 | func ReadFile(filename string) (string, error) { |
| 936 | exists, err := FileExists(filename) |
| 937 | |
| 938 | if err != nil { |
| 939 | return "", err |
| 940 | } |
| 941 | |
| 942 | if !exists { |
| 943 | errMsg := wski18n.T("File '{{.name}}' is not a valid file or it does not exist", |
| 944 | map[string]interface{}{ |
| 945 | "name": filename, |
| 946 | }) |
| 947 | whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXIT_CODE_ERR_USAGE, |
| 948 | whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE) |
| 949 | |
| 950 | return "", whiskErr |
| 951 | } |
| 952 | |
| 953 | file, err := ioutil.ReadFile(filename) |
| 954 | if err != nil { |
| 955 | whisk.Debug(whisk.DbgError, "os.ioutil.ReadFile(%s) error: %s\n", filename, err) |
| 956 | errMsg := wski18n.T("Unable to read the file '{{.name}}': {{.err}}", |
| 957 | map[string]interface{}{"name": filename, "err": err}) |
| 958 | whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXIT_CODE_ERR_GENERAL, |
| 959 | whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE) |
| 960 | return "", whiskErr |
| 961 | } |
| 962 | |
| 963 | return string(file), nil |
| 964 | } |
| 965 | |
| 966 | func writeFile(filename string, content string) error { |
| 967 | file, err := os.Create(filename) |
no test coverage detected