Select Git revision
client.go 4.87 KiB
package content
import (
"time"
"git.perx.ru/perxis/perxis-go/pkg/cache"
clientsSvc "git.perx.ru/perxis/perxis-go/pkg/clients/middleware"
clientsTransportGrpc "git.perx.ru/perxis/perxis-go/pkg/clients/transport/grpc"
collaboratorsSvc "git.perx.ru/perxis/perxis-go/pkg/collaborators/middleware"
collaboratorsTransportGrpc "git.perx.ru/perxis/perxis-go/pkg/collaborators/transport/grpc"
collectionsSvc "git.perx.ru/perxis/perxis-go/pkg/collections/middleware"
collectionsTransportGrpc "git.perx.ru/perxis/perxis-go/pkg/collections/transport/grpc"
environmentsSvc "git.perx.ru/perxis/perxis-go/pkg/environments/middleware"
environmentsTransportGrpc "git.perx.ru/perxis/perxis-go/pkg/environments/transport/grpc"
invitationsSvc "git.perx.ru/perxis/perxis-go/pkg/invitations/middleware"
invitationsTransportGrpc "git.perx.ru/perxis/perxis-go/pkg/invitations/transport/grpc"
itemsSvc "git.perx.ru/perxis/perxis-go/pkg/items/middleware"
itemsTransportGrpc "git.perx.ru/perxis/perxis-go/pkg/items/transport/grpc"
localesSvc "git.perx.ru/perxis/perxis-go/pkg/locales/middleware"
localsTransportGrpc "git.perx.ru/perxis/perxis-go/pkg/locales/transport/grpc"
referencesSvc "git.perx.ru/perxis/perxis-go/pkg/references/middleware"
referencesTransportGrpc "git.perx.ru/perxis/perxis-go/pkg/references/transport/grpc"
spacesSvc "git.perx.ru/perxis/perxis-go/pkg/spaces/middleware"
spacesTransportGrpc "git.perx.ru/perxis/perxis-go/pkg/spaces/transport/grpc"
rolesSvc "git.perx.ru/perxis/perxis-go/roles/middleware"
rolesTransportGrpc "git.perx.ru/perxis/perxis-go/roles/transport/grpc"
"go.uber.org/zap"
"google.golang.org/grpc"
)
const (
DefaultCacheSize = 1000
DefaultCacheTTL = time.Second * 10
)
func NewClient(conn *grpc.ClientConn, opts ...Option) *Content {
client := &Content{}
config := &Config{}
for _, o := range opts {
o(config)
}
if config.Logger == nil {
config.Logger = zap.NewNop()
}
client.Spaces = spacesTransportGrpc.NewClient(conn, config.ClientOptions...)
client.Environments = environmentsTransportGrpc.NewClient(conn, config.ClientOptions...)
client.Collections = collectionsTransportGrpc.NewClient(conn, config.ClientOptions...)
client.Items = itemsTransportGrpc.NewClient(conn, config.ClientOptions...)
client.Invitations = invitationsTransportGrpc.NewClient(conn, config.ClientOptions...)
client.Collaborators = collaboratorsTransportGrpc.NewClient(conn, config.ClientOptions...)
client.Clients = clientsTransportGrpc.NewClient(conn, config.ClientOptions...)
client.Locales = localsTransportGrpc.NewClient(conn, config.ClientOptions...)
client.Roles = rolesTransportGrpc.NewClient(conn, config.ClientOptions...)
client.References = referencesTransportGrpc.NewGRPCClient(conn, "", config.ClientOptions...)
if !config.NoDecode {
client.Items = itemsSvc.ClientEncodeMiddleware(client.Collections)(client.Items)
client.References = referencesSvc.ClientEncodeMiddleware(client.Collections)(client.References)
}
if !config.NoCache {
client = WithCaching(client, DefaultCacheSize, DefaultCacheTTL)
}
if !config.NoLog {
client = WithLogging(client, config.Logger, config.AccessLog)