aboutsummaryrefslogtreecommitdiff
path: root/pkg/u/file.go
blob: fafe0fb00f4b30262594af5ab6b32873515301bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package u

import (
	"errors"
	"log/slog"
	"os"
	"path/filepath"
)

func FileExist(filename string) bool {
	if _, err := os.Stat(filename); err == nil {
		return true

	} else if errors.Is(err, os.ErrNotExist) {
		return false
	} else {
		slog.Warn("Schrödinger's file: it may or may not exist", "file", filename) 
		// Schrodinger: file may or may not exist. To be extra safe it will
		// report the file doest not exist
		return false
	}
}

// This is just a slin wraper to make easier to compose path in the template
type Pathing string

func Root() Pathing {
	return "/"
}

func (s Pathing) AddPath(p string) Pathing {
	return Pathing(filepath.Join(string(s), p))
}

func (s Pathing) AddPaths(p []string) Pathing {
	f := filepath.Join(p...)
	return Pathing(filepath.Join(string(s), f))
}

func (s Pathing) Done() string {
	return string(s)
}