Skip to content
Snippets Groups Projects
Commit c8e1fe9f authored by ko_oler's avatar ko_oler
Browse files

- исправлено имя импорта

- добавлена функция для перевода в тип Any
- исправления в FindOptions
parent 0d015cd5
No related branches found
No related tags found
No related merge requests found
......@@ -16,9 +16,12 @@ type BatchProcessor struct {
FindPublishedOptions *FindPublishedOptions
Filter *Filter
pageSize, pageNum, offset, limit int
sort []string
processed int
// Deprecated использовать offset, limit
pageSize, pageNum int
offset, limit int
sort []string
processed int
}
func (b *BatchProcessor) getBatch(ctx context.Context) ([]*Item, bool, error) {
......@@ -37,7 +40,7 @@ func (b *BatchProcessor) getBatch(ctx context.Context) ([]*Item, bool, error) {
Regular: b.FindPublishedOptions.Regular,
Hidden: b.FindPublishedOptions.Hidden,
Templates: b.FindPublishedOptions.Templates,
FindOptions: *options.NewFindOptions(b.pageNum, b.pageSize, b.offset, b.limit, b.sort...),
FindOptions: *options.NewFindOptions(b.offset, b.limit, b.sort...),
},
)
} else {
......@@ -52,7 +55,7 @@ func (b *BatchProcessor) getBatch(ctx context.Context) ([]*Item, bool, error) {
Regular: b.FindOptions.Regular,
Hidden: b.FindOptions.Hidden,
Templates: b.FindOptions.Templates,
FindOptions: *options.NewFindOptions(b.pageNum, b.pageSize, b.offset, b.limit, b.sort...),
FindOptions: *options.NewFindOptions(b.offset, b.limit, b.sort...),
},
)
}
......
package log
import (
"encoding/json"
"time"
"git.perx.ru/perxis/perxis-go/proto/log"
pb "git.perx.ru/perxis/perxis-go/proto/log"
"github.com/golang/protobuf/ptypes/any"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/timestamppb"
wrappers "google.golang.org/protobuf/types/known/wrapperspb"
)
type Level int
const (
Info = Level(log.LogLevel_INFO)
Warning = Level(log.LogLevel_WARNING)
Error = Level(log.LogLevel_ERROR)
Critical = Level(log.LogLevel_CRITICAL)
Fatal = Level(log.LogLevel_FATAL)
Info = Level(pb.LogLevel_INFO)
Warning = Level(pb.LogLevel_WARNING)
Error = Level(pb.LogLevel_ERROR)
Critical = Level(pb.LogLevel_CRITICAL)
Fatal = Level(pb.LogLevel_FATAL)
)
func (l Level) String() string {
s := log.LogLevel_name[int32(l)]
s := pb.LogLevel_name[int32(l)]
if s == "" {
s = "UNKNOWN"
}
......@@ -39,24 +44,35 @@ type Entry struct {
Tags []string `json:"tags,omitempty" bson:"tags,omitempty"`
}
func EntryToPB(entry *Entry) *log.LogEntry {
logEntry := &log.LogEntry{
func convertInterfaceToAny(v interface{}) (*any.Any, error) {
anyValue := &any.Any{}
bytes, _ := json.Marshal(v)
bytesValue := &wrappers.BytesValue{
Value: bytes,
}
err := anypb.MarshalFrom(anyValue, bytesValue, proto.MarshalOptions{})
return anyValue, err
}
func EntryToPB(entry *Entry) *pb.LogEntry {
logEntry := &pb.LogEntry{
Id: entry.ID,
Timestamp: timestamppb.New(entry.Timestamp),
Level: log.LogLevel(entry.LogLevel),
Level: pb.LogLevel(entry.LogLevel),
Message: entry.Message,
Category: entry.Category,
Component: entry.Component,
Event: entry.Event,
Object: entry.Object,
Caller: entry.Caller,
Attr: nil, // todo: как с этим работать?
Tags: entry.Tags,
}
logEntry.Attr, _ = convertInterfaceToAny(entry.Attr)
return logEntry
}
func EntryFromPB(request *log.LogEntry) *Entry {
func EntryFromPB(request *pb.LogEntry) *Entry {
return &Entry{
ID: request.Id,
Timestamp: request.Timestamp.AsTime(),
......
......@@ -5,7 +5,7 @@ import (
itemstransportgrpc "git.perx.ru/perxis/perxis-go/pkg/items/transport/grpc"
"git.perx.ru/perxis/perxis-go/pkg/options"
"git.perx.ru/perxis/perxis-go/proto/log"
pb "git.perx.ru/perxis/perxis-go/proto/log"
)
type Service interface {
......@@ -34,12 +34,12 @@ type FindResult struct {
Total uint32
}
func FindResultToPB(result *FindResult) *log.FindResult {
findResult := &log.FindResult{
func FindResultToPB(result *FindResult) *pb.FindResult {
findResult := &pb.FindResult{
Total: result.Total,
}
entries := make([]*log.LogEntry, 0, len(result.Entries))
entries := make([]*pb.LogEntry, 0, len(result.Entries))
for _, e := range result.Entries {
entries = append(entries, EntryToPB(e))
}
......@@ -55,7 +55,7 @@ func FindResultToPB(result *FindResult) *log.FindResult {
return findResult
}
func FindResultFromPB(result *log.FindResult) *FindResult {
func FindResultFromPB(result *pb.FindResult) *FindResult {
findResult := &FindResult{
Total: result.Total,
}
......
......@@ -34,11 +34,11 @@ type FindOptions struct {
}
// NewFindOptions создает новые результаты поиска
func NewFindOptions(pageNum, pageSize, offset, limit int, sort ...string) *FindOptions {
func NewFindOptions(offset, limit int, sort ...string) *FindOptions {
return &FindOptions{
PaginationOptions: PaginationOptions{
PageNum: pageNum,
PageSize: pageSize,
PageNum: offset,
PageSize: limit,
Offset: offset,
Limit: limit,
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment