-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
37 lines (30 loc) · 945 Bytes
/
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
package main
import (
"net/http"
"ollamaGateway/config"
c "ollamaGateway/controllers"
"ollamaGateway/metrics"
"ollamaGateway/utils"
)
func main() {
if err := config.ReloadConfig(); err != nil {
panic("It was not possible to reload the config file:" + err.Error())
}
utils.ReloadLogger()
logger := utils.GetLogger()
config := config.GetConfig()
metrics.InitMetrics()
middApplyer := utils.NewMiddlewareApplyer(
c.RateLimitMiddleware,
c.IPAndAPIKeyMiddleware,
c.MetricsMiddleware,
)
http.HandleFunc("/", middApplyer.Apply(c.ProxyHandler))
http.HandleFunc("GET /config/reload", middApplyer.Apply(c.ReloadConfigHandler))
http.HandleFunc("GET /config/new-key", middApplyer.Apply(c.GenerateKeyHandler))
http.HandleFunc("GET "+config.Metrics.Endpoint, c.MetricsHandler)
logger.Info("Gateway running on " + config.GatewayAddress)
if err := http.ListenAndServe(config.GatewayAddress, nil); err != nil {
panic(err)
}
}