-
Notifications
You must be signed in to change notification settings - Fork 1
/
httpservice.go
52 lines (42 loc) · 1.56 KB
/
httpservice.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
46
47
48
49
50
51
52
// Copyright 2024 Outreach Corporation. All Rights Reserved.
// Description: This file exposes the private HTTP service for vcluster-fs-syncer.
// Managed: true
package vcluster_fs_syncer //nolint:revive // Why: We allow [-_].
import (
"context"
"fmt"
"net/http"
"github.com/getoutreach/httpx/pkg/handlers"
// Place any extra imports for your service code here
// <<Stencil::Block(imports)>>
// <</Stencil::Block>>
)
// PrivateHTTPDependencies is used to inject dependencies into the HTTPService service
// activity. Great examples of integrations to be placed into here would be a database
// connection or perhaps a redis client that the service activity needs to use.
type PrivateHTTPDependencies struct {
// <<Stencil::Block(privateHTTPDependencies)>>
// <</Stencil::Block>>
}
// HTTPService handles internal http requests, suchs as metrics, health
// and readiness checks. This is required for ALL services to have.
type HTTPService struct {
handlers.Service
cfg *Config
deps *PrivateHTTPDependencies
}
// NewHTTPService creates a new HTTPService service activity.
func NewHTTPService(cfg *Config, deps *PrivateHTTPDependencies) *HTTPService {
return &HTTPService{
cfg: cfg,
deps: deps,
}
}
// Run is the entrypoint for the HTTPService serviceActivity.
func (s *HTTPService) Run(ctx context.Context) error {
// create a http handler (handlers.Service does metrics, health etc)
// <<Stencil::Block(privatehandler)>>
s.App = http.NotFoundHandler()
// <</Stencil::Block>>
return s.Service.Run(ctx, fmt.Sprintf("%s:%d", s.cfg.ListenHost, s.cfg.HTTPPort))
}