/
default.go
123 lines (108 loc) · 2.96 KB
/
default.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
Main DI-package
*/
package di
import (
"context"
"github.com/authzed/authzed-go/v1"
"github.com/google/wire"
redisCache "github.com/redis/go-redis/v9"
"go.opentelemetry.io/otel/trace"
"google.golang.org/grpc"
"github.com/shortlink-org/shortlink/internal/di/pkg/autoMaxPro"
"github.com/shortlink-org/shortlink/internal/di/pkg/config"
shortctx "github.com/shortlink-org/shortlink/internal/di/pkg/context"
"github.com/shortlink-org/shortlink/internal/di/pkg/flags"
logger_di "github.com/shortlink-org/shortlink/internal/di/pkg/logger"
mq_di "github.com/shortlink-org/shortlink/internal/di/pkg/mq"
"github.com/shortlink-org/shortlink/internal/di/pkg/permission"
"github.com/shortlink-org/shortlink/internal/di/pkg/profiling"
"github.com/shortlink-org/shortlink/internal/di/pkg/store"
traicing_di "github.com/shortlink-org/shortlink/internal/di/pkg/traicing"
"github.com/shortlink-org/shortlink/pkg/cache"
"github.com/shortlink-org/shortlink/pkg/db"
"github.com/shortlink-org/shortlink/pkg/logger"
"github.com/shortlink-org/shortlink/pkg/mq"
"github.com/shortlink-org/shortlink/pkg/observability/monitoring"
"github.com/shortlink-org/shortlink/pkg/rpc"
)
// Service - helpers
type Service struct {
// Common
Ctx context.Context
Cfg *config.Config
Log logger.Logger
// Security
Auth *authzed.Client
// Delivery
DB db.DB
Cache redisCache.UniversalClient
MQ mq.MQ
ServerRPC *rpc.Server
ClientRPC *grpc.ClientConn
// Observability
Tracer trace.TracerProvider
Monitoring *monitoring.Monitoring
PprofEndpoint profiling.PprofEndpoint
AutoMaxPro autoMaxPro.AutoMaxPro
}
// DefaultSet ==========================================================================================================
var DefaultSet = wire.NewSet(
shortctx.New,
autoMaxPro.New,
flags.New,
config.New,
logger_di.New,
traicing_di.New,
monitoring.New,
cache.New,
profiling.New,
permission.New,
)
// FullSet =============================================================================================================
var FullSet = wire.NewSet(
DefaultSet,
NewFullService,
store.New,
mq_di.New,
rpc.InitServer,
rpc.InitClient,
)
func NewFullService(
// Common
ctx context.Context,
cfg *config.Config,
log logger.Logger,
// Delivery
serverRPC *rpc.Server,
clientRPC *grpc.ClientConn,
dataBus mq.MQ,
store_db db.DB,
shortcache redisCache.UniversalClient,
// Observability
monitor *monitoring.Monitoring,
tracer trace.TracerProvider,
pprofHTTP profiling.PprofEndpoint,
autoMaxProcsOption autoMaxPro.AutoMaxPro,
) (*Service, error) {
return &Service{
// Common
Ctx: ctx,
Cfg: cfg,
Log: log,
// Delivery
MQ: dataBus,
DB: store_db,
Cache: shortcache,
ClientRPC: clientRPC,
ServerRPC: serverRPC,
// Observability
Tracer: tracer,
Monitoring: monitor,
PprofEndpoint: pprofHTTP,
AutoMaxPro: autoMaxProcsOption,
}, nil
}
func InitializeFullService() (*Service, func(), error) {
panic(wire.Build(FullSet))
}