-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·89 lines (73 loc) · 2.22 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
package main
import (
"io/ioutil"
"log"
"os"
"os/signal"
"syscall"
"github.com/fatih/color"
bootstrap "github.com/openfaas/faas-provider"
"github.com/openfaas/faas-provider/types"
"github.com/vitwit/faas-akash/akash"
"github.com/vitwit/faas-akash/config"
akashTypes "github.com/vitwit/faas-akash/types"
)
func main() {
dir, err := ioutil.TempDir("./", "tmp")
if err != nil {
color.Red("error creating temp directory: %s", err)
return
}
//a non-nil map is required, write ops to a nil map can panic
svcMap := akashTypes.ServiceMap{}
// an optional config path can be provided
cfg, err := config.Read()
if err != nil {
log.Fatal(err)
}
done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-done
_ = os.RemoveAll(dir)
os.Exit(1)
}()
defer func() {
_ = os.RemoveAll(dir)
}()
Start(cfg, svcMap, dir)
}
// Start faas-akash
func Start(cfg *akashTypes.Config, serviceMap akashTypes.ServiceMap, dir string) {
//faasConfig := types.FaaSConfig{
// MaxIdleConns: 1000,
// MaxIdleConnsPerHost: 1000,
// ReadTimeout: cfg.ReadTimeout,
// WriteTimeout: cfg.WriteTimeout,
//}
resolver := akashTypes.InvokeResolver{
ServiceMap: serviceMap,
}
bootstrapHandlers := types.FaaSHandlers{
//FunctionProxy: proxy.NewHandlerFunc(faasConfig, resolver),
FunctionProxy: akash.Proxy(&resolver),
DeleteHandler: akash.DeleteHandler(),
DeployHandler: akash.Deploy(serviceMap, dir),
FunctionReader: akash.ReadHandler(serviceMap),
UpdateHandler: akash.Update(serviceMap, dir),
ReplicaReader: akash.ReplicaReader(serviceMap),
ListNamespaceHandler: akash.ListNamespaces(),
//ReplicaUpdater: func(w http.ResponseWriter, r *http.Request) {},
//HealthHandler: func(w http.ResponseWriter, r *http.Request) {},
//InfoHandler: func(w http.ResponseWriter, r *http.Request) {},
}
bootstrapConfig := types.FaaSConfig{
ReadTimeout: cfg.ReadTimeout,
WriteTimeout: cfg.WriteTimeout,
TCPPort: &cfg.Port,
EnableBasicAuth: false,
EnableHealth: true,
}
log.Printf("TCP port: %d\n", cfg.Port)
bootstrap.Serve(&bootstrapHandlers, &bootstrapConfig)
}