-
Notifications
You must be signed in to change notification settings - Fork 0
/
osext.go
57 lines (48 loc) · 1.2 KB
/
osext.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Package osext
package osext
import (
"os"
"path/filepath"
)
const (
osLinux = "linux"
osDarwin = "darwin"
osNetbsd = "netbsd"
osDragonfly = "dragonfly"
osSolaris = "solaris"
osFreebsd = "freebsd"
osOpenbsd = "openbsd"
)
// Внутренняя структура объекта пакета.
type impl struct {
cx string
ce error
wd string
we error
}
// New Конструктор объекта пакета.
func New() *impl {
var ost = new(impl)
ost.executableClean()
ost.wd, ost.we = os.Getwd()
return ost
}
func (ost *impl) executableClean() {
if ost.cx, ost.ce = ost.executable(); ost.ce != nil {
return
}
ost.cx = filepath.Clean(ost.cx)
return
}
// Executable returns an absolute path that can be used to re-invoke the current program. It may not be valid after
// the current program exits.
func (ost *impl) Executable() (string, error) { return ost.cx, ost.ce }
// ExecutableFolder Returns same path as Executable, returns just the folder path. Excludes the executable name and
// any trailing slash.
func (ost *impl) ExecutableFolder() (ret string, err error) {
if ret, err = ost.Executable(); err != nil {
return
}
ret, err = filepath.Dir(ret), nil
return
}