Skip to content

Commit 3c85d28

Browse files
authored
Unexport certain API types and functions (#2366)
1 parent c34c2bf commit 3c85d28

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

api/api.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
// @externalDocs.description OpenAPI
3333
// @externalDocs.url https://swagger.io/resources/open-api/
34-
type API struct {
34+
type api struct {
3535
cfg types.APIConfig
3636

3737
logger logrus.FieldLogger
@@ -41,43 +41,43 @@ type API struct {
4141
consoleController console.Controller
4242
linuxInstallController linuxinstall.Controller
4343

44-
handlers Handlers
44+
handlers handlers
4545
}
4646

47-
type APIOption func(*API)
47+
type apiOption func(*api)
4848

49-
func WithAuthController(authController auth.Controller) APIOption {
50-
return func(a *API) {
49+
func WithAuthController(authController auth.Controller) apiOption {
50+
return func(a *api) {
5151
a.authController = authController
5252
}
5353
}
5454

55-
func WithConsoleController(consoleController console.Controller) APIOption {
56-
return func(a *API) {
55+
func WithConsoleController(consoleController console.Controller) apiOption {
56+
return func(a *api) {
5757
a.consoleController = consoleController
5858
}
5959
}
6060

61-
func WithLinuxInstallController(linuxInstallController linuxinstall.Controller) APIOption {
62-
return func(a *API) {
61+
func WithLinuxInstallController(linuxInstallController linuxinstall.Controller) apiOption {
62+
return func(a *api) {
6363
a.linuxInstallController = linuxInstallController
6464
}
6565
}
6666

67-
func WithLogger(logger logrus.FieldLogger) APIOption {
68-
return func(a *API) {
67+
func WithLogger(logger logrus.FieldLogger) apiOption {
68+
return func(a *api) {
6969
a.logger = logger
7070
}
7171
}
7272

73-
func WithMetricsReporter(metricsReporter metrics.ReporterInterface) APIOption {
74-
return func(a *API) {
73+
func WithMetricsReporter(metricsReporter metrics.ReporterInterface) apiOption {
74+
return func(a *api) {
7575
a.metricsReporter = metricsReporter
7676
}
7777
}
7878

79-
func New(cfg types.APIConfig, opts ...APIOption) (*API, error) {
80-
api := &API{
79+
func New(cfg types.APIConfig, opts ...apiOption) (*api, error) {
80+
api := &api{
8181
cfg: cfg,
8282
}
8383

@@ -97,7 +97,7 @@ func New(cfg types.APIConfig, opts ...APIOption) (*API, error) {
9797
api.logger = l
9898
}
9999

100-
if err := api.InitHandlers(api.cfg); err != nil {
100+
if err := api.initHandlers(); err != nil {
101101
return nil, fmt.Errorf("init handlers: %w", err)
102102
}
103103

api/handlers.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@ import (
77
consolehandler "github.com/replicatedhq/embedded-cluster/api/internal/handlers/console"
88
healthhandler "github.com/replicatedhq/embedded-cluster/api/internal/handlers/health"
99
linuxhandler "github.com/replicatedhq/embedded-cluster/api/internal/handlers/linux"
10-
"github.com/replicatedhq/embedded-cluster/api/types"
1110
)
1211

13-
type Handlers struct {
12+
type handlers struct {
1413
auth *authhandler.Handler
1514
console *consolehandler.Handler
1615
health *healthhandler.Handler
1716
linux *linuxhandler.Handler
1817
}
1918

20-
func (a *API) InitHandlers(cfg types.APIConfig) error {
19+
func (a *api) initHandlers() error {
2120
// Auth handler
2221
authHandler, err := authhandler.New(
23-
cfg.Password,
22+
a.cfg.Password,
2423
authhandler.WithLogger(a.logger),
2524
authhandler.WithAuthController(a.authController),
2625
)
@@ -50,7 +49,7 @@ func (a *API) InitHandlers(cfg types.APIConfig) error {
5049

5150
// Linux handler
5251
linuxHandler, err := linuxhandler.New(
53-
cfg,
52+
a.cfg,
5453
linuxhandler.WithLogger(a.logger),
5554
linuxhandler.WithMetricsReporter(a.metricsReporter),
5655
linuxhandler.WithInstallController(a.linuxInstallController),

api/routes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
httpSwagger "github.com/swaggo/http-swagger/v2"
99
)
1010

11-
func (a *API) RegisterRoutes(router *mux.Router) {
11+
func (a *api) RegisterRoutes(router *mux.Router) {
1212
router.HandleFunc("/health", a.handlers.health.GetHealth).Methods("GET")
1313

1414
// Hack to fix issue
@@ -30,7 +30,7 @@ func (a *API) RegisterRoutes(router *mux.Router) {
3030
a.registerConsoleRoutes(authenticatedRouter)
3131
}
3232

33-
func (a *API) registerLinuxRoutes(router *mux.Router) {
33+
func (a *api) registerLinuxRoutes(router *mux.Router) {
3434
linuxRouter := router.PathPrefix("/linux").Subrouter()
3535

3636
installRouter := linuxRouter.PathPrefix("/install").Subrouter()
@@ -50,11 +50,11 @@ func (a *API) registerLinuxRoutes(router *mux.Router) {
5050
installRouter.HandleFunc("/status", a.handlers.linux.PostSetStatus).Methods("POST")
5151
}
5252

53-
func (a *API) registerKubernetesRoutes(router *mux.Router) {
53+
func (a *api) registerKubernetesRoutes(router *mux.Router) {
5454
// kubernetesRouter := router.PathPrefix("/kubernetes").Subrouter()
5555
}
5656

57-
func (a *API) registerConsoleRoutes(router *mux.Router) {
57+
func (a *api) registerConsoleRoutes(router *mux.Router) {
5858
consoleRouter := router.PathPrefix("/console").Subrouter()
5959
consoleRouter.HandleFunc("/available-network-interfaces", a.handlers.console.GetListAvailableNetworkInterfaces).Methods("GET")
6060
}

0 commit comments

Comments
 (0)