Skip to content

Commit 80b83c3

Browse files
committed
added os variables support
1 parent 0ea435c commit 80b83c3

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

controllers/functions.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
package controllers
22

33
import (
4+
"encoding/json"
5+
"fmt"
46
"godemon/models"
7+
"io/ioutil"
58
"os"
69
"time"
710
)
811

912
func ExecMOD() {
13+
jsonFile, err := os.Open("project.json")
14+
ErrorHandle(err)
15+
defer jsonFile.Close()
16+
byteValue, err := ioutil.ReadAll(jsonFile)
17+
ErrorHandle(err)
18+
var pr models.Project
19+
json.Unmarshal(byteValue, &pr)
20+
for i := 0; i < len(pr.Vars); i++ {
21+
os.Setenv(pr.Vars[i].Key, pr.Vars[i].Value)
22+
}
1023
execMOD()
1124
}
1225

@@ -26,6 +39,16 @@ func ProgramStarting(cnf *string, filepath string, modOrFile string, command str
2639
} else if *cnf == "deploy" {
2740
deploy()
2841
} else if init == true {
42+
if arch == "" && oso == "" {
43+
fmt.Println("\nPlease specify OS architecture and OS platform")
44+
os.Exit(1)
45+
} else if arch == "" {
46+
fmt.Println("\nPlease specify OS architecture")
47+
os.Exit(1)
48+
} else if oso == "" {
49+
fmt.Println("\nPlease specify OS platform")
50+
os.Exit(1)
51+
}
2952
initialize(name, arch, oso)
3053
} else if *help == true ||
3154
(*cnf == "" && filepath == "" && modOrFile == "" &&

controllers/pv.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func initialize(name string, arch string, oso string) {
3737
project.Name = name
3838
project.Arch = arch
3939
project.OS = oso
40+
project.Vars = append(project.Vars, models.Var{"", ""})
4041
var commands models.Commands
4142
var command models.Command
4243
command.Name = "run"

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func main() {
2727
}
2828
fmt.Println("File has been changed")
2929
if modOrFile == "mod" {
30-
os.Chdir("/home/nwagner/Desktop/godemon/godemon_test/")
30+
os.Chdir(filepath)
3131
controllers.TimeLog()
3232
cmd := exec.Command("go", "build", "-o", "app-godemon-app-godemon-tmp-generated")
3333
cmd.Stdout = os.Stdout

models/cnf.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ type Commands struct {
1010
Commands []Command `json:"commands"`
1111
}
1212

13+
type Var struct {
14+
Key string `json:"key"`
15+
Value string `json:"value"`
16+
}
17+
1318
type Project struct {
1419
Name string `json:"name"`
1520
Arch string `json:"arch"`
1621
OS string `json:"os"`
1722
Path string `json:"path"`
23+
Vars []Var `json:"dev-vars"`
1824
}

readme.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,16 @@ If you need help with clie use command `./godemon -help`
5353
4. Create configuration of project - sample code:
5454
```json
5555
{
56-
"name": "godemon_test",
57-
"arch": "amd64",
58-
"os": "windows",
59-
"path": "/home/nwagner/Desktop/godemon_test"
56+
"name": "test2",
57+
"arch": "amd64",
58+
"os": "linux",
59+
"path": "/home/nwagner/Desktop/godemon/test2",
60+
"dev-vars": [
61+
{
62+
"key": "PORT",
63+
"value": "8800"
64+
}
65+
]
6066
}
6167
```
6268
5. Now you can use 2 types of commands:
@@ -65,8 +71,16 @@ If you need help with clie use command `./godemon -help`
6571

6672
b) `godemon -cnf=deploy`
6773

68-
Types of `-cnf`:
74+
#### Types of `-cnf`:
6975

7076
1. cnf - using `godemon-conf.json` to hot live reload
7177
2. deploy - using `projects.json` to compile program for many platforms
7278
3. cmd - to use this you need to pass parameters like - `-path -modOrFile ` allows you to easy hot live reloading
79+
80+
#### What is `dev-vars`?
81+
`dev-vars` are OS variables that are using when godemon is running this app.
82+
83+
`"key"` - name of var
84+
85+
`"value"` - value of var
86+
##### Remember! it doesn't works when you deploy your app

0 commit comments

Comments
 (0)