-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (43 loc) · 1.34 KB
/
main.go
File metadata and controls
50 lines (43 loc) · 1.34 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
package main
import (
"log/slog"
"os"
"github.com/GoCodeAlone/modular"
"github.com/GoCodeAlone/modular/feeders"
"github.com/GoCodeAlone/modular/chimux"
"github.com/GoCodeAlone/modular/httpclient"
"github.com/GoCodeAlone/modular/httpserver"
"github.com/GoCodeAlone/modular/modules/reverseproxy"
)
type AppConfig struct {
// Empty config struct for the http-client example
// Configuration is handled by individual modules
}
func main() {
// Create a new application and set feeders per instance
app := modular.NewStdApplication(
modular.NewStdConfigProvider(&AppConfig{}),
slog.New(slog.NewTextHandler(
os.Stdout,
&slog.HandlerOptions{},
)),
)
if stdApp, ok := app.(*modular.StdApplication); ok {
stdApp.SetConfigFeeders([]modular.Feeder{
feeders.NewYamlFeeder("config.yaml"),
feeders.NewEnvFeeder(),
})
}
// Register the modules in the correct order
// First the httpclient module, so it's available for the reverseproxy module
app.RegisterModule(httpclient.NewHTTPClientModule())
// Then the modules that depend on it
app.RegisterModule(chimux.NewChiMuxModule())
app.RegisterModule(reverseproxy.NewModule())
app.RegisterModule(httpserver.NewHTTPServerModule())
// Run application with lifecycle management
if err := app.Run(); err != nil {
app.Logger().Error("Application error", "error", err)
os.Exit(1)
}
}