-
Notifications
You must be signed in to change notification settings - Fork 463
/
api.go
45 lines (34 loc) · 1.11 KB
/
api.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
38
39
40
41
42
43
44
45
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package api
import (
"context"
"io"
"github.com/talos-systems/talos/internal/app/machined/internal/api/reg"
"github.com/talos-systems/talos/internal/pkg/runtime"
"github.com/talos-systems/talos/pkg/constants"
"github.com/talos-systems/talos/pkg/grpc/factory"
)
// Service wraps machined API server
type Service struct{}
// NewService creates new Service
func NewService() *Service {
return &Service{}
}
// Main is an entrypoint the the API service
func (s *Service) Main(ctx context.Context, config runtime.Configurator, logWriter io.Writer) error {
api := reg.NewRegistrator(config)
server := factory.NewServer(api, factory.WithLog("machined ", logWriter))
listener, err := factory.NewListener(factory.Network("unix"), factory.SocketPath(constants.MachineSocketPath))
if err != nil {
return err
}
defer server.Stop()
go func() {
// nolint: errcheck
server.Serve(listener)
}()
<-ctx.Done()
return nil
}