-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda.go
97 lines (78 loc) · 1.87 KB
/
lambda.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
package lambda
import (
"embed"
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
"github.com/lambda-platform/lambda/config"
"github.com/lambda-platform/lambda/generator"
"github.com/lambda-platform/lambda/puzzle/views"
"os"
)
var viewsfs embed.FS
type Lambda struct {
App *fiber.App
ModuleName string
IgnoreStatic bool
}
func (lambda *Lambda) Start() {
if len(os.Args) < 2 {
lambda.App.Listen(":" + config.Config.App.Port)
} else {
command := os.Args[1]
switch command {
case "table":
if len(os.Args) < 3 {
fmt.Println("Please provide table name: table your-table-name")
} else {
table := os.Args[2]
generator.GetStruct(table)
}
case "proto":
if len(os.Args) < 3 {
fmt.Println("Please provide table name: table your-table-name")
} else {
table := os.Args[2]
generator.GetProtobuf(table)
}
default:
fmt.Printf("Unknown command: %s\n", command)
os.Exit(1)
}
}
//defer DB.DB.Close()
}
type Settings struct {
ModuleName string
IgnoreStatic bool
}
func New(lambdaSettings ...*Settings) *Lambda {
if len(lambdaSettings) == 0 {
panic("Lambda settings required")
}
engine := html.New("./views", ".html")
engine.Reload(false)
err := engine.Load()
if err != nil {
panic(err)
}
_, err = engine.Templates.New("puzzle").Parse(views.PuzzleTemplate)
if err != nil {
panic(err)
}
lambda := &Lambda{
App: fiber.New(fiber.Config{
Views: engine,
BodyLimit: 100 * 1024 * 1024, // this is the default limit of 100MB
ReadBufferSize: 1024 * 1024, // Set this to the desired size in 1MB
//JSONEncoder: json.Marshal,
//JSONDecoder: json.Unmarshal,
}),
ModuleName: lambdaSettings[0].ModuleName,
IgnoreStatic: lambdaSettings[0].IgnoreStatic,
}
if !lambdaSettings[0].IgnoreStatic {
lambda.App.Static("/", "public")
}
return lambda
}