Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
8a4b8e69bc | |||
d37d099619 | |||
e3a6e821d9 | |||
bf80400b7a |
10
.vscode/settings.json
vendored
10
.vscode/settings.json
vendored
@ -4,5 +4,13 @@
|
|||||||
"CONFIG_PATH": "${workspaceFolder}/application.yaml"
|
"CONFIG_PATH": "${workspaceFolder}/application.yaml"
|
||||||
},
|
},
|
||||||
"go.testEnvFile": "${workspaceFolder}/etc/unit_test.env",
|
"go.testEnvFile": "${workspaceFolder}/etc/unit_test.env",
|
||||||
"terminal.integrated.suggest.enabled": true
|
"terminal.integrated.suggest.enabled": true,
|
||||||
|
"protoc": {
|
||||||
|
"path": "/usr/local/bin/protoc",
|
||||||
|
"compile_on_save": false,
|
||||||
|
"options": [
|
||||||
|
"--proto_path=.",
|
||||||
|
"--proto_path=/usr/local/include",
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
@ -28,8 +28,10 @@ func (c *consumer) Run(ctx context.Context) error {
|
|||||||
// 发送的数据时Json格式, 接收用的JSON, 发送也需要使用JSON
|
// 发送的数据时Json格式, 接收用的JSON, 发送也需要使用JSON
|
||||||
err = e.Load(m.Value)
|
err = e.Load(m.Value)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
// 保存日志, 保持失败的次数统计起来,披露给外部, 编写一个采集器,来采统计失败次数
|
||||||
if err := event.GetService().SaveEvent(ctx, types.NewSet[*event.Event]().Add(e)); err != nil {
|
if err := event.GetService().SaveEvent(ctx, types.NewSet[*event.Event]().Add(e)); err != nil {
|
||||||
c.log.Error().Msgf("save event error, %s", err)
|
c.log.Error().Msgf("save event error, %s", err)
|
||||||
|
c.collector.Inc()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"122.51.31.227/go-course/go18/devcloud/audit/apps/event"
|
"122.51.31.227/go-course/go18/devcloud/audit/apps/event"
|
||||||
"github.com/infraboard/mcube/v2/ioc"
|
"github.com/infraboard/mcube/v2/ioc"
|
||||||
"github.com/infraboard/mcube/v2/ioc/config/log"
|
"github.com/infraboard/mcube/v2/ioc/config/log"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
|
||||||
ioc_kafka "github.com/infraboard/mcube/v2/ioc/config/kafka"
|
ioc_kafka "github.com/infraboard/mcube/v2/ioc/config/kafka"
|
||||||
@ -37,6 +38,9 @@ type consumer struct {
|
|||||||
GroupId string `toml:"group_id" json:"group_id" yaml:"group_id" env:"GROUP_ID"`
|
GroupId string `toml:"group_id" json:"group_id" yaml:"group_id" env:"GROUP_ID"`
|
||||||
// 当前这个消费者 配置的topic
|
// 当前这个消费者 配置的topic
|
||||||
Topics []string `toml:"topic" json:"topic" yaml:"topic" env:"TOPIC"`
|
Topics []string `toml:"topic" json:"topic" yaml:"topic" env:"TOPIC"`
|
||||||
|
|
||||||
|
// 采集器
|
||||||
|
collector *EventCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对象名称
|
// 对象名称
|
||||||
@ -48,6 +52,11 @@ func (i *consumer) Name() string {
|
|||||||
func (i *consumer) Init() error {
|
func (i *consumer) Init() error {
|
||||||
// 对象
|
// 对象
|
||||||
i.log = log.Sub(i.Name())
|
i.log = log.Sub(i.Name())
|
||||||
|
|
||||||
|
// 准备好采集器, 注册给Prometheus
|
||||||
|
i.collector = NewEventCollector()
|
||||||
|
prometheus.MustRegister(i.collector)
|
||||||
|
|
||||||
i.reader = ioc_kafka.ConsumerGroup(i.GroupId, i.Topics)
|
i.reader = ioc_kafka.ConsumerGroup(i.GroupId, i.Topics)
|
||||||
|
|
||||||
go i.Run(i.ctx)
|
go i.Run(i.ctx)
|
||||||
|
38
devcloud/audit/apps/event/consumer/metric.go
Normal file
38
devcloud/audit/apps/event/consumer/metric.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package consumer
|
||||||
|
|
||||||
|
import "github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
|
// # HELP save_event_error_count 事件入库失败个数统计
|
||||||
|
// # TYPE save_event_error_count gauge
|
||||||
|
// save_event_error_count{service="devcloud"} 0
|
||||||
|
func NewEventCollector() *EventCollector {
|
||||||
|
return &EventCollector{
|
||||||
|
errCountDesc: prometheus.NewDesc(
|
||||||
|
"save_event_error_count",
|
||||||
|
"事件入库失败个数统计",
|
||||||
|
[]string{},
|
||||||
|
prometheus.Labels{"service": "devcloud"},
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 收集事件指标的采集器
|
||||||
|
type EventCollector struct {
|
||||||
|
errCountDesc *prometheus.Desc
|
||||||
|
// 需要自己根据实践情况来维护这个变量
|
||||||
|
errCount int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *EventCollector) Inc() {
|
||||||
|
c.errCount++
|
||||||
|
}
|
||||||
|
|
||||||
|
// 指标元数据注册
|
||||||
|
func (c *EventCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||||
|
ch <- c.errCountDesc
|
||||||
|
}
|
||||||
|
|
||||||
|
// 指标的值的采集
|
||||||
|
func (c *EventCollector) Collect(ch chan<- prometheus.Metric) {
|
||||||
|
ch <- prometheus.MustNewConstMetric(c.errCountDesc, prometheus.GaugeValue, float64(c.errCount))
|
||||||
|
}
|
16
devcloud/mpaas/apps/k8s/README.md
Normal file
16
devcloud/mpaas/apps/k8s/README.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# k8s 集群管理
|
||||||
|
|
||||||
|
https://kubernetes.io/
|
||||||
|
|
||||||
|
|
||||||
|
k8s UI工具: Rancher, KubeSphere, Dashbaord k8s 集群管理工具(运维人员)
|
||||||
|
+ Deployment,StatfulSet, DaesonSet, Pod, Service, ...
|
||||||
|
|
||||||
|
我们要做的系统: 是做个 k8s的集群管理工具吗? 给软件研发人员使用的(应用的发布与部署)
|
||||||
|
|
||||||
|
依赖于K8s提供的能力,来实现一套发布系统
|
||||||
|
|
||||||
|
|
||||||
|
## 概念的定义
|
||||||
|
|
||||||
|
|
87
devcloud/mpaas/apps/k8s/design.drawio
Normal file
87
devcloud/mpaas/apps/k8s/design.drawio
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
<mxfile host="65bd71144e">
|
||||||
|
<diagram id="2lwm4o9OGl1Gjpf4ACLQ" name="第 1 页">
|
||||||
|
<mxGraphModel dx="1115" dy="631" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||||
|
<root>
|
||||||
|
<mxCell id="0"/>
|
||||||
|
<mxCell id="1" parent="0"/>
|
||||||
|
<mxCell id="4" value="查询制品" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="1" source="5" target="9">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="5" value="artifact<div>制品库</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="260" y="100" width="120" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="6" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="7" target="5">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="23" value="制品信息上报" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="6">
|
||||||
|
<mxGeometry x="-0.1818" y="-1" relative="1" as="geometry">
|
||||||
|
<mxPoint as="offset"/>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="7" value="CI工具" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="30" y="100" width="120" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="8" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="9" target="13">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="9" value="deploy<div>应用部署</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="260" y="250" width="120" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="10" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="12" target="9">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="11" value="选择适合的制品格式<div><br></div>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="10">
|
||||||
|
<mxGeometry x="0.2278" y="-3" relative="1" as="geometry">
|
||||||
|
<mxPoint x="29" y="-17" as="offset"/>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="12" value="cluster<div>应用集群</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="590" y="250" width="120" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="13" value="k8s 集群" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="260" y="430" width="120" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="14" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="18" target="13">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="15" value="watch" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="14">
|
||||||
|
<mxGeometry x="0.2242" y="-1" relative="1" as="geometry">
|
||||||
|
<mxPoint as="offset"/>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="16" style="edgeStyle=none;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="18" target="12">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="17" value="实时更新集群状态" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="16">
|
||||||
|
<mxGeometry x="0.0236" y="-4" relative="1" as="geometry">
|
||||||
|
<mxPoint as="offset"/>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="18" value="sync<div>部署同步</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="590" y="430" width="120" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="19" value="首次部署使用模版渲染" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="20" target="12">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="20" value="temlate<div>部署模版</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="590" y="100" width="120" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="21" style="edgeStyle=none;html=1;exitX=0;exitY=0.3333333333333333;exitDx=0;exitDy=0;exitPerimeter=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="22" target="12">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="22" value="Actor" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="770" y="260" width="30" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="24" value="应用部署 (应用发布流中最核心)" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="440" y="30" width="200" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="25" value="承载应用运行的实例" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="485" y="330" width="110" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="26" value="部署引擎" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="200" y="320" width="60" height="30" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
</root>
|
||||||
|
</mxGraphModel>
|
||||||
|
</diagram>
|
||||||
|
</mxfile>
|
3
skills/metric/README.md
Normal file
3
skills/metric/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Metric
|
||||||
|
|
||||||
|
https://www.mcube.top/guide/config/metric.html
|
@ -1,59 +1,108 @@
|
|||||||
<mxfile host="65bd71144e">
|
<mxfile host="65bd71144e">
|
||||||
<diagram id="yflk6MuM42xHFq2jSyhu" name="第 1 页">
|
<diagram id="yflk6MuM42xHFq2jSyhu" name="第 1 页">
|
||||||
<mxGraphModel dx="1333" dy="710" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
<mxGraphModel dx="1115" dy="597" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||||
<root>
|
<root>
|
||||||
<mxCell id="0"/>
|
<mxCell id="0"/>
|
||||||
<mxCell id="1" parent="0"/>
|
<mxCell id="1" parent="0"/>
|
||||||
<mxCell id="2" value="server a<div>fn</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
<mxCell id="2" value="server a<div>fn</div>" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||||
<mxGeometry x="170" y="170" width="120" height="60" as="geometry"/>
|
<mxGeometry x="170" y="170" width="120" height="60" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="6" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="5" target="2">
|
<mxCell id="6" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="5" target="2" edge="1">
|
||||||
<mxGeometry relative="1" as="geometry"/>
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="7" value="servier a: fn" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="6">
|
<mxCell id="7" value="servier a: fn" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="6" vertex="1" connectable="0">
|
||||||
<mxGeometry x="0.1941" y="-1" relative="1" as="geometry">
|
<mxGeometry x="0.1941" y="-1" relative="1" as="geometry">
|
||||||
<mxPoint as="offset"/>
|
<mxPoint as="offset"/>
|
||||||
</mxGeometry>
|
</mxGeometry>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="5" value="server b" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
<mxCell id="5" value="server b" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||||
<mxGeometry x="630" y="170" width="120" height="60" as="geometry"/>
|
<mxGeometry x="630" y="170" width="120" height="60" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="8" value="rpc" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
<mxCell id="8" value="rpc" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||||
<mxGeometry x="400" y="100" width="60" height="30" as="geometry"/>
|
<mxGeometry x="400" y="100" width="60" height="30" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="9" value="fn: (my_name) {hello, my_name}" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
<mxCell id="9" value="fn: (my_name) {hello, my_name}" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||||
<mxGeometry x="350" y="250" width="230" height="30" as="geometry"/>
|
<mxGeometry x="350" y="250" width="230" height="30" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="10" value="service c<div>python</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
<mxCell id="10" value="service c<div>python</div>" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||||
<mxGeometry x="630" y="390" width="120" height="60" as="geometry"/>
|
<mxGeometry x="630" y="390" width="120" height="60" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="11" value="service d<div>java</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
<mxCell id="11" value="service d<div>java</div>" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||||
<mxGeometry x="390" y="390" width="120" height="60" as="geometry"/>
|
<mxGeometry x="390" y="390" width="120" height="60" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="12" value="server b<div>go</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
<mxCell id="12" value="server b<div>go</div>" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||||
<mxGeometry x="150" y="390" width="120" height="60" as="geometry"/>
|
<mxGeometry x="150" y="390" width="120" height="60" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="19" style="edgeStyle=none;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;" edge="1" parent="1" source="13" target="16">
|
<mxCell id="19" style="edgeStyle=none;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;" parent="1" source="13" target="16" edge="1">
|
||||||
<mxGeometry relative="1" as="geometry"/>
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="20" style="edgeStyle=orthogonalEdgeStyle;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="13" target="17">
|
<mxCell id="20" style="edgeStyle=orthogonalEdgeStyle;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="13" target="17" edge="1">
|
||||||
<mxGeometry relative="1" as="geometry"/>
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="13" value="protofuf" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
<mxCell id="13" value="protofuf" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||||
<mxGeometry x="390" y="570" width="120" height="60" as="geometry"/>
|
<mxGeometry x="390" y="570" width="120" height="60" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="15" value="interface(struct)" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
<mxCell id="15" value="interface(struct)" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||||
<mxGeometry x="160" y="480" width="100" height="30" as="geometry"/>
|
<mxGeometry x="160" y="480" width="100" height="30" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="16" value="interface(class)" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
<mxCell id="16" value="interface(class)" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||||
<mxGeometry x="400" y="480" width="100" height="30" as="geometry"/>
|
<mxGeometry x="400" y="480" width="100" height="30" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="17" value="class" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
<mxCell id="17" value="class" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||||
<mxGeometry x="670" y="480" width="60" height="30" as="geometry"/>
|
<mxGeometry x="670" y="480" width="60" height="30" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
<mxCell id="18" style="edgeStyle=orthogonalEdgeStyle;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.43;entryY=1;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" source="13" target="15">
|
<mxCell id="18" style="edgeStyle=orthogonalEdgeStyle;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.43;entryY=1;entryDx=0;entryDy=0;entryPerimeter=0;" parent="1" source="13" target="15" edge="1">
|
||||||
<mxGeometry relative="1" as="geometry"/>
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
</mxCell>
|
</mxCell>
|
||||||
|
<mxCell id="30" style="edgeStyle=orthogonalEdgeStyle;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="21" target="22">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="31" value="GRPC" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="30">
|
||||||
|
<mxGeometry x="-0.2941" relative="1" as="geometry">
|
||||||
|
<mxPoint as="offset"/>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="32" style="edgeStyle=orthogonalEdgeStyle;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="21" target="25">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="21" value="业务网关(Restful API grpc-rest)" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="190" y="920" width="530" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="22" value="grpc service<div>app1</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="190" y="1050" width="120" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="23" value="<span style="color: rgb(0, 0, 0);">grpc service</span><div><span style="color: rgb(0, 0, 0);">app2</span></div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="340" y="1050" width="120" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="24" value="<span style="color: rgb(0, 0, 0);">grpc service</span><div><span style="color: rgb(0, 0, 0);">app3</span></div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="480" y="1050" width="120" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="25" value="<span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: center; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(251, 251, 251); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;">grpc service</span><div><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: center; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(251, 251, 251); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;">app3</span></div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="630" y="1050" width="120" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="28" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="1" source="27" target="21">
|
||||||
|
<mxGeometry relative="1" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="29" value="Restful API" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="28">
|
||||||
|
<mxGeometry x="-0.15" y="-4" relative="1" as="geometry">
|
||||||
|
<mxPoint as="offset"/>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="27" value="Browser" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||||
|
<mxGeometry x="190" y="800" width="530" height="60" as="geometry"/>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="33" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.425;entryY=1.033;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" source="23" target="22">
|
||||||
|
<mxGeometry relative="1" as="geometry">
|
||||||
|
<Array as="points">
|
||||||
|
<mxPoint x="330" y="1150"/>
|
||||||
|
</Array>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
|
<mxCell id="34" value="GRPC" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="33">
|
||||||
|
<mxGeometry x="-0.2337" y="-2" relative="1" as="geometry">
|
||||||
|
<mxPoint as="offset"/>
|
||||||
|
</mxGeometry>
|
||||||
|
</mxCell>
|
||||||
</root>
|
</root>
|
||||||
</mxGraphModel>
|
</mxGraphModel>
|
||||||
</diagram>
|
</diagram>
|
||||||
|
@ -10,6 +10,8 @@ type HelloService interface {
|
|||||||
+ RPC方法的定义
|
+ RPC方法的定义
|
||||||
+ PRC数据结构的定义
|
+ PRC数据结构的定义
|
||||||
|
|
||||||
|
安装vsocde的 proto语法高亮插件: vscode-proto3
|
||||||
|
|
||||||
## 插件安装
|
## 插件安装
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@ -154,4 +156,11 @@ func (c *helloServiceClient) Hello(ctx context.Context, in *Request, opts ...grp
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 其他服务 使用生成的client,调用grpc服务的方法
|
## 其他服务 使用生成的client,调用grpc服务的方法
|
||||||
|
|
||||||
|
|
||||||
|
## 包
|
||||||
|
|
||||||
|
```sh
|
||||||
|
protoc -I=. --go_out=. --go_opt=module="122.51.31.227/go-course/go18" skills/rpc/protobuf/app_service/interface.proto
|
||||||
|
```
|
165
skills/rpc/protobuf/app_service/interface.pb.go
Normal file
165
skills/rpc/protobuf/app_service/interface.pb.go
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// protoc-gen-go v1.36.8
|
||||||
|
// protoc v6.32.0
|
||||||
|
// source: skills/rpc/protobuf/app_service/interface.proto
|
||||||
|
|
||||||
|
package app_service
|
||||||
|
|
||||||
|
import (
|
||||||
|
reflect "reflect"
|
||||||
|
sync "sync"
|
||||||
|
unsafe "unsafe"
|
||||||
|
|
||||||
|
hello_service "122.51.31.227/go-course/go18/skills/rpc/protobuf/hello_service"
|
||||||
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Verify that this generated code is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||||
|
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||||
|
)
|
||||||
|
|
||||||
|
type App struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||||
|
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
|
||||||
|
// 通过包名引用其他包里面定义
|
||||||
|
Request *hello_service.Request `protobuf:"bytes,4,opt,name=request,proto3" json:"request,omitempty"`
|
||||||
|
Response *hello_service.Response `protobuf:"bytes,5,opt,name=response,proto3" json:"response,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *App) Reset() {
|
||||||
|
*x = App{}
|
||||||
|
mi := &file_skills_rpc_protobuf_app_service_interface_proto_msgTypes[0]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *App) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*App) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *App) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_skills_rpc_protobuf_app_service_interface_proto_msgTypes[0]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use App.ProtoReflect.Descriptor instead.
|
||||||
|
func (*App) Descriptor() ([]byte, []int) {
|
||||||
|
return file_skills_rpc_protobuf_app_service_interface_proto_rawDescGZIP(), []int{0}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *App) GetId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *App) GetName() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *App) GetDescription() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Description
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *App) GetRequest() *hello_service.Request {
|
||||||
|
if x != nil {
|
||||||
|
return x.Request
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *App) GetResponse() *hello_service.Response {
|
||||||
|
if x != nil {
|
||||||
|
return x.Response
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var File_skills_rpc_protobuf_app_service_interface_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
|
const file_skills_rpc_protobuf_app_service_interface_proto_rawDesc = "" +
|
||||||
|
"\n" +
|
||||||
|
"/skills/rpc/protobuf/app_service/interface.proto\x12\x03app\x1a1skills/rpc/protobuf/hello_service/interface.proto\"\xa2\x01\n" +
|
||||||
|
"\x03App\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +
|
||||||
|
"\x04name\x18\x02 \x01(\tR\x04name\x12 \n" +
|
||||||
|
"\vdescription\x18\x03 \x01(\tR\vdescription\x12(\n" +
|
||||||
|
"\arequest\x18\x04 \x01(\v2\x0e.hello.RequestR\arequest\x12+\n" +
|
||||||
|
"\bresponse\x18\x05 \x01(\v2\x0f.hello.ResponseR\bresponseB>Z<122.51.31.227/go-course/go18/skills/rpc/protobuf/app_serviceb\x06proto3"
|
||||||
|
|
||||||
|
var (
|
||||||
|
file_skills_rpc_protobuf_app_service_interface_proto_rawDescOnce sync.Once
|
||||||
|
file_skills_rpc_protobuf_app_service_interface_proto_rawDescData []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
func file_skills_rpc_protobuf_app_service_interface_proto_rawDescGZIP() []byte {
|
||||||
|
file_skills_rpc_protobuf_app_service_interface_proto_rawDescOnce.Do(func() {
|
||||||
|
file_skills_rpc_protobuf_app_service_interface_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_skills_rpc_protobuf_app_service_interface_proto_rawDesc), len(file_skills_rpc_protobuf_app_service_interface_proto_rawDesc)))
|
||||||
|
})
|
||||||
|
return file_skills_rpc_protobuf_app_service_interface_proto_rawDescData
|
||||||
|
}
|
||||||
|
|
||||||
|
var file_skills_rpc_protobuf_app_service_interface_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
||||||
|
var file_skills_rpc_protobuf_app_service_interface_proto_goTypes = []any{
|
||||||
|
(*App)(nil), // 0: app.App
|
||||||
|
(*hello_service.Request)(nil), // 1: hello.Request
|
||||||
|
(*hello_service.Response)(nil), // 2: hello.Response
|
||||||
|
}
|
||||||
|
var file_skills_rpc_protobuf_app_service_interface_proto_depIdxs = []int32{
|
||||||
|
1, // 0: app.App.request:type_name -> hello.Request
|
||||||
|
2, // 1: app.App.response:type_name -> hello.Response
|
||||||
|
2, // [2:2] is the sub-list for method output_type
|
||||||
|
2, // [2:2] is the sub-list for method input_type
|
||||||
|
2, // [2:2] is the sub-list for extension type_name
|
||||||
|
2, // [2:2] is the sub-list for extension extendee
|
||||||
|
0, // [0:2] is the sub-list for field type_name
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { file_skills_rpc_protobuf_app_service_interface_proto_init() }
|
||||||
|
func file_skills_rpc_protobuf_app_service_interface_proto_init() {
|
||||||
|
if File_skills_rpc_protobuf_app_service_interface_proto != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
type x struct{}
|
||||||
|
out := protoimpl.TypeBuilder{
|
||||||
|
File: protoimpl.DescBuilder{
|
||||||
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
|
RawDescriptor: unsafe.Slice(unsafe.StringData(file_skills_rpc_protobuf_app_service_interface_proto_rawDesc), len(file_skills_rpc_protobuf_app_service_interface_proto_rawDesc)),
|
||||||
|
NumEnums: 0,
|
||||||
|
NumMessages: 1,
|
||||||
|
NumExtensions: 0,
|
||||||
|
NumServices: 0,
|
||||||
|
},
|
||||||
|
GoTypes: file_skills_rpc_protobuf_app_service_interface_proto_goTypes,
|
||||||
|
DependencyIndexes: file_skills_rpc_protobuf_app_service_interface_proto_depIdxs,
|
||||||
|
MessageInfos: file_skills_rpc_protobuf_app_service_interface_proto_msgTypes,
|
||||||
|
}.Build()
|
||||||
|
File_skills_rpc_protobuf_app_service_interface_proto = out.File
|
||||||
|
file_skills_rpc_protobuf_app_service_interface_proto_goTypes = nil
|
||||||
|
file_skills_rpc_protobuf_app_service_interface_proto_depIdxs = nil
|
||||||
|
}
|
16
skills/rpc/protobuf/app_service/interface.proto
Normal file
16
skills/rpc/protobuf/app_service/interface.proto
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package app;
|
||||||
|
option go_package="122.51.31.227/go-course/go18/skills/rpc/protobuf/app_service";
|
||||||
|
|
||||||
|
// 导入包
|
||||||
|
import "skills/rpc/protobuf/hello_service/interface.proto";
|
||||||
|
|
||||||
|
message App {
|
||||||
|
string id = 1;
|
||||||
|
string name = 2;
|
||||||
|
string description = 3;
|
||||||
|
// 通过包名引用其他包里面定义
|
||||||
|
hello.Request request = 4;
|
||||||
|
hello.Response response = 5;
|
||||||
|
}
|
@ -9,6 +9,7 @@ package hello_service
|
|||||||
import (
|
import (
|
||||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
|
anypb "google.golang.org/protobuf/types/known/anypb"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
sync "sync"
|
sync "sync"
|
||||||
unsafe "unsafe"
|
unsafe "unsafe"
|
||||||
@ -21,9 +22,72 @@ const (
|
|||||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Corpus int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
Corpus_UNIVERSAL Corpus = 0
|
||||||
|
Corpus_WEB Corpus = 1
|
||||||
|
Corpus_IMAGES Corpus = 2
|
||||||
|
Corpus_LOCAL Corpus = 3
|
||||||
|
Corpus_NEWS Corpus = 4
|
||||||
|
Corpus_PRODUCTS Corpus = 5
|
||||||
|
Corpus_VIDEO Corpus = 6
|
||||||
|
)
|
||||||
|
|
||||||
|
// Enum value maps for Corpus.
|
||||||
|
var (
|
||||||
|
Corpus_name = map[int32]string{
|
||||||
|
0: "UNIVERSAL",
|
||||||
|
1: "WEB",
|
||||||
|
2: "IMAGES",
|
||||||
|
3: "LOCAL",
|
||||||
|
4: "NEWS",
|
||||||
|
5: "PRODUCTS",
|
||||||
|
6: "VIDEO",
|
||||||
|
}
|
||||||
|
Corpus_value = map[string]int32{
|
||||||
|
"UNIVERSAL": 0,
|
||||||
|
"WEB": 1,
|
||||||
|
"IMAGES": 2,
|
||||||
|
"LOCAL": 3,
|
||||||
|
"NEWS": 4,
|
||||||
|
"PRODUCTS": 5,
|
||||||
|
"VIDEO": 6,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (x Corpus) Enum() *Corpus {
|
||||||
|
p := new(Corpus)
|
||||||
|
*p = x
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x Corpus) String() string {
|
||||||
|
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Corpus) Descriptor() protoreflect.EnumDescriptor {
|
||||||
|
return file_skills_rpc_protobuf_hello_service_interface_proto_enumTypes[0].Descriptor()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Corpus) Type() protoreflect.EnumType {
|
||||||
|
return &file_skills_rpc_protobuf_hello_service_interface_proto_enumTypes[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x Corpus) Number() protoreflect.EnumNumber {
|
||||||
|
return protoreflect.EnumNumber(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use Corpus.Descriptor instead.
|
||||||
|
func (Corpus) EnumDescriptor() ([]byte, []int) {
|
||||||
|
return file_skills_rpc_protobuf_hello_service_interface_proto_rawDescGZIP(), []int{0}
|
||||||
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
|
Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||||
|
// map
|
||||||
|
Extras map[string]string `protobuf:"bytes,2,rep,name=extras,proto3" json:"extras,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@ -65,6 +129,66 @@ func (x *Request) GetValue() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Request) GetExtras() map[string]string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Extras
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type RequestSet struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Total int64 `protobuf:"varint,1,opt,name=total,proto3" json:"total,omitempty"`
|
||||||
|
// repeated 来描述一个数组
|
||||||
|
Items []*Request `protobuf:"bytes,2,rep,name=items,proto3" json:"items,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *RequestSet) Reset() {
|
||||||
|
*x = RequestSet{}
|
||||||
|
mi := &file_skills_rpc_protobuf_hello_service_interface_proto_msgTypes[1]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *RequestSet) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*RequestSet) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *RequestSet) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_skills_rpc_protobuf_hello_service_interface_proto_msgTypes[1]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use RequestSet.ProtoReflect.Descriptor instead.
|
||||||
|
func (*RequestSet) Descriptor() ([]byte, []int) {
|
||||||
|
return file_skills_rpc_protobuf_hello_service_interface_proto_rawDescGZIP(), []int{1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *RequestSet) GetTotal() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Total
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *RequestSet) GetItems() []*Request {
|
||||||
|
if x != nil {
|
||||||
|
return x.Items
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
|
Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
|
||||||
@ -74,7 +198,7 @@ type Response struct {
|
|||||||
|
|
||||||
func (x *Response) Reset() {
|
func (x *Response) Reset() {
|
||||||
*x = Response{}
|
*x = Response{}
|
||||||
mi := &file_skills_rpc_protobuf_hello_service_interface_proto_msgTypes[1]
|
mi := &file_skills_rpc_protobuf_hello_service_interface_proto_msgTypes[2]
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
ms.StoreMessageInfo(mi)
|
ms.StoreMessageInfo(mi)
|
||||||
}
|
}
|
||||||
@ -86,7 +210,7 @@ func (x *Response) String() string {
|
|||||||
func (*Response) ProtoMessage() {}
|
func (*Response) ProtoMessage() {}
|
||||||
|
|
||||||
func (x *Response) ProtoReflect() protoreflect.Message {
|
func (x *Response) ProtoReflect() protoreflect.Message {
|
||||||
mi := &file_skills_rpc_protobuf_hello_service_interface_proto_msgTypes[1]
|
mi := &file_skills_rpc_protobuf_hello_service_interface_proto_msgTypes[2]
|
||||||
if x != nil {
|
if x != nil {
|
||||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
if ms.LoadMessageInfo() == nil {
|
if ms.LoadMessageInfo() == nil {
|
||||||
@ -99,7 +223,7 @@ func (x *Response) ProtoReflect() protoreflect.Message {
|
|||||||
|
|
||||||
// Deprecated: Use Response.ProtoReflect.Descriptor instead.
|
// Deprecated: Use Response.ProtoReflect.Descriptor instead.
|
||||||
func (*Response) Descriptor() ([]byte, []int) {
|
func (*Response) Descriptor() ([]byte, []int) {
|
||||||
return file_skills_rpc_protobuf_hello_service_interface_proto_rawDescGZIP(), []int{1}
|
return file_skills_rpc_protobuf_hello_service_interface_proto_rawDescGZIP(), []int{2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Response) GetValue() string {
|
func (x *Response) GetValue() string {
|
||||||
@ -109,17 +233,90 @@ func (x *Response) GetValue() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ErrorStatus struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
|
||||||
|
Details []*anypb.Any `protobuf:"bytes,2,rep,name=details,proto3" json:"details,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ErrorStatus) Reset() {
|
||||||
|
*x = ErrorStatus{}
|
||||||
|
mi := &file_skills_rpc_protobuf_hello_service_interface_proto_msgTypes[3]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ErrorStatus) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ErrorStatus) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *ErrorStatus) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_skills_rpc_protobuf_hello_service_interface_proto_msgTypes[3]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use ErrorStatus.ProtoReflect.Descriptor instead.
|
||||||
|
func (*ErrorStatus) Descriptor() ([]byte, []int) {
|
||||||
|
return file_skills_rpc_protobuf_hello_service_interface_proto_rawDescGZIP(), []int{3}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ErrorStatus) GetMessage() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Message
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ErrorStatus) GetDetails() []*anypb.Any {
|
||||||
|
if x != nil {
|
||||||
|
return x.Details
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var File_skills_rpc_protobuf_hello_service_interface_proto protoreflect.FileDescriptor
|
var File_skills_rpc_protobuf_hello_service_interface_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
const file_skills_rpc_protobuf_hello_service_interface_proto_rawDesc = "" +
|
const file_skills_rpc_protobuf_hello_service_interface_proto_rawDesc = "" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"1skills/rpc/protobuf/hello_service/interface.proto\x12\x05hello\"\x1f\n" +
|
"1skills/rpc/protobuf/hello_service/interface.proto\x12\x05hello\x1a\x19google/protobuf/any.proto\"\x8e\x01\n" +
|
||||||
"\aRequest\x12\x14\n" +
|
"\aRequest\x12\x14\n" +
|
||||||
"\x05value\x18\x01 \x01(\tR\x05value\" \n" +
|
"\x05value\x18\x01 \x01(\tR\x05value\x122\n" +
|
||||||
|
"\x06extras\x18\x02 \x03(\v2\x1a.hello.Request.ExtrasEntryR\x06extras\x1a9\n" +
|
||||||
|
"\vExtrasEntry\x12\x10\n" +
|
||||||
|
"\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" +
|
||||||
|
"\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\"H\n" +
|
||||||
|
"\n" +
|
||||||
|
"RequestSet\x12\x14\n" +
|
||||||
|
"\x05total\x18\x01 \x01(\x03R\x05total\x12$\n" +
|
||||||
|
"\x05items\x18\x02 \x03(\v2\x0e.hello.RequestR\x05items\" \n" +
|
||||||
"\bResponse\x12\x14\n" +
|
"\bResponse\x12\x14\n" +
|
||||||
"\x05value\x18\x01 \x01(\tR\x05value28\n" +
|
"\x05value\x18\x01 \x01(\tR\x05value\"W\n" +
|
||||||
|
"\vErrorStatus\x12\x18\n" +
|
||||||
|
"\amessage\x18\x01 \x01(\tR\amessage\x12.\n" +
|
||||||
|
"\adetails\x18\x02 \x03(\v2\x14.google.protobuf.AnyR\adetails*Z\n" +
|
||||||
|
"\x06Corpus\x12\r\n" +
|
||||||
|
"\tUNIVERSAL\x10\x00\x12\a\n" +
|
||||||
|
"\x03WEB\x10\x01\x12\n" +
|
||||||
|
"\n" +
|
||||||
|
"\x06IMAGES\x10\x02\x12\t\n" +
|
||||||
|
"\x05LOCAL\x10\x03\x12\b\n" +
|
||||||
|
"\x04NEWS\x10\x04\x12\f\n" +
|
||||||
|
"\bPRODUCTS\x10\x05\x12\t\n" +
|
||||||
|
"\x05VIDEO\x10\x062j\n" +
|
||||||
"\fHelloService\x12(\n" +
|
"\fHelloService\x12(\n" +
|
||||||
"\x05Hello\x12\x0e.hello.Request\x1a\x0f.hello.ResponseB@Z>122.51.31.227/go-course/go18/skills/rpc/protobuf/hello_serviceb\x06proto3"
|
"\x05Hello\x12\x0e.hello.Request\x1a\x0f.hello.Response\x120\n" +
|
||||||
|
"\aChannel\x12\x0e.hello.Request\x1a\x0f.hello.Response\"\x00(\x010\x01B@Z>122.51.31.227/go-course/go18/skills/rpc/protobuf/hello_serviceb\x06proto3"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
file_skills_rpc_protobuf_hello_service_interface_proto_rawDescOnce sync.Once
|
file_skills_rpc_protobuf_hello_service_interface_proto_rawDescOnce sync.Once
|
||||||
@ -133,19 +330,30 @@ func file_skills_rpc_protobuf_hello_service_interface_proto_rawDescGZIP() []byte
|
|||||||
return file_skills_rpc_protobuf_hello_service_interface_proto_rawDescData
|
return file_skills_rpc_protobuf_hello_service_interface_proto_rawDescData
|
||||||
}
|
}
|
||||||
|
|
||||||
var file_skills_rpc_protobuf_hello_service_interface_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
var file_skills_rpc_protobuf_hello_service_interface_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||||
|
var file_skills_rpc_protobuf_hello_service_interface_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
|
||||||
var file_skills_rpc_protobuf_hello_service_interface_proto_goTypes = []any{
|
var file_skills_rpc_protobuf_hello_service_interface_proto_goTypes = []any{
|
||||||
(*Request)(nil), // 0: hello.Request
|
(Corpus)(0), // 0: hello.Corpus
|
||||||
(*Response)(nil), // 1: hello.Response
|
(*Request)(nil), // 1: hello.Request
|
||||||
|
(*RequestSet)(nil), // 2: hello.RequestSet
|
||||||
|
(*Response)(nil), // 3: hello.Response
|
||||||
|
(*ErrorStatus)(nil), // 4: hello.ErrorStatus
|
||||||
|
nil, // 5: hello.Request.ExtrasEntry
|
||||||
|
(*anypb.Any)(nil), // 6: google.protobuf.Any
|
||||||
}
|
}
|
||||||
var file_skills_rpc_protobuf_hello_service_interface_proto_depIdxs = []int32{
|
var file_skills_rpc_protobuf_hello_service_interface_proto_depIdxs = []int32{
|
||||||
0, // 0: hello.HelloService.Hello:input_type -> hello.Request
|
5, // 0: hello.Request.extras:type_name -> hello.Request.ExtrasEntry
|
||||||
1, // 1: hello.HelloService.Hello:output_type -> hello.Response
|
1, // 1: hello.RequestSet.items:type_name -> hello.Request
|
||||||
1, // [1:2] is the sub-list for method output_type
|
6, // 2: hello.ErrorStatus.details:type_name -> google.protobuf.Any
|
||||||
0, // [0:1] is the sub-list for method input_type
|
1, // 3: hello.HelloService.Hello:input_type -> hello.Request
|
||||||
0, // [0:0] is the sub-list for extension type_name
|
1, // 4: hello.HelloService.Channel:input_type -> hello.Request
|
||||||
0, // [0:0] is the sub-list for extension extendee
|
3, // 5: hello.HelloService.Hello:output_type -> hello.Response
|
||||||
0, // [0:0] is the sub-list for field type_name
|
3, // 6: hello.HelloService.Channel:output_type -> hello.Response
|
||||||
|
5, // [5:7] is the sub-list for method output_type
|
||||||
|
3, // [3:5] is the sub-list for method input_type
|
||||||
|
3, // [3:3] is the sub-list for extension type_name
|
||||||
|
3, // [3:3] is the sub-list for extension extendee
|
||||||
|
0, // [0:3] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_skills_rpc_protobuf_hello_service_interface_proto_init() }
|
func init() { file_skills_rpc_protobuf_hello_service_interface_proto_init() }
|
||||||
@ -158,13 +366,14 @@ func file_skills_rpc_protobuf_hello_service_interface_proto_init() {
|
|||||||
File: protoimpl.DescBuilder{
|
File: protoimpl.DescBuilder{
|
||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_skills_rpc_protobuf_hello_service_interface_proto_rawDesc), len(file_skills_rpc_protobuf_hello_service_interface_proto_rawDesc)),
|
RawDescriptor: unsafe.Slice(unsafe.StringData(file_skills_rpc_protobuf_hello_service_interface_proto_rawDesc), len(file_skills_rpc_protobuf_hello_service_interface_proto_rawDesc)),
|
||||||
NumEnums: 0,
|
NumEnums: 1,
|
||||||
NumMessages: 2,
|
NumMessages: 5,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 1,
|
NumServices: 1,
|
||||||
},
|
},
|
||||||
GoTypes: file_skills_rpc_protobuf_hello_service_interface_proto_goTypes,
|
GoTypes: file_skills_rpc_protobuf_hello_service_interface_proto_goTypes,
|
||||||
DependencyIndexes: file_skills_rpc_protobuf_hello_service_interface_proto_depIdxs,
|
DependencyIndexes: file_skills_rpc_protobuf_hello_service_interface_proto_depIdxs,
|
||||||
|
EnumInfos: file_skills_rpc_protobuf_hello_service_interface_proto_enumTypes,
|
||||||
MessageInfos: file_skills_rpc_protobuf_hello_service_interface_proto_msgTypes,
|
MessageInfos: file_skills_rpc_protobuf_hello_service_interface_proto_msgTypes,
|
||||||
}.Build()
|
}.Build()
|
||||||
File_skills_rpc_protobuf_hello_service_interface_proto = out.File
|
File_skills_rpc_protobuf_hello_service_interface_proto = out.File
|
||||||
|
@ -3,6 +3,9 @@ syntax = "proto3";
|
|||||||
package hello;
|
package hello;
|
||||||
option go_package="122.51.31.227/go-course/go18/skills/rpc/protobuf/hello_service";
|
option go_package="122.51.31.227/go-course/go18/skills/rpc/protobuf/hello_service";
|
||||||
|
|
||||||
|
// 这里是应用其他的proto文件, 后面会讲 ipmort用法
|
||||||
|
import "google/protobuf/any.proto";
|
||||||
|
|
||||||
// The HelloService service definition.
|
// The HelloService service definition.
|
||||||
service HelloService {
|
service HelloService {
|
||||||
// rpc 声明接口
|
// rpc 声明接口
|
||||||
@ -13,8 +16,31 @@ service HelloService {
|
|||||||
|
|
||||||
message Request {
|
message Request {
|
||||||
string value = 1;
|
string value = 1;
|
||||||
|
// map
|
||||||
|
map<string, string> extras = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestSet {
|
||||||
|
int64 total = 1;
|
||||||
|
// repeated 来描述一个数组
|
||||||
|
repeated Request items = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Response {
|
message Response {
|
||||||
string value = 1;
|
string value = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Corpus {
|
||||||
|
UNIVERSAL = 0;
|
||||||
|
WEB = 1;
|
||||||
|
IMAGES = 2;
|
||||||
|
LOCAL = 3;
|
||||||
|
NEWS = 4;
|
||||||
|
PRODUCTS = 5;
|
||||||
|
VIDEO = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ErrorStatus {
|
||||||
|
string message = 1;
|
||||||
|
repeated google.protobuf.Any details = 2;
|
||||||
}
|
}
|
35
skills/rpc/protobuf/hello_service/interface_test.go
Normal file
35
skills/rpc/protobuf/hello_service/interface_test.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package hello_service_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"122.51.31.227/go-course/go18/skills/rpc/protobuf/hello_service"
|
||||||
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAny(t *testing.T) {
|
||||||
|
status := hello_service.ErrorStatus{
|
||||||
|
Details: []*anypb.Any{},
|
||||||
|
}
|
||||||
|
|
||||||
|
d1 := hello_service.Request{Value: "test"}
|
||||||
|
any1, err := anypb.New(&d1)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
d2 := hello_service.Response{Value: "test"}
|
||||||
|
any2, err := anypb.New(&d2)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
status.Details = append(status.Details, any1, any2)
|
||||||
|
|
||||||
|
t.Log(status)
|
||||||
|
|
||||||
|
target := hello_service.Request{}
|
||||||
|
if err := status.Details[0].UnmarshalTo(&target); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(target.Value)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user