glaciers-in-archives/snowman

View on GitHub
internal/template/function/file.go

Summary

Maintainability
A
0 mins
Test Coverage
package function

import (
    "errors"
    "io/ioutil"
)

func ReadFile(filepath string) (string, error) {
    if filepath[0] == '/' || filepath[0] == '.' || filepath[0] == '~' {
        return "", errors.New("File path must be relative to the project root.")
    }

    bytes, err := ioutil.ReadFile(filepath)
    if err != nil {
        return "", err
    }

    return string(bytes), nil
}