add: anowflake email kafka, refa: redis connectg
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
Name: snowflake.rpc
|
||||
ListenOn: 0.0.0.0:8080
|
||||
#Etcd:
|
||||
# Hosts:
|
||||
# - 127.0.0.1:2379
|
||||
# Key: snowflake.rpc
|
||||
|
||||
Snowflake:
|
||||
DatacenterId: 1
|
||||
WorkerId: 0
|
||||
@@ -0,0 +1,11 @@
|
||||
package config
|
||||
|
||||
import "github.com/zeromicro/go-zero/zrpc"
|
||||
|
||||
type Config struct {
|
||||
zrpc.RpcServerConf
|
||||
Snowflake struct {
|
||||
DatacenterId int64
|
||||
WorkerId int64
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/snowflake/rpc/internal/svc"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type NextIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewNextIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NextIdLogic {
|
||||
return &NextIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *NextIdLogic) NextId(_ *snowflake.NextIdReq) (*snowflake.NextIdResp, error) {
|
||||
id, err := l.svcCtx.Generator.NextID()
|
||||
if err != nil {
|
||||
l.Error("generator.NextID", "err", err)
|
||||
return nil, err
|
||||
}
|
||||
return &snowflake.NextIdResp{Id: id}, nil
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/snowflake/rpc/internal/svc"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type NextIdsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewNextIdsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NextIdsLogic {
|
||||
return &NextIdsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *NextIdsLogic) NextIds(in *snowflake.NextIdsReq) (*snowflake.NextIdsResp, error) {
|
||||
if in.Count <= 0 || in.Count > 1000 {
|
||||
return nil, errors.New("count must be between 1 and 1000")
|
||||
}
|
||||
ids, err := l.svcCtx.Generator.NextIDs(int(in.Count))
|
||||
if err != nil {
|
||||
l.Errorf("generate snowflake ids failed: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
return &snowflake.NextIdsResp{Ids: ids}, nil
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
epoch = int64(1609459200000)
|
||||
datacenterIdBits = uint(5)
|
||||
workerIdBits = uint(5)
|
||||
sequenceBits = uint(12)
|
||||
|
||||
maxDatacenterId = -1 ^ (-1 << datacenterIdBits)
|
||||
maxWorkerId = -1 ^ (-1 << workerIdBits)
|
||||
maxSequence = -1 ^ (-1 << sequenceBits)
|
||||
|
||||
workerIdShift = sequenceBits
|
||||
datacenterIdShift = sequenceBits + workerIdBits
|
||||
timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits
|
||||
)
|
||||
|
||||
type Snowflake struct {
|
||||
mu sync.Mutex
|
||||
timestamp int64
|
||||
datacenterId int64
|
||||
workerId int64
|
||||
sequence int64
|
||||
}
|
||||
|
||||
func NewSnowflake(datacenterId, workerId int64) (*Snowflake, error) {
|
||||
if datacenterId < 0 || datacenterId > maxDatacenterId {
|
||||
return nil, errors.New("datacenter id must be between 0 and 31")
|
||||
}
|
||||
if workerId < 0 || workerId > maxWorkerId {
|
||||
return nil, errors.New("worker id must be between 0 and 31")
|
||||
}
|
||||
|
||||
return &Snowflake{
|
||||
timestamp: 0,
|
||||
datacenterId: datacenterId,
|
||||
workerId: workerId,
|
||||
sequence: 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Snowflake) NextID() (int64, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
now := time.Now().UnixMilli()
|
||||
|
||||
if now < s.timestamp {
|
||||
return 0, errors.New("clock moved backwards")
|
||||
}
|
||||
|
||||
if now == s.timestamp {
|
||||
s.sequence = (s.sequence + 1) & maxSequence
|
||||
if s.sequence == 0 {
|
||||
for now <= s.timestamp {
|
||||
now = time.Now().UnixMilli()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s.sequence = 0
|
||||
}
|
||||
|
||||
s.timestamp = now
|
||||
|
||||
id := ((now - epoch) << timestampLeftShift) |
|
||||
(s.datacenterId << datacenterIdShift) |
|
||||
(s.workerId << workerIdShift) |
|
||||
s.sequence
|
||||
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (s *Snowflake) NextIDs(count int) ([]int64, error) {
|
||||
if count <= 0 || count > 1000 {
|
||||
return nil, errors.New("count must be between 1 and 1000")
|
||||
}
|
||||
|
||||
ids := make([]int64, count)
|
||||
for i := 0; i < count; i++ {
|
||||
id, err := s.NextID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids[i] = id
|
||||
}
|
||||
|
||||
return ids, nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.2
|
||||
// Source: snowflake.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/snowflake/rpc/internal/logic"
|
||||
"juwan-backend/app/snowflake/rpc/internal/svc"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
)
|
||||
|
||||
type SnowflakeServiceServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
snowflake.UnimplementedSnowflakeServiceServer
|
||||
}
|
||||
|
||||
func NewSnowflakeServiceServer(svcCtx *svc.ServiceContext) *SnowflakeServiceServer {
|
||||
return &SnowflakeServiceServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SnowflakeServiceServer) NextId(ctx context.Context, in *snowflake.NextIdReq) (*snowflake.NextIdResp, error) {
|
||||
l := logic.NewNextIdLogic(ctx, s.svcCtx)
|
||||
return l.NextId(in)
|
||||
}
|
||||
|
||||
func (s *SnowflakeServiceServer) NextIds(ctx context.Context, in *snowflake.NextIdsReq) (*snowflake.NextIdsResp, error) {
|
||||
l := logic.NewNextIdsLogic(ctx, s.svcCtx)
|
||||
return l.NextIds(in)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"juwan-backend/app/snowflake/rpc/internal/config"
|
||||
generator "juwan-backend/app/snowflake/rpc/internal/pkg"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
Generator *generator.Snowflake
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
gen, err := generator.NewSnowflake(
|
||||
c.Snowflake.DatacenterId,
|
||||
c.Snowflake.WorkerId,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
Generator: gen,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"juwan-backend/app/snowflake/rpc/internal/config"
|
||||
"juwan-backend/app/snowflake/rpc/internal/server"
|
||||
"juwan-backend/app/snowflake/rpc/internal/svc"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/core/service"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/snowflake.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
ctx := svc.NewServiceContext(c)
|
||||
|
||||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||
snowflake.RegisterSnowflakeServiceServer(grpcServer, server.NewSnowflakeServiceServer(ctx))
|
||||
|
||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
}
|
||||
})
|
||||
defer s.Stop()
|
||||
|
||||
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
||||
s.Start()
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc v3.19.4
|
||||
// source: snowflake.proto
|
||||
|
||||
package snowflake
|
||||
|
||||
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 NextIdReq struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *NextIdReq) Reset() {
|
||||
*x = NextIdReq{}
|
||||
mi := &file_snowflake_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *NextIdReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*NextIdReq) ProtoMessage() {}
|
||||
|
||||
func (x *NextIdReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_snowflake_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 NextIdReq.ProtoReflect.Descriptor instead.
|
||||
func (*NextIdReq) Descriptor() ([]byte, []int) {
|
||||
return file_snowflake_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
type NextIdResp struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *NextIdResp) Reset() {
|
||||
*x = NextIdResp{}
|
||||
mi := &file_snowflake_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *NextIdResp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*NextIdResp) ProtoMessage() {}
|
||||
|
||||
func (x *NextIdResp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_snowflake_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 NextIdResp.ProtoReflect.Descriptor instead.
|
||||
func (*NextIdResp) Descriptor() ([]byte, []int) {
|
||||
return file_snowflake_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *NextIdResp) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type NextIdsReq struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Count int32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *NextIdsReq) Reset() {
|
||||
*x = NextIdsReq{}
|
||||
mi := &file_snowflake_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *NextIdsReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*NextIdsReq) ProtoMessage() {}
|
||||
|
||||
func (x *NextIdsReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_snowflake_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 NextIdsReq.ProtoReflect.Descriptor instead.
|
||||
func (*NextIdsReq) Descriptor() ([]byte, []int) {
|
||||
return file_snowflake_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *NextIdsReq) GetCount() int32 {
|
||||
if x != nil {
|
||||
return x.Count
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type NextIdsResp struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Ids []int64 `protobuf:"varint,1,rep,packed,name=ids,proto3" json:"ids,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *NextIdsResp) Reset() {
|
||||
*x = NextIdsResp{}
|
||||
mi := &file_snowflake_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *NextIdsResp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*NextIdsResp) ProtoMessage() {}
|
||||
|
||||
func (x *NextIdsResp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_snowflake_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 NextIdsResp.ProtoReflect.Descriptor instead.
|
||||
func (*NextIdsResp) Descriptor() ([]byte, []int) {
|
||||
return file_snowflake_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *NextIdsResp) GetIds() []int64 {
|
||||
if x != nil {
|
||||
return x.Ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_snowflake_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_snowflake_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"\x0fsnowflake.proto\x12\tsnowflake\"\v\n" +
|
||||
"\tNextIdReq\"\x1c\n" +
|
||||
"\n" +
|
||||
"NextIdResp\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\x03R\x02id\"\"\n" +
|
||||
"\n" +
|
||||
"NextIdsReq\x12\x14\n" +
|
||||
"\x05count\x18\x01 \x01(\x05R\x05count\"\x1f\n" +
|
||||
"\vNextIdsResp\x12\x10\n" +
|
||||
"\x03ids\x18\x01 \x03(\x03R\x03ids2\x83\x01\n" +
|
||||
"\x10SnowflakeService\x125\n" +
|
||||
"\x06NextId\x12\x14.snowflake.NextIdReq\x1a\x15.snowflake.NextIdResp\x128\n" +
|
||||
"\aNextIds\x12\x15.snowflake.NextIdsReq\x1a\x16.snowflake.NextIdsRespB\rZ\v./snowflakeb\x06proto3"
|
||||
|
||||
var (
|
||||
file_snowflake_proto_rawDescOnce sync.Once
|
||||
file_snowflake_proto_rawDescData []byte
|
||||
)
|
||||
|
||||
func file_snowflake_proto_rawDescGZIP() []byte {
|
||||
file_snowflake_proto_rawDescOnce.Do(func() {
|
||||
file_snowflake_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_snowflake_proto_rawDesc), len(file_snowflake_proto_rawDesc)))
|
||||
})
|
||||
return file_snowflake_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_snowflake_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
|
||||
var file_snowflake_proto_goTypes = []any{
|
||||
(*NextIdReq)(nil), // 0: snowflake.NextIdReq
|
||||
(*NextIdResp)(nil), // 1: snowflake.NextIdResp
|
||||
(*NextIdsReq)(nil), // 2: snowflake.NextIdsReq
|
||||
(*NextIdsResp)(nil), // 3: snowflake.NextIdsResp
|
||||
}
|
||||
var file_snowflake_proto_depIdxs = []int32{
|
||||
0, // 0: snowflake.SnowflakeService.NextId:input_type -> snowflake.NextIdReq
|
||||
2, // 1: snowflake.SnowflakeService.NextIds:input_type -> snowflake.NextIdsReq
|
||||
1, // 2: snowflake.SnowflakeService.NextId:output_type -> snowflake.NextIdResp
|
||||
3, // 3: snowflake.SnowflakeService.NextIds:output_type -> snowflake.NextIdsResp
|
||||
2, // [2:4] is the sub-list for method output_type
|
||||
0, // [0:2] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_snowflake_proto_init() }
|
||||
func file_snowflake_proto_init() {
|
||||
if File_snowflake_proto != nil {
|
||||
return
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_snowflake_proto_rawDesc), len(file_snowflake_proto_rawDesc)),
|
||||
NumEnums: 0,
|
||||
NumMessages: 4,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_snowflake_proto_goTypes,
|
||||
DependencyIndexes: file_snowflake_proto_depIdxs,
|
||||
MessageInfos: file_snowflake_proto_msgTypes,
|
||||
}.Build()
|
||||
File_snowflake_proto = out.File
|
||||
file_snowflake_proto_goTypes = nil
|
||||
file_snowflake_proto_depIdxs = nil
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.6.1
|
||||
// - protoc v3.19.4
|
||||
// source: snowflake.proto
|
||||
|
||||
package snowflake
|
||||
|
||||
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 (
|
||||
SnowflakeService_NextId_FullMethodName = "/snowflake.SnowflakeService/NextId"
|
||||
SnowflakeService_NextIds_FullMethodName = "/snowflake.SnowflakeService/NextIds"
|
||||
)
|
||||
|
||||
// SnowflakeServiceClient is the client API for SnowflakeService 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 SnowflakeServiceClient interface {
|
||||
NextId(ctx context.Context, in *NextIdReq, opts ...grpc.CallOption) (*NextIdResp, error)
|
||||
NextIds(ctx context.Context, in *NextIdsReq, opts ...grpc.CallOption) (*NextIdsResp, error)
|
||||
}
|
||||
|
||||
type snowflakeServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewSnowflakeServiceClient(cc grpc.ClientConnInterface) SnowflakeServiceClient {
|
||||
return &snowflakeServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *snowflakeServiceClient) NextId(ctx context.Context, in *NextIdReq, opts ...grpc.CallOption) (*NextIdResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(NextIdResp)
|
||||
err := c.cc.Invoke(ctx, SnowflakeService_NextId_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *snowflakeServiceClient) NextIds(ctx context.Context, in *NextIdsReq, opts ...grpc.CallOption) (*NextIdsResp, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(NextIdsResp)
|
||||
err := c.cc.Invoke(ctx, SnowflakeService_NextIds_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// SnowflakeServiceServer is the server API for SnowflakeService service.
|
||||
// All implementations must embed UnimplementedSnowflakeServiceServer
|
||||
// for forward compatibility.
|
||||
type SnowflakeServiceServer interface {
|
||||
NextId(context.Context, *NextIdReq) (*NextIdResp, error)
|
||||
NextIds(context.Context, *NextIdsReq) (*NextIdsResp, error)
|
||||
mustEmbedUnimplementedSnowflakeServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedSnowflakeServiceServer 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 UnimplementedSnowflakeServiceServer struct{}
|
||||
|
||||
func (UnimplementedSnowflakeServiceServer) NextId(context.Context, *NextIdReq) (*NextIdResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method NextId not implemented")
|
||||
}
|
||||
func (UnimplementedSnowflakeServiceServer) NextIds(context.Context, *NextIdsReq) (*NextIdsResp, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method NextIds not implemented")
|
||||
}
|
||||
func (UnimplementedSnowflakeServiceServer) mustEmbedUnimplementedSnowflakeServiceServer() {}
|
||||
func (UnimplementedSnowflakeServiceServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafeSnowflakeServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to SnowflakeServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeSnowflakeServiceServer interface {
|
||||
mustEmbedUnimplementedSnowflakeServiceServer()
|
||||
}
|
||||
|
||||
func RegisterSnowflakeServiceServer(s grpc.ServiceRegistrar, srv SnowflakeServiceServer) {
|
||||
// If the following call panics, it indicates UnimplementedSnowflakeServiceServer 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(&SnowflakeService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _SnowflakeService_NextId_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(NextIdReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SnowflakeServiceServer).NextId(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: SnowflakeService_NextId_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SnowflakeServiceServer).NextId(ctx, req.(*NextIdReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _SnowflakeService_NextIds_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(NextIdsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SnowflakeServiceServer).NextIds(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: SnowflakeService_NextIds_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SnowflakeServiceServer).NextIds(ctx, req.(*NextIdsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// SnowflakeService_ServiceDesc is the grpc.ServiceDesc for SnowflakeService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var SnowflakeService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "snowflake.SnowflakeService",
|
||||
HandlerType: (*SnowflakeServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "NextId",
|
||||
Handler: _SnowflakeService_NextId_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "NextIds",
|
||||
Handler: _SnowflakeService_NextIds_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "snowflake.proto",
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.2
|
||||
// Source: snowflake.proto
|
||||
|
||||
package snowflakeservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
NextIdReq = snowflake.NextIdReq
|
||||
NextIdResp = snowflake.NextIdResp
|
||||
NextIdsReq = snowflake.NextIdsReq
|
||||
NextIdsResp = snowflake.NextIdsResp
|
||||
|
||||
SnowflakeService interface {
|
||||
NextId(ctx context.Context, in *NextIdReq, opts ...grpc.CallOption) (*NextIdResp, error)
|
||||
NextIds(ctx context.Context, in *NextIdsReq, opts ...grpc.CallOption) (*NextIdsResp, error)
|
||||
}
|
||||
|
||||
defaultSnowflakeService struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewSnowflakeService(cli zrpc.Client) SnowflakeService {
|
||||
return &defaultSnowflakeService{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultSnowflakeService) NextId(ctx context.Context, in *NextIdReq, opts ...grpc.CallOption) (*NextIdResp, error) {
|
||||
client := snowflake.NewSnowflakeServiceClient(m.cli.Conn())
|
||||
return client.NextId(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultSnowflakeService) NextIds(ctx context.Context, in *NextIdsReq, opts ...grpc.CallOption) (*NextIdsResp, error) {
|
||||
client := snowflake.NewSnowflakeServiceClient(m.cli.Conn())
|
||||
return client.NextIds(ctx, in, opts...)
|
||||
}
|
||||
Reference in New Issue
Block a user