update middleware

This commit is contained in:
Yavolte 2025-06-09 09:26:29 +08:00
parent 5403f14ccd
commit 47b1ed0168
9 changed files with 318 additions and 14 deletions

12
app.go
View File

@ -123,12 +123,16 @@ func (s *Service) preStart(ctx context.Context) (err error) {
}
if s.opts.scope != nil {
s.injectVars(s.opts.scope)
s.opts.scope.Init(ctx)
if err = s.opts.scope.Init(ctx); err != nil {
return
}
s.refValues = append(s.refValues, reflect.ValueOf(s.opts.scope))
}
if s.opts.serviceLoader != nil {
s.injectVars(s.opts.serviceLoader)
s.opts.serviceLoader.Init(ctx)
if err = s.opts.serviceLoader.Init(ctx); err != nil {
return
}
s.refValues = append(s.refValues, reflect.ValueOf(s.opts.serviceLoader))
}
for _, srv := range s.opts.servers {
@ -137,9 +141,9 @@ func (s *Service) preStart(ctx context.Context) (err error) {
return svr.Start(ctx)
})
}
if s.opts.scope != nil {
if s.opts.serviceLoader != nil {
s.errGroup.Go(func() error {
return s.opts.scope.Run(ctx)
return s.opts.serviceLoader.Run(ctx)
})
}
if s.opts.registry != nil {

View File

@ -0,0 +1 @@
package auth

View File

@ -1,5 +0,0 @@
package middleware
type Transporter interface {
}

View File

@ -102,7 +102,7 @@ const file_command_proto_rawDesc = "" +
"\x0eCommandOptions\x12\x12\n" +
"\x04path\x18\x01 \x01(\tR\x04path\x12 \n" +
"\vdescription\x18\x02 \x01(\tR\vdescription:S\n" +
"\acommand\x12\x1e.google.protobuf.MethodOptions\x18ц\x03 \x01(\v2\x14.aeus.CommandOptionsR\acommand\x88\x01\x01B-Z+git.nobla.cn/golang/aeus/pkg/protoc/commandb\x06proto3"
"\acommand\x12\x1e.google.protobuf.MethodOptions\x18ц\x03 \x01(\v2\x14.aeus.CommandOptionsR\acommand\x88\x01\x01B,Z*git.nobla.cn/golang/aeus/pkg/proto/commandb\x06proto3"
var (
file_command_proto_rawDescOnce sync.Once

View File

@ -4,7 +4,7 @@ package aeus;
import "google/protobuf/descriptor.proto";
option go_package = "git.nobla.cn/golang/aeus/pkg/protoc/command";
option go_package = "git.nobla.cn/golang/aeus/pkg/proto/command";
message CommandOptions {

View File

@ -0,0 +1,269 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.6
// protoc v5.29.3
// source: rest.proto
package rest
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
descriptorpb "google.golang.org/protobuf/types/descriptorpb"
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 RestFieldOptions struct {
state protoimpl.MessageState `protogen:"open.v1"`
Gorm string `protobuf:"bytes,1,opt,name=gorm,proto3" json:"gorm,omitempty"`
Comment string `protobuf:"bytes,2,opt,name=comment,proto3" json:"comment,omitempty"`
Scenarios string `protobuf:"bytes,3,opt,name=scenarios,proto3" json:"scenarios,omitempty"`
Position string `protobuf:"bytes,4,opt,name=position,proto3" json:"position,omitempty"`
Format string `protobuf:"bytes,5,opt,name=format,proto3" json:"format,omitempty"`
Props string `protobuf:"bytes,6,opt,name=props,proto3" json:"props,omitempty"`
Rule string `protobuf:"bytes,7,opt,name=rule,proto3" json:"rule,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *RestFieldOptions) Reset() {
*x = RestFieldOptions{}
mi := &file_rest_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *RestFieldOptions) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RestFieldOptions) ProtoMessage() {}
func (x *RestFieldOptions) ProtoReflect() protoreflect.Message {
mi := &file_rest_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 RestFieldOptions.ProtoReflect.Descriptor instead.
func (*RestFieldOptions) Descriptor() ([]byte, []int) {
return file_rest_proto_rawDescGZIP(), []int{0}
}
func (x *RestFieldOptions) GetGorm() string {
if x != nil {
return x.Gorm
}
return ""
}
func (x *RestFieldOptions) GetComment() string {
if x != nil {
return x.Comment
}
return ""
}
func (x *RestFieldOptions) GetScenarios() string {
if x != nil {
return x.Scenarios
}
return ""
}
func (x *RestFieldOptions) GetPosition() string {
if x != nil {
return x.Position
}
return ""
}
func (x *RestFieldOptions) GetFormat() string {
if x != nil {
return x.Format
}
return ""
}
func (x *RestFieldOptions) GetProps() string {
if x != nil {
return x.Props
}
return ""
}
func (x *RestFieldOptions) GetRule() string {
if x != nil {
return x.Rule
}
return ""
}
type RestMessageOptions struct {
state protoimpl.MessageState `protogen:"open.v1"`
Table string `protobuf:"bytes,1,opt,name=table,proto3" json:"table,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *RestMessageOptions) Reset() {
*x = RestMessageOptions{}
mi := &file_rest_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *RestMessageOptions) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RestMessageOptions) ProtoMessage() {}
func (x *RestMessageOptions) ProtoReflect() protoreflect.Message {
mi := &file_rest_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 RestMessageOptions.ProtoReflect.Descriptor instead.
func (*RestMessageOptions) Descriptor() ([]byte, []int) {
return file_rest_proto_rawDescGZIP(), []int{1}
}
func (x *RestMessageOptions) GetTable() string {
if x != nil {
return x.Table
}
return ""
}
var file_rest_proto_extTypes = []protoimpl.ExtensionInfo{
{
ExtendedType: (*descriptorpb.FieldOptions)(nil),
ExtensionType: (*RestFieldOptions)(nil),
Field: 52118,
Name: "aeus.field",
Tag: "bytes,52118,opt,name=field",
Filename: "rest.proto",
},
{
ExtendedType: (*descriptorpb.MessageOptions)(nil),
ExtensionType: (*RestMessageOptions)(nil),
Field: 52119,
Name: "aeus.opts",
Tag: "bytes,52119,opt,name=opts",
Filename: "rest.proto",
},
}
// Extension fields to descriptorpb.FieldOptions.
var (
// ormable will cause orm code to be generated for this field
//
// optional aeus.RestFieldOptions field = 52118;
E_Field = &file_rest_proto_extTypes[0]
)
// Extension fields to descriptorpb.MessageOptions.
var (
// ormable will cause orm code to be generated for this message/object
//
// optional aeus.RestMessageOptions opts = 52119;
E_Opts = &file_rest_proto_extTypes[1]
)
var File_rest_proto protoreflect.FileDescriptor
const file_rest_proto_rawDesc = "" +
"\n" +
"\n" +
"rest.proto\x12\x04aeus\x1a google/protobuf/descriptor.proto\"\xbc\x01\n" +
"\x10RestFieldOptions\x12\x12\n" +
"\x04gorm\x18\x01 \x01(\tR\x04gorm\x12\x18\n" +
"\acomment\x18\x02 \x01(\tR\acomment\x12\x1c\n" +
"\tscenarios\x18\x03 \x01(\tR\tscenarios\x12\x1a\n" +
"\bposition\x18\x04 \x01(\tR\bposition\x12\x16\n" +
"\x06format\x18\x05 \x01(\tR\x06format\x12\x14\n" +
"\x05props\x18\x06 \x01(\tR\x05props\x12\x12\n" +
"\x04rule\x18\a \x01(\tR\x04rule\"*\n" +
"\x12RestMessageOptions\x12\x14\n" +
"\x05table\x18\x01 \x01(\tR\x05table:M\n" +
"\x05field\x12\x1d.google.protobuf.FieldOptions\x18\x96\x97\x03 \x01(\v2\x16.aeus.RestFieldOptionsR\x05field:O\n" +
"\x04opts\x12\x1f.google.protobuf.MessageOptions\x18\x97\x97\x03 \x01(\v2\x18.aeus.RestMessageOptionsR\x04optsB)Z'git.nobla.cn/golang/aeus/pkg/proto/restb\x06proto3"
var (
file_rest_proto_rawDescOnce sync.Once
file_rest_proto_rawDescData []byte
)
func file_rest_proto_rawDescGZIP() []byte {
file_rest_proto_rawDescOnce.Do(func() {
file_rest_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_rest_proto_rawDesc), len(file_rest_proto_rawDesc)))
})
return file_rest_proto_rawDescData
}
var file_rest_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_rest_proto_goTypes = []any{
(*RestFieldOptions)(nil), // 0: aeus.RestFieldOptions
(*RestMessageOptions)(nil), // 1: aeus.RestMessageOptions
(*descriptorpb.FieldOptions)(nil), // 2: google.protobuf.FieldOptions
(*descriptorpb.MessageOptions)(nil), // 3: google.protobuf.MessageOptions
}
var file_rest_proto_depIdxs = []int32{
2, // 0: aeus.field:extendee -> google.protobuf.FieldOptions
3, // 1: aeus.opts:extendee -> google.protobuf.MessageOptions
0, // 2: aeus.field:type_name -> aeus.RestFieldOptions
1, // 3: aeus.opts:type_name -> aeus.RestMessageOptions
4, // [4:4] is the sub-list for method output_type
4, // [4:4] is the sub-list for method input_type
2, // [2:4] is the sub-list for extension type_name
0, // [0:2] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_rest_proto_init() }
func file_rest_proto_init() {
if File_rest_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_rest_proto_rawDesc), len(file_rest_proto_rawDesc)),
NumEnums: 0,
NumMessages: 2,
NumExtensions: 2,
NumServices: 0,
},
GoTypes: file_rest_proto_goTypes,
DependencyIndexes: file_rest_proto_depIdxs,
MessageInfos: file_rest_proto_msgTypes,
ExtensionInfos: file_rest_proto_extTypes,
}.Build()
File_rest_proto = out.File
file_rest_proto_goTypes = nil
file_rest_proto_depIdxs = nil
}

View File

@ -0,0 +1,33 @@
syntax = "proto3";
package aeus;
import "google/protobuf/descriptor.proto";
option go_package = "git.nobla.cn/golang/aeus/pkg/proto/rest";
extend google.protobuf.FieldOptions {
// ormable will cause orm code to be generated for this field
RestFieldOptions field = 52118;
}
message RestFieldOptions {
string gorm = 1;
string comment = 2;
string scenarios= 3;
string position= 4;
string format = 5;
string props = 6;
string rule= 7;
}
extend google.protobuf.MessageOptions {
// ormable will cause orm code to be generated for this message/object
RestMessageOptions opts = 52119;
}
message RestMessageOptions {
string table = 1;
}

View File

@ -57,6 +57,8 @@ func (s *Server) unaryServerInterceptor() grpc.UnaryServerInterceptor {
ctx = metadata.MergeContext(ctx, md, true)
ctx = context.WithValue(ctx, requestValueContextKey{}, req)
err = h(ctx)
// grpcmd.AppendToOutgoingContext(ctx, grpcmd.New(metadata.FromContext(ctx)))
// grpc.SetHeader()
return
}
}

View File

@ -17,13 +17,13 @@ type (
// application scope interface.
Scope interface {
Init(ctx context.Context)
Run(ctx context.Context) (err error)
Init(ctx context.Context) (err error)
}
// service loader interface.
ServiceLoader interface {
Init(ctx context.Context)
Init(ctx context.Context) (err error)
Run(ctx context.Context) (err error)
}
// endpoint interface.