-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (47 loc) · 1.09 KB
/
main.go
File metadata and controls
57 lines (47 loc) · 1.09 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
package main
import (
"embed"
"log"
"os"
"reflect"
"time"
_ "github.com/joho/godotenv/autoload"
"github.com/oleoneto/go-toolkit/helpers"
"github.com/oleoneto/httpy/cmd/cli"
"github.com/oleoneto/httpy/pkg"
"github.com/oleoneto/httpy/pkg/extensions"
"github.com/sirupsen/logrus"
)
func main() {
schema, err := sqlSchema.ReadFile("pkg/dbsql/schema.sql")
if err != nil {
log.Fatalln(err)
}
LoadExtensions()
cli.Execute(pkg.CLIConfig{
Plugins: plugins,
SQLSchema: schema,
DefaultTimeout: helpers.PointerTo(1 * time.Minute),
})
}
var data []byte
var plugins map[string]reflect.Value
var supportedExtensions = []string{
"RequestTransformerFunc",
"ResponseTransformerFunc",
"ResponsePassesValidationFunc",
}
//go:embed pkg/dbsql/schema.sql
var sqlSchema embed.FS
func LoadExtensions() {
if filepath, ok := os.LookupEnv("PLUGINS_FILEPATH"); ok {
var err error
if data, err = os.ReadFile(filepath); err != nil {
panic(err)
}
plugins = extensions.Load(string(data), supportedExtensions)
for k, v := range plugins {
logrus.Warnln("Loaded extension:", k, v)
}
}
}