Repository navigation
Expand file tree
/
Copy pathhelpers.go
More file actions
executable file
·121 lines (102 loc) · 2.72 KB
/
Copy pathhelpers.go
File metadata and controls
executable file
·121 lines (102 loc) · 2.72 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/fatih/color"
"github.com/joho/godotenv"
)
func setup(arg1, arg2 string) {
if arg1 != "new" && arg1 != "version" && arg1 != "help" {
err := godotenv.Load()
if err != nil {
exitGracefully(err)
}
path, err := os.Getwd()
if err != nil {
exitGracefully(err)
}
gho.RootPath = path
gho.DB.DataType = os.Getenv("DATABASE_TYPE")
}
}
func getDSN() string {
dbType := gho.DB.DataType
if dbType == "pgx" {
dbType = "postgres"
}
if dbType == "postgres" {
var dsn string
if os.Getenv("DATABASE_PASS") != "" {
dsn = fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s",
os.Getenv("DATABASE_USER"),
os.Getenv("DATABASE_PASS"),
os.Getenv("DATABASE_HOST"),
os.Getenv("DATABASE_PORT"),
os.Getenv("DATABASE_NAME"),
os.Getenv("DATABASE_SSL_MODE"))
} else {
dsn = fmt.Sprintf("postgres://%s@%s:%s/%s?sslmode=%s",
os.Getenv("DATABASE_USER"),
os.Getenv("DATABASE_HOST"),
os.Getenv("DATABASE_PORT"),
os.Getenv("DATABASE_NAME"),
os.Getenv("DATABASE_SSL_MODE"))
}
return dsn
}
return "mysql://" + gho.BuildDSN()
}
func showHelp() {
color.Green(`Available commands:
help - show the help commands
version - print application version
migrate - runs all up migrations
migrate down - reverses most recent migration
migrate reset - runs all down / up migrations
make migration <name> <format> - two new up and down migrations
make auth - new auth tables, models, middleware
make handler <name> - stub handler in the handlers folder
make model <name> - new model in the data directory
make session - database table as a session store
make mail <name> - two starter mail templates
`)
}
func updateSourceFiles(path string, fi os.FileInfo, err error) error {
// check for an error before doing anything else
if err != nil {
return err
}
// check if current file is directory
if fi.IsDir() {
return nil
}
// only check go files
matched, err := filepath.Match("*.go", fi.Name())
if err != nil {
return err
}
// we have a matching file
if matched {
// read file contents
read, err := os.ReadFile(path)
if err != nil {
exitGracefully(err)
}
newContents := strings.Replace(string(read), "myapp", appURL, -1)
// write the changed file
err = os.WriteFile(path, []byte(newContents), 0)
if err != nil {
exitGracefully(err)
}
}
return nil
}
func updateSource() {
// walk entire project folder, including subfolders
err := filepath.Walk(".", updateSourceFiles)
if err != nil {
exitGracefully(err)
}
}