-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
119 lines (108 loc) · 3.07 KB
/
main.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
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
package main
import (
"embed"
"encoding/json"
"fmt"
"math/rand"
"os"
"time"
"github.com/andrewarrow/feedback/aigen"
"github.com/andrewarrow/feedback/files"
"github.com/andrewarrow/feedback/gogen"
"github.com/andrewarrow/feedback/persist"
"github.com/andrewarrow/feedback/prefix"
"github.com/andrewarrow/feedback/router"
"github.com/andrewarrow/feedback/util"
)
//go:embed feedback.json
var embeddedFile []byte
//go:embed views/*.html
var embeddedTemplates embed.FS
//go:embed assets/**/*.*
var embeddedAssets embed.FS
func PrintHelp() {
fmt.Println("")
fmt.Println("feedback v1.0")
fmt.Println("")
fmt.Println(" help # this menu")
fmt.Println(" reset # reset database")
fmt.Println(" run # ")
fmt.Println("")
}
func main() {
rand.Seed(time.Now().UnixNano())
if len(os.Args) == 1 {
PrintHelp()
return
}
arg := os.Args[1]
prefix.FeedbackName = os.Getenv("FEEDBACK_NAME")
if arg == "reset" {
//r := router.NewRouter("DATABASE_URL")
//r.ResetDatabase()
} else if arg == "genmd" {
model := util.GetArg(2)
path := util.GetArg(3)
jsonBytes := getFeedbackJsonFile(path)
r := router.NewRouter("NO_DB", jsonBytes)
gogen.MakeMarkDown(r.Site, model)
} else if arg == "gencode" {
model := util.GetArg(2)
path := util.GetArg(3)
jsonBytes := getFeedbackJsonFile(path)
r := router.NewRouter("NO_DB", jsonBytes)
gogen.MakeRoutes(r.Site.Routes, model)
} else if arg == "ai" {
// davinci 2049 tokens
// gpt-3.5-turbo 4096 tokens lowest cost
// code-davinci-002 8001 tokens
prompt := util.GetArg(2)
aigen.RunImage(prompt)
} else if arg == "hash" {
text := util.PseudoUuid()
//text = "testing123"
hash := router.HashPassword(text)
fmt.Println(text)
fmt.Printf("update lyfe_users set username='',password='%s' where firebase_uid='';\n\n", hash)
} else if arg == "scan" {
//r := router.NewRouter("DATABASE_URL", embeddedFile)
db := os.Getenv("DATABASE_URL")
var site router.FeedbackSite
site.Models = persist.ScanSchema(db)
asBytes, _ := json.Marshal(site)
jqed := util.PipeToJq(string(asBytes))
files.SaveFile("feedback.json", jqed)
//tablesString := util.GetArg(2)
//list := persist.ModelsForTables(r.Db, tablesString)
//asBytes := router.ModelsToBytes(list)
//persist.SaveSchema(asBytes)
} else if arg == "guids" {
path := util.GetArg(2)
jsonBytes := getFeedbackJsonFile(path)
r := router.NewRouter("DATABASE_URL", jsonBytes)
router.MakeGuidsInTables(r.Db, r.Site.Models)
} else if arg == "init" {
path := util.GetArg(2)
router.InitNewApp(path)
} else if arg == "run" {
path := util.GetArg(2)
jsonBytes := getFeedbackJsonFile(path)
router.EmbeddedTemplates = embeddedTemplates
router.EmbeddedAssets = embeddedAssets
r := router.NewRouter("DATABASE_URL", jsonBytes)
r.BucketPath = "/Users/aa/bucket"
r.ListenAndServe(":3000")
} else if arg == "help" {
PrintHelp()
}
}
func getFeedbackJsonFile(path string) []byte {
var jsonBytes []byte
if path != "" {
asString := files.ReadFile(path)
jsonBytes = []byte(asString)
} else {
jsonBytes = embeddedFile
}
return jsonBytes
}