mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 09:49:33 +08:00
refactor: move ReadFile to hrp/loader
This commit is contained in:
@@ -237,7 +237,7 @@ func InterfaceType(raw interface{}) string {
|
||||
|
||||
func loadFromCSV(path string) []map[string]interface{} {
|
||||
log.Info().Str("path", path).Msg("load csv file")
|
||||
file, err := ReadFile(path)
|
||||
file, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("read csv file failed")
|
||||
os.Exit(code.GetErrorCode(err))
|
||||
@@ -263,7 +263,7 @@ func loadFromCSV(path string) []map[string]interface{} {
|
||||
|
||||
func loadMessage(path string) []byte {
|
||||
log.Info().Str("path", path).Msg("load message file")
|
||||
file, err := ReadFile(path)
|
||||
file, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("read message file failed")
|
||||
os.Exit(code.GetErrorCode(err))
|
||||
@@ -271,22 +271,6 @@ func loadMessage(path string) []byte {
|
||||
return file
|
||||
}
|
||||
|
||||
func ReadFile(path string) ([]byte, error) {
|
||||
var err error
|
||||
path, err = filepath.Abs(path)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("path", path).Msg("convert absolute path failed")
|
||||
return nil, errors.Wrap(code.LoadFileError, err.Error())
|
||||
}
|
||||
|
||||
file, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("read file failed")
|
||||
return nil, errors.Wrap(code.LoadFileError, err.Error())
|
||||
}
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func GetFileNameWithoutExtension(path string) string {
|
||||
base := filepath.Base(path)
|
||||
ext := filepath.Ext(base)
|
||||
|
||||
Reference in New Issue
Block a user