mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
78 lines
2.7 KiB
Go
78 lines
2.7 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/api/apiproto"
|
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/clientspace"
|
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/client/document"
|
|
clientstorage "github.com/anytypeio/go-anytype-infrastructure-experiments/client/storage"
|
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/account"
|
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app/logger"
|
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonfile/fileservice"
|
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage"
|
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/config"
|
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/rpc/server"
|
|
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/secure"
|
|
"storj.io/drpc"
|
|
)
|
|
|
|
const CName = "api.service"
|
|
|
|
var log = logger.NewNamed(CName)
|
|
|
|
func New() Service {
|
|
return &service{BaseDrpcServer: server.NewBaseDrpcServer()}
|
|
}
|
|
|
|
type Service interface {
|
|
app.ComponentRunnable
|
|
drpc.Mux
|
|
}
|
|
|
|
type service struct {
|
|
transport secure.Service
|
|
cfg *config.Config
|
|
spaceService clientspace.Service
|
|
storageService clientstorage.ClientStorage
|
|
docService document.Service
|
|
account account.Service
|
|
file fileservice.FileService
|
|
*server.BaseDrpcServer
|
|
}
|
|
|
|
func (s *service) Init(a *app.App) (err error) {
|
|
s.spaceService = a.MustComponent(clientspace.CName).(clientspace.Service)
|
|
s.storageService = a.MustComponent(storage.CName).(clientstorage.ClientStorage)
|
|
s.docService = a.MustComponent(document.CName).(document.Service)
|
|
s.account = a.MustComponent(account.CName).(account.Service)
|
|
s.cfg = a.MustComponent(config.CName).(*config.Config)
|
|
s.transport = a.MustComponent(secure.CName).(secure.Service)
|
|
s.file = a.MustComponent(fileservice.CName).(fileservice.FileService)
|
|
return nil
|
|
}
|
|
|
|
func (s *service) Name() (name string) {
|
|
return CName
|
|
}
|
|
|
|
func (s *service) Run(ctx context.Context) (err error) {
|
|
params := server.Params{
|
|
BufferSizeMb: s.cfg.Stream.MaxMsgSizeMb,
|
|
TimeoutMillis: s.cfg.Stream.TimeoutMilliseconds,
|
|
ListenAddrs: s.cfg.APIServer.ListenAddrs,
|
|
Wrapper: func(handler drpc.Handler) drpc.Handler {
|
|
return handler
|
|
},
|
|
Converter: s.transport.BasicListener,
|
|
}
|
|
err = s.BaseDrpcServer.Run(ctx, params)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return apiproto.DRPCRegisterClientApi(s, &rpcHandler{s.spaceService, s.storageService, s.docService, s.account, s.file})
|
|
}
|
|
|
|
func (s *service) Close(ctx context.Context) (err error) {
|
|
return s.BaseDrpcServer.Close(ctx)
|
|
}
|