Compare commits
112 Commits
Author | SHA1 | Date | |
---|---|---|---|
a271ac6a7c | |||
|
cf898e56c3 | ||
13a6eeabcd | |||
|
dcc86f296f | ||
c00475f81e | |||
|
10c99ca3bc | ||
|
253f7098ec | ||
c33c12e4ea | |||
|
2b0f740a9b | ||
|
e043a86c2d | ||
3fce9cde40 | |||
|
258301608f | ||
2a783a93fd | |||
|
32afee35cf | ||
e752df958e | |||
|
9a7dbf5055 | ||
9d336a6bd8 | |||
|
7593b0c432 | ||
35358356d6 | |||
|
59ec7db6c6 | ||
deeb1c7f20 | |||
|
c0a819b3ab | ||
|
0bbe3b2746 | ||
|
fe7cadd0e4 | ||
19ba2870ce | |||
|
925c2ab1ff | ||
241a799cc0 | |||
|
1f793a35ac | ||
|
04a91b69ad | ||
|
d42b759b4d | ||
|
e965a3002b | ||
|
c62cf6302e | ||
|
ac9275d0f1 | ||
|
95de9e92c1 | ||
823b9bee8f | |||
|
5028d90408 | ||
7e9b563a57 | |||
|
44e550f79b | ||
|
fddab119de | ||
18fc28d580 | |||
|
ff080c2448 | ||
|
80e9c7222a | ||
|
5857a1534e | ||
|
6f7a0a7471 | ||
|
c0fda29193 | ||
4bb87b532c | |||
|
f4ae21a6bb | ||
3b156b79e9 | |||
|
23200052ce | ||
|
5d5d4329b5 | ||
431de96592 | |||
|
f94de62c5c | ||
|
119be4e203 | ||
402a6e9e5a | |||
|
f06d551f49 | ||
3cd27c71d9 | |||
|
2b51411bdd | ||
|
2978fe4e6b | ||
|
de86255236 | ||
|
80563b7128 | ||
3e6223f5f3 | |||
89326d504d | |||
|
63f325d54e | ||
|
02d50f4eba | ||
|
f921f610a4 | ||
|
d67c91e01c | ||
64625c693e | |||
7f73c3f778 | |||
|
73c20641ee | ||
5b32e5553d | |||
|
b2b2482195 | ||
|
265879f4d5 | ||
|
bb317df17e | ||
|
c6d1b037e7 | ||
|
c434d21fa9 | ||
|
79dc80a4b1 | ||
|
6aaeda3c56 | ||
|
933d9ceb21 | ||
|
f15aa2d047 | ||
|
67a19cb903 | ||
|
9dad75d8f2 | ||
|
06853a596d | ||
|
e9751f94b2 | ||
|
fa0391a096 | ||
|
e634516bf5 | ||
|
901447f41d | ||
|
34afbcba0f | ||
|
f47de75420 | ||
bd3ae7b171 | |||
a5b049abf9 | |||
|
6625c96cc8 | ||
|
0c9abeb090 | ||
|
cf6b6ad6d5 | ||
|
f7a5ff14b8 | ||
|
0d019a71aa | ||
|
c0648393e1 | ||
|
1dc9af129b | ||
|
7134464584 | ||
|
01df6f91a6 | ||
|
6fdb6ed696 | ||
12d8babf3e | |||
|
51ab30b966 | ||
c6f3d3c733 | |||
cdac4f975a | |||
2db8ac7034 | |||
|
40addc47f4 | ||
|
a149822d68 | ||
3aedc5ade9 | |||
13e25c6b50 | |||
|
26b5de2e69 | ||
c56b205e36 | |||
|
263223162c |
19
.github/dependabot.yml
vendored
Normal file
19
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
# Maintain dependencies for GitHub Actions
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
|
||||
# Maintain dependencies for Golang
|
||||
- package-ecosystem: "gomod"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
13
.github/stale.sh
vendored
13
.github/stale.sh
vendored
@@ -1,13 +0,0 @@
|
||||
#!/bin/bash -ex
|
||||
|
||||
export PATH=$PATH:$(pwd)/bin
|
||||
export GO111MODULE=on
|
||||
export GOBIN=$(pwd)/bin
|
||||
|
||||
#go get github.com/rvflash/goup@v0.4.1
|
||||
|
||||
#goup -v ./...
|
||||
#go get github.com/psampaz/go-mod-outdated@v0.6.0
|
||||
go list -u -m -mod=mod -json all | go-mod-outdated -update -direct -ci || true
|
||||
|
||||
#go list -u -m -json all | go-mod-outdated -update
|
20
.github/workflows/autoapprove.yml
vendored
Normal file
20
.github/workflows/autoapprove.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: "autoapprove"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
autoapprove:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: approve
|
||||
uses: hmarr/auto-approve-action@v3
|
||||
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
|
||||
id: approve
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
21
.github/workflows/automerge.yml
vendored
Normal file
21
.github/workflows/automerge.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
name: "automerge"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'vtolstov'
|
||||
steps:
|
||||
- name: merge
|
||||
id: merge
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
13
.github/workflows/build.yml
vendored
13
.github/workflows/build.yml
vendored
@@ -3,19 +3,20 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v1
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.15
|
||||
go-version: 1.17
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
@@ -31,9 +32,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v1
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
|
78
.github/workflows/codeql-analysis.yml
vendored
Normal file
78
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "codeql"
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["prbuild"]
|
||||
types:
|
||||
- completed
|
||||
push:
|
||||
branches: [ master, v3 ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master, v3 ]
|
||||
schedule:
|
||||
- cron: '34 1 * * 0'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'go' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: setup
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.17
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: init
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: analyze
|
||||
uses: github/codeql-action/analyze@v2
|
27
.github/workflows/dependabot-automerge.yml
vendored
Normal file
27
.github/workflows/dependabot-automerge.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
name: "dependabot-automerge"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
steps:
|
||||
- name: metadata
|
||||
id: metadata
|
||||
uses: dependabot/fetch-metadata@v1.3.6
|
||||
with:
|
||||
github-token: "${{ secrets.TOKEN }}"
|
||||
- name: merge
|
||||
id: merge
|
||||
if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
13
.github/workflows/pr.yml
vendored
13
.github/workflows/pr.yml
vendored
@@ -3,19 +3,20 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v1
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.15
|
||||
go-version: 1.17
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
@@ -31,9 +32,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v1
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
|
@@ -1,3 +1,3 @@
|
||||
package service
|
||||
|
||||
//go:generate protoc -I./proto -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --micro_out=components=micro|grpc,debug=true,paths=source_relative:./proto proto/service.proto
|
||||
//go:generate protoc -I./proto -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --go-micro_out=components=micro|rpc,standalone=true,debug=true,paths=source_relative:./micro proto/service.proto
|
||||
|
14
go.mod
14
go.mod
@@ -1,12 +1,10 @@
|
||||
module github.com/unistack-org/micro-logger-service/v3
|
||||
module go.unistack.org/micro-logger-service/v3
|
||||
|
||||
go 1.14
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/golang/protobuf v1.4.3
|
||||
github.com/google/uuid v1.1.5
|
||||
github.com/unistack-org/micro/v3 v3.1.3
|
||||
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d // indirect
|
||||
google.golang.org/grpc v1.27.1
|
||||
google.golang.org/protobuf v1.25.0
|
||||
github.com/google/uuid v1.3.0
|
||||
go.unistack.org/micro/v3 v3.10.11
|
||||
google.golang.org/grpc v1.52.3
|
||||
google.golang.org/protobuf v1.28.1
|
||||
)
|
||||
|
30
micro/service_micro.pb.go
Normal file
30
micro/service_micro.pb.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// protoc-gen-go-micro version: v3.5.3
|
||||
// source: service.proto
|
||||
|
||||
package servicepb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
proto "go.unistack.org/micro-logger-service/v3/proto"
|
||||
api "go.unistack.org/micro/v3/api"
|
||||
client "go.unistack.org/micro/v3/client"
|
||||
)
|
||||
|
||||
var (
|
||||
LoggerServiceName = "LoggerService"
|
||||
|
||||
LoggerServiceEndpoints = []api.Endpoint{}
|
||||
)
|
||||
|
||||
func NewLoggerServiceEndpoints() []api.Endpoint {
|
||||
return LoggerServiceEndpoints
|
||||
}
|
||||
|
||||
type LoggerServiceClient interface {
|
||||
Log(ctx context.Context, req *proto.LogReq, opts ...client.CallOption) (*proto.LogRsp, error)
|
||||
}
|
||||
|
||||
type LoggerServiceServer interface {
|
||||
Log(ctx context.Context, req *proto.LogReq, rsp *proto.LogRsp) error
|
||||
}
|
54
micro/service_micro_rpc.pb.go
Normal file
54
micro/service_micro_rpc.pb.go
Normal file
@@ -0,0 +1,54 @@
|
||||
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
|
||||
// protoc-gen-go-micro version: v3.5.3
|
||||
// source: service.proto
|
||||
|
||||
package servicepb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
proto "go.unistack.org/micro-logger-service/v3/proto"
|
||||
api "go.unistack.org/micro/v3/api"
|
||||
client "go.unistack.org/micro/v3/client"
|
||||
server "go.unistack.org/micro/v3/server"
|
||||
)
|
||||
|
||||
type loggerServiceClient struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewLoggerServiceClient(name string, c client.Client) LoggerServiceClient {
|
||||
return &loggerServiceClient{c: c, name: name}
|
||||
}
|
||||
|
||||
func (c *loggerServiceClient) Log(ctx context.Context, req *proto.LogReq, opts ...client.CallOption) (*proto.LogRsp, error) {
|
||||
rsp := &proto.LogRsp{}
|
||||
err := c.c.Call(ctx, c.c.NewRequest(c.name, "LoggerService.Log", req), rsp, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
type loggerServiceServer struct {
|
||||
LoggerServiceServer
|
||||
}
|
||||
|
||||
func (h *loggerServiceServer) Log(ctx context.Context, req *proto.LogReq, rsp *proto.LogRsp) error {
|
||||
return h.LoggerServiceServer.Log(ctx, req, rsp)
|
||||
}
|
||||
|
||||
func RegisterLoggerServiceServer(s server.Server, sh LoggerServiceServer, opts ...server.HandlerOption) error {
|
||||
type loggerService interface {
|
||||
Log(ctx context.Context, req *proto.LogReq, rsp *proto.LogRsp) error
|
||||
}
|
||||
type LoggerService struct {
|
||||
loggerService
|
||||
}
|
||||
h := &loggerServiceServer{sh}
|
||||
var nopts []server.HandlerOption
|
||||
for _, endpoint := range LoggerServiceEndpoints {
|
||||
nopts = append(nopts, api.WithEndpoint(&endpoint))
|
||||
}
|
||||
return s.Handle(s.NewHandler(&LoggerService{h}, append(nopts, opts...)...))
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/store"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/store"
|
||||
)
|
||||
|
||||
type clientKey struct{}
|
||||
|
@@ -1,13 +1,12 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.25.0-devel
|
||||
// protoc v3.6.1
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.19.4
|
||||
// source: service.proto
|
||||
|
||||
package service
|
||||
package servicepb
|
||||
|
||||
import (
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
@@ -21,18 +20,14 @@ const (
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// This is a compile-time assertion that a sufficiently up-to-date version
|
||||
// of the legacy proto package is being used.
|
||||
const _ = proto.ProtoPackageIsVersion4
|
||||
|
||||
type Empty struct {
|
||||
type LogRsp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
}
|
||||
|
||||
func (x *Empty) Reset() {
|
||||
*x = Empty{}
|
||||
func (x *LogRsp) Reset() {
|
||||
*x = LogRsp{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_service_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
@@ -40,13 +35,13 @@ func (x *Empty) Reset() {
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Empty) String() string {
|
||||
func (x *LogRsp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Empty) ProtoMessage() {}
|
||||
func (*LogRsp) ProtoMessage() {}
|
||||
|
||||
func (x *Empty) ProtoReflect() protoreflect.Message {
|
||||
func (x *LogRsp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_service_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
@@ -58,12 +53,12 @@ func (x *Empty) ProtoReflect() protoreflect.Message {
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Empty.ProtoReflect.Descriptor instead.
|
||||
func (*Empty) Descriptor() ([]byte, []int) {
|
||||
// Deprecated: Use LogRsp.ProtoReflect.Descriptor instead.
|
||||
func (*LogRsp) Descriptor() ([]byte, []int) {
|
||||
return file_service_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
type LogReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
@@ -74,8 +69,8 @@ type Message struct {
|
||||
Fields []*Field `protobuf:"bytes,4,rep,name=fields,proto3" json:"fields,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Message) Reset() {
|
||||
*x = Message{}
|
||||
func (x *LogReq) Reset() {
|
||||
*x = LogReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_service_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
@@ -83,13 +78,13 @@ func (x *Message) Reset() {
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Message) String() string {
|
||||
func (x *LogReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Message) ProtoMessage() {}
|
||||
func (*LogReq) ProtoMessage() {}
|
||||
|
||||
func (x *Message) ProtoReflect() protoreflect.Message {
|
||||
func (x *LogReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_service_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
@@ -101,33 +96,33 @@ func (x *Message) ProtoReflect() protoreflect.Message {
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Message.ProtoReflect.Descriptor instead.
|
||||
func (*Message) Descriptor() ([]byte, []int) {
|
||||
// Deprecated: Use LogReq.ProtoReflect.Descriptor instead.
|
||||
func (*LogReq) Descriptor() ([]byte, []int) {
|
||||
return file_service_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *Message) GetLevel() int32 {
|
||||
func (x *LogReq) GetLevel() int32 {
|
||||
if x != nil {
|
||||
return x.Level
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Message) GetFormat() string {
|
||||
func (x *LogReq) GetFormat() string {
|
||||
if x != nil {
|
||||
return x.Format
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Message) GetMsg() string {
|
||||
func (x *LogReq) GetMsg() string {
|
||||
if x != nil {
|
||||
return x.Msg
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Message) GetFields() []*Field {
|
||||
func (x *LogReq) GetFields() []*Field {
|
||||
if x != nil {
|
||||
return x.Fields
|
||||
}
|
||||
@@ -140,12 +135,7 @@ type Field struct {
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
// Types that are assignable to Val:
|
||||
// *Field_DoubleVal
|
||||
// *Field_FloatVal
|
||||
// *Field_Int32Val
|
||||
// *Field_Int64Val
|
||||
Val isField_Val `protobuf_oneof:"val"`
|
||||
Val string `protobuf:"bytes,2,opt,name=val,proto3" json:"val,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Field) Reset() {
|
||||
@@ -187,99 +177,37 @@ func (x *Field) GetKey() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Field) GetVal() isField_Val {
|
||||
if m != nil {
|
||||
return m.Val
|
||||
func (x *Field) GetVal() string {
|
||||
if x != nil {
|
||||
return x.Val
|
||||
}
|
||||
return nil
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Field) GetDoubleVal() float64 {
|
||||
if x, ok := x.GetVal().(*Field_DoubleVal); ok {
|
||||
return x.DoubleVal
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Field) GetFloatVal() float32 {
|
||||
if x, ok := x.GetVal().(*Field_FloatVal); ok {
|
||||
return x.FloatVal
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Field) GetInt32Val() int32 {
|
||||
if x, ok := x.GetVal().(*Field_Int32Val); ok {
|
||||
return x.Int32Val
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Field) GetInt64Val() int64 {
|
||||
if x, ok := x.GetVal().(*Field_Int64Val); ok {
|
||||
return x.Int64Val
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type isField_Val interface {
|
||||
isField_Val()
|
||||
}
|
||||
|
||||
type Field_DoubleVal struct {
|
||||
DoubleVal float64 `protobuf:"fixed64,2,opt,name=double_val,json=doubleVal,proto3,oneof"`
|
||||
}
|
||||
|
||||
type Field_FloatVal struct {
|
||||
FloatVal float32 `protobuf:"fixed32,3,opt,name=float_val,json=floatVal,proto3,oneof"`
|
||||
}
|
||||
|
||||
type Field_Int32Val struct {
|
||||
Int32Val int32 `protobuf:"varint,4,opt,name=int32_val,json=int32Val,proto3,oneof"`
|
||||
}
|
||||
|
||||
type Field_Int64Val struct {
|
||||
Int64Val int64 `protobuf:"varint,5,opt,name=int64_val,json=int64Val,proto3,oneof"` //1
|
||||
}
|
||||
|
||||
func (*Field_DoubleVal) isField_Val() {}
|
||||
|
||||
func (*Field_FloatVal) isField_Val() {}
|
||||
|
||||
func (*Field_Int32Val) isField_Val() {}
|
||||
|
||||
func (*Field_Int64Val) isField_Val() {}
|
||||
|
||||
var File_service_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_service_proto_rawDesc = []byte{
|
||||
0x0a, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
|
||||
0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74,
|
||||
0x79, 0x22, 0x71, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05,
|
||||
0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x65, 0x76,
|
||||
0x65, 0x6c, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x06, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73,
|
||||
0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x26, 0x0a, 0x06,
|
||||
0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x73,
|
||||
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x52, 0x06, 0x66, 0x69,
|
||||
0x65, 0x6c, 0x64, 0x73, 0x22, 0x9e, 0x01, 0x0a, 0x05, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x10,
|
||||
0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79,
|
||||
0x12, 0x1f, 0x0a, 0x0a, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x5f, 0x76, 0x61, 0x6c, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x01, 0x48, 0x00, 0x52, 0x09, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x56, 0x61,
|
||||
0x6c, 0x12, 0x1d, 0x0a, 0x09, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x5f, 0x76, 0x61, 0x6c, 0x18, 0x03,
|
||||
0x20, 0x01, 0x28, 0x02, 0x48, 0x00, 0x52, 0x08, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x56, 0x61, 0x6c,
|
||||
0x12, 0x1d, 0x0a, 0x09, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x5f, 0x76, 0x61, 0x6c, 0x18, 0x04, 0x20,
|
||||
0x01, 0x28, 0x05, 0x48, 0x00, 0x52, 0x08, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x56, 0x61, 0x6c, 0x12,
|
||||
0x1d, 0x0a, 0x09, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x5f, 0x76, 0x61, 0x6c, 0x18, 0x05, 0x20, 0x01,
|
||||
0x28, 0x03, 0x48, 0x00, 0x52, 0x08, 0x69, 0x6e, 0x74, 0x36, 0x34, 0x56, 0x61, 0x6c, 0x42, 0x05,
|
||||
0x0a, 0x03, 0x76, 0x61, 0x6c, 0x32, 0x33, 0x0a, 0x06, 0x4c, 0x6f, 0x67, 0x67, 0x65, 0x72, 0x12,
|
||||
0x29, 0x0a, 0x03, 0x4c, 0x6f, 0x67, 0x12, 0x10, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||
0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, 0x0e, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69,
|
||||
0x63, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x42, 0x36, 0x5a, 0x34, 0x67, 0x69,
|
||||
0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x75, 0x6e, 0x69, 0x73, 0x74, 0x61, 0x63,
|
||||
0x6b, 0x2d, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d, 0x6c, 0x6f, 0x67, 0x67,
|
||||
0x65, 0x72, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x3b, 0x73, 0x65, 0x72, 0x76, 0x69,
|
||||
0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x09, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x22, 0x08, 0x0a, 0x06, 0x4c, 0x6f,
|
||||
0x67, 0x52, 0x73, 0x70, 0x22, 0x72, 0x0a, 0x06, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x12, 0x14,
|
||||
0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c,
|
||||
0x65, 0x76, 0x65, 0x6c, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x12, 0x10, 0x0a, 0x03,
|
||||
0x6d, 0x73, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x28,
|
||||
0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10,
|
||||
0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64,
|
||||
0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x22, 0x2b, 0x0a, 0x05, 0x46, 0x69, 0x65, 0x6c,
|
||||
0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
|
||||
0x6b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x03, 0x76, 0x61, 0x6c, 0x32, 0x3e, 0x0a, 0x0d, 0x4c, 0x6f, 0x67, 0x67, 0x65, 0x72, 0x53,
|
||||
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2d, 0x0a, 0x03, 0x4c, 0x6f, 0x67, 0x12, 0x11, 0x2e,
|
||||
0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x71,
|
||||
0x1a, 0x11, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4c, 0x6f, 0x67,
|
||||
0x52, 0x73, 0x70, 0x22, 0x00, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x6f, 0x2e, 0x75, 0x6e, 0x69, 0x73,
|
||||
0x74, 0x61, 0x63, 0x6b, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d, 0x6c,
|
||||
0x6f, 0x67, 0x67, 0x65, 0x72, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x76, 0x33,
|
||||
0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -296,14 +224,14 @@ func file_service_proto_rawDescGZIP() []byte {
|
||||
|
||||
var file_service_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
|
||||
var file_service_proto_goTypes = []interface{}{
|
||||
(*Empty)(nil), // 0: service.Empty
|
||||
(*Message)(nil), // 1: service.Message
|
||||
(*Field)(nil), // 2: service.Field
|
||||
(*LogRsp)(nil), // 0: servicepb.LogRsp
|
||||
(*LogReq)(nil), // 1: servicepb.LogReq
|
||||
(*Field)(nil), // 2: servicepb.Field
|
||||
}
|
||||
var file_service_proto_depIdxs = []int32{
|
||||
2, // 0: service.Message.fields:type_name -> service.Field
|
||||
1, // 1: service.Logger.Log:input_type -> service.Message
|
||||
0, // 2: service.Logger.Log:output_type -> service.Empty
|
||||
2, // 0: servicepb.LogReq.fields:type_name -> servicepb.Field
|
||||
1, // 1: servicepb.LoggerService.Log:input_type -> servicepb.LogReq
|
||||
0, // 2: servicepb.LoggerService.Log:output_type -> servicepb.LogRsp
|
||||
2, // [2:3] is the sub-list for method output_type
|
||||
1, // [1:2] is the sub-list for method input_type
|
||||
1, // [1:1] is the sub-list for extension type_name
|
||||
@@ -318,7 +246,7 @@ func file_service_proto_init() {
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Empty); i {
|
||||
switch v := v.(*LogRsp); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -330,7 +258,7 @@ func file_service_proto_init() {
|
||||
}
|
||||
}
|
||||
file_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Message); i {
|
||||
switch v := v.(*LogReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -354,12 +282,6 @@ func file_service_proto_init() {
|
||||
}
|
||||
}
|
||||
}
|
||||
file_service_proto_msgTypes[2].OneofWrappers = []interface{}{
|
||||
(*Field_DoubleVal)(nil),
|
||||
(*Field_FloatVal)(nil),
|
||||
(*Field_Int32Val)(nil),
|
||||
(*Field_Int64Val)(nil),
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
|
@@ -1,15 +1,15 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package service;
|
||||
option go_package="github.com/unistack-org/micro-logger-service;service";
|
||||
package servicepb;
|
||||
option go_package="go.unistack.org/micro-logger-service/v3/proto;servicepb";
|
||||
|
||||
service Logger {
|
||||
rpc Log(Message) returns (Empty) {};
|
||||
service LoggerService {
|
||||
rpc Log(LogReq) returns (LogRsp) {};
|
||||
}
|
||||
|
||||
message Empty {};
|
||||
message LogRsp {};
|
||||
|
||||
message Message {
|
||||
message LogReq {
|
||||
int32 level = 1;
|
||||
string format = 2;
|
||||
string msg = 3;
|
||||
@@ -18,11 +18,5 @@ message Message {
|
||||
|
||||
message Field {
|
||||
string key = 1;
|
||||
oneof val {
|
||||
double double_val = 2;
|
||||
float float_val = 3;
|
||||
int32 int32_val = 4;
|
||||
int64 int64_val = 5;
|
||||
//1
|
||||
};
|
||||
string val = 2;
|
||||
};
|
||||
|
@@ -1,6 +1,10 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.2.0
|
||||
// - protoc v3.19.4
|
||||
// source: service.proto
|
||||
|
||||
package service
|
||||
package servicepb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
@@ -11,78 +15,89 @@ import (
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
const _ = grpc.SupportPackageIsVersion6
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// LoggerClient is the client API for Logger service.
|
||||
// LoggerServiceClient is the client API for LoggerService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type LoggerClient interface {
|
||||
Log(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Empty, error)
|
||||
type LoggerServiceClient interface {
|
||||
Log(ctx context.Context, in *LogReq, opts ...grpc.CallOption) (*LogRsp, error)
|
||||
}
|
||||
|
||||
type loggerClient struct {
|
||||
type loggerServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewLoggerClient(cc grpc.ClientConnInterface) LoggerClient {
|
||||
return &loggerClient{cc}
|
||||
func NewLoggerServiceClient(cc grpc.ClientConnInterface) LoggerServiceClient {
|
||||
return &loggerServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *loggerClient) Log(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Empty, error) {
|
||||
out := new(Empty)
|
||||
err := c.cc.Invoke(ctx, "/service.Logger/Log", in, out, opts...)
|
||||
func (c *loggerServiceClient) Log(ctx context.Context, in *LogReq, opts ...grpc.CallOption) (*LogRsp, error) {
|
||||
out := new(LogRsp)
|
||||
err := c.cc.Invoke(ctx, "/servicepb.LoggerService/Log", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// LoggerServer is the server API for Logger service.
|
||||
// All implementations must embed UnimplementedLoggerServer
|
||||
// LoggerServiceServer is the server API for LoggerService service.
|
||||
// All implementations must embed UnimplementedLoggerServiceServer
|
||||
// for forward compatibility
|
||||
type LoggerServer interface {
|
||||
Log(context.Context, *Message) (*Empty, error)
|
||||
mustEmbedUnimplementedLoggerServer()
|
||||
type LoggerServiceServer interface {
|
||||
Log(context.Context, *LogReq) (*LogRsp, error)
|
||||
mustEmbedUnimplementedLoggerServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedLoggerServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedLoggerServer struct {
|
||||
// UnimplementedLoggerServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedLoggerServiceServer struct {
|
||||
}
|
||||
|
||||
func (*UnimplementedLoggerServer) Log(context.Context, *Message) (*Empty, error) {
|
||||
func (UnimplementedLoggerServiceServer) Log(context.Context, *LogReq) (*LogRsp, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Log not implemented")
|
||||
}
|
||||
func (*UnimplementedLoggerServer) mustEmbedUnimplementedLoggerServer() {}
|
||||
func (UnimplementedLoggerServiceServer) mustEmbedUnimplementedLoggerServiceServer() {}
|
||||
|
||||
func RegisterLoggerServer(s *grpc.Server, srv LoggerServer) {
|
||||
s.RegisterService(&_Logger_serviceDesc, srv)
|
||||
// UnsafeLoggerServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to LoggerServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeLoggerServiceServer interface {
|
||||
mustEmbedUnimplementedLoggerServiceServer()
|
||||
}
|
||||
|
||||
func _Logger_Log_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Message)
|
||||
func RegisterLoggerServiceServer(s grpc.ServiceRegistrar, srv LoggerServiceServer) {
|
||||
s.RegisterService(&LoggerService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _LoggerService_Log_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(LogReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(LoggerServer).Log(ctx, in)
|
||||
return srv.(LoggerServiceServer).Log(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/service.Logger/Log",
|
||||
FullMethod: "/servicepb.LoggerService/Log",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(LoggerServer).Log(ctx, req.(*Message))
|
||||
return srv.(LoggerServiceServer).Log(ctx, req.(*LogReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var _Logger_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "service.Logger",
|
||||
HandlerType: (*LoggerServer)(nil),
|
||||
// LoggerService_ServiceDesc is the grpc.ServiceDesc for LoggerService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var LoggerService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "servicepb.LoggerService",
|
||||
HandlerType: (*LoggerServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "Log",
|
||||
Handler: _Logger_Log_Handler,
|
||||
Handler: _LoggerService_Log_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
|
@@ -1,44 +0,0 @@
|
||||
// Code generated by protoc-gen-micro
|
||||
// source: service.proto
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
micro_api "github.com/unistack-org/micro/v3/api"
|
||||
micro_client "github.com/unistack-org/micro/v3/client"
|
||||
micro_server "github.com/unistack-org/micro/v3/server"
|
||||
)
|
||||
|
||||
// NewLoggerEndpoints provides api endpoints metdata for Logger service
|
||||
func NewLoggerEndpoints() []*micro_api.Endpoint {
|
||||
var endpoints []*micro_api.Endpoint
|
||||
return endpoints
|
||||
}
|
||||
|
||||
// LoggerService interface
|
||||
type LoggerService interface {
|
||||
Log(context.Context, *Message, ...micro_client.CallOption) (*Empty, error)
|
||||
}
|
||||
|
||||
// Micro server stuff
|
||||
|
||||
// LoggerHandler server handler
|
||||
type LoggerHandler interface {
|
||||
Log(context.Context, *Message, *Empty) error
|
||||
}
|
||||
|
||||
// RegisterLoggerHandler registers server handler
|
||||
func RegisterLoggerHandler(s micro_server.Server, sh LoggerHandler, opts ...micro_server.HandlerOption) error {
|
||||
type logger interface {
|
||||
Log(context.Context, *Message, *Empty) error
|
||||
}
|
||||
type Logger struct {
|
||||
logger
|
||||
}
|
||||
h := &loggerHandler{sh}
|
||||
for _, endpoint := range NewLoggerEndpoints() {
|
||||
opts = append(opts, micro_api.WithEndpoint(endpoint))
|
||||
}
|
||||
return s.Handle(s.NewHandler(&Logger{h}, opts...))
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
// Code generated by protoc-gen-micro
|
||||
// source: service.proto
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
micro_client "github.com/unistack-org/micro/v3/client"
|
||||
micro_server "github.com/unistack-org/micro/v3/server"
|
||||
)
|
||||
|
||||
var (
|
||||
_ micro_server.Option
|
||||
_ micro_client.Option
|
||||
)
|
||||
|
||||
type loggerService struct {
|
||||
c micro_client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
// Micro client stuff
|
||||
|
||||
// NewLoggerService create new service client
|
||||
func NewLoggerService(name string, c micro_client.Client) LoggerService {
|
||||
return &loggerService{c: c, name: name}
|
||||
}
|
||||
|
||||
func (c *loggerService) Log(ctx context.Context, req *Message, opts ...micro_client.CallOption) (*Empty, error) {
|
||||
rsp := &Empty{}
|
||||
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Logger.Log", req), rsp, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rsp, nil
|
||||
}
|
||||
|
||||
// Micro server stuff
|
||||
|
||||
type loggerHandler struct {
|
||||
LoggerHandler
|
||||
}
|
||||
|
||||
func (h *loggerHandler) Log(ctx context.Context, req *Message, rsp *Empty) error {
|
||||
return h.LoggerHandler.Log(ctx, req, rsp)
|
||||
}
|
63
service.go
63
service.go
@@ -1,4 +1,4 @@
|
||||
package service
|
||||
package service // import "go.unistack.org/micro-logger-service/v3"
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -6,21 +6,36 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/google/uuid"
|
||||
pb "github.com/unistack-org/micro-logger-service/v3/proto"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/store"
|
||||
pbmicro "go.unistack.org/micro-logger-service/v3/micro"
|
||||
pb "go.unistack.org/micro-logger-service/v3/proto"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
"go.unistack.org/micro/v3/store"
|
||||
)
|
||||
|
||||
var _ logger.Logger = &serviceLogger{}
|
||||
|
||||
type serviceLogger struct {
|
||||
opts logger.Options
|
||||
service string
|
||||
client pb.LoggerService
|
||||
client pbmicro.LoggerServiceClient
|
||||
store store.Store
|
||||
fields map[string]interface{}
|
||||
}
|
||||
|
||||
func (l *serviceLogger) Clone(opts ...logger.Option) logger.Logger {
|
||||
nl := &serviceLogger{service: l.service, store: l.store, client: l.client, opts: l.opts}
|
||||
for _, o := range opts {
|
||||
o(&nl.opts)
|
||||
}
|
||||
return nl
|
||||
}
|
||||
|
||||
func (l *serviceLogger) Level(lvl logger.Level) {
|
||||
l.opts.Level = lvl
|
||||
}
|
||||
|
||||
func (l *serviceLogger) Init(opts ...logger.Option) error {
|
||||
// TODO: optimize to store only []string as fields
|
||||
for _, o := range opts {
|
||||
o(&l.opts)
|
||||
}
|
||||
@@ -43,18 +58,14 @@ func (l *serviceLogger) Init(opts ...logger.Option) error {
|
||||
return fmt.Errorf("missing Client option")
|
||||
}
|
||||
|
||||
l.client = pb.NewLoggerService(l.service, cli)
|
||||
l.client = pbmicro.NewLoggerServiceClient(l.service, cli)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *serviceLogger) Fields(fields map[string]interface{}) logger.Logger {
|
||||
nl := &serviceLogger{opts: l.opts, client: l.client, store: l.store}
|
||||
nl.fields = make(map[string]interface{}, len(fields))
|
||||
for k, v := range fields {
|
||||
nl.fields[k] = v
|
||||
}
|
||||
return nl
|
||||
func (l *serviceLogger) Fields(fields ...interface{}) logger.Logger {
|
||||
// TODO: optimize to store only []string as fields
|
||||
return l.Clone(logger.WithFields(fields...))
|
||||
}
|
||||
|
||||
func (l *serviceLogger) V(level logger.Level) bool {
|
||||
@@ -113,17 +124,15 @@ func (l *serviceLogger) Fatalf(ctx context.Context, msg string, args ...interfac
|
||||
|
||||
func (l *serviceLogger) Log(ctx context.Context, level logger.Level, args ...interface{}) {
|
||||
msg := l.newMessage(level, "", args...)
|
||||
_, err := l.client.Log(ctx, msg)
|
||||
if err != nil {
|
||||
l.storeMessage(ctx, msg)
|
||||
if _, err := l.client.Log(ctx, msg); err != nil {
|
||||
_ = l.storeMessage(ctx, msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *serviceLogger) Logf(ctx context.Context, level logger.Level, format string, args ...interface{}) {
|
||||
msg := l.newMessage(level, "", args...)
|
||||
_, err := l.client.Log(ctx, msg)
|
||||
if err != nil {
|
||||
l.storeMessage(ctx, msg)
|
||||
if _, err := l.client.Log(ctx, msg); err != nil {
|
||||
_ = l.storeMessage(ctx, msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,12 +151,18 @@ func NewLogger(opts ...logger.Option) logger.Logger {
|
||||
return l
|
||||
}
|
||||
|
||||
func (l *serviceLogger) newMessage(level logger.Level, format string, args ...interface{}) *pb.Message {
|
||||
msg := &pb.Message{Level: int32(level), Format: format}
|
||||
func (l *serviceLogger) newMessage(level logger.Level, format string, args ...interface{}) *pb.LogReq {
|
||||
msg := &pb.LogReq{Level: int32(level), Format: format, Fields: make([]*pb.Field, 0, len(l.opts.Fields)/2)}
|
||||
for idx := 0; idx < len(l.opts.Fields); idx += 2 {
|
||||
msg.Fields = append(msg.Fields, &pb.Field{
|
||||
Key: fmt.Sprintf("%v", l.opts.Fields[idx]),
|
||||
Val: fmt.Sprintf("%v", l.opts.Fields[idx+1]),
|
||||
})
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
func (l *serviceLogger) storeMessage(ctx context.Context, msg *pb.Message) error {
|
||||
func (l *serviceLogger) storeMessage(ctx context.Context, msg *pb.LogReq) error {
|
||||
if l.store == nil {
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user