Compare commits

...

10 Commits

Author SHA1 Message Date
bcd2f45575 补充resource模块接口实现 2025-03-02 17:41:18 +08:00
ac8baa536f 补充Makefile 2025-03-02 16:29:27 +08:00
f53853f53a 补充cmdb业务定义 2025-03-02 15:12:59 +08:00
dcd5136a8c 补充cmdb设计 2025-03-02 14:27:57 +08:00
5597e735fc 补充grpc逻辑 2025-03-02 09:57:02 +08:00
e9b2a72b15 补充grpc steam 2025-02-16 18:13:10 +08:00
8569acbdbb 补充GRPC Hello World 2025-02-16 17:30:04 +08:00
f70e404ef7 protobuf 语法介绍 2025-02-16 16:42:14 +08:00
506c3cc98f 补充protobuf语法 2025-02-16 16:14:23 +08:00
737a4340ae 补充protobuf安装 2025-02-16 14:56:06 +08:00
44 changed files with 3501 additions and 48 deletions

0
.vscode/settings.json vendored Normal file
View File

View File

@ -1 +1,2 @@
# 微服务项目(cmdb)

6
devcloud-mini/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,6 @@
{
"go.testEnvFile": "${workspaceFolder}/etc/unit_test.env",
"go.testEnvVars": {
"CmdbConfigPath": "${workspaceFolder}/cmdb/etc/application.toml"
}
}

13
devcloud-mini/Makefile Normal file
View File

@ -0,0 +1,13 @@
PROJECT_NAME := cmdb
OUTPUT_NAME := cmdb
MAIN_FILE := main.go
PKG := gitlab.com/go-course-project/go17/devcloud-mini
gen: ## Init Service
@protoc -I=. --go_out=. --go_opt=module=${PKG} --go-grpc_out=. --go-grpc_opt=module=${PKG} cmdb/apps/*/*.proto
@go fmt ./...
@protoc-go-inject-tag -input='cmdb/apps/*/*.pb.go'
@mcube enum -p -m cmdb/apps/*/*.pb.go
help: ## Display this help screen
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

View File

@ -0,0 +1,54 @@
PROJECT_NAME := cmdb
OUTPUT_NAME := cmdb
MAIN_FILE := main.go
PKG := gitlab.com/go-course-project/go17/devcloud-mini/cmdb
.PHONY: all dep lint vet test test-coverage build clean
all: build
dep: ## Get the dependencies
@go mod tidy
lint: ## Lint Golang files
@golint -set_exit_status ${PKG_LIST}
vet: ## Run go vet
@go vet ${PKG_LIST}
test: ## Run unittests
@go test -short ${PKG_LIST}
test-coverage: ## Run tests with coverage
@go test -short -coverprofile cover.out -covermode=atomic ${PKG_LIST}
@cat cover.out >> coverage.txt
build: dep ## Build the binary file
@go build -a -o dist/${OUTPUT_NAME} -ldflags "-s -w" -ldflags "-X '${VERSION_PATH}.GIT_BRANCH=${BUILD_BRANCH}' -X '${VERSION_PATH}.GIT_COMMIT=${BUILD_COMMIT}' -X '${VERSION_PATH}.BUILD_TIME=${BUILD_TIME}' -X '${VERSION_PATH}.GO_VERSION=${BUILD_GO_VERSION}'" ${MAIN_FILE}
linux: dep ## Build the binary file
@GOOS=linux GOARCH=amd64 go build -a -o dist/${OUTPUT_NAME} -ldflags "-s -w" -ldflags "-X '${VERSION_PATH}.GIT_BRANCH=${BUILD_BRANCH}' -X '${VERSION_PATH}.GIT_COMMIT=${BUILD_COMMIT}' -X '${VERSION_PATH}.BUILD_TIME=${BUILD_TIME}' -X '${VERSION_PATH}.GO_VERSION=${BUILD_GO_VERSION}'" ${MAIN_FILE}
init: dep ## Inital project
@go run main.go init
run: dep ## Run Server
@go run main.go start
clean: ## Remove previous build
@go clean .
@rm -f dist/${PROJECT_NAME}
install: ## Install depence go package
@go install github.com/infraboard/mcube/v2/cmd/mcube@latest
@go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
@go install github.com/favadi/protoc-go-inject-tag@latest
pb: ## Copy mcube protobuf files to common/pb
@mkdir -pv common/pb/github.com/infraboard/mcube/v2/pb
@cp -r ${MCUBE_PKG_PATH}/pb/* common/pb/github.com/infraboard/mcube/v2/pb
@sudo rm -rf common/pb/github.com/infraboard/mcube/v2/pb/*/*.go
help: ## Display this help screen
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

View File

@ -0,0 +1,34 @@
# cmdb
## 需求
核心: 资源管理(资源中心): ECS, RDS, DOMAIN, IP, ...
怎么进行资源管理: excel手动管理, 无法其他系统对接(核心数据)
1. 资源检索: IP --> 是那个业务方(ECS, EIP, ELB, ...)
2. 资源过期提醒
3. 密码轮转
4. 自动化的系统,自动部署(app --> app ecs)
5. 监控, 自动发现,这个机器是那个业务方,不能把高级直接发给业务方
6. 管理,登录维护,谁能登录哪些机器,以什么用户
## 设计
资源管理模型的设计:
1. 基于模型的CMDB设计
2. 云管的CMDB设计
## 功能模块开发
1. resource
2. secret
3. tag
业务功能 以GRPC方式实现然后选择以何种方式 提供API(RESTful/GRPC), 不适用于 先有叻RESTful API后补充GRPC:
1. 内部包
2. 暴露为 RESTful API
3. 暴露为 GRPC rpc
## 接入用户中心,接入审计中心

View File

@ -0,0 +1,5 @@
package apps
import (
_ "gitlab.com/go-course-project/go17/devcloud-mini/cmdb/apps/resource/impl"
)

View File

@ -0,0 +1,4 @@
# 资源管理模块
# CRUD

View File

@ -0,0 +1,32 @@
package impl
import (
"github.com/infraboard/mcube/v2/ioc"
"github.com/infraboard/mcube/v2/ioc/config/grpc"
ioc_mongo "github.com/infraboard/mcube/v2/ioc/config/mongo"
"gitlab.com/go-course-project/go17/devcloud-mini/cmdb/apps/resource"
"go.mongodb.org/mongo-driver/mongo"
)
func init() {
ioc.Controller().Registry(&ResourceServiceImpl{})
}
type ResourceServiceImpl struct {
resource.UnimplementedRpcServer
ioc.ObjectImpl
col *mongo.Collection
}
func (s *ResourceServiceImpl) Name() string {
return resource.AppName
}
func (s *ResourceServiceImpl) Init() error {
// 注册给GRPC
resource.RegisterRpcServer(grpc.Get().Server(), s)
// 定义使用的集合
s.col = ioc_mongo.DB().Collection("resources")
return nil
}

View File

@ -0,0 +1,17 @@
package impl_test
import (
"context"
"gitlab.com/go-course-project/go17/devcloud-mini/cmdb/apps/resource"
"gitlab.com/go-course-project/go17/devcloud-mini/cmdb/test"
)
var (
ctx = context.Background()
svc = resource.GetService()
)
func init() {
test.SetUp()
}

View File

@ -0,0 +1,31 @@
package impl
import (
"context"
"gitlab.com/go-course-project/go17/devcloud-mini/cmdb/apps/resource"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s *ResourceServiceImpl) Search(context.Context, *resource.SearchRequest) (*resource.ResourceSet, error) {
return nil, status.Errorf(codes.Unimplemented, "method Search not implemented")
}
func (s *ResourceServiceImpl) Save(ctx context.Context, in *resource.Resource) (*resource.Resource, error) {
if err := in.Validate(); err != nil {
return nil, err
}
// 保持数据, 需要从ioc里面获取一个mongodb实例
_, err := s.col.InsertOne(ctx, in)
if err != nil {
return nil, err
}
return in, nil
}
func (s *ResourceServiceImpl) DeleteResource(context.Context, *resource.DeleteResourceRequest) error {
return nil
}

View File

@ -0,0 +1,27 @@
package impl_test
import (
"testing"
"time"
"gitlab.com/go-course-project/go17/devcloud-mini/cmdb/apps/resource"
)
func TestSave(t *testing.T) {
resp, err := svc.Save(ctx, &resource.Resource{
Meta: &resource.Meta{
Id: "ins-002",
Domain: "test",
Namespace: "default",
SyncAt: time.Now().Unix(),
},
Spec: &resource.Spec{
Name: "test",
},
Status: &resource.Status{},
})
if err != nil {
t.Fatal(err)
}
t.Log(resp)
}

View File

@ -0,0 +1,42 @@
package resource
import (
context "context"
"github.com/infraboard/mcube/v2/exception"
"github.com/infraboard/mcube/v2/ioc"
"github.com/infraboard/mcube/v2/ioc/config/validator"
)
const (
AppName = "resource"
)
func GetService() Service {
return ioc.Controller().Get(AppName).(Service)
}
type Service interface {
// 需要对外暴露为rpc的
RpcServer
// 删除
DeleteResource(context.Context, *DeleteResourceRequest) error
}
func NewDeleteResourceRequest() *DeleteResourceRequest {
return &DeleteResourceRequest{}
}
// 支持多个
type DeleteResourceRequest struct {
ResourceIds []string `json:"resource_ids"`
}
func (s *Resource) Validate() error {
err := validator.Validate(s)
if err != nil {
return exception.NewBadRequest("参数校验失败, %s", err)
}
return nil
}

View File

@ -0,0 +1,923 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.5
// protoc v5.29.3
// source: cmdb/apps/resource/service.proto
package resource
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
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 VENDOR int32
const (
VENDOR_ALIYUN VENDOR = 0
VENDOR_TENCENT VENDOR = 1
VENDOR_HUAWEI VENDOR = 2
VENDOR_VSPHERE VENDOR = 3
VENDOR_AMAZON VENDOR = 4
)
// Enum value maps for VENDOR.
var (
VENDOR_name = map[int32]string{
0: "ALIYUN",
1: "TENCENT",
2: "HUAWEI",
3: "VSPHERE",
4: "AMAZON",
}
VENDOR_value = map[string]int32{
"ALIYUN": 0,
"TENCENT": 1,
"HUAWEI": 2,
"VSPHERE": 3,
"AMAZON": 4,
}
)
func (x VENDOR) Enum() *VENDOR {
p := new(VENDOR)
*p = x
return p
}
func (x VENDOR) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (VENDOR) Descriptor() protoreflect.EnumDescriptor {
return file_cmdb_apps_resource_service_proto_enumTypes[0].Descriptor()
}
func (VENDOR) Type() protoreflect.EnumType {
return &file_cmdb_apps_resource_service_proto_enumTypes[0]
}
func (x VENDOR) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use VENDOR.Descriptor instead.
func (VENDOR) EnumDescriptor() ([]byte, []int) {
return file_cmdb_apps_resource_service_proto_rawDescGZIP(), []int{0}
}
type TYPE int32
const (
TYPE_HOST TYPE = 0
TYPE_RDS TYPE = 1
)
// Enum value maps for TYPE.
var (
TYPE_name = map[int32]string{
0: "HOST",
1: "RDS",
}
TYPE_value = map[string]int32{
"HOST": 0,
"RDS": 1,
}
)
func (x TYPE) Enum() *TYPE {
p := new(TYPE)
*p = x
return p
}
func (x TYPE) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (TYPE) Descriptor() protoreflect.EnumDescriptor {
return file_cmdb_apps_resource_service_proto_enumTypes[1].Descriptor()
}
func (TYPE) Type() protoreflect.EnumType {
return &file_cmdb_apps_resource_service_proto_enumTypes[1]
}
func (x TYPE) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use TYPE.Descriptor instead.
func (TYPE) EnumDescriptor() ([]byte, []int) {
return file_cmdb_apps_resource_service_proto_rawDescGZIP(), []int{1}
}
type SearchRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
// 页大小
PageSize int64 `protobuf:"varint,1,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
// 页码
PageNumber int64 `protobuf:"varint,2,opt,name=page_number,json=pageNumber,proto3" json:"page_number,omitempty"`
// 名称做模糊搜索
Keywords string `protobuf:"bytes,3,opt,name=keywords,proto3" json:"keywords,omitempty"`
// 资源类型
Type *TYPE `protobuf:"varint,4,opt,name=type,proto3,enum=go17.cmdb.resource.TYPE,oneof" json:"type,omitempty"`
// 标签
Tag map[string]string `protobuf:"bytes,5,rep,name=tag,proto3" json:"tag,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *SearchRequest) Reset() {
*x = SearchRequest{}
mi := &file_cmdb_apps_resource_service_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SearchRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SearchRequest) ProtoMessage() {}
func (x *SearchRequest) ProtoReflect() protoreflect.Message {
mi := &file_cmdb_apps_resource_service_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 SearchRequest.ProtoReflect.Descriptor instead.
func (*SearchRequest) Descriptor() ([]byte, []int) {
return file_cmdb_apps_resource_service_proto_rawDescGZIP(), []int{0}
}
func (x *SearchRequest) GetPageSize() int64 {
if x != nil {
return x.PageSize
}
return 0
}
func (x *SearchRequest) GetPageNumber() int64 {
if x != nil {
return x.PageNumber
}
return 0
}
func (x *SearchRequest) GetKeywords() string {
if x != nil {
return x.Keywords
}
return ""
}
func (x *SearchRequest) GetType() TYPE {
if x != nil && x.Type != nil {
return *x.Type
}
return TYPE_HOST
}
func (x *SearchRequest) GetTag() map[string]string {
if x != nil {
return x.Tag
}
return nil
}
type ResourceSet struct {
state protoimpl.MessageState `protogen:"open.v1"`
// 总量
Total int64 `protobuf:"varint,1,opt,name=total,proto3" json:"total,omitempty"`
// 资源清单
Items []*Resource `protobuf:"bytes,2,rep,name=items,proto3" json:"items,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ResourceSet) Reset() {
*x = ResourceSet{}
mi := &file_cmdb_apps_resource_service_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ResourceSet) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ResourceSet) ProtoMessage() {}
func (x *ResourceSet) ProtoReflect() protoreflect.Message {
mi := &file_cmdb_apps_resource_service_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 ResourceSet.ProtoReflect.Descriptor instead.
func (*ResourceSet) Descriptor() ([]byte, []int) {
return file_cmdb_apps_resource_service_proto_rawDescGZIP(), []int{1}
}
func (x *ResourceSet) GetTotal() int64 {
if x != nil {
return x.Total
}
return 0
}
func (x *ResourceSet) GetItems() []*Resource {
if x != nil {
return x.Items
}
return nil
}
type Resource struct {
state protoimpl.MessageState `protogen:"open.v1"`
// @gotags: bson:"inline" validate:"required"
Meta *Meta `protobuf:"bytes,1,opt,name=Meta,proto3" json:"Meta,omitempty" bson:"inline" validate:"required"`
// @gotags: bson:"inline" validate:"required"
Spec *Spec `protobuf:"bytes,2,opt,name=Spec,proto3" json:"Spec,omitempty" bson:"inline" validate:"required"`
// @gotags: bson:"inline" validate:"required"
Status *Status `protobuf:"bytes,3,opt,name=Status,proto3" json:"Status,omitempty" bson:"inline" validate:"required"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Resource) Reset() {
*x = Resource{}
mi := &file_cmdb_apps_resource_service_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Resource) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Resource) ProtoMessage() {}
func (x *Resource) ProtoReflect() protoreflect.Message {
mi := &file_cmdb_apps_resource_service_proto_msgTypes[2]
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 Resource.ProtoReflect.Descriptor instead.
func (*Resource) Descriptor() ([]byte, []int) {
return file_cmdb_apps_resource_service_proto_rawDescGZIP(), []int{2}
}
func (x *Resource) GetMeta() *Meta {
if x != nil {
return x.Meta
}
return nil
}
func (x *Resource) GetSpec() *Spec {
if x != nil {
return x.Spec
}
return nil
}
func (x *Resource) GetStatus() *Status {
if x != nil {
return x.Status
}
return nil
}
type Meta struct {
state protoimpl.MessageState `protogen:"open.v1"`
// 全局唯一Id, 直接使用个云商自己的Id
// @gotags: json:"id" bson:"_id" validate:"required"
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id" validate:"required"`
// 资源所属域
// @gotags: json:"domain" validate:"required"
Domain string `protobuf:"bytes,2,opt,name=domain,proto3" json:"domain" validate:"required"`
// 资源所属空间
// @gotags: json:"namespace" validate:"required"
Namespace string `protobuf:"bytes,3,opt,name=namespace,proto3" json:"namespace" validate:"required"`
// 资源所属环境
// @gotags: json:"env"
Env string `protobuf:"bytes,4,opt,name=env,proto3" json:"env"`
// 创建时间
// @gotags: json:"create_at"
CreateAt int64 `protobuf:"varint,5,opt,name=create_at,json=createAt,proto3" json:"create_at"`
// 删除时间
// @gotags: json:"detete_at"
DeteteAt int64 `protobuf:"varint,6,opt,name=detete_at,json=deteteAt,proto3" json:"detete_at"`
// 删除人
// @gotags: json:"detete_by"
DeteteBy string `protobuf:"bytes,7,opt,name=detete_by,json=deteteBy,proto3" json:"detete_by"`
// 同步时间
// @gotags: json:"sync_at" validate:"required"
SyncAt int64 `protobuf:"varint,8,opt,name=sync_at,json=syncAt,proto3" json:"sync_at" validate:"required"`
// 同步人
// @gotags: json:"sync_by"
SyncBy string `protobuf:"bytes,9,opt,name=sync_by,json=syncBy,proto3" json:"sync_by"`
// 用于同步的凭证ID
// @gotags: json:"credential_id"
CredentialId string `protobuf:"bytes,10,opt,name=credential_id,json=credentialId,proto3" json:"credential_id"`
// 序列号
// @gotags: json:"serial_number"
SerialNumber string `protobuf:"bytes,11,opt,name=serial_number,json=serialNumber,proto3" json:"serial_number"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Meta) Reset() {
*x = Meta{}
mi := &file_cmdb_apps_resource_service_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Meta) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Meta) ProtoMessage() {}
func (x *Meta) ProtoReflect() protoreflect.Message {
mi := &file_cmdb_apps_resource_service_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 Meta.ProtoReflect.Descriptor instead.
func (*Meta) Descriptor() ([]byte, []int) {
return file_cmdb_apps_resource_service_proto_rawDescGZIP(), []int{3}
}
func (x *Meta) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *Meta) GetDomain() string {
if x != nil {
return x.Domain
}
return ""
}
func (x *Meta) GetNamespace() string {
if x != nil {
return x.Namespace
}
return ""
}
func (x *Meta) GetEnv() string {
if x != nil {
return x.Env
}
return ""
}
func (x *Meta) GetCreateAt() int64 {
if x != nil {
return x.CreateAt
}
return 0
}
func (x *Meta) GetDeteteAt() int64 {
if x != nil {
return x.DeteteAt
}
return 0
}
func (x *Meta) GetDeteteBy() string {
if x != nil {
return x.DeteteBy
}
return ""
}
func (x *Meta) GetSyncAt() int64 {
if x != nil {
return x.SyncAt
}
return 0
}
func (x *Meta) GetSyncBy() string {
if x != nil {
return x.SyncBy
}
return ""
}
func (x *Meta) GetCredentialId() string {
if x != nil {
return x.CredentialId
}
return ""
}
func (x *Meta) GetSerialNumber() string {
if x != nil {
return x.SerialNumber
}
return ""
}
type Spec struct {
state protoimpl.MessageState `protogen:"open.v1"`
// 厂商
// @gotags: json:"vendor"
Vendor VENDOR `protobuf:"varint,1,opt,name=vendor,proto3,enum=go17.cmdb.resource.VENDOR" json:"vendor"`
// 资源类型
// @gotags: json:"resource_type"
ResourceType TYPE `protobuf:"varint,2,opt,name=resource_type,json=resourceType,proto3,enum=go17.cmdb.resource.TYPE" json:"resource_type"`
// 地域
// @gotags: json:"region"
Region string `protobuf:"bytes,3,opt,name=region,proto3" json:"region"`
// 区域
// @gotags: json:"zone"
Zone string `protobuf:"bytes,4,opt,name=zone,proto3" json:"zone"`
// 资源所属账号
// @gotags: json:"owner"
Owner string `protobuf:"bytes,5,opt,name=owner,proto3" json:"owner"`
// 名称
// @gotags: json:"name"
Name string `protobuf:"bytes,6,opt,name=name,proto3" json:"name"`
// 规格
// @gotags: json:"type"
Type string `protobuf:"bytes,7,opt,name=type,proto3" json:"type"`
// 描述
// @gotags: json:"description"
Description string `protobuf:"bytes,8,opt,name=description,proto3" json:"description"`
// 资源占用Cpu数量
// @gotags: json:"cpu"
Cpu int32 `protobuf:"varint,9,opt,name=cpu,proto3" json:"cpu"`
// 资源使用的内存
// @gotags: json:"memory"
Memory int64 `protobuf:"varint,10,opt,name=memory,proto3" json:"memory"`
// 资源使用的存储
// @gotags: json:"storage"
Storage int64 `protobuf:"varint,11,opt,name=storage,proto3" json:"storage"`
// 公网IP带宽, 单位M
// @gotags: json:"band_width"
BandWidth int64 `protobuf:"varint,12,opt,name=band_width,json=bandWidth,proto3" json:"band_width"`
// 资源标签
// @gotags: json:"tags"
Tags map[string]string `protobuf:"bytes,13,rep,name=tags,proto3" json:"tags" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
// 额外的通用属性
// @gotags: json:"extra" gorm:"serializer:json"
Extra map[string]string `protobuf:"bytes,14,rep,name=extra,proto3" json:"extra" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value" gorm:"serializer:json"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Spec) Reset() {
*x = Spec{}
mi := &file_cmdb_apps_resource_service_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Spec) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Spec) ProtoMessage() {}
func (x *Spec) ProtoReflect() protoreflect.Message {
mi := &file_cmdb_apps_resource_service_proto_msgTypes[4]
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 Spec.ProtoReflect.Descriptor instead.
func (*Spec) Descriptor() ([]byte, []int) {
return file_cmdb_apps_resource_service_proto_rawDescGZIP(), []int{4}
}
func (x *Spec) GetVendor() VENDOR {
if x != nil {
return x.Vendor
}
return VENDOR_ALIYUN
}
func (x *Spec) GetResourceType() TYPE {
if x != nil {
return x.ResourceType
}
return TYPE_HOST
}
func (x *Spec) GetRegion() string {
if x != nil {
return x.Region
}
return ""
}
func (x *Spec) GetZone() string {
if x != nil {
return x.Zone
}
return ""
}
func (x *Spec) GetOwner() string {
if x != nil {
return x.Owner
}
return ""
}
func (x *Spec) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *Spec) GetType() string {
if x != nil {
return x.Type
}
return ""
}
func (x *Spec) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
func (x *Spec) GetCpu() int32 {
if x != nil {
return x.Cpu
}
return 0
}
func (x *Spec) GetMemory() int64 {
if x != nil {
return x.Memory
}
return 0
}
func (x *Spec) GetStorage() int64 {
if x != nil {
return x.Storage
}
return 0
}
func (x *Spec) GetBandWidth() int64 {
if x != nil {
return x.BandWidth
}
return 0
}
func (x *Spec) GetTags() map[string]string {
if x != nil {
return x.Tags
}
return nil
}
func (x *Spec) GetExtra() map[string]string {
if x != nil {
return x.Extra
}
return nil
}
type Status struct {
state protoimpl.MessageState `protogen:"open.v1"`
// 资源当前状态
// @gotags: json:"phase"
Phase string `protobuf:"bytes,1,opt,name=phase,proto3" json:"phase"`
// 资源当前状态描述
// @gotags: json:"describe"
Describe string `protobuf:"bytes,2,opt,name=describe,proto3" json:"describe"`
// 资源访问地址
// 公网地址, 或者域名
// @gotags: json:"public_address" gorm:"serializer:json"
PublicAddress []string `protobuf:"bytes,3,rep,name=public_address,json=publicAddress,proto3" json:"public_address" gorm:"serializer:json"`
// 内网地址, 或者域名
// @gotags: json:"private_address" gorm:"serializer:json"
PrivateAddress []string `protobuf:"bytes,4,rep,name=private_address,json=privateAddress,proto3" json:"private_address" gorm:"serializer:json"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Status) Reset() {
*x = Status{}
mi := &file_cmdb_apps_resource_service_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Status) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Status) ProtoMessage() {}
func (x *Status) ProtoReflect() protoreflect.Message {
mi := &file_cmdb_apps_resource_service_proto_msgTypes[5]
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 Status.ProtoReflect.Descriptor instead.
func (*Status) Descriptor() ([]byte, []int) {
return file_cmdb_apps_resource_service_proto_rawDescGZIP(), []int{5}
}
func (x *Status) GetPhase() string {
if x != nil {
return x.Phase
}
return ""
}
func (x *Status) GetDescribe() string {
if x != nil {
return x.Describe
}
return ""
}
func (x *Status) GetPublicAddress() []string {
if x != nil {
return x.PublicAddress
}
return nil
}
func (x *Status) GetPrivateAddress() []string {
if x != nil {
return x.PrivateAddress
}
return nil
}
var File_cmdb_apps_resource_service_proto protoreflect.FileDescriptor
var file_cmdb_apps_resource_service_proto_rawDesc = string([]byte{
0x0a, 0x20, 0x63, 0x6d, 0x64, 0x62, 0x2f, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x72, 0x65, 0x73, 0x6f,
0x75, 0x72, 0x63, 0x65, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x12, 0x12, 0x67, 0x6f, 0x31, 0x37, 0x2e, 0x63, 0x6d, 0x64, 0x62, 0x2e, 0x72, 0x65,
0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x9b, 0x02, 0x0a, 0x0d, 0x53, 0x65, 0x61, 0x72, 0x63,
0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x61, 0x67, 0x65,
0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x61, 0x67,
0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x6e, 0x75,
0x6d, 0x62, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x70, 0x61, 0x67, 0x65,
0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72,
0x64, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72,
0x64, 0x73, 0x12, 0x31, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e,
0x32, 0x18, 0x2e, 0x67, 0x6f, 0x31, 0x37, 0x2e, 0x63, 0x6d, 0x64, 0x62, 0x2e, 0x72, 0x65, 0x73,
0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x54, 0x59, 0x50, 0x45, 0x48, 0x00, 0x52, 0x04, 0x74, 0x79,
0x70, 0x65, 0x88, 0x01, 0x01, 0x12, 0x3c, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x05, 0x20, 0x03,
0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x67, 0x6f, 0x31, 0x37, 0x2e, 0x63, 0x6d, 0x64, 0x62, 0x2e, 0x72,
0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x54, 0x61, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x03,
0x74, 0x61, 0x67, 0x1a, 0x36, 0x0a, 0x08, 0x54, 0x61, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12,
0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65,
0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f,
0x74, 0x79, 0x70, 0x65, 0x22, 0x57, 0x0a, 0x0b, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65,
0x53, 0x65, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01,
0x28, 0x03, 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x12, 0x32, 0x0a, 0x05, 0x69, 0x74, 0x65,
0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x31, 0x37, 0x2e,
0x63, 0x6d, 0x64, 0x62, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x52, 0x65,
0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x9a, 0x01,
0x0a, 0x08, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x2c, 0x0a, 0x04, 0x4d, 0x65,
0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x67, 0x6f, 0x31, 0x37, 0x2e,
0x63, 0x6d, 0x64, 0x62, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x4d, 0x65,
0x74, 0x61, 0x52, 0x04, 0x4d, 0x65, 0x74, 0x61, 0x12, 0x2c, 0x0a, 0x04, 0x53, 0x70, 0x65, 0x63,
0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x67, 0x6f, 0x31, 0x37, 0x2e, 0x63, 0x6d,
0x64, 0x62, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x53, 0x70, 0x65, 0x63,
0x52, 0x04, 0x53, 0x70, 0x65, 0x63, 0x12, 0x32, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73,
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x31, 0x37, 0x2e, 0x63, 0x6d,
0x64, 0x62, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74,
0x75, 0x73, 0x52, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0xb1, 0x02, 0x0a, 0x04, 0x4d,
0x65, 0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x12, 0x1c, 0x0a, 0x09, 0x6e,
0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09,
0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x76,
0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x65, 0x6e, 0x76, 0x12, 0x1b, 0x0a, 0x09, 0x63,
0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x61, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08,
0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x65, 0x74, 0x65,
0x74, 0x65, 0x5f, 0x61, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x74,
0x65, 0x74, 0x65, 0x41, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x65, 0x74, 0x65, 0x74, 0x65, 0x5f,
0x62, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x65, 0x74, 0x65, 0x74, 0x65,
0x42, 0x79, 0x12, 0x17, 0x0a, 0x07, 0x73, 0x79, 0x6e, 0x63, 0x5f, 0x61, 0x74, 0x18, 0x08, 0x20,
0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x79, 0x6e, 0x63, 0x41, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x73,
0x79, 0x6e, 0x63, 0x5f, 0x62, 0x79, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x79,
0x6e, 0x63, 0x42, 0x79, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69,
0x61, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x72, 0x65,
0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x73, 0x65, 0x72,
0x69, 0x61, 0x6c, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09,
0x52, 0x0c, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0xce,
0x04, 0x0a, 0x04, 0x53, 0x70, 0x65, 0x63, 0x12, 0x32, 0x0a, 0x06, 0x76, 0x65, 0x6e, 0x64, 0x6f,
0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x31, 0x37, 0x2e, 0x63,
0x6d, 0x64, 0x62, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x56, 0x45, 0x4e,
0x44, 0x4f, 0x52, 0x52, 0x06, 0x76, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x12, 0x3d, 0x0a, 0x0d, 0x72,
0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x0e, 0x32, 0x18, 0x2e, 0x67, 0x6f, 0x31, 0x37, 0x2e, 0x63, 0x6d, 0x64, 0x62, 0x2e, 0x72,
0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x54, 0x59, 0x50, 0x45, 0x52, 0x0c, 0x72, 0x65,
0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65,
0x67, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x67, 0x69,
0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x7a, 0x6f, 0x6e, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09,
0x52, 0x04, 0x7a, 0x6f, 0x6e, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x18,
0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
0x74, 0x79, 0x70, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72,
0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x70, 0x75, 0x18, 0x09, 0x20,
0x01, 0x28, 0x05, 0x52, 0x03, 0x63, 0x70, 0x75, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x6d, 0x6f,
0x72, 0x79, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79,
0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28,
0x03, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x62, 0x61,
0x6e, 0x64, 0x5f, 0x77, 0x69, 0x64, 0x74, 0x68, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09,
0x62, 0x61, 0x6e, 0x64, 0x57, 0x69, 0x64, 0x74, 0x68, 0x12, 0x36, 0x0a, 0x04, 0x74, 0x61, 0x67,
0x73, 0x18, 0x0d, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x67, 0x6f, 0x31, 0x37, 0x2e, 0x63,
0x6d, 0x64, 0x62, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x53, 0x70, 0x65,
0x63, 0x2e, 0x54, 0x61, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, 0x74, 0x61, 0x67,
0x73, 0x12, 0x39, 0x0a, 0x05, 0x65, 0x78, 0x74, 0x72, 0x61, 0x18, 0x0e, 0x20, 0x03, 0x28, 0x0b,
0x32, 0x23, 0x2e, 0x67, 0x6f, 0x31, 0x37, 0x2e, 0x63, 0x6d, 0x64, 0x62, 0x2e, 0x72, 0x65, 0x73,
0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x53, 0x70, 0x65, 0x63, 0x2e, 0x45, 0x78, 0x74, 0x72, 0x61,
0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x65, 0x78, 0x74, 0x72, 0x61, 0x1a, 0x37, 0x0a, 0x09,
0x54, 0x61, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76,
0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75,
0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x38, 0x0a, 0x0a, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e,
0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22,
0x8a, 0x01, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x68,
0x61, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70, 0x68, 0x61, 0x73, 0x65,
0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x08, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x12, 0x25, 0x0a, 0x0e,
0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03,
0x20, 0x03, 0x28, 0x09, 0x52, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x41, 0x64, 0x64, 0x72,
0x65, 0x73, 0x73, 0x12, 0x27, 0x0a, 0x0f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x5f, 0x61,
0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0e, 0x70, 0x72,
0x69, 0x76, 0x61, 0x74, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x2a, 0x46, 0x0a, 0x06,
0x56, 0x45, 0x4e, 0x44, 0x4f, 0x52, 0x12, 0x0a, 0x0a, 0x06, 0x41, 0x4c, 0x49, 0x59, 0x55, 0x4e,
0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x54, 0x45, 0x4e, 0x43, 0x45, 0x4e, 0x54, 0x10, 0x01, 0x12,
0x0a, 0x0a, 0x06, 0x48, 0x55, 0x41, 0x57, 0x45, 0x49, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x56,
0x53, 0x50, 0x48, 0x45, 0x52, 0x45, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06, 0x41, 0x4d, 0x41, 0x5a,
0x4f, 0x4e, 0x10, 0x04, 0x2a, 0x19, 0x0a, 0x04, 0x54, 0x59, 0x50, 0x45, 0x12, 0x08, 0x0a, 0x04,
0x48, 0x4f, 0x53, 0x54, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x52, 0x44, 0x53, 0x10, 0x01, 0x32,
0x97, 0x01, 0x0a, 0x03, 0x52, 0x70, 0x63, 0x12, 0x4c, 0x0a, 0x06, 0x53, 0x65, 0x61, 0x72, 0x63,
0x68, 0x12, 0x21, 0x2e, 0x67, 0x6f, 0x31, 0x37, 0x2e, 0x63, 0x6d, 0x64, 0x62, 0x2e, 0x72, 0x65,
0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x67, 0x6f, 0x31, 0x37, 0x2e, 0x63, 0x6d, 0x64, 0x62,
0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72,
0x63, 0x65, 0x53, 0x65, 0x74, 0x12, 0x42, 0x0a, 0x04, 0x53, 0x61, 0x76, 0x65, 0x12, 0x1c, 0x2e,
0x67, 0x6f, 0x31, 0x37, 0x2e, 0x63, 0x6d, 0x64, 0x62, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72,
0x63, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x1a, 0x1c, 0x2e, 0x67, 0x6f,
0x31, 0x37, 0x2e, 0x63, 0x6d, 0x64, 0x62, 0x2e, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65,
0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x42, 0x44, 0x5a, 0x42, 0x67, 0x69, 0x74,
0x6c, 0x61, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x63, 0x6f, 0x75, 0x72, 0x73,
0x65, 0x2d, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x67, 0x6f, 0x31, 0x37, 0x2f, 0x64,
0x65, 0x76, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2d, 0x6d, 0x69, 0x6e, 0x69, 0x2f, 0x63, 0x6d, 0x64,
0x62, 0x2f, 0x61, 0x70, 0x70, 0x73, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
})
var (
file_cmdb_apps_resource_service_proto_rawDescOnce sync.Once
file_cmdb_apps_resource_service_proto_rawDescData []byte
)
func file_cmdb_apps_resource_service_proto_rawDescGZIP() []byte {
file_cmdb_apps_resource_service_proto_rawDescOnce.Do(func() {
file_cmdb_apps_resource_service_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_cmdb_apps_resource_service_proto_rawDesc), len(file_cmdb_apps_resource_service_proto_rawDesc)))
})
return file_cmdb_apps_resource_service_proto_rawDescData
}
var file_cmdb_apps_resource_service_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
var file_cmdb_apps_resource_service_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
var file_cmdb_apps_resource_service_proto_goTypes = []any{
(VENDOR)(0), // 0: go17.cmdb.resource.VENDOR
(TYPE)(0), // 1: go17.cmdb.resource.TYPE
(*SearchRequest)(nil), // 2: go17.cmdb.resource.SearchRequest
(*ResourceSet)(nil), // 3: go17.cmdb.resource.ResourceSet
(*Resource)(nil), // 4: go17.cmdb.resource.Resource
(*Meta)(nil), // 5: go17.cmdb.resource.Meta
(*Spec)(nil), // 6: go17.cmdb.resource.Spec
(*Status)(nil), // 7: go17.cmdb.resource.Status
nil, // 8: go17.cmdb.resource.SearchRequest.TagEntry
nil, // 9: go17.cmdb.resource.Spec.TagsEntry
nil, // 10: go17.cmdb.resource.Spec.ExtraEntry
}
var file_cmdb_apps_resource_service_proto_depIdxs = []int32{
1, // 0: go17.cmdb.resource.SearchRequest.type:type_name -> go17.cmdb.resource.TYPE
8, // 1: go17.cmdb.resource.SearchRequest.tag:type_name -> go17.cmdb.resource.SearchRequest.TagEntry
4, // 2: go17.cmdb.resource.ResourceSet.items:type_name -> go17.cmdb.resource.Resource
5, // 3: go17.cmdb.resource.Resource.Meta:type_name -> go17.cmdb.resource.Meta
6, // 4: go17.cmdb.resource.Resource.Spec:type_name -> go17.cmdb.resource.Spec
7, // 5: go17.cmdb.resource.Resource.Status:type_name -> go17.cmdb.resource.Status
0, // 6: go17.cmdb.resource.Spec.vendor:type_name -> go17.cmdb.resource.VENDOR
1, // 7: go17.cmdb.resource.Spec.resource_type:type_name -> go17.cmdb.resource.TYPE
9, // 8: go17.cmdb.resource.Spec.tags:type_name -> go17.cmdb.resource.Spec.TagsEntry
10, // 9: go17.cmdb.resource.Spec.extra:type_name -> go17.cmdb.resource.Spec.ExtraEntry
2, // 10: go17.cmdb.resource.Rpc.Search:input_type -> go17.cmdb.resource.SearchRequest
4, // 11: go17.cmdb.resource.Rpc.Save:input_type -> go17.cmdb.resource.Resource
3, // 12: go17.cmdb.resource.Rpc.Search:output_type -> go17.cmdb.resource.ResourceSet
4, // 13: go17.cmdb.resource.Rpc.Save:output_type -> go17.cmdb.resource.Resource
12, // [12:14] is the sub-list for method output_type
10, // [10:12] is the sub-list for method input_type
10, // [10:10] is the sub-list for extension type_name
10, // [10:10] is the sub-list for extension extendee
0, // [0:10] is the sub-list for field type_name
}
func init() { file_cmdb_apps_resource_service_proto_init() }
func file_cmdb_apps_resource_service_proto_init() {
if File_cmdb_apps_resource_service_proto != nil {
return
}
file_cmdb_apps_resource_service_proto_msgTypes[0].OneofWrappers = []any{}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_cmdb_apps_resource_service_proto_rawDesc), len(file_cmdb_apps_resource_service_proto_rawDesc)),
NumEnums: 2,
NumMessages: 9,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_cmdb_apps_resource_service_proto_goTypes,
DependencyIndexes: file_cmdb_apps_resource_service_proto_depIdxs,
EnumInfos: file_cmdb_apps_resource_service_proto_enumTypes,
MessageInfos: file_cmdb_apps_resource_service_proto_msgTypes,
}.Build()
File_cmdb_apps_resource_service_proto = out.File
file_cmdb_apps_resource_service_proto_goTypes = nil
file_cmdb_apps_resource_service_proto_depIdxs = nil
}

View File

@ -0,0 +1,150 @@
syntax = "proto3";
package go17.cmdb.resource;
option go_package="gitlab.com/go-course-project/go17/devcloud-mini/cmdb/apps/resource";
service Rpc {
//
rpc Search(SearchRequest) returns(ResourceSet);
// Save
rpc Save(Resource) returns(Resource);
}
message SearchRequest {
//
int64 page_size = 1;
//
int64 page_number = 2;
//
string keywords = 3;
//
optional TYPE type = 4;
//
map<string,string> tag = 5;
}
message ResourceSet {
//
int64 total = 1;
//
repeated Resource items = 2;
}
message Resource {
// @gotags: bson:"inline" validate:"required"
Meta Meta = 1;
// @gotags: bson:"inline" validate:"required"
Spec Spec = 2;
// @gotags: bson:"inline" validate:"required"
Status Status = 3;
}
message Meta {
// Id, 使Id
// @gotags: json:"id" bson:"_id" validate:"required"
string id = 1;
//
// @gotags: json:"domain" validate:"required"
string domain = 2;
//
// @gotags: json:"namespace" validate:"required"
string namespace = 3;
//
// @gotags: json:"env"
string env = 4;
//
// @gotags: json:"create_at"
int64 create_at = 5;
//
// @gotags: json:"detete_at"
int64 detete_at = 6;
//
// @gotags: json:"detete_by"
string detete_by = 7;
//
// @gotags: json:"sync_at" validate:"required"
int64 sync_at = 8;
//
// @gotags: json:"sync_by"
string sync_by = 9;
// ID
// @gotags: json:"credential_id"
string credential_id = 10;
//
// @gotags: json:"serial_number"
string serial_number = 11;
}
enum VENDOR {
ALIYUN = 0;
TENCENT = 1;
HUAWEI = 2;
VSPHERE = 3;
AMAZON = 4;
}
enum TYPE {
HOST = 0;
RDS = 1;
}
message Spec {
//
// @gotags: json:"vendor"
VENDOR vendor = 1;
//
// @gotags: json:"resource_type"
TYPE resource_type = 2;
//
// @gotags: json:"region"
string region = 3;
//
// @gotags: json:"zone"
string zone = 4;
//
// @gotags: json:"owner"
string owner = 5;
//
// @gotags: json:"name"
string name = 6;
//
// @gotags: json:"type"
string type = 7;
//
// @gotags: json:"description"
string description = 8;
// Cpu数量
// @gotags: json:"cpu"
int32 cpu = 9;
// 使
// @gotags: json:"memory"
int64 memory = 10;
// 使
// @gotags: json:"storage"
int64 storage = 11;
// IP带宽, M
// @gotags: json:"band_width"
int64 band_width = 12;
//
// @gotags: json:"tags"
map<string,string> tags = 13;
//
// @gotags: json:"extra" gorm:"serializer:json"
map<string,string> extra = 14;
}
message Status {
//
// @gotags: json:"phase"
string phase = 1;
//
// @gotags: json:"describe"
string describe = 2;
// 访
// ,
// @gotags: json:"public_address" gorm:"serializer:json"
repeated string public_address = 3;
// ,
// @gotags: json:"private_address" gorm:"serializer:json"
repeated string private_address = 4;
}

View File

@ -0,0 +1,100 @@
// Code generated by github.com/infraboard/mcube/v2
// DO NOT EDIT
package resource
import (
"bytes"
"fmt"
"strings"
)
// ParseVENDORFromString Parse VENDOR from string
func ParseVENDORFromString(str string) (VENDOR, error) {
key := strings.Trim(string(str), `"`)
v, ok := VENDOR_value[strings.ToUpper(key)]
if !ok {
return 0, fmt.Errorf("unknown VENDOR: %s", str)
}
return VENDOR(v), nil
}
// Equal type compare
func (t VENDOR) Equal(target VENDOR) bool {
return t == target
}
// IsIn todo
func (t VENDOR) IsIn(targets ...VENDOR) bool {
for _, target := range targets {
if t.Equal(target) {
return true
}
}
return false
}
// MarshalJSON todo
func (t VENDOR) MarshalJSON() ([]byte, error) {
b := bytes.NewBufferString(`"`)
b.WriteString(strings.ToUpper(t.String()))
b.WriteString(`"`)
return b.Bytes(), nil
}
// UnmarshalJSON todo
func (t *VENDOR) UnmarshalJSON(b []byte) error {
ins, err := ParseVENDORFromString(string(b))
if err != nil {
return err
}
*t = ins
return nil
}
// ParseTYPEFromString Parse TYPE from string
func ParseTYPEFromString(str string) (TYPE, error) {
key := strings.Trim(string(str), `"`)
v, ok := TYPE_value[strings.ToUpper(key)]
if !ok {
return 0, fmt.Errorf("unknown TYPE: %s", str)
}
return TYPE(v), nil
}
// Equal type compare
func (t TYPE) Equal(target TYPE) bool {
return t == target
}
// IsIn todo
func (t TYPE) IsIn(targets ...TYPE) bool {
for _, target := range targets {
if t.Equal(target) {
return true
}
}
return false
}
// MarshalJSON todo
func (t TYPE) MarshalJSON() ([]byte, error) {
b := bytes.NewBufferString(`"`)
b.WriteString(strings.ToUpper(t.String()))
b.WriteString(`"`)
return b.Bytes(), nil
}
// UnmarshalJSON todo
func (t *TYPE) UnmarshalJSON(b []byte) error {
ins, err := ParseTYPEFromString(string(b))
if err != nil {
return err
}
*t = ins
return nil
}

View File

@ -0,0 +1,163 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v5.29.3
// source: cmdb/apps/resource/service.proto
package resource
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Rpc_Search_FullMethodName = "/go17.cmdb.resource.Rpc/Search"
Rpc_Save_FullMethodName = "/go17.cmdb.resource.Rpc/Save"
)
// RpcClient is the client API for Rpc 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 RpcClient interface {
// 资源搜索
Search(ctx context.Context, in *SearchRequest, opts ...grpc.CallOption) (*ResourceSet, error)
// Save 更新与创建同时
Save(ctx context.Context, in *Resource, opts ...grpc.CallOption) (*Resource, error)
}
type rpcClient struct {
cc grpc.ClientConnInterface
}
func NewRpcClient(cc grpc.ClientConnInterface) RpcClient {
return &rpcClient{cc}
}
func (c *rpcClient) Search(ctx context.Context, in *SearchRequest, opts ...grpc.CallOption) (*ResourceSet, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ResourceSet)
err := c.cc.Invoke(ctx, Rpc_Search_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *rpcClient) Save(ctx context.Context, in *Resource, opts ...grpc.CallOption) (*Resource, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Resource)
err := c.cc.Invoke(ctx, Rpc_Save_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// RpcServer is the server API for Rpc service.
// All implementations must embed UnimplementedRpcServer
// for forward compatibility.
type RpcServer interface {
// 资源搜索
Search(context.Context, *SearchRequest) (*ResourceSet, error)
// Save 更新与创建同时
Save(context.Context, *Resource) (*Resource, error)
mustEmbedUnimplementedRpcServer()
}
// UnimplementedRpcServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedRpcServer struct{}
func (UnimplementedRpcServer) Search(context.Context, *SearchRequest) (*ResourceSet, error) {
return nil, status.Errorf(codes.Unimplemented, "method Search not implemented")
}
func (UnimplementedRpcServer) Save(context.Context, *Resource) (*Resource, error) {
return nil, status.Errorf(codes.Unimplemented, "method Save not implemented")
}
func (UnimplementedRpcServer) mustEmbedUnimplementedRpcServer() {}
func (UnimplementedRpcServer) testEmbeddedByValue() {}
// UnsafeRpcServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to RpcServer will
// result in compilation errors.
type UnsafeRpcServer interface {
mustEmbedUnimplementedRpcServer()
}
func RegisterRpcServer(s grpc.ServiceRegistrar, srv RpcServer) {
// If the following call pancis, it indicates UnimplementedRpcServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Rpc_ServiceDesc, srv)
}
func _Rpc_Search_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SearchRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RpcServer).Search(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Rpc_Search_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RpcServer).Search(ctx, req.(*SearchRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Rpc_Save_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Resource)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RpcServer).Save(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Rpc_Save_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RpcServer).Save(ctx, req.(*Resource))
}
return interceptor(ctx, in, info, handler)
}
// Rpc_ServiceDesc is the grpc.ServiceDesc for Rpc service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Rpc_ServiceDesc = grpc.ServiceDesc{
ServiceName: "go17.cmdb.resource.Rpc",
HandlerType: (*RpcServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Search",
Handler: _Rpc_Search_Handler,
},
{
MethodName: "Save",
Handler: _Rpc_Save_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "cmdb/apps/resource/service.proto",
}

View File

@ -0,0 +1,2 @@
# 资源账号

View File

@ -0,0 +1 @@
# 资源标签

View File

@ -0,0 +1,37 @@
<mxfile host="65bd71144e">
<diagram id="7pEBGre3FdwmhDWsT8h2" name="第 1 页">
<mxGraphModel dx="873" dy="479" 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="10" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="2" target="9">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="2" value="resource&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;资源管理&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="170" y="230" width="190" height="90" as="geometry"/>
</mxCell>
<mxCell id="5" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="1" source="3" target="2">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="3" value="&lt;div&gt;secret&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;资源账号: sync&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="460" y="230" width="190" height="90" as="geometry"/>
</mxCell>
<mxCell id="6" style="edgeStyle=none;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;" edge="1" parent="1" source="4" target="2">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="4" value="&lt;div&gt;tags&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;资源管理&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="170" y="370" width="190" height="90" as="geometry"/>
</mxCell>
<mxCell id="8" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="1" source="7" target="2">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="7" value="资源检索" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="25" y="80" width="480" height="60" as="geometry"/>
</mxCell>
<mxCell id="9" value="prom&lt;div&gt;资源发现&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="10" y="230" width="110" height="90" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@ -0,0 +1,61 @@
<mxfile host="65bd71144e">
<diagram id="0q7lRh8tqNagHdUdpmmi" name="第 1 页">
<mxGraphModel dx="873" dy="570" 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="2" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="270" y="140" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="3" value="动态模型库" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="250" y="20" width="150" height="30" as="geometry"/>
</mxCell>
<mxCell id="4" value="Actor" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" vertex="1" parent="1">
<mxGeometry x="90" y="50" width="30" height="60" as="geometry"/>
</mxCell>
<mxCell id="10" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.25;entryDx=0;entryDy=0;" edge="1" parent="1" source="5" target="2">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="5" value="使用者" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="80" y="140" width="60" height="30" as="geometry"/>
</mxCell>
<mxCell id="6" value="Actor" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" vertex="1" parent="1">
<mxGeometry x="550" y="50" width="30" height="60" as="geometry"/>
</mxCell>
<mxCell id="8" style="edgeStyle=none;html=1;exitX=0;exitY=1;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="7" target="2">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="7" value="系统配置人员" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="520" y="140" width="100" height="30" as="geometry"/>
</mxCell>
<mxCell id="9" value="&lt;h1 style=&quot;margin-top: 0px;&quot;&gt;模型创建&lt;/h1&gt;&lt;p&gt;虚拟机:&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; 1. IP, 说明,数据类型, ...&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; 2. Name&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; 3. 创建时间&lt;/p&gt;" style="text;html=1;whiteSpace=wrap;overflow=hidden;rounded=0;" vertex="1" parent="1">
<mxGeometry x="640" y="40" width="180" height="160" as="geometry"/>
</mxCell>
<mxCell id="14" style="edgeStyle=orthogonalEdgeStyle;html=1;exitX=0;exitY=0.3333333333333333;exitDx=0;exitDy=0;exitPerimeter=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="12" target="2">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="12" value="Actor" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" vertex="1" parent="1">
<mxGeometry x="550" y="240" width="30" height="60" as="geometry"/>
</mxCell>
<mxCell id="13" value="数据录入" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="530" y="330" width="100" height="30" as="geometry"/>
</mxCell>
<mxCell id="15" value="&lt;h1 style=&quot;margin-top: 0px;&quot;&gt;录入数据&lt;/h1&gt;&lt;p&gt;虚拟机:&amp;nbsp; 1. 阿里云10.10.1.1 ...&lt;/p&gt;" style="text;html=1;whiteSpace=wrap;overflow=hidden;rounded=0;" vertex="1" parent="1">
<mxGeometry x="640" y="240" width="180" height="160" as="geometry"/>
</mxCell>
<mxCell id="16" value="IP" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="45" y="180" width="120" height="30" as="geometry"/>
</mxCell>
<mxCell id="17" value="github: 蓝鲸,其他的一些商业产品, 是个底座,上层的业务功能需要自己开发(需求), 开发周期很长" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="40" y="350" width="280" height="70" as="geometry"/>
</mxCell>
<mxCell id="18" value="云管业务模块(业务开发模型)" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="270" y="450" width="220" height="30" as="geometry"/>
</mxCell>
<mxCell id="19" value="" style="shape=image;verticalLabelPosition=bottom;labelBackgroundColor=default;verticalAlign=top;aspect=fixed;imageAspect=0;image=https://gitee.com/infraboard/go-course/raw/master/image/cmdb/cmdb.png;" vertex="1" parent="1">
<mxGeometry x="39" y="490" width="750" height="391.88" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@ -0,0 +1,90 @@
<mxfile host="65bd71144e">
<diagram id="lpFlQF22u-EUjqCC0xD_" name="第 1 页">
<mxGraphModel dx="873" dy="504" 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="13" style="edgeStyle=none;html=1;exitX=0;exitY=0.25;exitDx=0;exitDy=0;entryX=1;entryY=0.25;entryDx=0;entryDy=0;" edge="1" parent="1" source="2" target="3">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="14" value="鉴权" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="13">
<mxGeometry x="0.1647" relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="20" 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="2" target="19">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="22" style="edgeStyle=none;html=1;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=0.75;entryDx=0;entryDy=0;" edge="1" parent="1" source="2" target="3">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="23" value="RPC(获取用户名称)&lt;div&gt;(user_ids ...)&lt;/div&gt;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="22">
<mxGeometry x="0.2912" y="1" relative="1" as="geometry">
<mxPoint x="23" y="14" as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="2" value="cmdb" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="364" y="290" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="3" value="mcenter&lt;div&gt;用户中心&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="70" y="290" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="7" 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="4" target="6">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="4" value="Actor" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" vertex="1" parent="1">
<mxGeometry x="670" y="100" width="30" height="60" as="geometry"/>
</mxCell>
<mxCell id="9" style="edgeStyle=none;html=1;exitX=0.75;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="5" target="2">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="28" value="RPC" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="9">
<mxGeometry x="-0.2297" y="2" relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="10" style="edgeStyle=none;html=1;exitX=0.25;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="5" target="3">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="27" value="RPC" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="10">
<mxGeometry x="-0.3174" y="-3" relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="5" value="业务逻辑 封装( 业务网关)&lt;div&gt;ecs_list (cmdb ecs_list, user_list)&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="70" y="180" width="410" height="60" as="geometry"/>
</mxCell>
<mxCell id="25" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="1" source="6" target="24">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="6" value="UI" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="70" y="20" width="410" height="60" as="geometry"/>
</mxCell>
<mxCell id="15" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="560" y="230" width="240" height="140" as="geometry"/>
</mxCell>
<mxCell id="16" value="ecs&amp;nbsp; user_name" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="580" y="250" width="120" height="20" as="geometry"/>
</mxCell>
<mxCell id="17" value="ecs&amp;nbsp; user_name" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="580" y="280" width="120" height="20" as="geometry"/>
</mxCell>
<mxCell id="18" value="ecs user_name" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="580" y="310" width="120" height="20" as="geometry"/>
</mxCell>
<mxCell id="19" value="ecs&amp;nbsp; user_id, user_name" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="356" y="400" width="136" height="40" as="geometry"/>
</mxCell>
<mxCell id="21" value="user" style="shape=cube;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;darkOpacity=0.05;darkOpacity2=0.1;" vertex="1" parent="1">
<mxGeometry x="215" y="470" width="120" height="80" as="geometry"/>
</mxCell>
<mxCell id="26" 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="24" target="5">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="24" value="&amp;nbsp;API Gateway&lt;div&gt;/api&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="70" y="100" width="410" height="60" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@ -0,0 +1,23 @@
[app]
name = "cmdb"
description = "cmdb"
[http]
# 开启GRPC服务
enable = true
# HTTP服务Host
host = "127.0.0.1"
# HTTP服务端口
port = 8010
[grpc]
# 开启GRPC服务
enable = true
# Server监听的地址
host = "127.0.0.1"
# Server监听的端口
port = 18010
[mongo]
endpoints = ["127.0.0.1:27017"]
database = "go17"

View File

@ -0,0 +1,12 @@
package main
import (
"github.com/infraboard/mcube/v2/ioc/server/cmd"
_ "gitlab.com/go-course-project/go17/devcloud-mini/cmdb/apps"
)
// mcube
func main() {
cmd.Start()
}

View File

@ -0,0 +1,15 @@
package test
import (
"fmt"
"os"
"github.com/infraboard/mcube/v2/ioc"
_ "gitlab.com/go-course-project/go17/devcloud-mini/cmdb/apps"
)
func SetUp() {
fmt.Println(os.Getwd())
ioc.DevelopmentSetupWithPath(os.Getenv("CmdbConfigPath"))
}

39
go.mod
View File

@ -6,9 +6,12 @@ require (
github.com/gin-gonic/gin v1.10.0
github.com/go-playground/validator/v10 v10.20.0
github.com/google/uuid v1.6.0
github.com/infraboard/mcube/v2 v2.0.44
github.com/infraboard/mcube/v2 v2.0.49
github.com/rs/zerolog v1.32.0
golang.org/x/crypto v0.23.0
go.mongodb.org/mongo-driver v1.14.0
golang.org/x/crypto v0.31.0
google.golang.org/grpc v1.70.0
google.golang.org/protobuf v1.35.2
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.5.7
@ -28,7 +31,7 @@ require (
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/glebarez/go-sqlite v1.22.0 // indirect
github.com/glebarez/sqlite v1.11.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
@ -38,6 +41,7 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
@ -48,6 +52,7 @@ require (
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
@ -55,6 +60,7 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
@ -64,24 +70,27 @@ require (
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/uptrace/opentelemetry-go-extra/otelgorm v0.2.3 // indirect
github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.3 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/sdk v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.1 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect
gorm.io/driver/postgres v1.5.9 // indirect
modernc.org/libc v1.37.6 // indirect
modernc.org/mathutil v1.6.0 // indirect

108
go.sum
View File

@ -30,8 +30,8 @@ github.com/glebarez/go-sqlite v1.22.0/go.mod h1:PlBIdHe0+aUEFn+r2/uthrWq4FxbzugL
github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw=
github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
@ -55,6 +55,10 @@ github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
@ -67,8 +71,8 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 h1:Wqo399gCIufwto+VfwCSvsnfGpF
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0/go.mod h1:qmOFXW2epJhM0qSnUUYpldc7gVz2KMQwJ/QYCDIa7XU=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/infraboard/mcube/v2 v2.0.44 h1:dspnLDspWpz5r6YgFTOmIlWE4kjog0082luhvd8AUds=
github.com/infraboard/mcube/v2 v2.0.44/go.mod h1:UkjuO7zbehNNvAsA1kZMB2ztaZlDY9XmTfBnNnilzB4=
github.com/infraboard/mcube/v2 v2.0.49 h1:V8Q8j5vOiYSnQmcVBeVGPlyJxNVsyniJgoKCGvGwy8c=
github.com/infraboard/mcube/v2 v2.0.49/go.mod h1:gnr0xPPDPHvCS6JAzvdjqJ62J2+vUZTkobomjTXKsx0=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
@ -85,6 +89,8 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
@ -108,6 +114,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@ -146,53 +154,89 @@ github.com/uptrace/opentelemetry-go-extra/otelgorm v0.2.3 h1:girTS67d1m8+XUJLbNB
github.com/uptrace/opentelemetry-go-extra/otelgorm v0.2.3/go.mod h1:kjsn/ilDe5TABXwTy7Dg/Lfr2pRAjrCD+yPV+pbhOMY=
github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.3 h1:LNi0Qa7869/loPjz2kmMvp/jwZZnMZ9scMJKhDJ1DIo=
github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.3/go.mod h1:jyigonKik3C5V895QNiAGpKYKEvFuqjw9qAEZks1mUg=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.49.0 h1:1f31+6grJmV3X4lxcEvUy13i5/kfDw1nJZwhd8mA4tg=
go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.49.0/go.mod h1:1P/02zM3OwkX9uki+Wmxw3a5GVb6KUXRsa7m7bOC9Fg=
go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo v0.49.0 h1:qF3LdpkD3Kbaw0Smsh+SVcJI/mtYGz9ZdCmu0YF2Lo4=
go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo v0.49.0/go.mod h1:eqNF9g7W06ubrU7jk6M6UW9OTrcSPZvVY10cw9DUJ7c=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 h1:4Pp6oUg3+e/6M4C0A/3kJ2VYa++dsWVTtGgLVj5xtHg=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0/go.mod h1:Mjt1i1INqiaoZOMGR1RIUJN+i3ChKoFRqzrRQhlkbs0=
go.opentelemetry.io/contrib/propagators/b3 v1.24.0 h1:n4xwCdTx3pZqZs2CjS/CUZAs03y3dZcGhC/FepKtEUY=
go.opentelemetry.io/contrib/propagators/b3 v1.24.0/go.mod h1:k5wRxKRU2uXx2F8uNJ4TaonuEO/V7/5xoz7kdsDACT8=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U=
go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 h1:t6wl9SPayj+c7lEIFgm4ooDBZVb01IhLB4InpomhRw8=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0/go.mod h1:iSDOcsnSA5INXzZtwaBPrKp/lWu/V14Dd+llD0oI2EA=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 h1:Xw8U6u2f8DK2XAkGRFV7BBLENgnTGX9i4rQRxJf+/vs=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0/go.mod h1:6KW1Fm6R/s6Z3PGXwSJN2K4eT6wQB3vXX6CVnYX9NmM=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M=
go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8=
go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4=
go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU=
go.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiyYCU9snn1CU=
go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ=
go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM=
go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
go.opentelemetry.io/proto/otlp v1.1.0 h1:2Di21piLrCqJ3U3eXGCTPHE9R8Nh+0uglSnOyxikMeI=
go.opentelemetry.io/proto/otlp v1.1.0/go.mod h1:GpBHCBWiqvVLDqmHZsoMM3C5ySeKTC7ej/RNTae6MdY=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY=
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo=
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de h1:jFNzHPIeuzhdRwVhbZdiym9q0ory/xY3sA+v2wPg8I0=
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a h1:OAiGFfOiA0v9MRYsSidp3ubZaBnteRUyn3xB2ZQ5G/E=
google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a/go.mod h1:jehYqy3+AhJU9ve55aNOaSml7wUXjF9x6z2LcCfpAhY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1:hgh8P4EuoxpsuKMXX/To36nOFD7vixReXgn8lPGnt+o=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=
google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ=
google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

4
skills/grpc/README.md Normal file
View File

@ -0,0 +1,4 @@
# GRPC 入门
[课件](https://gitee.com/infraboard/go-course/blob/master/day15/grpc.md)

View File

@ -0,0 +1,60 @@
package main
import (
"context"
"fmt"
"io"
"time"
"gitlab.com/go-course-project/go17/skills/grpc/service"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func main() {
// Deprecated: use WithTransportCredentials and insecure.NewCredentials()
// instead. Will be supported throughout 1.x.
conn, err := grpc.NewClient("localhost:18080", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
panic(err)
}
client := service.NewHelloServiceClient(conn)
// resp, err := client.Hello(context.Background(), &service.HelloRequest{
// MyName: "bob",
// })
// if err != nil {
// panic(err)
// }
// fmt.Println(resp)
stream, err := client.Chat(context.Background())
if err != nil {
panic(err)
}
// 1. 处理返回结果的在后台
go func() {
for {
resp, err := stream.Recv()
if err != nil {
// 如果遇到io.EOF表示客户端流被关闭
if err == io.EOF {
break
}
fmt.Println(err)
return
}
fmt.Println(resp)
}
}()
// 2. 发送请求的在主Goroutine
for i := range 10 {
stream.Send(&service.ChatRequest{
Id: uint64(i + 1),
Message: "test",
})
time.Sleep(1 * time.Second)
}
}

View File

@ -0,0 +1,10 @@
package global
import "google.golang.org/grpc"
// 1. 示例化一个grpc server对象
var Server = grpc.NewServer()
func Init() {
}

View File

@ -0,0 +1,59 @@
package hello
import (
"context"
"fmt"
"io"
"github.com/infraboard/mcube/v2/ioc"
grpc_server "github.com/infraboard/mcube/v2/ioc/config/grpc"
"gitlab.com/go-course-project/go17/skills/grpc/service"
"google.golang.org/grpc"
)
func init() {
ioc.Controller().Registry(&HelloServiceServer{})
}
type HelloServiceServer struct {
service.UnimplementedHelloServiceServer
ioc.ObjectImpl
}
func (s *HelloServiceServer) Name() string {
return "hello"
}
func (s *HelloServiceServer) Init() error {
// 需要拿到全局的 grpc server对象, ioc
service.RegisterHelloServiceServer(grpc_server.Get().Server(), &HelloServiceServer{})
return nil
}
func (HelloServiceServer) Hello(ctx context.Context, req *service.HelloRequest) (*service.HelloResponse, error) {
return &service.HelloResponse{
Message: "hello, " + req.MyName,
}, nil
}
func (HelloServiceServer) Chat(stream grpc.BidiStreamingServer[service.ChatRequest, service.ChatResponse]) error {
// 1. 获取用户的请求,然后处理, 处理完成后通过stream 返回给客户端
for {
// 接收一个请求
req, err := stream.Recv()
if err != nil {
// 如果遇到io.EOF表示客户端流被关闭
if err == io.EOF {
return nil
}
return err
}
// 2. 处理请求
fmt.Println(req.Message)
stream.Send(&service.ChatResponse{
Id: req.Id,
IsSuccess: true,
})
}
}

30
skills/grpc/mcube/main.go Normal file
View File

@ -0,0 +1,30 @@
package main
import (
"context"
"github.com/infraboard/mcube/v2/ioc"
"github.com/infraboard/mcube/v2/ioc/server"
_ "gitlab.com/go-course-project/go17/skills/grpc/mcube/apps/hello"
)
func main() {
// ioc 的初始化
ioc.DevelopmentSetup()
if err := server.Run(context.Background()); err != nil {
panic(err)
}
// server := grpc_server.Get().Server()
// // 2. 启动grpc服务
// lis, err := net.Listen("tcp", ":1234")
// if err != nil {
// panic(err)
// }
// if err := server.Serve(lis); err != nil {
// panic(err)
// }
}

View File

@ -0,0 +1,62 @@
package main
import (
"context"
"fmt"
"io"
"net"
"gitlab.com/go-course-project/go17/skills/grpc/service"
"google.golang.org/grpc"
)
type HelloServiceServer struct {
service.UnimplementedHelloServiceServer
}
func (HelloServiceServer) Hello(ctx context.Context, req *service.HelloRequest) (*service.HelloResponse, error) {
return &service.HelloResponse{
Message: "hello, " + req.MyName,
}, nil
}
func (HelloServiceServer) Chat(stream grpc.BidiStreamingServer[service.ChatRequest, service.ChatResponse]) error {
// 1. 获取用户的请求,然后处理, 处理完成后通过stream 返回给客户端
for {
// 接收一个请求
req, err := stream.Recv()
if err != nil {
// 如果遇到io.EOF表示客户端流被关闭
if err == io.EOF {
return nil
}
return err
}
// 2. 处理请求
fmt.Println(req.Message)
stream.Send(&service.ChatResponse{
Id: req.Id,
IsSuccess: true,
})
}
}
func main() {
// 1. 示例化一个grpc server对象
server := grpc.NewServer()
service.RegisterHelloServiceServer(server, &HelloServiceServer{})
// service.RegisterHelloServiceServer(server, svc1)
// service.RegisterHelloServiceServer(server, svc2)
// 全部托管到IOC
// Init=> service.RegisterHelloServiceServer(server, &HelloServiceServer{})
// 2. 启动grpc服务
lis, err := net.Listen("tcp", ":1234")
if err != nil {
panic(err)
}
if err := server.Serve(lis); err != nil {
panic(err)
}
}

View File

@ -0,0 +1,15 @@
# grpc
```sh
protoc -I=. --go_out=. --go-grpc_out=. --go_opt=module="gitlab.com/go-course-project/go17" --go-grpc_opt=module="gitlab.com/go-course-project/go17" skills/grpc/service/*.proto
```
```sh
# protoc-gen-go 插件之前已经安装
# go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
# 安装protoc-gen-go-grpc插件
#
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
```

View File

@ -0,0 +1,348 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.5
// protoc v5.29.3
// source: skills/grpc/service/hello.proto
package service
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
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 HelloRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
MyName string `protobuf:"bytes,1,opt,name=my_name,json=myName,proto3" json:"my_name,omitempty"`
Age int64 `protobuf:"varint,2,opt,name=age,proto3" json:"age,omitempty"`
MagicNumber []int64 `protobuf:"varint,3,rep,packed,name=magic_number,json=magicNumber,proto3" json:"magic_number,omitempty"`
Extras map[string]string `protobuf:"bytes,4,rep,name=extras,proto3" json:"extras,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *HelloRequest) Reset() {
*x = HelloRequest{}
mi := &file_skills_grpc_service_hello_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *HelloRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HelloRequest) ProtoMessage() {}
func (x *HelloRequest) ProtoReflect() protoreflect.Message {
mi := &file_skills_grpc_service_hello_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 HelloRequest.ProtoReflect.Descriptor instead.
func (*HelloRequest) Descriptor() ([]byte, []int) {
return file_skills_grpc_service_hello_proto_rawDescGZIP(), []int{0}
}
func (x *HelloRequest) GetMyName() string {
if x != nil {
return x.MyName
}
return ""
}
func (x *HelloRequest) GetAge() int64 {
if x != nil {
return x.Age
}
return 0
}
func (x *HelloRequest) GetMagicNumber() []int64 {
if x != nil {
return x.MagicNumber
}
return nil
}
func (x *HelloRequest) GetExtras() map[string]string {
if x != nil {
return x.Extras
}
return nil
}
type HelloResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *HelloResponse) Reset() {
*x = HelloResponse{}
mi := &file_skills_grpc_service_hello_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *HelloResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HelloResponse) ProtoMessage() {}
func (x *HelloResponse) ProtoReflect() protoreflect.Message {
mi := &file_skills_grpc_service_hello_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 HelloResponse.ProtoReflect.Descriptor instead.
func (*HelloResponse) Descriptor() ([]byte, []int) {
return file_skills_grpc_service_hello_proto_rawDescGZIP(), []int{1}
}
func (x *HelloResponse) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
type ChatRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ChatRequest) Reset() {
*x = ChatRequest{}
mi := &file_skills_grpc_service_hello_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ChatRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ChatRequest) ProtoMessage() {}
func (x *ChatRequest) ProtoReflect() protoreflect.Message {
mi := &file_skills_grpc_service_hello_proto_msgTypes[2]
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 ChatRequest.ProtoReflect.Descriptor instead.
func (*ChatRequest) Descriptor() ([]byte, []int) {
return file_skills_grpc_service_hello_proto_rawDescGZIP(), []int{2}
}
func (x *ChatRequest) GetId() uint64 {
if x != nil {
return x.Id
}
return 0
}
func (x *ChatRequest) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
type ChatResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
IsSuccess bool `protobuf:"varint,2,opt,name=is_success,json=isSuccess,proto3" json:"is_success,omitempty"`
Message string `protobuf:"bytes,3,opt,name=message,proto3" json:"message,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ChatResponse) Reset() {
*x = ChatResponse{}
mi := &file_skills_grpc_service_hello_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ChatResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ChatResponse) ProtoMessage() {}
func (x *ChatResponse) ProtoReflect() protoreflect.Message {
mi := &file_skills_grpc_service_hello_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 ChatResponse.ProtoReflect.Descriptor instead.
func (*ChatResponse) Descriptor() ([]byte, []int) {
return file_skills_grpc_service_hello_proto_rawDescGZIP(), []int{3}
}
func (x *ChatResponse) GetId() uint64 {
if x != nil {
return x.Id
}
return 0
}
func (x *ChatResponse) GetIsSuccess() bool {
if x != nil {
return x.IsSuccess
}
return false
}
func (x *ChatResponse) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
var File_skills_grpc_service_hello_proto protoreflect.FileDescriptor
var file_skills_grpc_service_hello_proto_rawDesc = string([]byte{
0x0a, 0x1f, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x73, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x12, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0xd0, 0x01, 0x0a, 0x0c, 0x48, 0x65, 0x6c,
0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x6d, 0x79, 0x5f,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x79, 0x4e, 0x61,
0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52,
0x03, 0x61, 0x67, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x61, 0x67, 0x69, 0x63, 0x5f, 0x6e, 0x75,
0x6d, 0x62, 0x65, 0x72, 0x18, 0x03, 0x20, 0x03, 0x28, 0x03, 0x52, 0x0b, 0x6d, 0x61, 0x67, 0x69,
0x63, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x37, 0x0a, 0x06, 0x65, 0x78, 0x74, 0x72, 0x61,
0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e,
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x74,
0x72, 0x61, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x65, 0x78, 0x74, 0x72, 0x61, 0x73,
0x1a, 0x39, 0x0a, 0x0b, 0x45, 0x78, 0x74, 0x72, 0x61, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12,
0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65,
0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x29, 0x0a, 0x0d, 0x48,
0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07,
0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x37, 0x0a, 0x0b, 0x43, 0x68, 0x61, 0x74, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22,
0x57, 0x0a, 0x0c, 0x43, 0x68, 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12,
0x1d, 0x0a, 0x0a, 0x69, 0x73, 0x5f, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20,
0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x12, 0x18,
0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x77, 0x0a, 0x0c, 0x48, 0x65, 0x6c, 0x6c,
0x6f, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x32, 0x0a, 0x05, 0x48, 0x65, 0x6c, 0x6c,
0x6f, 0x12, 0x13, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x48,
0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x33, 0x0a, 0x04,
0x43, 0x68, 0x61, 0x74, 0x12, 0x12, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x43, 0x68, 0x61,
0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f,
0x2e, 0x43, 0x68, 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x30,
0x01, 0x42, 0x37, 0x5a, 0x35, 0x67, 0x69, 0x74, 0x6c, 0x61, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
0x67, 0x6f, 0x2d, 0x63, 0x6f, 0x75, 0x72, 0x73, 0x65, 0x2d, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63,
0x74, 0x2f, 0x67, 0x6f, 0x31, 0x37, 0x2f, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x73, 0x2f, 0x67, 0x72,
0x70, 0x63, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
})
var (
file_skills_grpc_service_hello_proto_rawDescOnce sync.Once
file_skills_grpc_service_hello_proto_rawDescData []byte
)
func file_skills_grpc_service_hello_proto_rawDescGZIP() []byte {
file_skills_grpc_service_hello_proto_rawDescOnce.Do(func() {
file_skills_grpc_service_hello_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_skills_grpc_service_hello_proto_rawDesc), len(file_skills_grpc_service_hello_proto_rawDesc)))
})
return file_skills_grpc_service_hello_proto_rawDescData
}
var file_skills_grpc_service_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_skills_grpc_service_hello_proto_goTypes = []any{
(*HelloRequest)(nil), // 0: hello.HelloRequest
(*HelloResponse)(nil), // 1: hello.HelloResponse
(*ChatRequest)(nil), // 2: hello.ChatRequest
(*ChatResponse)(nil), // 3: hello.ChatResponse
nil, // 4: hello.HelloRequest.ExtrasEntry
}
var file_skills_grpc_service_hello_proto_depIdxs = []int32{
4, // 0: hello.HelloRequest.extras:type_name -> hello.HelloRequest.ExtrasEntry
0, // 1: hello.HelloService.Hello:input_type -> hello.HelloRequest
2, // 2: hello.HelloService.Chat:input_type -> hello.ChatRequest
1, // 3: hello.HelloService.Hello:output_type -> hello.HelloResponse
3, // 4: hello.HelloService.Chat:output_type -> hello.ChatResponse
3, // [3:5] is the sub-list for method output_type
1, // [1:3] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_skills_grpc_service_hello_proto_init() }
func file_skills_grpc_service_hello_proto_init() {
if File_skills_grpc_service_hello_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_skills_grpc_service_hello_proto_rawDesc), len(file_skills_grpc_service_hello_proto_rawDesc)),
NumEnums: 0,
NumMessages: 5,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_skills_grpc_service_hello_proto_goTypes,
DependencyIndexes: file_skills_grpc_service_hello_proto_depIdxs,
MessageInfos: file_skills_grpc_service_hello_proto_msgTypes,
}.Build()
File_skills_grpc_service_hello_proto = out.File
file_skills_grpc_service_hello_proto_goTypes = nil
file_skills_grpc_service_hello_proto_depIdxs = nil
}

View File

@ -0,0 +1,33 @@
syntax = "proto3";
package hello;
option go_package="gitlab.com/go-course-project/go17/skills/grpc/service";
message HelloRequest {
string my_name = 1;
int64 age = 2;
repeated int64 magic_number = 3;
map<string,string> extras = 4;
}
message HelloResponse {
string message = 1;
}
message ChatRequest {
uint64 id = 1;
string message = 2;
}
message ChatResponse {
uint64 id = 1;
bool is_success = 2;
string message = 3;
}
// grpc
service HelloService {
rpc Hello(HelloRequest) returns(HelloResponse);
//
rpc Chat(stream ChatRequest) returns(stream ChatResponse);
}

View File

@ -0,0 +1,160 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v5.29.3
// source: skills/grpc/service/hello.proto
package service
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
HelloService_Hello_FullMethodName = "/hello.HelloService/Hello"
HelloService_Chat_FullMethodName = "/hello.HelloService/Chat"
)
// HelloServiceClient is the client API for HelloService 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.
//
// grpc 接口声明
type HelloServiceClient interface {
Hello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error)
// 双向流接口
Chat(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[ChatRequest, ChatResponse], error)
}
type helloServiceClient struct {
cc grpc.ClientConnInterface
}
func NewHelloServiceClient(cc grpc.ClientConnInterface) HelloServiceClient {
return &helloServiceClient{cc}
}
func (c *helloServiceClient) Hello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(HelloResponse)
err := c.cc.Invoke(ctx, HelloService_Hello_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *helloServiceClient) Chat(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[ChatRequest, ChatResponse], error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
stream, err := c.cc.NewStream(ctx, &HelloService_ServiceDesc.Streams[0], HelloService_Chat_FullMethodName, cOpts...)
if err != nil {
return nil, err
}
x := &grpc.GenericClientStream[ChatRequest, ChatResponse]{ClientStream: stream}
return x, nil
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type HelloService_ChatClient = grpc.BidiStreamingClient[ChatRequest, ChatResponse]
// HelloServiceServer is the server API for HelloService service.
// All implementations must embed UnimplementedHelloServiceServer
// for forward compatibility.
//
// grpc 接口声明
type HelloServiceServer interface {
Hello(context.Context, *HelloRequest) (*HelloResponse, error)
// 双向流接口
Chat(grpc.BidiStreamingServer[ChatRequest, ChatResponse]) error
mustEmbedUnimplementedHelloServiceServer()
}
// UnimplementedHelloServiceServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedHelloServiceServer struct{}
func (UnimplementedHelloServiceServer) Hello(context.Context, *HelloRequest) (*HelloResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Hello not implemented")
}
func (UnimplementedHelloServiceServer) Chat(grpc.BidiStreamingServer[ChatRequest, ChatResponse]) error {
return status.Errorf(codes.Unimplemented, "method Chat not implemented")
}
func (UnimplementedHelloServiceServer) mustEmbedUnimplementedHelloServiceServer() {}
func (UnimplementedHelloServiceServer) testEmbeddedByValue() {}
// UnsafeHelloServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to HelloServiceServer will
// result in compilation errors.
type UnsafeHelloServiceServer interface {
mustEmbedUnimplementedHelloServiceServer()
}
func RegisterHelloServiceServer(s grpc.ServiceRegistrar, srv HelloServiceServer) {
// If the following call pancis, it indicates UnimplementedHelloServiceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&HelloService_ServiceDesc, srv)
}
func _HelloService_Hello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HelloRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(HelloServiceServer).Hello(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: HelloService_Hello_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(HelloServiceServer).Hello(ctx, req.(*HelloRequest))
}
return interceptor(ctx, in, info, handler)
}
func _HelloService_Chat_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(HelloServiceServer).Chat(&grpc.GenericServerStream[ChatRequest, ChatResponse]{ServerStream: stream})
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type HelloService_ChatServer = grpc.BidiStreamingServer[ChatRequest, ChatResponse]
// HelloService_ServiceDesc is the grpc.ServiceDesc for HelloService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var HelloService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "hello.HelloService",
HandlerType: (*HelloServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Hello",
Handler: _HelloService_Hello_Handler,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "Chat",
Handler: _HelloService_Chat_Handler,
ServerStreams: true,
ClientStreams: true,
},
},
Metadata: "skills/grpc/service/hello.proto",
}

41
skills/protobuf/README.md Normal file
View File

@ -0,0 +1,41 @@
# Probuf 基础使用
[大纲](https://gitee.com/infraboard/go-course/blob/master/day15/protobuf.md)
```json
{"name": "bob", "age": 10}
```
```
bob10
: 数据结构的长度: 开始位置0: offset: 3
|bob|10|
1: "name"
2: "age"
```
## 安装
1. protoc
```sh
$ protoc --version
libprotoc 3.19.1
```
2. go 语言插件
```sh
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
```
3.
```sh
# 项目的根目录 作为命令执行目录 -I=.
$ protoc -I=. --go_out=. --go_opt=module="gitlab.com/go-course-project/go17" skills/protobuf/hello.proto
```
4. 一次编译多个文件
```sh
protoc -I=. --go_out=. --go_opt=module="gitlab.com/go-course-project/go17" skills/protobuf/*.proto
```

303
skills/protobuf/event.pb.go Normal file
View File

@ -0,0 +1,303 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.5
// protoc v5.29.3
// source: skills/protobuf/event.proto
package protobuf
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
anypb "google.golang.org/protobuf/types/known/anypb"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
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 EVENT_TYPE int32
const (
EVENT_TYPE_ECS EVENT_TYPE = 0
EVENT_TYPE_RDS EVENT_TYPE = 1
)
// Enum value maps for EVENT_TYPE.
var (
EVENT_TYPE_name = map[int32]string{
0: "ECS",
1: "RDS",
}
EVENT_TYPE_value = map[string]int32{
"ECS": 0,
"RDS": 1,
}
)
func (x EVENT_TYPE) Enum() *EVENT_TYPE {
p := new(EVENT_TYPE)
*p = x
return p
}
func (x EVENT_TYPE) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (EVENT_TYPE) Descriptor() protoreflect.EnumDescriptor {
return file_skills_protobuf_event_proto_enumTypes[0].Descriptor()
}
func (EVENT_TYPE) Type() protoreflect.EnumType {
return &file_skills_protobuf_event_proto_enumTypes[0]
}
func (x EVENT_TYPE) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use EVENT_TYPE.Descriptor instead.
func (EVENT_TYPE) EnumDescriptor() ([]byte, []int) {
return file_skills_protobuf_event_proto_rawDescGZIP(), []int{0}
}
type EVENT_ECS struct {
state protoimpl.MessageState `protogen:"open.v1"`
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *EVENT_ECS) Reset() {
*x = EVENT_ECS{}
mi := &file_skills_protobuf_event_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *EVENT_ECS) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*EVENT_ECS) ProtoMessage() {}
func (x *EVENT_ECS) ProtoReflect() protoreflect.Message {
mi := &file_skills_protobuf_event_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 EVENT_ECS.ProtoReflect.Descriptor instead.
func (*EVENT_ECS) Descriptor() ([]byte, []int) {
return file_skills_protobuf_event_proto_rawDescGZIP(), []int{0}
}
func (x *EVENT_ECS) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
type EVENT_RDS struct {
state protoimpl.MessageState `protogen:"open.v1"`
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *EVENT_RDS) Reset() {
*x = EVENT_RDS{}
mi := &file_skills_protobuf_event_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *EVENT_RDS) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*EVENT_RDS) ProtoMessage() {}
func (x *EVENT_RDS) ProtoReflect() protoreflect.Message {
mi := &file_skills_protobuf_event_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 EVENT_RDS.ProtoReflect.Descriptor instead.
func (*EVENT_RDS) Descriptor() ([]byte, []int) {
return file_skills_protobuf_event_proto_rawDescGZIP(), []int{1}
}
func (x *EVENT_RDS) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
type Event struct {
state protoimpl.MessageState `protogen:"open.v1"`
// 事件类型(ECS/RDS/...)
// ECS
Type EVENT_TYPE `protobuf:"varint,1,opt,name=type,proto3,enum=hello.EVENT_TYPE" json:"type,omitempty"`
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
Detail []*anypb.Any `protobuf:"bytes,3,rep,name=detail,proto3" json:"detail,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Event) Reset() {
*x = Event{}
mi := &file_skills_protobuf_event_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Event) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Event) ProtoMessage() {}
func (x *Event) ProtoReflect() protoreflect.Message {
mi := &file_skills_protobuf_event_proto_msgTypes[2]
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 Event.ProtoReflect.Descriptor instead.
func (*Event) Descriptor() ([]byte, []int) {
return file_skills_protobuf_event_proto_rawDescGZIP(), []int{2}
}
func (x *Event) GetType() EVENT_TYPE {
if x != nil {
return x.Type
}
return EVENT_TYPE_ECS
}
func (x *Event) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
func (x *Event) GetDetail() []*anypb.Any {
if x != nil {
return x.Detail
}
return nil
}
var File_skills_protobuf_event_proto protoreflect.FileDescriptor
var file_skills_protobuf_event_proto_rawDesc = string([]byte{
0x0a, 0x1b, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
0x66, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x68,
0x65, 0x6c, 0x6c, 0x6f, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22,
0x25, 0x0a, 0x09, 0x45, 0x56, 0x45, 0x4e, 0x54, 0x5f, 0x45, 0x43, 0x53, 0x12, 0x18, 0x0a, 0x07,
0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x25, 0x0a, 0x09, 0x45, 0x56, 0x45, 0x4e, 0x54, 0x5f,
0x52, 0x44, 0x53, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x76, 0x0a,
0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01,
0x20, 0x01, 0x28, 0x0e, 0x32, 0x11, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x45, 0x56, 0x45,
0x4e, 0x54, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a,
0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x2c, 0x0a, 0x06, 0x64, 0x65, 0x74, 0x61, 0x69,
0x6c, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x06, 0x64,
0x65, 0x74, 0x61, 0x69, 0x6c, 0x2a, 0x1e, 0x0a, 0x0a, 0x45, 0x56, 0x45, 0x4e, 0x54, 0x5f, 0x54,
0x59, 0x50, 0x45, 0x12, 0x07, 0x0a, 0x03, 0x45, 0x43, 0x53, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03,
0x52, 0x44, 0x53, 0x10, 0x01, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x6c, 0x61, 0x62, 0x2e,
0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x63, 0x6f, 0x75, 0x72, 0x73, 0x65, 0x2d, 0x70, 0x72,
0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x67, 0x6f, 0x31, 0x37, 0x2f, 0x73, 0x6b, 0x69, 0x6c, 0x6c,
0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
})
var (
file_skills_protobuf_event_proto_rawDescOnce sync.Once
file_skills_protobuf_event_proto_rawDescData []byte
)
func file_skills_protobuf_event_proto_rawDescGZIP() []byte {
file_skills_protobuf_event_proto_rawDescOnce.Do(func() {
file_skills_protobuf_event_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_skills_protobuf_event_proto_rawDesc), len(file_skills_protobuf_event_proto_rawDesc)))
})
return file_skills_protobuf_event_proto_rawDescData
}
var file_skills_protobuf_event_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_skills_protobuf_event_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_skills_protobuf_event_proto_goTypes = []any{
(EVENT_TYPE)(0), // 0: hello.EVENT_TYPE
(*EVENT_ECS)(nil), // 1: hello.EVENT_ECS
(*EVENT_RDS)(nil), // 2: hello.EVENT_RDS
(*Event)(nil), // 3: hello.Event
(*anypb.Any)(nil), // 4: google.protobuf.Any
}
var file_skills_protobuf_event_proto_depIdxs = []int32{
0, // 0: hello.Event.type:type_name -> hello.EVENT_TYPE
4, // 1: hello.Event.detail:type_name -> google.protobuf.Any
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_protobuf_event_proto_init() }
func file_skills_protobuf_event_proto_init() {
if File_skills_protobuf_event_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_skills_protobuf_event_proto_rawDesc), len(file_skills_protobuf_event_proto_rawDesc)),
NumEnums: 1,
NumMessages: 3,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_skills_protobuf_event_proto_goTypes,
DependencyIndexes: file_skills_protobuf_event_proto_depIdxs,
EnumInfos: file_skills_protobuf_event_proto_enumTypes,
MessageInfos: file_skills_protobuf_event_proto_msgTypes,
}.Build()
File_skills_protobuf_event_proto = out.File
file_skills_protobuf_event_proto_goTypes = nil
file_skills_protobuf_event_proto_depIdxs = nil
}

View File

@ -0,0 +1,32 @@
syntax = "proto3";
package hello;
option go_package="gitlab.com/go-course-project/go17/skills/protobuf";
import "google/protobuf/any.proto";
enum EVENT_TYPE {
ECS = 0;
RDS = 1;
}
message EVENT_ECS {
string message = 1;
}
message EVENT_RDS {
string message = 1;
}
message Event {
// (ECS/RDS/...)
// ECS
EVENT_TYPE type = 1;
string message = 2;
repeated google.protobuf.Any detail = 3;
}

316
skills/protobuf/hello.pb.go Normal file
View File

@ -0,0 +1,316 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.5
// protoc v5.29.3
// source: skills/protobuf/hello.proto
package protobuf
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
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 DESCRIBE_BY int32
const (
DESCRIBE_BY_ID DESCRIBE_BY = 0
DESCRIBE_BY_NAME DESCRIBE_BY = 1
)
// Enum value maps for DESCRIBE_BY.
var (
DESCRIBE_BY_name = map[int32]string{
0: "ID",
1: "NAME",
}
DESCRIBE_BY_value = map[string]int32{
"ID": 0,
"NAME": 1,
}
)
func (x DESCRIBE_BY) Enum() *DESCRIBE_BY {
p := new(DESCRIBE_BY)
*p = x
return p
}
func (x DESCRIBE_BY) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (DESCRIBE_BY) Descriptor() protoreflect.EnumDescriptor {
return file_skills_protobuf_hello_proto_enumTypes[0].Descriptor()
}
func (DESCRIBE_BY) Type() protoreflect.EnumType {
return &file_skills_protobuf_hello_proto_enumTypes[0]
}
func (x DESCRIBE_BY) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use DESCRIBE_BY.Descriptor instead.
func (DESCRIBE_BY) EnumDescriptor() ([]byte, []int) {
return file_skills_protobuf_hello_proto_rawDescGZIP(), []int{0}
}
type HelloRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
MyName string `protobuf:"bytes,1,opt,name=my_name,json=myName,proto3" json:"my_name,omitempty"`
Age int64 `protobuf:"varint,2,opt,name=age,proto3" json:"age,omitempty"`
MagicNumber []int64 `protobuf:"varint,3,rep,packed,name=magic_number,json=magicNumber,proto3" json:"magic_number,omitempty"`
Extras map[string]string `protobuf:"bytes,4,rep,name=extras,proto3" json:"extras,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *HelloRequest) Reset() {
*x = HelloRequest{}
mi := &file_skills_protobuf_hello_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *HelloRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HelloRequest) ProtoMessage() {}
func (x *HelloRequest) ProtoReflect() protoreflect.Message {
mi := &file_skills_protobuf_hello_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 HelloRequest.ProtoReflect.Descriptor instead.
func (*HelloRequest) Descriptor() ([]byte, []int) {
return file_skills_protobuf_hello_proto_rawDescGZIP(), []int{0}
}
func (x *HelloRequest) GetMyName() string {
if x != nil {
return x.MyName
}
return ""
}
func (x *HelloRequest) GetAge() int64 {
if x != nil {
return x.Age
}
return 0
}
func (x *HelloRequest) GetMagicNumber() []int64 {
if x != nil {
return x.MagicNumber
}
return nil
}
func (x *HelloRequest) GetExtras() map[string]string {
if x != nil {
return x.Extras
}
return nil
}
type HelloResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *HelloResponse) Reset() {
*x = HelloResponse{}
mi := &file_skills_protobuf_hello_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *HelloResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HelloResponse) ProtoMessage() {}
func (x *HelloResponse) ProtoReflect() protoreflect.Message {
mi := &file_skills_protobuf_hello_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 HelloResponse.ProtoReflect.Descriptor instead.
func (*HelloResponse) Descriptor() ([]byte, []int) {
return file_skills_protobuf_hello_proto_rawDescGZIP(), []int{1}
}
func (x *HelloResponse) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
type EventSet struct {
state protoimpl.MessageState `protogen:"open.v1"`
Items []*Event `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *EventSet) Reset() {
*x = EventSet{}
mi := &file_skills_protobuf_hello_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *EventSet) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*EventSet) ProtoMessage() {}
func (x *EventSet) ProtoReflect() protoreflect.Message {
mi := &file_skills_protobuf_hello_proto_msgTypes[2]
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 EventSet.ProtoReflect.Descriptor instead.
func (*EventSet) Descriptor() ([]byte, []int) {
return file_skills_protobuf_hello_proto_rawDescGZIP(), []int{2}
}
func (x *EventSet) GetItems() []*Event {
if x != nil {
return x.Items
}
return nil
}
var File_skills_protobuf_hello_proto protoreflect.FileDescriptor
var file_skills_protobuf_hello_proto_rawDesc = string([]byte{
0x0a, 0x1b, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
0x66, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x68,
0x65, 0x6c, 0x6c, 0x6f, 0x1a, 0x1b, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x73, 0x2f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x22, 0xd0, 0x01, 0x0a, 0x0c, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x6d, 0x79, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x61,
0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x61, 0x67, 0x65, 0x12, 0x21, 0x0a,
0x0c, 0x6d, 0x61, 0x67, 0x69, 0x63, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x03, 0x20,
0x03, 0x28, 0x03, 0x52, 0x0b, 0x6d, 0x61, 0x67, 0x69, 0x63, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72,
0x12, 0x37, 0x0a, 0x06, 0x65, 0x78, 0x74, 0x72, 0x61, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b,
0x32, 0x1f, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x72, 0x61, 0x73, 0x45, 0x6e, 0x74, 0x72,
0x79, 0x52, 0x06, 0x65, 0x78, 0x74, 0x72, 0x61, 0x73, 0x1a, 0x39, 0x0a, 0x0b, 0x45, 0x78, 0x74,
0x72, 0x61, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x3a, 0x02, 0x38, 0x01, 0x22, 0x29, 0x0a, 0x0d, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22,
0x2e, 0x0a, 0x08, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x74, 0x12, 0x22, 0x0a, 0x05, 0x69,
0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x68, 0x65, 0x6c,
0x6c, 0x6f, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x2a,
0x1f, 0x0a, 0x0b, 0x44, 0x45, 0x53, 0x43, 0x52, 0x49, 0x42, 0x45, 0x5f, 0x42, 0x59, 0x12, 0x06,
0x0a, 0x02, 0x49, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x41, 0x4d, 0x45, 0x10, 0x01,
0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x6c, 0x61, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67,
0x6f, 0x2d, 0x63, 0x6f, 0x75, 0x72, 0x73, 0x65, 0x2d, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74,
0x2f, 0x67, 0x6f, 0x31, 0x37, 0x2f, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x73, 0x2f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x62, 0x75, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
})
var (
file_skills_protobuf_hello_proto_rawDescOnce sync.Once
file_skills_protobuf_hello_proto_rawDescData []byte
)
func file_skills_protobuf_hello_proto_rawDescGZIP() []byte {
file_skills_protobuf_hello_proto_rawDescOnce.Do(func() {
file_skills_protobuf_hello_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_skills_protobuf_hello_proto_rawDesc), len(file_skills_protobuf_hello_proto_rawDesc)))
})
return file_skills_protobuf_hello_proto_rawDescData
}
var file_skills_protobuf_hello_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_skills_protobuf_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_skills_protobuf_hello_proto_goTypes = []any{
(DESCRIBE_BY)(0), // 0: hello.DESCRIBE_BY
(*HelloRequest)(nil), // 1: hello.HelloRequest
(*HelloResponse)(nil), // 2: hello.HelloResponse
(*EventSet)(nil), // 3: hello.EventSet
nil, // 4: hello.HelloRequest.ExtrasEntry
(*Event)(nil), // 5: hello.Event
}
var file_skills_protobuf_hello_proto_depIdxs = []int32{
4, // 0: hello.HelloRequest.extras:type_name -> hello.HelloRequest.ExtrasEntry
5, // 1: hello.EventSet.items:type_name -> hello.Event
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_protobuf_hello_proto_init() }
func file_skills_protobuf_hello_proto_init() {
if File_skills_protobuf_hello_proto != nil {
return
}
file_skills_protobuf_event_proto_init()
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_skills_protobuf_hello_proto_rawDesc), len(file_skills_protobuf_hello_proto_rawDesc)),
NumEnums: 1,
NumMessages: 4,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_skills_protobuf_hello_proto_goTypes,
DependencyIndexes: file_skills_protobuf_hello_proto_depIdxs,
EnumInfos: file_skills_protobuf_hello_proto_enumTypes,
MessageInfos: file_skills_protobuf_hello_proto_msgTypes,
}.Build()
File_skills_protobuf_hello_proto = out.File
file_skills_protobuf_hello_proto_goTypes = nil
file_skills_protobuf_hello_proto_depIdxs = nil
}

View File

@ -0,0 +1,52 @@
package protobuf_test
import (
"testing"
"gitlab.com/go-course-project/go17/skills/protobuf"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
)
func TestHelloRequest(t *testing.T) {
req := &protobuf.HelloRequest{MyName: "bob", Age: 64}
data, err := proto.Marshal(req)
if err != nil {
t.Fatal(err)
}
t.Log(string(data))
req2 := &protobuf.HelloRequest{}
err = proto.Unmarshal(data, req2)
if err != nil {
t.Fatal(err)
}
t.Log(req2)
t.Log(protobuf.DESCRIBE_BY_ID)
}
func TestAny(t *testing.T) {
// 1. Pack
req := &protobuf.Event{
Type: protobuf.EVENT_TYPE_ECS,
Message: "test for any",
Detail: []*anypb.Any{},
}
ecsAny, err := anypb.New(&protobuf.EVENT_ECS{Message: "1"})
if err != nil {
t.Fatal(err)
}
req.Detail = append(req.Detail, ecsAny)
t.Log(req)
// 2. Unpack
t.Log(req.Detail[0])
ecsEvent := &protobuf.EVENT_ECS{}
if err := req.Detail[0].UnmarshalTo(ecsEvent); err != nil {
t.Fatal(err)
}
t.Log(ecsEvent)
}

View File

@ -0,0 +1,31 @@
syntax = "proto3";
package hello;
option go_package="gitlab.com/go-course-project/go17/skills/protobuf";
import "skills/protobuf/event.proto";
message HelloRequest {
string my_name = 1;
int64 age = 2;
repeated int64 magic_number = 3;
map<string,string> extras = 4;
}
message HelloResponse {
string message = 1;
}
enum DESCRIBE_BY {
ID = 0;
NAME = 1;
}
message EventSet {
repeated Event items = 1;
}

View File

@ -53,5 +53,6 @@ func main() {
rpc.ServeRequest(jsonrpc.NewServerCodec(conn))
})
// protobuf.HelloRequest.MyName
http.ListenAndServe(":1234", nil)
}