Compare commits
5 Commits
master
...
2.0_wangqi
Author | SHA1 | Date |
---|---|---|
|
2215c8b9a5 | |
|
fa058438f9 | |
|
768c9d10ac | |
|
87cf22db9e | |
|
31ab769516 |
|
@ -0,0 +1,64 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
Username = "c2net2@pcl.ac.cn"
|
||||
Password = "c2net123"
|
||||
TokenUrl = "http://192.168.242.41:8001/openaiserver/v1/authmanage/token"
|
||||
Success = 200
|
||||
)
|
||||
|
||||
var (
|
||||
token, expiredAt = GenerateToken()
|
||||
login = Login{
|
||||
Username: Username,
|
||||
Password: Password,
|
||||
}
|
||||
)
|
||||
|
||||
func GenerateToken() (string, time.Time) {
|
||||
jsonStr, _ := json.Marshal(login)
|
||||
req_url, err := http.NewRequest("POST", TokenUrl, bytes.NewBuffer(jsonStr))
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer req_url.Body.Close()
|
||||
|
||||
c := http.Client{Timeout: time.Duration(3) * time.Second}
|
||||
|
||||
respUrl, err := c.Do(req_url)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if respUrl.StatusCode != Success {
|
||||
panic("获取token失败")
|
||||
}
|
||||
|
||||
defer respUrl.Body.Close()
|
||||
|
||||
var loginResp LoginResp
|
||||
|
||||
result, _ := io.ReadAll(respUrl.Body)
|
||||
json.Unmarshal(result, &loginResp)
|
||||
|
||||
var d time.Duration
|
||||
d = time.Second * time.Duration(loginResp.Payload.Expiration)
|
||||
return loginResp.Payload.Token, time.Now().Add(d)
|
||||
}
|
||||
|
||||
func GetToken() string {
|
||||
if time.Now().After(expiredAt) {
|
||||
token, expiredAt = GenerateToken()
|
||||
}
|
||||
return token
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package common
|
||||
|
||||
type Login struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type LoginResp struct {
|
||||
Success bool `json:"success"`
|
||||
Payload struct {
|
||||
Token string `json:"token"`
|
||||
Expiration int `json:"expiration"`
|
||||
} `json:"payload"`
|
||||
Error interface{} `json:"error"`
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
Name: pcmhanwuji.rpc
|
||||
ListenOn: 0.0.0.0:2004
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 10.101.15.170:31890
|
||||
Key: pcmhanwuji.rpc
|
||||
User: root
|
||||
Pass: I9wLvrRufj
|
|
@ -0,0 +1,250 @@
|
|||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.1
|
||||
// protoc v3.19.4
|
||||
// source: pcm-hanwuji.proto
|
||||
|
||||
package hanwuji
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
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 CreateDataSetReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
ApplyIds []string `protobuf:"bytes,1,rep,name=applyIds,proto3" json:"applyIds,omitempty"` // @gotags: copier:"ApplyIds"
|
||||
Desc string `protobuf:"bytes,2,opt,name=desc,proto3" json:"desc,omitempty"` // @gotags: copier:"Desc"
|
||||
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` // @gotags: copier:"Name"
|
||||
TypeId string `protobuf:"bytes,4,opt,name=typeId,proto3" json:"typeId,omitempty"` // @gotags: copier:"TypeId"
|
||||
}
|
||||
|
||||
func (x *CreateDataSetReq) Reset() {
|
||||
*x = CreateDataSetReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_pcm_hanwuji_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *CreateDataSetReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CreateDataSetReq) ProtoMessage() {}
|
||||
|
||||
func (x *CreateDataSetReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_pcm_hanwuji_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use CreateDataSetReq.ProtoReflect.Descriptor instead.
|
||||
func (*CreateDataSetReq) Descriptor() ([]byte, []int) {
|
||||
return file_pcm_hanwuji_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *CreateDataSetReq) GetApplyIds() []string {
|
||||
if x != nil {
|
||||
return x.ApplyIds
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *CreateDataSetReq) GetDesc() string {
|
||||
if x != nil {
|
||||
return x.Desc
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *CreateDataSetReq) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *CreateDataSetReq) GetTypeId() string {
|
||||
if x != nil {
|
||||
return x.TypeId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type CreateDataSetResq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // @gotags: copier:"Id"
|
||||
Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // @gotags: copier:"Version"
|
||||
}
|
||||
|
||||
func (x *CreateDataSetResq) Reset() {
|
||||
*x = CreateDataSetResq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_pcm_hanwuji_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *CreateDataSetResq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CreateDataSetResq) ProtoMessage() {}
|
||||
|
||||
func (x *CreateDataSetResq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_pcm_hanwuji_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use CreateDataSetResq.ProtoReflect.Descriptor instead.
|
||||
func (*CreateDataSetResq) Descriptor() ([]byte, []int) {
|
||||
return file_pcm_hanwuji_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *CreateDataSetResq) GetId() string {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *CreateDataSetResq) GetVersion() string {
|
||||
if x != nil {
|
||||
return x.Version
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_pcm_hanwuji_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_pcm_hanwuji_proto_rawDesc = []byte{
|
||||
0x0a, 0x11, 0x70, 0x63, 0x6d, 0x2d, 0x68, 0x61, 0x6e, 0x77, 0x75, 0x6a, 0x69, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x12, 0x07, 0x68, 0x61, 0x6e, 0x77, 0x75, 0x6a, 0x69, 0x22, 0x6e, 0x0a, 0x10,
|
||||
0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x53, 0x65, 0x74, 0x52, 0x65, 0x71,
|
||||
0x12, 0x1a, 0x0a, 0x08, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x49, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03,
|
||||
0x28, 0x09, 0x52, 0x08, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x49, 0x64, 0x73, 0x12, 0x12, 0x0a, 0x04,
|
||||
0x64, 0x65, 0x73, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x65, 0x73, 0x63,
|
||||
0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x79, 0x70, 0x65, 0x49, 0x64, 0x18, 0x04,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x79, 0x70, 0x65, 0x49, 0x64, 0x22, 0x3d, 0x0a, 0x11,
|
||||
0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x53, 0x65, 0x74, 0x52, 0x65, 0x73,
|
||||
0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69,
|
||||
0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x32, 0x51, 0x0a, 0x07, 0x48,
|
||||
0x61, 0x6e, 0x77, 0x75, 0x6a, 0x69, 0x12, 0x46, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
|
||||
0x44, 0x61, 0x74, 0x61, 0x53, 0x65, 0x74, 0x12, 0x19, 0x2e, 0x68, 0x61, 0x6e, 0x77, 0x75, 0x6a,
|
||||
0x69, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x53, 0x65, 0x74, 0x52,
|
||||
0x65, 0x71, 0x1a, 0x1a, 0x2e, 0x68, 0x61, 0x6e, 0x77, 0x75, 0x6a, 0x69, 0x2e, 0x43, 0x72, 0x65,
|
||||
0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x53, 0x65, 0x74, 0x52, 0x65, 0x73, 0x71, 0x42, 0x0a,
|
||||
0x5a, 0x08, 0x2f, 0x68, 0x61, 0x6e, 0x77, 0x75, 0x6a, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_pcm_hanwuji_proto_rawDescOnce sync.Once
|
||||
file_pcm_hanwuji_proto_rawDescData = file_pcm_hanwuji_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_pcm_hanwuji_proto_rawDescGZIP() []byte {
|
||||
file_pcm_hanwuji_proto_rawDescOnce.Do(func() {
|
||||
file_pcm_hanwuji_proto_rawDescData = protoimpl.X.CompressGZIP(file_pcm_hanwuji_proto_rawDescData)
|
||||
})
|
||||
return file_pcm_hanwuji_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_pcm_hanwuji_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_pcm_hanwuji_proto_goTypes = []interface{}{
|
||||
(*CreateDataSetReq)(nil), // 0: hanwuji.CreateDataSetReq
|
||||
(*CreateDataSetResq)(nil), // 1: hanwuji.CreateDataSetResq
|
||||
}
|
||||
var file_pcm_hanwuji_proto_depIdxs = []int32{
|
||||
0, // 0: hanwuji.Hanwuji.CreateDataSet:input_type -> hanwuji.CreateDataSetReq
|
||||
1, // 1: hanwuji.Hanwuji.CreateDataSet:output_type -> hanwuji.CreateDataSetResq
|
||||
1, // [1:2] is the sub-list for method output_type
|
||||
0, // [0:1] 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_pcm_hanwuji_proto_init() }
|
||||
func file_pcm_hanwuji_proto_init() {
|
||||
if File_pcm_hanwuji_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_pcm_hanwuji_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*CreateDataSetReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_pcm_hanwuji_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*CreateDataSetResq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_pcm_hanwuji_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_pcm_hanwuji_proto_goTypes,
|
||||
DependencyIndexes: file_pcm_hanwuji_proto_depIdxs,
|
||||
MessageInfos: file_pcm_hanwuji_proto_msgTypes,
|
||||
}.Build()
|
||||
File_pcm_hanwuji_proto = out.File
|
||||
file_pcm_hanwuji_proto_rawDesc = nil
|
||||
file_pcm_hanwuji_proto_goTypes = nil
|
||||
file_pcm_hanwuji_proto_depIdxs = nil
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.2.0
|
||||
// - protoc v3.19.4
|
||||
// source: pcm-hanwuji.proto
|
||||
|
||||
package hanwuji
|
||||
|
||||
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.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// HanwujiClient is the client API for Hanwuji 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 HanwujiClient interface {
|
||||
//get modelarts Token
|
||||
CreateDataSet(ctx context.Context, in *CreateDataSetReq, opts ...grpc.CallOption) (*CreateDataSetResq, error)
|
||||
}
|
||||
|
||||
type hanwujiClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewHanwujiClient(cc grpc.ClientConnInterface) HanwujiClient {
|
||||
return &hanwujiClient{cc}
|
||||
}
|
||||
|
||||
func (c *hanwujiClient) CreateDataSet(ctx context.Context, in *CreateDataSetReq, opts ...grpc.CallOption) (*CreateDataSetResq, error) {
|
||||
out := new(CreateDataSetResq)
|
||||
err := c.cc.Invoke(ctx, "/hanwuji.Hanwuji/CreateDataSet", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// HanwujiServer is the server API for Hanwuji service.
|
||||
// All implementations must embed UnimplementedHanwujiServer
|
||||
// for forward compatibility
|
||||
type HanwujiServer interface {
|
||||
//get modelarts Token
|
||||
CreateDataSet(context.Context, *CreateDataSetReq) (*CreateDataSetResq, error)
|
||||
mustEmbedUnimplementedHanwujiServer()
|
||||
}
|
||||
|
||||
// UnimplementedHanwujiServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedHanwujiServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedHanwujiServer) CreateDataSet(context.Context, *CreateDataSetReq) (*CreateDataSetResq, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateDataSet not implemented")
|
||||
}
|
||||
func (UnimplementedHanwujiServer) mustEmbedUnimplementedHanwujiServer() {}
|
||||
|
||||
// UnsafeHanwujiServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to HanwujiServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeHanwujiServer interface {
|
||||
mustEmbedUnimplementedHanwujiServer()
|
||||
}
|
||||
|
||||
func RegisterHanwujiServer(s grpc.ServiceRegistrar, srv HanwujiServer) {
|
||||
s.RegisterService(&Hanwuji_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _Hanwuji_CreateDataSet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateDataSetReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(HanwujiServer).CreateDataSet(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/hanwuji.Hanwuji/CreateDataSet",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(HanwujiServer).CreateDataSet(ctx, req.(*CreateDataSetReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Hanwuji_ServiceDesc is the grpc.ServiceDesc for Hanwuji service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var Hanwuji_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "hanwuji.Hanwuji",
|
||||
HandlerType: (*HanwujiServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "CreateDataSet",
|
||||
Handler: _Hanwuji_CreateDataSet_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "pcm-hanwuji.proto",
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
// Source: pcm-hanwuji.proto
|
||||
|
||||
package hanwujiclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"PCM/adaptor/PCM-AI/PCM-HANWUJI/rpc/hanwuji"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
CreateDataSetReq = hanwuji.CreateDataSetReq
|
||||
CreateDataSetResq = hanwuji.CreateDataSetResq
|
||||
|
||||
Hanwuji interface {
|
||||
// get modelarts Token
|
||||
CreateDataSet(ctx context.Context, in *CreateDataSetReq, opts ...grpc.CallOption) (*CreateDataSetResq, error)
|
||||
}
|
||||
|
||||
defaultHanwuji struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewHanwuji(cli zrpc.Client) Hanwuji {
|
||||
return &defaultHanwuji{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
// get modelarts Token
|
||||
func (m *defaultHanwuji) CreateDataSet(ctx context.Context, in *CreateDataSetReq, opts ...grpc.CallOption) (*CreateDataSetResq, error) {
|
||||
client := hanwuji.NewHanwujiClient(m.cli.Conn())
|
||||
return client.CreateDataSet(ctx, in, opts...)
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
zrpc.RpcServerConf
|
||||
LogConf logx.LogConf
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"PCM/adaptor/PCM-AI/PCM-HANWUJI/rpc/common"
|
||||
"PCM/common/tool"
|
||||
"context"
|
||||
"k8s.io/apimachinery/pkg/util/json"
|
||||
"strings"
|
||||
|
||||
"PCM/adaptor/PCM-AI/PCM-HANWUJI/rpc/hanwuji"
|
||||
"PCM/adaptor/PCM-AI/PCM-HANWUJI/rpc/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateDataSetLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateDataSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateDataSetLogic {
|
||||
return &CreateDataSetLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// get modelarts Token
|
||||
func (l *CreateDataSetLogic) CreateDataSet(in *hanwuji.CreateDataSetReq) (*hanwuji.CreateDataSetResq, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
var resp hanwuji.CreateDataSetResq
|
||||
url := "http://192.168.242.41:8001/openaiserver/v1/datasetmanage/dataset"
|
||||
reqByte, err := json.Marshal(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
payload := strings.NewReader(string(reqByte))
|
||||
token := common.GetToken()
|
||||
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.POST, url, payload, token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if statusCode == 200 {
|
||||
json.Unmarshal(body, &resp)
|
||||
} else if statusCode == 400 {
|
||||
json.Unmarshal(body, &resp)
|
||||
}
|
||||
return &hanwuji.CreateDataSetResq{}, nil
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
// Source: pcm-hanwuji.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"PCM/adaptor/PCM-AI/PCM-HANWUJI/rpc/hanwuji"
|
||||
"PCM/adaptor/PCM-AI/PCM-HANWUJI/rpc/internal/logic"
|
||||
"PCM/adaptor/PCM-AI/PCM-HANWUJI/rpc/internal/svc"
|
||||
)
|
||||
|
||||
type HanwujiServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
hanwuji.UnimplementedHanwujiServer
|
||||
}
|
||||
|
||||
func NewHanwujiServer(svcCtx *svc.ServiceContext) *HanwujiServer {
|
||||
return &HanwujiServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// get modelarts Token
|
||||
func (s *HanwujiServer) CreateDataSet(ctx context.Context, in *hanwuji.CreateDataSetReq) (*hanwuji.CreateDataSetResq, error) {
|
||||
l := logic.NewCreateDataSetLogic(ctx, s.svcCtx)
|
||||
return l.CreateDataSet(in)
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package svc
|
||||
|
||||
import "PCM/adaptor/PCM-AI/PCM-HANWUJI/rpc/internal/config"
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package hanwuji;
|
||||
option go_package = "/hanwuji";
|
||||
|
||||
/******************find CreateDataset start*************************/
|
||||
|
||||
|
||||
message CreateDataSetReq {
|
||||
repeated string applyIds = 1; // @gotags: copier:"ApplyIds"
|
||||
string desc = 2; // @gotags: copier:"Desc"
|
||||
string name = 3; // @gotags: copier:"Name"
|
||||
string typeId = 4; // @gotags: copier:"TypeId"
|
||||
|
||||
}
|
||||
|
||||
message CreateDataSetResq{
|
||||
string id =1; // @gotags: copier:"Id"
|
||||
string version =2; // @gotags: copier:"Version"
|
||||
}
|
||||
|
||||
/******************find CreateDataset end*************************/
|
||||
|
||||
service Hanwuji{
|
||||
|
||||
//get modelarts Token
|
||||
rpc CreateDataSet(CreateDataSetReq) returns (CreateDataSetResq);
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"PCM/adaptor/PCM-AI/PCM-HANWUJI/rpc/hanwuji"
|
||||
"PCM/adaptor/PCM-AI/PCM-HANWUJI/rpc/internal/config"
|
||||
"PCM/adaptor/PCM-AI/PCM-HANWUJI/rpc/internal/server"
|
||||
"PCM/adaptor/PCM-AI/PCM-HANWUJI/rpc/internal/svc"
|
||||
"flag"
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"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", "adaptor/PCM-AI/PCM-HANWUJI/rpc/etc/pcmhanwuji.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
// start log component
|
||||
logx.MustSetup(c.LogConf)
|
||||
ctx := svc.NewServiceContext(c)
|
||||
|
||||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||
hanwuji.RegisterHanwujiServer(grpcServer, server.NewHanwujiServer(ctx))
|
||||
|
||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
}
|
||||
})
|
||||
defer s.Stop()
|
||||
|
||||
logx.Infof("Starting rpc server at %s...\n", c.ListenOn)
|
||||
s.Start()
|
||||
}
|
Loading…
Reference in New Issue