@@ -13,6 +13,8 @@ import (
13
13
"github.com/sirupsen/logrus"
14
14
)
15
15
16
+ // API represents the main HTTP API server for the Embedded Cluster application.
17
+ //
16
18
// @title Embedded Cluster API
17
19
// @version 0.1
18
20
// @description This is the API for the Embedded Cluster project.
@@ -31,7 +33,7 @@ import (
31
33
32
34
// @externalDocs.description OpenAPI
33
35
// @externalDocs.url https://swagger.io/resources/open-api/
34
- type api struct {
36
+ type API struct {
35
37
cfg types.APIConfig
36
38
37
39
logger logrus.FieldLogger
@@ -44,40 +46,47 @@ type api struct {
44
46
handlers handlers
45
47
}
46
48
47
- type apiOption func (* api )
49
+ // Option is a function that configures the API.
50
+ type Option func (* API )
48
51
49
- func WithAuthController (authController auth.Controller ) apiOption {
50
- return func (a * api ) {
52
+ // WithAuthController configures the auth controller for the API.
53
+ func WithAuthController (authController auth.Controller ) Option {
54
+ return func (a * API ) {
51
55
a .authController = authController
52
56
}
53
57
}
54
58
55
- func WithConsoleController (consoleController console.Controller ) apiOption {
56
- return func (a * api ) {
59
+ // WithConsoleController configures the console controller for the API.
60
+ func WithConsoleController (consoleController console.Controller ) Option {
61
+ return func (a * API ) {
57
62
a .consoleController = consoleController
58
63
}
59
64
}
60
65
61
- func WithLinuxInstallController (linuxInstallController linuxinstall.Controller ) apiOption {
62
- return func (a * api ) {
66
+ // WithLinuxInstallController configures the linux install controller for the API.
67
+ func WithLinuxInstallController (linuxInstallController linuxinstall.Controller ) Option {
68
+ return func (a * API ) {
63
69
a .linuxInstallController = linuxInstallController
64
70
}
65
71
}
66
72
67
- func WithLogger (logger logrus.FieldLogger ) apiOption {
68
- return func (a * api ) {
73
+ // WithLogger configures the logger for the API. If not provided, a default logger will be created.
74
+ func WithLogger (logger logrus.FieldLogger ) Option {
75
+ return func (a * API ) {
69
76
a .logger = logger
70
77
}
71
78
}
72
79
73
- func WithMetricsReporter (metricsReporter metrics.ReporterInterface ) apiOption {
74
- return func (a * api ) {
80
+ // WithMetricsReporter configures the metrics reporter for the API.
81
+ func WithMetricsReporter (metricsReporter metrics.ReporterInterface ) Option {
82
+ return func (a * API ) {
75
83
a .metricsReporter = metricsReporter
76
84
}
77
85
}
78
86
79
- func New (cfg types.APIConfig , opts ... apiOption ) (* api , error ) {
80
- api := & api {
87
+ // New creates a new API instance.
88
+ func New (cfg types.APIConfig , opts ... Option ) (* API , error ) {
89
+ api := & API {
81
90
cfg : cfg ,
82
91
}
83
92
0 commit comments