-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
service.go
50 lines (44 loc) · 1.57 KB
/
service.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
package http
import (
"fmt"
grpcService "github.com/plgd-dev/hub/v2/certificate-authority/service/grpc"
"github.com/plgd-dev/hub/v2/http-gateway/uri"
"github.com/plgd-dev/hub/v2/pkg/fsnotify"
"github.com/plgd-dev/hub/v2/pkg/log"
kitNetHttp "github.com/plgd-dev/hub/v2/pkg/net/http"
httpService "github.com/plgd-dev/hub/v2/pkg/net/http/service"
"github.com/plgd-dev/hub/v2/pkg/security/jwt/validator"
"go.opentelemetry.io/otel/trace"
)
// Service handle HTTP request
type Service struct {
*httpService.Service
requestHandler *RequestHandler
}
// New parses configuration and creates new Server with provided store and bus
func New(serviceName string, config Config, ca *grpcService.CertificateAuthorityServer, validator *validator.Validator, fileWatcher *fsnotify.Watcher, logger log.Logger, tracerProvider trace.TracerProvider) (*Service, error) {
service, err := httpService.New(httpService.Config{
HTTPConnection: config.Connection,
HTTPServer: config.Server,
ServiceName: serviceName,
AuthRules: kitNetHttp.NewDefaultAuthorizationRules(uri.API),
// WhiteEndpointList: whiteList,
FileWatcher: fileWatcher,
Logger: logger,
TraceProvider: tracerProvider,
Validator: validator,
// QueryCaseInsensitive: map[string]string{},
})
if err != nil {
return nil, fmt.Errorf("cannot create http service: %w", err)
}
requestHandler, err := NewRequestHandler(&config, service.GetRouter(), ca)
if err != nil {
_ = service.Close()
return nil, err
}
return &Service{
Service: service,
requestHandler: requestHandler,
}, nil
}