mirror of
https://github.com/qdm12/gluetun.git
synced 2025-12-11 13:56:50 -06:00
- Better settings tree structure logged using `qdm12/gotree` - Read settings from environment variables, then files, then secret files - Settings methods to default them, merge them and override them - `DNS_PLAINTEXT_ADDRESS` default changed to `127.0.0.1` to use DoT. Warning added if set to something else. - `HTTPPROXY_LISTENING_ADDRESS` instead of `HTTPPROXY_PORT` (with retro-compatibility)
32 lines
614 B
Go
32 lines
614 B
Go
package helpers
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
var (
|
|
ErrFileDoesNotExist = errors.New("file does not exist")
|
|
ErrFileRead = errors.New("cannot read file")
|
|
ErrFileClose = errors.New("cannot close file")
|
|
)
|
|
|
|
func FileExists(path string) (err error) {
|
|
path = filepath.Clean(path)
|
|
|
|
f, err := os.Open(path)
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
return fmt.Errorf("%w: %s", ErrFileDoesNotExist, path)
|
|
} else if err != nil {
|
|
return fmt.Errorf("%w: %s", ErrFileRead, err)
|
|
}
|
|
|
|
if err := f.Close(); err != nil {
|
|
return fmt.Errorf("%w: %s", ErrFileClose, err)
|
|
}
|
|
|
|
return nil
|
|
}
|