This commit is contained in:
xiabin 2025-02-21 18:24:39 +08:00
parent 6bd6517a0d
commit 0004b0655f
13 changed files with 809 additions and 1 deletions

View File

@ -0,0 +1,39 @@
package main
import (
"fmt"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/config"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/admin_service"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/internal/server"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/internal/svc"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
const ServiceName = "admin_service"
func main() {
var c config.Config
err := config.GetConfig(&c, ServiceName)
if err != nil {
panic(err)
}
ctx := svc.NewServiceContext(c)
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
admin_service.RegisterAdminServiceServer(grpcServer, server.NewAdminServiceServer(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.RpcServerConf.ListenOn)
s.Start()
}

View File

@ -0,0 +1,37 @@
syntax = "proto3";
package admin_service;
option go_package = "./admin_service";
message Request {
string ping = 1;
}
message Response {
string pong = 1;
}
message GetAppListRequest {
}
message GetAppListResponse {
repeated AppInfo app_list = 1;
}
message AppInfo {
int32 id = 1;
int32 type = 2;
string app_id = 3;
string secret = 4;
string remark = 5;
float ecpm = 6;
uint32 ipu = 7;
}
service admin_service {
rpc Ping(Request) returns(Response);
//app列表
rpc GetAppList(GetAppListRequest) returns(GetAppListResponse);
}

View File

@ -0,0 +1,378 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.4
// protoc v3.19.4
// source: admin_service.proto
package admin_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 Request struct {
state protoimpl.MessageState `protogen:"open.v1"`
Ping string `protobuf:"bytes,1,opt,name=ping,proto3" json:"ping,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Request) Reset() {
*x = Request{}
mi := &file_admin_service_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Request) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Request) ProtoMessage() {}
func (x *Request) ProtoReflect() protoreflect.Message {
mi := &file_admin_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 Request.ProtoReflect.Descriptor instead.
func (*Request) Descriptor() ([]byte, []int) {
return file_admin_service_proto_rawDescGZIP(), []int{0}
}
func (x *Request) GetPing() string {
if x != nil {
return x.Ping
}
return ""
}
type Response struct {
state protoimpl.MessageState `protogen:"open.v1"`
Pong string `protobuf:"bytes,1,opt,name=pong,proto3" json:"pong,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Response) Reset() {
*x = Response{}
mi := &file_admin_service_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Response) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Response) ProtoMessage() {}
func (x *Response) ProtoReflect() protoreflect.Message {
mi := &file_admin_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 Response.ProtoReflect.Descriptor instead.
func (*Response) Descriptor() ([]byte, []int) {
return file_admin_service_proto_rawDescGZIP(), []int{1}
}
func (x *Response) GetPong() string {
if x != nil {
return x.Pong
}
return ""
}
type GetAppListRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetAppListRequest) Reset() {
*x = GetAppListRequest{}
mi := &file_admin_service_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetAppListRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetAppListRequest) ProtoMessage() {}
func (x *GetAppListRequest) ProtoReflect() protoreflect.Message {
mi := &file_admin_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 GetAppListRequest.ProtoReflect.Descriptor instead.
func (*GetAppListRequest) Descriptor() ([]byte, []int) {
return file_admin_service_proto_rawDescGZIP(), []int{2}
}
type GetAppListResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
AppList []*AppInfo `protobuf:"bytes,1,rep,name=app_list,json=appList,proto3" json:"app_list,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetAppListResponse) Reset() {
*x = GetAppListResponse{}
mi := &file_admin_service_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetAppListResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetAppListResponse) ProtoMessage() {}
func (x *GetAppListResponse) ProtoReflect() protoreflect.Message {
mi := &file_admin_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 GetAppListResponse.ProtoReflect.Descriptor instead.
func (*GetAppListResponse) Descriptor() ([]byte, []int) {
return file_admin_service_proto_rawDescGZIP(), []int{3}
}
func (x *GetAppListResponse) GetAppList() []*AppInfo {
if x != nil {
return x.AppList
}
return nil
}
type AppInfo struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Type int32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"`
AppId string `protobuf:"bytes,3,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"`
Secret string `protobuf:"bytes,4,opt,name=secret,proto3" json:"secret,omitempty"`
Remark string `protobuf:"bytes,5,opt,name=remark,proto3" json:"remark,omitempty"`
Ecpm float32 `protobuf:"fixed32,6,opt,name=ecpm,proto3" json:"ecpm,omitempty"`
Ipu uint32 `protobuf:"varint,7,opt,name=ipu,proto3" json:"ipu,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AppInfo) Reset() {
*x = AppInfo{}
mi := &file_admin_service_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AppInfo) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AppInfo) ProtoMessage() {}
func (x *AppInfo) ProtoReflect() protoreflect.Message {
mi := &file_admin_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 AppInfo.ProtoReflect.Descriptor instead.
func (*AppInfo) Descriptor() ([]byte, []int) {
return file_admin_service_proto_rawDescGZIP(), []int{4}
}
func (x *AppInfo) GetId() int32 {
if x != nil {
return x.Id
}
return 0
}
func (x *AppInfo) GetType() int32 {
if x != nil {
return x.Type
}
return 0
}
func (x *AppInfo) GetAppId() string {
if x != nil {
return x.AppId
}
return ""
}
func (x *AppInfo) GetSecret() string {
if x != nil {
return x.Secret
}
return ""
}
func (x *AppInfo) GetRemark() string {
if x != nil {
return x.Remark
}
return ""
}
func (x *AppInfo) GetEcpm() float32 {
if x != nil {
return x.Ecpm
}
return 0
}
func (x *AppInfo) GetIpu() uint32 {
if x != nil {
return x.Ipu
}
return 0
}
var File_admin_service_proto protoreflect.FileDescriptor
var file_admin_service_proto_rawDesc = string([]byte{
0x0a, 0x13, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0d, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x22, 0x1d, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
0x12, 0x0a, 0x04, 0x70, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70,
0x69, 0x6e, 0x67, 0x22, 0x1e, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
0x12, 0x0a, 0x04, 0x70, 0x6f, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70,
0x6f, 0x6e, 0x67, 0x22, 0x13, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x4c, 0x69, 0x73,
0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x47, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x41,
0x70, 0x70, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x31,
0x0a, 0x08, 0x61, 0x70, 0x70, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b,
0x32, 0x16, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x2e, 0x41, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x07, 0x61, 0x70, 0x70, 0x4c, 0x69, 0x73,
0x74, 0x22, 0x9a, 0x01, 0x0a, 0x07, 0x41, 0x70, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x0e, 0x0a,
0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a,
0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x79, 0x70,
0x65, 0x12, 0x15, 0x0a, 0x06, 0x61, 0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28,
0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x63, 0x72,
0x65, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74,
0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09,
0x52, 0x06, 0x72, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x65, 0x63, 0x70, 0x6d,
0x18, 0x06, 0x20, 0x01, 0x28, 0x02, 0x52, 0x04, 0x65, 0x63, 0x70, 0x6d, 0x12, 0x10, 0x0a, 0x03,
0x69, 0x70, 0x75, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x69, 0x70, 0x75, 0x32, 0x9b,
0x01, 0x0a, 0x0d, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x12, 0x37, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x16, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e,
0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x17, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x51, 0x0a, 0x0a, 0x47, 0x65, 0x74,
0x41, 0x70, 0x70, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x20, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f,
0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x4c, 0x69,
0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x61, 0x64, 0x6d, 0x69,
0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70,
0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x11, 0x5a, 0x0f,
0x2e, 0x2f, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
})
var (
file_admin_service_proto_rawDescOnce sync.Once
file_admin_service_proto_rawDescData []byte
)
func file_admin_service_proto_rawDescGZIP() []byte {
file_admin_service_proto_rawDescOnce.Do(func() {
file_admin_service_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_admin_service_proto_rawDesc), len(file_admin_service_proto_rawDesc)))
})
return file_admin_service_proto_rawDescData
}
var file_admin_service_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_admin_service_proto_goTypes = []any{
(*Request)(nil), // 0: admin_service.Request
(*Response)(nil), // 1: admin_service.Response
(*GetAppListRequest)(nil), // 2: admin_service.GetAppListRequest
(*GetAppListResponse)(nil), // 3: admin_service.GetAppListResponse
(*AppInfo)(nil), // 4: admin_service.AppInfo
}
var file_admin_service_proto_depIdxs = []int32{
4, // 0: admin_service.GetAppListResponse.app_list:type_name -> admin_service.AppInfo
0, // 1: admin_service.admin_service.Ping:input_type -> admin_service.Request
2, // 2: admin_service.admin_service.GetAppList:input_type -> admin_service.GetAppListRequest
1, // 3: admin_service.admin_service.Ping:output_type -> admin_service.Response
3, // 4: admin_service.admin_service.GetAppList:output_type -> admin_service.GetAppListResponse
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_admin_service_proto_init() }
func file_admin_service_proto_init() {
if File_admin_service_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_admin_service_proto_rawDesc), len(file_admin_service_proto_rawDesc)),
NumEnums: 0,
NumMessages: 5,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_admin_service_proto_goTypes,
DependencyIndexes: file_admin_service_proto_depIdxs,
MessageInfos: file_admin_service_proto_msgTypes,
}.Build()
File_admin_service_proto = out.File
file_admin_service_proto_goTypes = nil
file_admin_service_proto_depIdxs = nil
}

View File

@ -0,0 +1,161 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v3.19.4
// source: admin_service.proto
package admin_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 (
AdminService_Ping_FullMethodName = "/admin_service.admin_service/Ping"
AdminService_GetAppList_FullMethodName = "/admin_service.admin_service/GetAppList"
)
// AdminServiceClient is the client API for AdminService 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 AdminServiceClient interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
// 获取app列表
GetAppList(ctx context.Context, in *GetAppListRequest, opts ...grpc.CallOption) (*GetAppListResponse, error)
}
type adminServiceClient struct {
cc grpc.ClientConnInterface
}
func NewAdminServiceClient(cc grpc.ClientConnInterface) AdminServiceClient {
return &adminServiceClient{cc}
}
func (c *adminServiceClient) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Response)
err := c.cc.Invoke(ctx, AdminService_Ping_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *adminServiceClient) GetAppList(ctx context.Context, in *GetAppListRequest, opts ...grpc.CallOption) (*GetAppListResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetAppListResponse)
err := c.cc.Invoke(ctx, AdminService_GetAppList_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// AdminServiceServer is the server API for AdminService service.
// All implementations must embed UnimplementedAdminServiceServer
// for forward compatibility.
type AdminServiceServer interface {
Ping(context.Context, *Request) (*Response, error)
// 获取app列表
GetAppList(context.Context, *GetAppListRequest) (*GetAppListResponse, error)
mustEmbedUnimplementedAdminServiceServer()
}
// UnimplementedAdminServiceServer 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 UnimplementedAdminServiceServer struct{}
func (UnimplementedAdminServiceServer) Ping(context.Context, *Request) (*Response, error) {
return nil, status.Errorf(codes.Unimplemented, "method Ping not implemented")
}
func (UnimplementedAdminServiceServer) GetAppList(context.Context, *GetAppListRequest) (*GetAppListResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetAppList not implemented")
}
func (UnimplementedAdminServiceServer) mustEmbedUnimplementedAdminServiceServer() {}
func (UnimplementedAdminServiceServer) testEmbeddedByValue() {}
// UnsafeAdminServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to AdminServiceServer will
// result in compilation errors.
type UnsafeAdminServiceServer interface {
mustEmbedUnimplementedAdminServiceServer()
}
func RegisterAdminServiceServer(s grpc.ServiceRegistrar, srv AdminServiceServer) {
// If the following call pancis, it indicates UnimplementedAdminServiceServer 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(&AdminService_ServiceDesc, srv)
}
func _AdminService_Ping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Request)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(AdminServiceServer).Ping(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: AdminService_Ping_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(AdminServiceServer).Ping(ctx, req.(*Request))
}
return interceptor(ctx, in, info, handler)
}
func _AdminService_GetAppList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetAppListRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(AdminServiceServer).GetAppList(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: AdminService_GetAppList_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(AdminServiceServer).GetAppList(ctx, req.(*GetAppListRequest))
}
return interceptor(ctx, in, info, handler)
}
// AdminService_ServiceDesc is the grpc.ServiceDesc for AdminService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var AdminService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "admin_service.admin_service",
HandlerType: (*AdminServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Ping",
Handler: _AdminService_Ping_Handler,
},
{
MethodName: "GetAppList",
Handler: _AdminService_GetAppList_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "admin_service.proto",
}

View File

@ -0,0 +1,49 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.6
// Source: admin_service.proto
package admin_service_client
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/admin_service"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
)
type (
AppInfo = admin_service.AppInfo
GetAppListRequest = admin_service.GetAppListRequest
GetAppListResponse = admin_service.GetAppListResponse
Request = admin_service.Request
Response = admin_service.Response
AdminService interface {
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
// 获取app列表
GetAppList(ctx context.Context, in *GetAppListRequest, opts ...grpc.CallOption) (*GetAppListResponse, error)
}
defaultAdminService struct {
cli zrpc.Client
}
)
func NewAdminService(cli zrpc.Client) AdminService {
return &defaultAdminService{
cli: cli,
}
}
func (m *defaultAdminService) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
client := admin_service.NewAdminServiceClient(m.cli.Conn())
return client.Ping(ctx, in, opts...)
}
// 获取app列表
func (m *defaultAdminService) GetAppList(ctx context.Context, in *GetAppListRequest, opts ...grpc.CallOption) (*GetAppListResponse, error) {
client := admin_service.NewAdminServiceClient(m.cli.Conn())
return client.GetAppList(ctx, in, opts...)
}

View File

@ -0,0 +1,6 @@
Name: adminservice.rpc
ListenOn: 0.0.0.0:8080
Etcd:
Hosts:
- 127.0.0.1:2379
Key: adminservice.rpc

View File

@ -0,0 +1,7 @@
package config
import "github.com/zeromicro/go-zero/zrpc"
type Config struct {
zrpc.RpcServerConf
}

View File

@ -0,0 +1,41 @@
package logic
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/admin_service"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type GetAppListLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetAppListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAppListLogic {
return &GetAppListLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
type AppData struct {
AppId string `json:"appId"`
AppSecret string `json:"appSecret"`
Type string `json:"type"`
}
// 获取app列表
func (l *GetAppListLogic) GetAppList(in *admin_service.GetAppListRequest) (res *admin_service.GetAppListResponse, err error) {
res = &admin_service.GetAppListResponse{}
b, err := l.svcCtx.EtcdCli.Get(context.Background(), "/youtu/appData")
if err != nil {
return nil, err
}
return &admin_service.GetAppListResponse{}, nil
}

View File

@ -0,0 +1,28 @@
package logic
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/admin_service"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type PingLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
return &PingLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *PingLogic) Ping(in *admin_service.Request) (*admin_service.Response, error) {
return &admin_service.Response{Pong: in.Ping}, nil
}

View File

@ -0,0 +1,35 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.6
// Source: admin_service.proto
package server
import (
"context"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/admin_service"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/internal/logic"
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/admin_service/internal/svc"
)
type AdminServiceServer struct {
svcCtx *svc.ServiceContext
admin_service.UnimplementedAdminServiceServer
}
func NewAdminServiceServer(svcCtx *svc.ServiceContext) *AdminServiceServer {
return &AdminServiceServer{
svcCtx: svcCtx,
}
}
func (s *AdminServiceServer) Ping(ctx context.Context, in *admin_service.Request) (*admin_service.Response, error) {
l := logic.NewPingLogic(ctx, s.svcCtx)
return l.Ping(in)
}
// 获取app列表
func (s *AdminServiceServer) GetAppList(ctx context.Context, in *admin_service.GetAppListRequest) (*admin_service.GetAppListResponse, error) {
l := logic.NewGetAppListLogic(ctx, s.svcCtx)
return l.GetAppList(in)
}

View File

@ -0,0 +1,25 @@
package svc
import (
"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/config"
"github.com/spf13/viper"
clientv3 "go.etcd.io/etcd/client/v3"
)
type ServiceContext struct {
Config config.Config
EtcdCli *clientv3.Client
}
func NewServiceContext(c config.Config) *ServiceContext {
cli, err := clientv3.NewFromURL(viper.GetString(config.EtcdAddrKey))
if err != nil {
panic(err)
}
return &ServiceContext{
Config: c,
EtcdCli: cli,
}
}

View File

@ -2,6 +2,7 @@ package svc
import (
"encoding/json"
"log/slog"
"sync"
)
@ -47,5 +48,6 @@ func (c *EcpmConfigCli) SetAllByJson(data []byte) {
return
}
slog.Info("set ecpm config", slog.AnyValue(list))
c.SetAll(list)
}

View File

@ -1 +1 @@
[{"appId":"tt5bc32d7ec4f6ccb907","eCPM":100,"IPU":1},{"appId":"tt8b32fd8f14071db707","eCPM":300,"IPU":4}]
[{"appId":"tt5bc32d7ec4f6ccb907","eCPM":100,"IPU":1},{"appId":"tt8b32fd8f14071db707","eCPM":300,"IPU":4},{"appId":"ttb80fceb2273b8d3202","eCPM":100,"IPU":1}]