Skip to content

Commit af4a0a5

Browse files
committed
godemon-cnf.json and project.json split to project.json
1 parent d212a93 commit af4a0a5

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

controllers/pv.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,13 @@ func initialize(name string, arch string, oso string) {
3838
project.Arch = arch
3939
project.OS = oso
4040
project.Vars = append(project.Vars, models.Var{"", ""})
41-
var commands models.Commands
4241
var command models.Command
4342
command.Name = "run"
4443
command.Path = path
4544
command.Option = "mod"
46-
commands.Commands = append(commands.Commands, command)
45+
project.Commands = append(project.Commands, command)
4746
file, _ := json.MarshalIndent(project, "", " ")
4847
_ = ioutil.WriteFile("project.json", file, 0644)
49-
file, _ = json.MarshalIndent(commands, "", " ")
50-
_ = ioutil.WriteFile("godemon-cnf.json", file, 0644)
5148
cmd := exec.Command("go", "mod", "init", name)
5249
cmd.Stdout = os.Stdout
5350
cmd.Stderr = os.Stderr
@@ -56,17 +53,17 @@ func initialize(name string, arch string, oso string) {
5653
}
5754

5855
func cnfFunc(command string, filepath string, modOrFile string) (string, string) {
59-
jsonFile, err := os.Open("godemon-cnf.json")
56+
jsonFile, err := os.Open("project.json")
6057
ErrorHandle(err)
6158
defer jsonFile.Close()
6259
byteValue, err := ioutil.ReadAll(jsonFile)
6360
ErrorHandle(err)
64-
var commands models.Commands
65-
json.Unmarshal(byteValue, &commands)
66-
for i := 0; i < len(commands.Commands); i++ {
67-
if command == commands.Commands[i].Name {
68-
filepath = commands.Commands[i].Path
69-
modOrFile = commands.Commands[i].Option
61+
var project models.Project
62+
json.Unmarshal(byteValue, &project)
63+
for i := 0; i < len(project.Commands); i++ {
64+
if command == project.Commands[i].Name {
65+
filepath = project.Commands[i].Path
66+
modOrFile = project.Commands[i].Option
7067
}
7168
}
7269
return filepath, modOrFile

models/cnf.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ type Command struct {
66
Option string `json:"file"`
77
}
88

9-
type Commands struct {
10-
Commands []Command `json:"commands"`
11-
}
12-
139
type Var struct {
1410
Key string `json:"key"`
1511
Value string `json:"value"`
1612
}
1713

1814
type Project struct {
19-
Name string `json:"name"`
20-
Arch string `json:"arch"`
21-
OS string `json:"os"`
22-
Path string `json:"path"`
23-
Vars []Var `json:"dev-vars"`
15+
Name string `json:"name"`
16+
Arch string `json:"arch"`
17+
OS string `json:"os"`
18+
Path string `json:"path"`
19+
Vars []Var `json:"dev-vars"`
20+
Commands []Command `json:"commands"`
2421
}

0 commit comments

Comments
 (0)