aceberg/ForAuth

View on GitHub
internal/check/path.go

Summary

Maintainability
A
0 mins
Test Coverage
package check

import (
    "os"
    "path/filepath"
)

// Path - create path if not exists
func Path(path string) bool {

    _, err := os.Stat(path)

    if path != "" && err != nil {

        dir := filepath.Dir(path)

        err = os.MkdirAll(dir, os.ModePerm)
        IfError(err)

        _, err = os.Create(path)
        IfError(err)

        return false
    }

    return true
}

// Exists - check is file exists
func Exists(path string) bool {

    _, err := os.Stat(path)

    if path != "" && err != nil {

        return false
    }

    return true
}

// IsYaml - check if file got .yaml or .yml extension
func IsYaml(path string) bool {

    if Exists(path) {
        ext := filepath.Ext(path)
        if ext == ".yaml" || ext == ".yml" {
            return true
        }
    }

    return false
}