-
Notifications
You must be signed in to change notification settings - Fork 30
/
procfile.go
63 lines (48 loc) · 950 Bytes
/
procfile.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
58
59
60
61
62
63
package main
import (
"io"
"os"
"regexp"
)
type procfileEntry struct {
Name string
Command string
Port int
}
func parseProcfile(path string, portBase, portStep int) (entries []procfileEntry) {
var f io.Reader
switch path {
case "-":
f = os.Stdin
default:
file, err := os.Open(path)
fatalOnErr(err)
defer file.Close()
f = file
}
re, _ := regexp.Compile(`^([\w-]+):\s+(.+)$`)
port := portBase
names := make(map[string]bool)
err := scanLines(f, func(b []byte) bool {
if len(b) == 0 {
return true
}
params := re.FindStringSubmatch(string(b))
if len(params) != 3 {
return true
}
name, cmd := params[1], params[2]
if names[name] {
fatal("Process names must be uniq")
}
names[name] = true
entries = append(entries, procfileEntry{name, cmd, port})
port += portStep
return true
})
fatalOnErr(err)
if len(entries) == 0 {
fatal("No entries was found in Procfile")
}
return
}