-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.go
More file actions
48 lines (41 loc) · 1012 Bytes
/
path.go
File metadata and controls
48 lines (41 loc) · 1012 Bytes
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
package main
import (
"fmt"
"path"
)
func base() {
// retorna o ultimo elemento do path
fmt.Println(path.Base("/b"))
fmt.Println(path.Base("/b/a"))
fmt.Println(path.Base("/"))
fmt.Println(path.Base(""))
}
func clean() {
paths := []string{
"a/c",
"a//c",
"a/c/.",
"a/c/b/..",
"/../a/c",
"/../a/b/../././/c",
"",
}
// Clean retorna o nome do caminho mais curto equivalente ao caminho por processamento puramente lexical.
for _, p := range paths {
fmt.Printf("Clean(%q) = %q\n", p, path.Clean(p))
}
}
func main() {
clean()
base()
// Ext retorna a extensão do nome do arquivo usada pelo path.
fmt.Println(path.Ext("/a/b/c/bar.css"))
// Join une qualquer número de elementos de path em um único path, separando-os com barras.
// Elementos vazios são ignorados.
fmt.Println(path.Join("a", "b", "c"))
fmt.Println(path.Join("a", "b/c"))
fmt.Println(path.Join("a/b", "c"))
fmt.Println(path.Join("", ""))
fmt.Println(path.Join("a", ""))
fmt.Println(path.Join("", "a"))
}