-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathmain.go
More file actions
121 lines (99 loc) · 3.24 KB
/
main.go
File metadata and controls
121 lines (99 loc) · 3.24 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
_ "time/tzdata"
"github.com/talkincode/toughradius/v9/config"
"github.com/talkincode/toughradius/v9/internal/adminapi"
"github.com/talkincode/toughradius/v9/internal/app"
"github.com/talkincode/toughradius/v9/internal/radiusd"
"github.com/talkincode/toughradius/v9/internal/webserver"
"github.com/talkincode/toughradius/v9/pkg/common"
"golang.org/x/sync/errgroup"
// Import vendor parsers for auto-registration via init()
"github.com/talkincode/toughradius/v9/internal/radiusd/plugins"
_ "github.com/talkincode/toughradius/v9/internal/radiusd/plugins/vendorparsers/parsers"
)
var g errgroup.Group
// Build information, injected via ldflags at compile time
// Example: go build -ldflags "-X main.version=1.0.0 -X main.buildTime=2024-01-01T00:00:00Z -X main.gitCommit=abc123"
var (
version = "develop"
buildTime = "unknown"
gitCommit = "unknown"
)
var (
h = flag.Bool("h", false, "help usage")
showVer = flag.Bool("v", false, "show version")
conffile = flag.String("c", "", "config yaml file")
initdb = flag.Bool("initdb", false, "run initdb")
printcfg = flag.Bool("printcfg", false, "print config")
)
func PrintVersion() {
_, _ = fmt.Fprintf(os.Stdout, "ToughRADIUS %s\n", version) //nolint:errcheck
_, _ = fmt.Fprintf(os.Stdout, "Build Time: %s\n", buildTime) //nolint:errcheck
_, _ = fmt.Fprintf(os.Stdout, "Git Commit: %s\n", gitCommit) //nolint:errcheck
_, _ = fmt.Fprintf(os.Stdout, "Go Version: %s\n", runtime.Version()) //nolint:errcheck
_, _ = fmt.Fprintf(os.Stdout, "OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) //nolint:errcheck
}
func printHelp() {
if *h {
flag.PrintDefaults()
os.Exit(0)
}
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
if *showVer {
PrintVersion()
os.Exit(0)
}
printHelp()
_config := config.LoadConfig(*conffile)
if *printcfg {
fmt.Printf("%+v\n", common.ToJson(_config))
return
}
// Create and initialize application context
application := app.NewApplication(_config)
application.Init(_config)
if *initdb {
application.InitDb()
return
}
defer application.Release()
// Initialize web server and admin API with dependency injection
g.Go(func() error {
webserver.Init(application)
adminapi.Init(application)
return webserver.Listen(application)
})
// Initialize RADIUS service with dependency injection
radiusService := radiusd.NewRadiusService(application)
defer radiusService.Release()
// Initialize plugin system after RadiusService is created
plugins.InitPlugins(application, radiusService.SessionRepo, radiusService.AccountingRepo)
// Start RADIUS Auth server
g.Go(func() error {
return radiusd.ListenRadiusAuthServer(application, radiusd.NewAuthService(radiusService))
})
// Start RADIUS Acct server
g.Go(func() error {
return radiusd.ListenRadiusAcctServer(application, radiusd.NewAcctService(radiusService))
})
// Start RadSec server
g.Go(func() error {
radsec := radiusd.NewRadsecService(
radiusd.NewAuthService(radiusService),
radiusd.NewAcctService(radiusService),
)
return radiusd.ListenRadsecServer(application, radsec)
})
if err := g.Wait(); err != nil {
log.Fatal(err)
}
}