airshipui/util/utilfile/utilfile.go
Danny Massa a0d1b40230 Adding Angular to UI
Angular was added to organize the FE
of the UI application better. In doing so I
have rebuilt the build scripts, added a routing
mechanism for the Go server to route and
serve the compiled TS pages from Angular.

Change-Id: I7ae2cacfd90372fa536b1639e5b54a8da786e2cd
2020-08-04 10:58:46 -05:00

54 lines
1.3 KiB
Go

/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package utilfile
import (
"os"
"path/filepath"
"github.com/pkg/errors"
)
// Exists returns if a file or directory exists.
func Exists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return true, err
}
// FilePath returns the absolute path for a file name.
func FilePath(dirPath string, fileName string) (string, error) {
dir, dirPathErr := DirPath(dirPath)
if dirPathErr != nil {
return "", errors.WithStack(dirPathErr)
}
return filepath.Join(dir, fileName), nil
}
// DirPath returns the absolute path for a directory name.
func DirPath(dirPath string) (string, error) {
pwd, getwdErr := os.Getwd()
if getwdErr != nil {
return "", errors.WithStack(getwdErr)
}
return filepath.Join(pwd, dirPath), nil
}