batman wrote basic implementation of client, needs more work but is usable for now
Brijesh Wawdhane ops@brijesh.dev
Fri, 27 Dec 2024 20:51:23 +0530
12 files changed,
8238 insertions(+),
0 deletions(-)
A
client.go
@@ -0,0 +1,73 @@
+package argus_client + +import ( + "context" + "errors" + "net/http" + + "github.com/wbrijesh/argus_client/rpc/logs" + + "time" + + "github.com/google/uuid" +) + +type Client struct { + apiKey string + client logs.LogsService +} + +type ClientConfig struct { + ApiKey string + BaseUrl string +} + +func NewClient(config ClientConfig) *Client { + return &Client{ + apiKey: config.ApiKey, + client: logs.NewLogsServiceProtobufClient(config.BaseUrl, &http.Client{}), + } +} + +type LogLevel logs.LogLevel + +const ( + LevelDebug LogLevel = LogLevel(logs.LogLevel_DEBUG) + LevelInfo LogLevel = LogLevel(logs.LogLevel_INFO) + LevelWarn LogLevel = LogLevel(logs.LogLevel_WARN) + LevelError LogLevel = LogLevel(logs.LogLevel_ERROR) + LevelFatal LogLevel = LogLevel(logs.LogLevel_FATAL) +) + +type LogEntry struct { + Level LogLevel + Message string +} + +func (c *Client) SendLogs(entries []LogEntry) error { + if len(entries) == 0 { + return nil + } else if len(entries) > 30 { + return errors.New("cannot send more than 30 logs at a time") + } + + ctx := context.Background() + + pbLogs := make([]*logs.LogEntry, len(entries)) + + for i, entry := range entries { + pbLogs[i] = &logs.LogEntry{ + LogId: uuid.New().String(), + Timestamp: time.Now().Format(time.RFC3339), + Level: logs.LogLevel(entry.Level), + Message: entry.Message, + } + } + + _, err := c.client.SendLogs(ctx, &logs.SendLogsRequest{ + ApiKey: c.apiKey, + Logs: pbLogs, + }) + + return err +}
A
go.mod
@@ -0,0 +1,11 @@
+module github.com/wbrijesh/argus_client + +go 1.23.3 + +require ( + github.com/google/uuid v1.6.0 + github.com/twitchtv/twirp v8.1.3+incompatible + google.golang.org/protobuf v1.36.1 +) + +require github.com/pkg/errors v0.9.1 // indirect
A
go.sum
@@ -0,0 +1,12 @@
+github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/twitchtv/twirp v8.1.3+incompatible h1:+F4TdErPgSUbMZMwp13Q/KgDVuI7HJXP61mNV3/7iuU= +github.com/twitchtv/twirp v8.1.3+incompatible/go.mod h1:RRJoFSAmTEh2weEqWtpPE3vFK5YBhA6bqp2l1kfCC5A= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk= +google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
A
rpc/applications/service.pb.go
@@ -0,0 +1,909 @@
+// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.35.2 +// protoc v5.29.1 +// source: rpc/applications/service.proto + +package applications + +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 Application struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + UserId string `protobuf:"bytes,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` + Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"` + CreatedAt string `protobuf:"bytes,5,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + UpdatedAt string `protobuf:"bytes,6,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"` +} + +func (x *Application) Reset() { + *x = Application{} + mi := &file_rpc_applications_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Application) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Application) ProtoMessage() {} + +func (x *Application) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_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 Application.ProtoReflect.Descriptor instead. +func (*Application) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{0} +} + +func (x *Application) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *Application) GetUserId() string { + if x != nil { + return x.UserId + } + return "" +} + +func (x *Application) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Application) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *Application) GetCreatedAt() string { + if x != nil { + return x.CreatedAt + } + return "" +} + +func (x *Application) GetUpdatedAt() string { + if x != nil { + return x.UpdatedAt + } + return "" +} + +type CreateApplicationRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` +} + +func (x *CreateApplicationRequest) Reset() { + *x = CreateApplicationRequest{} + mi := &file_rpc_applications_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CreateApplicationRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateApplicationRequest) ProtoMessage() {} + +func (x *CreateApplicationRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_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 CreateApplicationRequest.ProtoReflect.Descriptor instead. +func (*CreateApplicationRequest) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{1} +} + +func (x *CreateApplicationRequest) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *CreateApplicationRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *CreateApplicationRequest) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +type CreateApplicationResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Application *Application `protobuf:"bytes,1,opt,name=application,proto3" json:"application,omitempty"` + Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` // The API key for the application +} + +func (x *CreateApplicationResponse) Reset() { + *x = CreateApplicationResponse{} + mi := &file_rpc_applications_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CreateApplicationResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateApplicationResponse) ProtoMessage() {} + +func (x *CreateApplicationResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_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 CreateApplicationResponse.ProtoReflect.Descriptor instead. +func (*CreateApplicationResponse) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{2} +} + +func (x *CreateApplicationResponse) GetApplication() *Application { + if x != nil { + return x.Application + } + return nil +} + +func (x *CreateApplicationResponse) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +type ListApplicationsRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` +} + +func (x *ListApplicationsRequest) Reset() { + *x = ListApplicationsRequest{} + mi := &file_rpc_applications_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ListApplicationsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListApplicationsRequest) ProtoMessage() {} + +func (x *ListApplicationsRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_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 ListApplicationsRequest.ProtoReflect.Descriptor instead. +func (*ListApplicationsRequest) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{3} +} + +func (x *ListApplicationsRequest) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +type ListApplicationsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Applications []*Application `protobuf:"bytes,1,rep,name=applications,proto3" json:"applications,omitempty"` +} + +func (x *ListApplicationsResponse) Reset() { + *x = ListApplicationsResponse{} + mi := &file_rpc_applications_service_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ListApplicationsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListApplicationsResponse) ProtoMessage() {} + +func (x *ListApplicationsResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_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 ListApplicationsResponse.ProtoReflect.Descriptor instead. +func (*ListApplicationsResponse) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{4} +} + +func (x *ListApplicationsResponse) GetApplications() []*Application { + if x != nil { + return x.Applications + } + return nil +} + +type GetApplicationRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + ApplicationId string `protobuf:"bytes,2,opt,name=application_id,json=applicationId,proto3" json:"application_id,omitempty"` +} + +func (x *GetApplicationRequest) Reset() { + *x = GetApplicationRequest{} + mi := &file_rpc_applications_service_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetApplicationRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetApplicationRequest) ProtoMessage() {} + +func (x *GetApplicationRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_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 GetApplicationRequest.ProtoReflect.Descriptor instead. +func (*GetApplicationRequest) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{5} +} + +func (x *GetApplicationRequest) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *GetApplicationRequest) GetApplicationId() string { + if x != nil { + return x.ApplicationId + } + return "" +} + +type GetApplicationResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Application *Application `protobuf:"bytes,1,opt,name=application,proto3" json:"application,omitempty"` +} + +func (x *GetApplicationResponse) Reset() { + *x = GetApplicationResponse{} + mi := &file_rpc_applications_service_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetApplicationResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetApplicationResponse) ProtoMessage() {} + +func (x *GetApplicationResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_service_proto_msgTypes[6] + 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 GetApplicationResponse.ProtoReflect.Descriptor instead. +func (*GetApplicationResponse) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{6} +} + +func (x *GetApplicationResponse) GetApplication() *Application { + if x != nil { + return x.Application + } + return nil +} + +type UpdateApplicationRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + ApplicationId string `protobuf:"bytes,2,opt,name=application_id,json=applicationId,proto3" json:"application_id,omitempty"` + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` + Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"` +} + +func (x *UpdateApplicationRequest) Reset() { + *x = UpdateApplicationRequest{} + mi := &file_rpc_applications_service_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateApplicationRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateApplicationRequest) ProtoMessage() {} + +func (x *UpdateApplicationRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_service_proto_msgTypes[7] + 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 UpdateApplicationRequest.ProtoReflect.Descriptor instead. +func (*UpdateApplicationRequest) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{7} +} + +func (x *UpdateApplicationRequest) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *UpdateApplicationRequest) GetApplicationId() string { + if x != nil { + return x.ApplicationId + } + return "" +} + +func (x *UpdateApplicationRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *UpdateApplicationRequest) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +type UpdateApplicationResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Application *Application `protobuf:"bytes,1,opt,name=application,proto3" json:"application,omitempty"` +} + +func (x *UpdateApplicationResponse) Reset() { + *x = UpdateApplicationResponse{} + mi := &file_rpc_applications_service_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateApplicationResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateApplicationResponse) ProtoMessage() {} + +func (x *UpdateApplicationResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_service_proto_msgTypes[8] + 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 UpdateApplicationResponse.ProtoReflect.Descriptor instead. +func (*UpdateApplicationResponse) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{8} +} + +func (x *UpdateApplicationResponse) GetApplication() *Application { + if x != nil { + return x.Application + } + return nil +} + +type DeleteApplicationRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + ApplicationId string `protobuf:"bytes,2,opt,name=application_id,json=applicationId,proto3" json:"application_id,omitempty"` +} + +func (x *DeleteApplicationRequest) Reset() { + *x = DeleteApplicationRequest{} + mi := &file_rpc_applications_service_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DeleteApplicationRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteApplicationRequest) ProtoMessage() {} + +func (x *DeleteApplicationRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_service_proto_msgTypes[9] + 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 DeleteApplicationRequest.ProtoReflect.Descriptor instead. +func (*DeleteApplicationRequest) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{9} +} + +func (x *DeleteApplicationRequest) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *DeleteApplicationRequest) GetApplicationId() string { + if x != nil { + return x.ApplicationId + } + return "" +} + +type DeleteApplicationResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *DeleteApplicationResponse) Reset() { + *x = DeleteApplicationResponse{} + mi := &file_rpc_applications_service_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DeleteApplicationResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteApplicationResponse) ProtoMessage() {} + +func (x *DeleteApplicationResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_service_proto_msgTypes[10] + 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 DeleteApplicationResponse.ProtoReflect.Descriptor instead. +func (*DeleteApplicationResponse) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{10} +} + +type RegenerateKeyRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + ApplicationId string `protobuf:"bytes,2,opt,name=application_id,json=applicationId,proto3" json:"application_id,omitempty"` +} + +func (x *RegenerateKeyRequest) Reset() { + *x = RegenerateKeyRequest{} + mi := &file_rpc_applications_service_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RegenerateKeyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegenerateKeyRequest) ProtoMessage() {} + +func (x *RegenerateKeyRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_service_proto_msgTypes[11] + 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 RegenerateKeyRequest.ProtoReflect.Descriptor instead. +func (*RegenerateKeyRequest) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{11} +} + +func (x *RegenerateKeyRequest) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *RegenerateKeyRequest) GetApplicationId() string { + if x != nil { + return x.ApplicationId + } + return "" +} + +type RegenerateKeyResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` // The new API key +} + +func (x *RegenerateKeyResponse) Reset() { + *x = RegenerateKeyResponse{} + mi := &file_rpc_applications_service_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RegenerateKeyResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegenerateKeyResponse) ProtoMessage() {} + +func (x *RegenerateKeyResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_applications_service_proto_msgTypes[12] + 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 RegenerateKeyResponse.ProtoReflect.Descriptor instead. +func (*RegenerateKeyResponse) Descriptor() ([]byte, []int) { + return file_rpc_applications_service_proto_rawDescGZIP(), []int{12} +} + +func (x *RegenerateKeyResponse) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +var File_rpc_applications_service_proto protoreflect.FileDescriptor + +var file_rpc_applications_service_proto_rawDesc = []byte{ + 0x0a, 0x1e, 0x72, 0x70, 0x63, 0x2f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x0c, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0xaa, + 0x01, 0x0a, 0x0b, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0e, + 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x17, + 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, + 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, + 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1d, 0x0a, 0x0a, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x22, 0x66, 0x0a, 0x18, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x12, 0x0a, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, + 0x69, 0x6f, 0x6e, 0x22, 0x6a, 0x0a, 0x19, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x3b, 0x0a, 0x0b, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x52, 0x0b, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, + 0x2f, 0x0a, 0x17, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, + 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x22, 0x59, 0x0a, 0x18, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3d, 0x0a, 0x0c, + 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0c, 0x61, + 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x54, 0x0a, 0x15, 0x47, + 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x70, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0d, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, + 0x64, 0x22, 0x55, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x0b, 0x61, + 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x19, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, + 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x61, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x8d, 0x01, 0x0a, 0x18, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x61, + 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0d, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, + 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, + 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x58, 0x0a, 0x19, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x0b, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x61, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x22, 0x57, 0x0a, 0x18, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x70, 0x70, 0x6c, + 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, + 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, + 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x61, 0x70, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x1b, 0x0a, 0x19, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x53, 0x0a, 0x14, 0x52, 0x65, 0x67, 0x65, + 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, + 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x29, 0x0a, + 0x15, 0x52, 0x65, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x32, 0xe1, 0x04, 0x0a, 0x13, 0x41, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x12, 0x64, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, + 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, + 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x61, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x70, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x25, 0x2e, 0x61, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x70, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x26, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5b, 0x0a, 0x0e, 0x47, 0x65, 0x74, + 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x23, 0x2e, 0x61, 0x70, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x70, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x24, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, + 0x47, 0x65, 0x74, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x64, 0x0a, 0x11, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x2e, 0x61, 0x70, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x64, 0x0a, 0x11, + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x26, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x61, 0x70, 0x70, 0x6c, + 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, + 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x58, 0x0a, 0x0d, 0x52, 0x65, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, + 0x4b, 0x65, 0x79, 0x12, 0x22, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x2e, 0x52, 0x65, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x52, 0x65, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, + 0x65, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x1d, 0x5a, 0x1b, + 0x61, 0x72, 0x67, 0x75, 0x73, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x61, + 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_rpc_applications_service_proto_rawDescOnce sync.Once + file_rpc_applications_service_proto_rawDescData = file_rpc_applications_service_proto_rawDesc +) + +func file_rpc_applications_service_proto_rawDescGZIP() []byte { + file_rpc_applications_service_proto_rawDescOnce.Do(func() { + file_rpc_applications_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_rpc_applications_service_proto_rawDescData) + }) + return file_rpc_applications_service_proto_rawDescData +} + +var file_rpc_applications_service_proto_msgTypes = make([]protoimpl.MessageInfo, 13) +var file_rpc_applications_service_proto_goTypes = []any{ + (*Application)(nil), // 0: applications.Application + (*CreateApplicationRequest)(nil), // 1: applications.CreateApplicationRequest + (*CreateApplicationResponse)(nil), // 2: applications.CreateApplicationResponse + (*ListApplicationsRequest)(nil), // 3: applications.ListApplicationsRequest + (*ListApplicationsResponse)(nil), // 4: applications.ListApplicationsResponse + (*GetApplicationRequest)(nil), // 5: applications.GetApplicationRequest + (*GetApplicationResponse)(nil), // 6: applications.GetApplicationResponse + (*UpdateApplicationRequest)(nil), // 7: applications.UpdateApplicationRequest + (*UpdateApplicationResponse)(nil), // 8: applications.UpdateApplicationResponse + (*DeleteApplicationRequest)(nil), // 9: applications.DeleteApplicationRequest + (*DeleteApplicationResponse)(nil), // 10: applications.DeleteApplicationResponse + (*RegenerateKeyRequest)(nil), // 11: applications.RegenerateKeyRequest + (*RegenerateKeyResponse)(nil), // 12: applications.RegenerateKeyResponse +} +var file_rpc_applications_service_proto_depIdxs = []int32{ + 0, // 0: applications.CreateApplicationResponse.application:type_name -> applications.Application + 0, // 1: applications.ListApplicationsResponse.applications:type_name -> applications.Application + 0, // 2: applications.GetApplicationResponse.application:type_name -> applications.Application + 0, // 3: applications.UpdateApplicationResponse.application:type_name -> applications.Application + 1, // 4: applications.ApplicationsService.CreateApplication:input_type -> applications.CreateApplicationRequest + 3, // 5: applications.ApplicationsService.ListApplications:input_type -> applications.ListApplicationsRequest + 5, // 6: applications.ApplicationsService.GetApplication:input_type -> applications.GetApplicationRequest + 7, // 7: applications.ApplicationsService.UpdateApplication:input_type -> applications.UpdateApplicationRequest + 9, // 8: applications.ApplicationsService.DeleteApplication:input_type -> applications.DeleteApplicationRequest + 11, // 9: applications.ApplicationsService.RegenerateKey:input_type -> applications.RegenerateKeyRequest + 2, // 10: applications.ApplicationsService.CreateApplication:output_type -> applications.CreateApplicationResponse + 4, // 11: applications.ApplicationsService.ListApplications:output_type -> applications.ListApplicationsResponse + 6, // 12: applications.ApplicationsService.GetApplication:output_type -> applications.GetApplicationResponse + 8, // 13: applications.ApplicationsService.UpdateApplication:output_type -> applications.UpdateApplicationResponse + 10, // 14: applications.ApplicationsService.DeleteApplication:output_type -> applications.DeleteApplicationResponse + 12, // 15: applications.ApplicationsService.RegenerateKey:output_type -> applications.RegenerateKeyResponse + 10, // [10:16] is the sub-list for method output_type + 4, // [4:10] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name +} + +func init() { file_rpc_applications_service_proto_init() } +func file_rpc_applications_service_proto_init() { + if File_rpc_applications_service_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_rpc_applications_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 13, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_rpc_applications_service_proto_goTypes, + DependencyIndexes: file_rpc_applications_service_proto_depIdxs, + MessageInfos: file_rpc_applications_service_proto_msgTypes, + }.Build() + File_rpc_applications_service_proto = out.File + file_rpc_applications_service_proto_rawDesc = nil + file_rpc_applications_service_proto_goTypes = nil + file_rpc_applications_service_proto_depIdxs = nil +}
A
rpc/applications/service.proto
@@ -0,0 +1,77 @@
+syntax = "proto3"; + +package applications; +option go_package = "argus-core/rpc/applications"; + +service ApplicationsService { + rpc CreateApplication(CreateApplicationRequest) returns (CreateApplicationResponse); + rpc ListApplications(ListApplicationsRequest) returns (ListApplicationsResponse); + rpc GetApplication(GetApplicationRequest) returns (GetApplicationResponse); + rpc UpdateApplication(UpdateApplicationRequest) returns (UpdateApplicationResponse); + rpc DeleteApplication(DeleteApplicationRequest) returns (DeleteApplicationResponse); + rpc RegenerateKey(RegenerateKeyRequest) returns (RegenerateKeyResponse); +} + +message Application { + string id = 1; + string user_id = 2; + string name = 3; + string description = 4; + string created_at = 5; + string updated_at = 6; +} + +message CreateApplicationRequest { + string token = 1; + string name = 2; + string description = 3; +} + +message CreateApplicationResponse { + Application application = 1; + string key = 2; // The API key for the application +} + +message ListApplicationsRequest { + string token = 1; +} + +message ListApplicationsResponse { + repeated Application applications = 1; +} + +message GetApplicationRequest { + string token = 1; + string application_id = 2; +} + +message GetApplicationResponse { + Application application = 1; +} + +message UpdateApplicationRequest { + string token = 1; + string application_id = 2; + string name = 3; + string description = 4; +} + +message UpdateApplicationResponse { + Application application = 1; +} + +message DeleteApplicationRequest { + string token = 1; + string application_id = 2; +} + +message DeleteApplicationResponse {} + +message RegenerateKeyRequest { + string token = 1; + string application_id = 2; +} + +message RegenerateKeyResponse { + string key = 1; // The new API key +}
A
rpc/applications/service.twirp.go
@@ -0,0 +1,2518 @@
+// Code generated by protoc-gen-twirp v8.1.3, DO NOT EDIT. +// source: rpc/applications/service.proto + +package applications + +import context "context" +import fmt "fmt" +import http "net/http" +import io "io" +import json "encoding/json" +import strconv "strconv" +import strings "strings" + +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" +import twirp "github.com/twitchtv/twirp" +import ctxsetters "github.com/twitchtv/twirp/ctxsetters" + +import bytes "bytes" +import errors "errors" +import path "path" +import url "net/url" + +// Version compatibility assertion. +// If the constant is not defined in the package, that likely means +// the package needs to be updated to work with this generated code. +// See https://twitchtv.github.io/twirp/docs/version_matrix.html +const _ = twirp.TwirpPackageMinVersion_8_1_0 + +// ============================= +// ApplicationsService Interface +// ============================= + +type ApplicationsService interface { + CreateApplication(context.Context, *CreateApplicationRequest) (*CreateApplicationResponse, error) + + ListApplications(context.Context, *ListApplicationsRequest) (*ListApplicationsResponse, error) + + GetApplication(context.Context, *GetApplicationRequest) (*GetApplicationResponse, error) + + UpdateApplication(context.Context, *UpdateApplicationRequest) (*UpdateApplicationResponse, error) + + DeleteApplication(context.Context, *DeleteApplicationRequest) (*DeleteApplicationResponse, error) + + RegenerateKey(context.Context, *RegenerateKeyRequest) (*RegenerateKeyResponse, error) +} + +// =================================== +// ApplicationsService Protobuf Client +// =================================== + +type applicationsServiceProtobufClient struct { + client HTTPClient + urls [6]string + interceptor twirp.Interceptor + opts twirp.ClientOptions +} + +// NewApplicationsServiceProtobufClient creates a Protobuf client that implements the ApplicationsService interface. +// It communicates using Protobuf and can be configured with a custom HTTPClient. +func NewApplicationsServiceProtobufClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) ApplicationsService { + if c, ok := client.(*http.Client); ok { + client = withoutRedirects(c) + } + + clientOpts := twirp.ClientOptions{} + for _, o := range opts { + o(&clientOpts) + } + + // Using ReadOpt allows backwards and forwards compatibility with new options in the future + literalURLs := false + _ = clientOpts.ReadOpt("literalURLs", &literalURLs) + var pathPrefix string + if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok { + pathPrefix = "/twirp" // default prefix + } + + // Build method URLs: <baseURL>[<prefix>]/<package>.<Service>/<Method> + serviceURL := sanitizeBaseURL(baseURL) + serviceURL += baseServicePath(pathPrefix, "applications", "ApplicationsService") + urls := [6]string{ + serviceURL + "CreateApplication", + serviceURL + "ListApplications", + serviceURL + "GetApplication", + serviceURL + "UpdateApplication", + serviceURL + "DeleteApplication", + serviceURL + "RegenerateKey", + } + + return &applicationsServiceProtobufClient{ + client: client, + urls: urls, + interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...), + opts: clientOpts, + } +} + +func (c *applicationsServiceProtobufClient) CreateApplication(ctx context.Context, in *CreateApplicationRequest) (*CreateApplicationResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithMethodName(ctx, "CreateApplication") + caller := c.callCreateApplication + if c.interceptor != nil { + caller = func(ctx context.Context, req *CreateApplicationRequest) (*CreateApplicationResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*CreateApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*CreateApplicationRequest) when calling interceptor") + } + return c.callCreateApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*CreateApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*CreateApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *applicationsServiceProtobufClient) callCreateApplication(ctx context.Context, in *CreateApplicationRequest) (*CreateApplicationResponse, error) { + out := new(CreateApplicationResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[0], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *applicationsServiceProtobufClient) ListApplications(ctx context.Context, in *ListApplicationsRequest) (*ListApplicationsResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithMethodName(ctx, "ListApplications") + caller := c.callListApplications + if c.interceptor != nil { + caller = func(ctx context.Context, req *ListApplicationsRequest) (*ListApplicationsResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*ListApplicationsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*ListApplicationsRequest) when calling interceptor") + } + return c.callListApplications(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*ListApplicationsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*ListApplicationsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *applicationsServiceProtobufClient) callListApplications(ctx context.Context, in *ListApplicationsRequest) (*ListApplicationsResponse, error) { + out := new(ListApplicationsResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[1], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *applicationsServiceProtobufClient) GetApplication(ctx context.Context, in *GetApplicationRequest) (*GetApplicationResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithMethodName(ctx, "GetApplication") + caller := c.callGetApplication + if c.interceptor != nil { + caller = func(ctx context.Context, req *GetApplicationRequest) (*GetApplicationResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*GetApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*GetApplicationRequest) when calling interceptor") + } + return c.callGetApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*GetApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*GetApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *applicationsServiceProtobufClient) callGetApplication(ctx context.Context, in *GetApplicationRequest) (*GetApplicationResponse, error) { + out := new(GetApplicationResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[2], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *applicationsServiceProtobufClient) UpdateApplication(ctx context.Context, in *UpdateApplicationRequest) (*UpdateApplicationResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithMethodName(ctx, "UpdateApplication") + caller := c.callUpdateApplication + if c.interceptor != nil { + caller = func(ctx context.Context, req *UpdateApplicationRequest) (*UpdateApplicationResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*UpdateApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*UpdateApplicationRequest) when calling interceptor") + } + return c.callUpdateApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*UpdateApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*UpdateApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *applicationsServiceProtobufClient) callUpdateApplication(ctx context.Context, in *UpdateApplicationRequest) (*UpdateApplicationResponse, error) { + out := new(UpdateApplicationResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[3], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *applicationsServiceProtobufClient) DeleteApplication(ctx context.Context, in *DeleteApplicationRequest) (*DeleteApplicationResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithMethodName(ctx, "DeleteApplication") + caller := c.callDeleteApplication + if c.interceptor != nil { + caller = func(ctx context.Context, req *DeleteApplicationRequest) (*DeleteApplicationResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*DeleteApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*DeleteApplicationRequest) when calling interceptor") + } + return c.callDeleteApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*DeleteApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*DeleteApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *applicationsServiceProtobufClient) callDeleteApplication(ctx context.Context, in *DeleteApplicationRequest) (*DeleteApplicationResponse, error) { + out := new(DeleteApplicationResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[4], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *applicationsServiceProtobufClient) RegenerateKey(ctx context.Context, in *RegenerateKeyRequest) (*RegenerateKeyResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithMethodName(ctx, "RegenerateKey") + caller := c.callRegenerateKey + if c.interceptor != nil { + caller = func(ctx context.Context, req *RegenerateKeyRequest) (*RegenerateKeyResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*RegenerateKeyRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*RegenerateKeyRequest) when calling interceptor") + } + return c.callRegenerateKey(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*RegenerateKeyResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*RegenerateKeyResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *applicationsServiceProtobufClient) callRegenerateKey(ctx context.Context, in *RegenerateKeyRequest) (*RegenerateKeyResponse, error) { + out := new(RegenerateKeyResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[5], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +// =============================== +// ApplicationsService JSON Client +// =============================== + +type applicationsServiceJSONClient struct { + client HTTPClient + urls [6]string + interceptor twirp.Interceptor + opts twirp.ClientOptions +} + +// NewApplicationsServiceJSONClient creates a JSON client that implements the ApplicationsService interface. +// It communicates using JSON and can be configured with a custom HTTPClient. +func NewApplicationsServiceJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) ApplicationsService { + if c, ok := client.(*http.Client); ok { + client = withoutRedirects(c) + } + + clientOpts := twirp.ClientOptions{} + for _, o := range opts { + o(&clientOpts) + } + + // Using ReadOpt allows backwards and forwards compatibility with new options in the future + literalURLs := false + _ = clientOpts.ReadOpt("literalURLs", &literalURLs) + var pathPrefix string + if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok { + pathPrefix = "/twirp" // default prefix + } + + // Build method URLs: <baseURL>[<prefix>]/<package>.<Service>/<Method> + serviceURL := sanitizeBaseURL(baseURL) + serviceURL += baseServicePath(pathPrefix, "applications", "ApplicationsService") + urls := [6]string{ + serviceURL + "CreateApplication", + serviceURL + "ListApplications", + serviceURL + "GetApplication", + serviceURL + "UpdateApplication", + serviceURL + "DeleteApplication", + serviceURL + "RegenerateKey", + } + + return &applicationsServiceJSONClient{ + client: client, + urls: urls, + interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...), + opts: clientOpts, + } +} + +func (c *applicationsServiceJSONClient) CreateApplication(ctx context.Context, in *CreateApplicationRequest) (*CreateApplicationResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithMethodName(ctx, "CreateApplication") + caller := c.callCreateApplication + if c.interceptor != nil { + caller = func(ctx context.Context, req *CreateApplicationRequest) (*CreateApplicationResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*CreateApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*CreateApplicationRequest) when calling interceptor") + } + return c.callCreateApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*CreateApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*CreateApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *applicationsServiceJSONClient) callCreateApplication(ctx context.Context, in *CreateApplicationRequest) (*CreateApplicationResponse, error) { + out := new(CreateApplicationResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[0], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *applicationsServiceJSONClient) ListApplications(ctx context.Context, in *ListApplicationsRequest) (*ListApplicationsResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithMethodName(ctx, "ListApplications") + caller := c.callListApplications + if c.interceptor != nil { + caller = func(ctx context.Context, req *ListApplicationsRequest) (*ListApplicationsResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*ListApplicationsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*ListApplicationsRequest) when calling interceptor") + } + return c.callListApplications(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*ListApplicationsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*ListApplicationsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *applicationsServiceJSONClient) callListApplications(ctx context.Context, in *ListApplicationsRequest) (*ListApplicationsResponse, error) { + out := new(ListApplicationsResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[1], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *applicationsServiceJSONClient) GetApplication(ctx context.Context, in *GetApplicationRequest) (*GetApplicationResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithMethodName(ctx, "GetApplication") + caller := c.callGetApplication + if c.interceptor != nil { + caller = func(ctx context.Context, req *GetApplicationRequest) (*GetApplicationResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*GetApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*GetApplicationRequest) when calling interceptor") + } + return c.callGetApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*GetApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*GetApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *applicationsServiceJSONClient) callGetApplication(ctx context.Context, in *GetApplicationRequest) (*GetApplicationResponse, error) { + out := new(GetApplicationResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[2], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *applicationsServiceJSONClient) UpdateApplication(ctx context.Context, in *UpdateApplicationRequest) (*UpdateApplicationResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithMethodName(ctx, "UpdateApplication") + caller := c.callUpdateApplication + if c.interceptor != nil { + caller = func(ctx context.Context, req *UpdateApplicationRequest) (*UpdateApplicationResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*UpdateApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*UpdateApplicationRequest) when calling interceptor") + } + return c.callUpdateApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*UpdateApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*UpdateApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *applicationsServiceJSONClient) callUpdateApplication(ctx context.Context, in *UpdateApplicationRequest) (*UpdateApplicationResponse, error) { + out := new(UpdateApplicationResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[3], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *applicationsServiceJSONClient) DeleteApplication(ctx context.Context, in *DeleteApplicationRequest) (*DeleteApplicationResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithMethodName(ctx, "DeleteApplication") + caller := c.callDeleteApplication + if c.interceptor != nil { + caller = func(ctx context.Context, req *DeleteApplicationRequest) (*DeleteApplicationResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*DeleteApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*DeleteApplicationRequest) when calling interceptor") + } + return c.callDeleteApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*DeleteApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*DeleteApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *applicationsServiceJSONClient) callDeleteApplication(ctx context.Context, in *DeleteApplicationRequest) (*DeleteApplicationResponse, error) { + out := new(DeleteApplicationResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[4], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *applicationsServiceJSONClient) RegenerateKey(ctx context.Context, in *RegenerateKeyRequest) (*RegenerateKeyResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithMethodName(ctx, "RegenerateKey") + caller := c.callRegenerateKey + if c.interceptor != nil { + caller = func(ctx context.Context, req *RegenerateKeyRequest) (*RegenerateKeyResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*RegenerateKeyRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*RegenerateKeyRequest) when calling interceptor") + } + return c.callRegenerateKey(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*RegenerateKeyResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*RegenerateKeyResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *applicationsServiceJSONClient) callRegenerateKey(ctx context.Context, in *RegenerateKeyRequest) (*RegenerateKeyResponse, error) { + out := new(RegenerateKeyResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[5], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +// ================================== +// ApplicationsService Server Handler +// ================================== + +type applicationsServiceServer struct { + ApplicationsService + interceptor twirp.Interceptor + hooks *twirp.ServerHooks + pathPrefix string // prefix for routing + jsonSkipDefaults bool // do not include unpopulated fields (default values) in the response + jsonCamelCase bool // JSON fields are serialized as lowerCamelCase rather than keeping the original proto names +} + +// NewApplicationsServiceServer builds a TwirpServer that can be used as an http.Handler to handle +// HTTP requests that are routed to the right method in the provided svc implementation. +// The opts are twirp.ServerOption modifiers, for example twirp.WithServerHooks(hooks). +func NewApplicationsServiceServer(svc ApplicationsService, opts ...interface{}) TwirpServer { + serverOpts := newServerOpts(opts) + + // Using ReadOpt allows backwards and forwards compatibility with new options in the future + jsonSkipDefaults := false + _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) + jsonCamelCase := false + _ = serverOpts.ReadOpt("jsonCamelCase", &jsonCamelCase) + var pathPrefix string + if ok := serverOpts.ReadOpt("pathPrefix", &pathPrefix); !ok { + pathPrefix = "/twirp" // default prefix + } + + return &applicationsServiceServer{ + ApplicationsService: svc, + hooks: serverOpts.Hooks, + interceptor: twirp.ChainInterceptors(serverOpts.Interceptors...), + pathPrefix: pathPrefix, + jsonSkipDefaults: jsonSkipDefaults, + jsonCamelCase: jsonCamelCase, + } +} + +// writeError writes an HTTP response with a valid Twirp error format, and triggers hooks. +// If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err) +func (s *applicationsServiceServer) writeError(ctx context.Context, resp http.ResponseWriter, err error) { + writeError(ctx, resp, err, s.hooks) +} + +// handleRequestBodyError is used to handle error when the twirp server cannot read request +func (s *applicationsServiceServer) handleRequestBodyError(ctx context.Context, resp http.ResponseWriter, msg string, err error) { + if context.Canceled == ctx.Err() { + s.writeError(ctx, resp, twirp.NewError(twirp.Canceled, "failed to read request: context canceled")) + return + } + if context.DeadlineExceeded == ctx.Err() { + s.writeError(ctx, resp, twirp.NewError(twirp.DeadlineExceeded, "failed to read request: deadline exceeded")) + return + } + s.writeError(ctx, resp, twirp.WrapError(malformedRequestError(msg), err)) +} + +// ApplicationsServicePathPrefix is a convenience constant that may identify URL paths. +// Should be used with caution, it only matches routes generated by Twirp Go clients, +// with the default "/twirp" prefix and default CamelCase service and method names. +// More info: https://twitchtv.github.io/twirp/docs/routing.html +const ApplicationsServicePathPrefix = "/twirp/applications.ApplicationsService/" + +func (s *applicationsServiceServer) ServeHTTP(resp http.ResponseWriter, req *http.Request) { + ctx := req.Context() + ctx = ctxsetters.WithPackageName(ctx, "applications") + ctx = ctxsetters.WithServiceName(ctx, "ApplicationsService") + ctx = ctxsetters.WithResponseWriter(ctx, resp) + + var err error + ctx, err = callRequestReceived(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + if req.Method != "POST" { + msg := fmt.Sprintf("unsupported method %q (only POST is allowed)", req.Method) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } + + // Verify path format: [<prefix>]/<package>.<Service>/<Method> + prefix, pkgService, method := parseTwirpPath(req.URL.Path) + if pkgService != "applications.ApplicationsService" { + msg := fmt.Sprintf("no handler for path %q", req.URL.Path) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } + if prefix != s.pathPrefix { + msg := fmt.Sprintf("invalid path prefix %q, expected %q, on path %q", prefix, s.pathPrefix, req.URL.Path) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } + + switch method { + case "CreateApplication": + s.serveCreateApplication(ctx, resp, req) + return + case "ListApplications": + s.serveListApplications(ctx, resp, req) + return + case "GetApplication": + s.serveGetApplication(ctx, resp, req) + return + case "UpdateApplication": + s.serveUpdateApplication(ctx, resp, req) + return + case "DeleteApplication": + s.serveDeleteApplication(ctx, resp, req) + return + case "RegenerateKey": + s.serveRegenerateKey(ctx, resp, req) + return + default: + msg := fmt.Sprintf("no handler for path %q", req.URL.Path) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } +} + +func (s *applicationsServiceServer) serveCreateApplication(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveCreateApplicationJSON(ctx, resp, req) + case "application/protobuf": + s.serveCreateApplicationProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *applicationsServiceServer) serveCreateApplicationJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "CreateApplication") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(CreateApplicationRequest) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.ApplicationsService.CreateApplication + if s.interceptor != nil { + handler = func(ctx context.Context, req *CreateApplicationRequest) (*CreateApplicationResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*CreateApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*CreateApplicationRequest) when calling interceptor") + } + return s.ApplicationsService.CreateApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*CreateApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*CreateApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *CreateApplicationResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *CreateApplicationResponse and nil error while calling CreateApplication. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *applicationsServiceServer) serveCreateApplicationProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "CreateApplication") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := io.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(CreateApplicationRequest) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.ApplicationsService.CreateApplication + if s.interceptor != nil { + handler = func(ctx context.Context, req *CreateApplicationRequest) (*CreateApplicationResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*CreateApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*CreateApplicationRequest) when calling interceptor") + } + return s.ApplicationsService.CreateApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*CreateApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*CreateApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *CreateApplicationResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *CreateApplicationResponse and nil error while calling CreateApplication. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *applicationsServiceServer) serveListApplications(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveListApplicationsJSON(ctx, resp, req) + case "application/protobuf": + s.serveListApplicationsProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *applicationsServiceServer) serveListApplicationsJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "ListApplications") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(ListApplicationsRequest) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.ApplicationsService.ListApplications + if s.interceptor != nil { + handler = func(ctx context.Context, req *ListApplicationsRequest) (*ListApplicationsResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*ListApplicationsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*ListApplicationsRequest) when calling interceptor") + } + return s.ApplicationsService.ListApplications(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*ListApplicationsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*ListApplicationsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *ListApplicationsResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *ListApplicationsResponse and nil error while calling ListApplications. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *applicationsServiceServer) serveListApplicationsProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "ListApplications") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := io.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(ListApplicationsRequest) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.ApplicationsService.ListApplications + if s.interceptor != nil { + handler = func(ctx context.Context, req *ListApplicationsRequest) (*ListApplicationsResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*ListApplicationsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*ListApplicationsRequest) when calling interceptor") + } + return s.ApplicationsService.ListApplications(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*ListApplicationsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*ListApplicationsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *ListApplicationsResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *ListApplicationsResponse and nil error while calling ListApplications. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *applicationsServiceServer) serveGetApplication(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveGetApplicationJSON(ctx, resp, req) + case "application/protobuf": + s.serveGetApplicationProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *applicationsServiceServer) serveGetApplicationJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "GetApplication") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(GetApplicationRequest) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.ApplicationsService.GetApplication + if s.interceptor != nil { + handler = func(ctx context.Context, req *GetApplicationRequest) (*GetApplicationResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*GetApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*GetApplicationRequest) when calling interceptor") + } + return s.ApplicationsService.GetApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*GetApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*GetApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *GetApplicationResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *GetApplicationResponse and nil error while calling GetApplication. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *applicationsServiceServer) serveGetApplicationProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "GetApplication") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := io.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(GetApplicationRequest) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.ApplicationsService.GetApplication + if s.interceptor != nil { + handler = func(ctx context.Context, req *GetApplicationRequest) (*GetApplicationResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*GetApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*GetApplicationRequest) when calling interceptor") + } + return s.ApplicationsService.GetApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*GetApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*GetApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *GetApplicationResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *GetApplicationResponse and nil error while calling GetApplication. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *applicationsServiceServer) serveUpdateApplication(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveUpdateApplicationJSON(ctx, resp, req) + case "application/protobuf": + s.serveUpdateApplicationProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *applicationsServiceServer) serveUpdateApplicationJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "UpdateApplication") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(UpdateApplicationRequest) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.ApplicationsService.UpdateApplication + if s.interceptor != nil { + handler = func(ctx context.Context, req *UpdateApplicationRequest) (*UpdateApplicationResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*UpdateApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*UpdateApplicationRequest) when calling interceptor") + } + return s.ApplicationsService.UpdateApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*UpdateApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*UpdateApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *UpdateApplicationResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *UpdateApplicationResponse and nil error while calling UpdateApplication. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *applicationsServiceServer) serveUpdateApplicationProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "UpdateApplication") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := io.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(UpdateApplicationRequest) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.ApplicationsService.UpdateApplication + if s.interceptor != nil { + handler = func(ctx context.Context, req *UpdateApplicationRequest) (*UpdateApplicationResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*UpdateApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*UpdateApplicationRequest) when calling interceptor") + } + return s.ApplicationsService.UpdateApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*UpdateApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*UpdateApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *UpdateApplicationResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *UpdateApplicationResponse and nil error while calling UpdateApplication. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *applicationsServiceServer) serveDeleteApplication(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveDeleteApplicationJSON(ctx, resp, req) + case "application/protobuf": + s.serveDeleteApplicationProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *applicationsServiceServer) serveDeleteApplicationJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "DeleteApplication") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(DeleteApplicationRequest) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.ApplicationsService.DeleteApplication + if s.interceptor != nil { + handler = func(ctx context.Context, req *DeleteApplicationRequest) (*DeleteApplicationResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*DeleteApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*DeleteApplicationRequest) when calling interceptor") + } + return s.ApplicationsService.DeleteApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*DeleteApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*DeleteApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *DeleteApplicationResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *DeleteApplicationResponse and nil error while calling DeleteApplication. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *applicationsServiceServer) serveDeleteApplicationProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "DeleteApplication") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := io.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(DeleteApplicationRequest) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.ApplicationsService.DeleteApplication + if s.interceptor != nil { + handler = func(ctx context.Context, req *DeleteApplicationRequest) (*DeleteApplicationResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*DeleteApplicationRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*DeleteApplicationRequest) when calling interceptor") + } + return s.ApplicationsService.DeleteApplication(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*DeleteApplicationResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*DeleteApplicationResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *DeleteApplicationResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *DeleteApplicationResponse and nil error while calling DeleteApplication. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *applicationsServiceServer) serveRegenerateKey(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveRegenerateKeyJSON(ctx, resp, req) + case "application/protobuf": + s.serveRegenerateKeyProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *applicationsServiceServer) serveRegenerateKeyJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "RegenerateKey") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(RegenerateKeyRequest) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.ApplicationsService.RegenerateKey + if s.interceptor != nil { + handler = func(ctx context.Context, req *RegenerateKeyRequest) (*RegenerateKeyResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*RegenerateKeyRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*RegenerateKeyRequest) when calling interceptor") + } + return s.ApplicationsService.RegenerateKey(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*RegenerateKeyResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*RegenerateKeyResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *RegenerateKeyResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *RegenerateKeyResponse and nil error while calling RegenerateKey. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *applicationsServiceServer) serveRegenerateKeyProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "RegenerateKey") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := io.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(RegenerateKeyRequest) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.ApplicationsService.RegenerateKey + if s.interceptor != nil { + handler = func(ctx context.Context, req *RegenerateKeyRequest) (*RegenerateKeyResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*RegenerateKeyRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*RegenerateKeyRequest) when calling interceptor") + } + return s.ApplicationsService.RegenerateKey(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*RegenerateKeyResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*RegenerateKeyResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *RegenerateKeyResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *RegenerateKeyResponse and nil error while calling RegenerateKey. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *applicationsServiceServer) ServiceDescriptor() ([]byte, int) { + return twirpFileDescriptor0, 0 +} + +func (s *applicationsServiceServer) ProtocGenTwirpVersion() string { + return "v8.1.3" +} + +// PathPrefix returns the base service path, in the form: "/<prefix>/<package>.<Service>/" +// that is everything in a Twirp route except for the <Method>. This can be used for routing, +// for example to identify the requests that are targeted to this service in a mux. +func (s *applicationsServiceServer) PathPrefix() string { + return baseServicePath(s.pathPrefix, "applications", "ApplicationsService") +} + +// ===== +// Utils +// ===== + +// HTTPClient is the interface used by generated clients to send HTTP requests. +// It is fulfilled by *(net/http).Client, which is sufficient for most users. +// Users can provide their own implementation for special retry policies. +// +// HTTPClient implementations should not follow redirects. Redirects are +// automatically disabled if *(net/http).Client is passed to client +// constructors. See the withoutRedirects function in this file for more +// details. +type HTTPClient interface { + Do(req *http.Request) (*http.Response, error) +} + +// TwirpServer is the interface generated server structs will support: they're +// HTTP handlers with additional methods for accessing metadata about the +// service. Those accessors are a low-level API for building reflection tools. +// Most people can think of TwirpServers as just http.Handlers. +type TwirpServer interface { + http.Handler + + // ServiceDescriptor returns gzipped bytes describing the .proto file that + // this service was generated from. Once unzipped, the bytes can be + // unmarshalled as a + // google.golang.org/protobuf/types/descriptorpb.FileDescriptorProto. + // + // The returned integer is the index of this particular service within that + // FileDescriptorProto's 'Service' slice of ServiceDescriptorProtos. This is a + // low-level field, expected to be used for reflection. + ServiceDescriptor() ([]byte, int) + + // ProtocGenTwirpVersion is the semantic version string of the version of + // twirp used to generate this file. + ProtocGenTwirpVersion() string + + // PathPrefix returns the HTTP URL path prefix for all methods handled by this + // service. This can be used with an HTTP mux to route Twirp requests. + // The path prefix is in the form: "/<prefix>/<package>.<Service>/" + // that is, everything in a Twirp route except for the <Method> at the end. + PathPrefix() string +} + +func newServerOpts(opts []interface{}) *twirp.ServerOptions { + serverOpts := &twirp.ServerOptions{} + for _, opt := range opts { + switch o := opt.(type) { + case twirp.ServerOption: + o(serverOpts) + case *twirp.ServerHooks: // backwards compatibility, allow to specify hooks as an argument + twirp.WithServerHooks(o)(serverOpts) + case nil: // backwards compatibility, allow nil value for the argument + continue + default: + panic(fmt.Sprintf("Invalid option type %T, please use a twirp.ServerOption", o)) + } + } + return serverOpts +} + +// WriteError writes an HTTP response with a valid Twirp error format (code, msg, meta). +// Useful outside of the Twirp server (e.g. http middleware), but does not trigger hooks. +// If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err) +func WriteError(resp http.ResponseWriter, err error) { + writeError(context.Background(), resp, err, nil) +} + +// writeError writes Twirp errors in the response and triggers hooks. +func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks *twirp.ServerHooks) { + // Convert to a twirp.Error. Non-twirp errors are converted to internal errors. + var twerr twirp.Error + if !errors.As(err, &twerr) { + twerr = twirp.InternalErrorWith(err) + } + + statusCode := twirp.ServerHTTPStatusFromErrorCode(twerr.Code()) + ctx = ctxsetters.WithStatusCode(ctx, statusCode) + ctx = callError(ctx, hooks, twerr) + + respBody := marshalErrorToJSON(twerr) + + resp.Header().Set("Content-Type", "application/json") // Error responses are always JSON + resp.Header().Set("Content-Length", strconv.Itoa(len(respBody))) + resp.WriteHeader(statusCode) // set HTTP status code and send response + + _, writeErr := resp.Write(respBody) + if writeErr != nil { + // We have three options here. We could log the error, call the Error + // hook, or just silently ignore the error. + // + // Logging is unacceptable because we don't have a user-controlled + // logger; writing out to stderr without permission is too rude. + // + // Calling the Error hook would confuse users: it would mean the Error + // hook got called twice for one request, which is likely to lead to + // duplicated log messages and metrics, no matter how well we document + // the behavior. + // + // Silently ignoring the error is our least-bad option. It's highly + // likely that the connection is broken and the original 'err' says + // so anyway. + _ = writeErr + } + + callResponseSent(ctx, hooks) +} + +// sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. +// If the URL is unparsable, the baseURL is returned unchanged. +func sanitizeBaseURL(baseURL string) string { + u, err := url.Parse(baseURL) + if err != nil { + return baseURL // invalid URL will fail later when making requests + } + if u.Scheme == "" { + u.Scheme = "http" + } + return u.String() +} + +// baseServicePath composes the path prefix for the service (without <Method>). +// e.g.: baseServicePath("/twirp", "my.pkg", "MyService") +// +// returns => "/twirp/my.pkg.MyService/" +// +// e.g.: baseServicePath("", "", "MyService") +// +// returns => "/MyService/" +func baseServicePath(prefix, pkg, service string) string { + fullServiceName := service + if pkg != "" { + fullServiceName = pkg + "." + service + } + return path.Join("/", prefix, fullServiceName) + "/" +} + +// parseTwirpPath extracts path components form a valid Twirp route. +// Expected format: "[<prefix>]/<package>.<Service>/<Method>" +// e.g.: prefix, pkgService, method := parseTwirpPath("/twirp/pkg.Svc/MakeHat") +func parseTwirpPath(path string) (string, string, string) { + parts := strings.Split(path, "/") + if len(parts) < 2 { + return "", "", "" + } + method := parts[len(parts)-1] + pkgService := parts[len(parts)-2] + prefix := strings.Join(parts[0:len(parts)-2], "/") + return prefix, pkgService, method +} + +// getCustomHTTPReqHeaders retrieves a copy of any headers that are set in +// a context through the twirp.WithHTTPRequestHeaders function. +// If there are no headers set, or if they have the wrong type, nil is returned. +func getCustomHTTPReqHeaders(ctx context.Context) http.Header { + header, ok := twirp.HTTPRequestHeaders(ctx) + if !ok || header == nil { + return nil + } + copied := make(http.Header) + for k, vv := range header { + if vv == nil { + copied[k] = nil + continue + } + copied[k] = make([]string, len(vv)) + copy(copied[k], vv) + } + return copied +} + +// newRequest makes an http.Request from a client, adding common headers. +func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType string) (*http.Request, error) { + req, err := http.NewRequest("POST", url, reqBody) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if customHeader := getCustomHTTPReqHeaders(ctx); customHeader != nil { + req.Header = customHeader + } + req.Header.Set("Accept", contentType) + req.Header.Set("Content-Type", contentType) + req.Header.Set("Twirp-Version", "v8.1.3") + return req, nil +} + +// JSON serialization for errors +type twerrJSON struct { + Code string `json:"code"` + Msg string `json:"msg"` + Meta map[string]string `json:"meta,omitempty"` +} + +// marshalErrorToJSON returns JSON from a twirp.Error, that can be used as HTTP error response body. +// If serialization fails, it will use a descriptive Internal error instead. +func marshalErrorToJSON(twerr twirp.Error) []byte { + // make sure that msg is not too large + msg := twerr.Msg() + if len(msg) > 1e6 { + msg = msg[:1e6] + } + + tj := twerrJSON{ + Code: string(twerr.Code()), + Msg: msg, + Meta: twerr.MetaMap(), + } + + buf, err := json.Marshal(&tj) + if err != nil { + buf = []byte("{\"type\": \"" + twirp.Internal + "\", \"msg\": \"There was an error but it could not be serialized into JSON\"}") // fallback + } + + return buf +} + +// errorFromResponse builds a twirp.Error from a non-200 HTTP response. +// If the response has a valid serialized Twirp error, then it's returned. +// If not, the response status code is used to generate a similar twirp +// error. See twirpErrorFromIntermediary for more info on intermediary errors. +func errorFromResponse(resp *http.Response) twirp.Error { + statusCode := resp.StatusCode + statusText := http.StatusText(statusCode) + + if isHTTPRedirect(statusCode) { + // Unexpected redirect: it must be an error from an intermediary. + // Twirp clients don't follow redirects automatically, Twirp only handles + // POST requests, redirects should only happen on GET and HEAD requests. + location := resp.Header.Get("Location") + msg := fmt.Sprintf("unexpected HTTP status code %d %q received, Location=%q", statusCode, statusText, location) + return twirpErrorFromIntermediary(statusCode, msg, location) + } + + respBodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + return wrapInternal(err, "failed to read server error response body") + } + + var tj twerrJSON + dec := json.NewDecoder(bytes.NewReader(respBodyBytes)) + dec.DisallowUnknownFields() + if err := dec.Decode(&tj); err != nil || tj.Code == "" { + // Invalid JSON response; it must be an error from an intermediary. + msg := fmt.Sprintf("Error from intermediary with HTTP status code %d %q", statusCode, statusText) + return twirpErrorFromIntermediary(statusCode, msg, string(respBodyBytes)) + } + + errorCode := twirp.ErrorCode(tj.Code) + if !twirp.IsValidErrorCode(errorCode) { + msg := "invalid type returned from server error response: " + tj.Code + return twirp.InternalError(msg).WithMeta("body", string(respBodyBytes)) + } + + twerr := twirp.NewError(errorCode, tj.Msg) + for k, v := range tj.Meta { + twerr = twerr.WithMeta(k, v) + } + return twerr +} + +// twirpErrorFromIntermediary maps HTTP errors from non-twirp sources to twirp errors. +// The mapping is similar to gRPC: https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md. +// Returned twirp Errors have some additional metadata for inspection. +func twirpErrorFromIntermediary(status int, msg string, bodyOrLocation string) twirp.Error { + var code twirp.ErrorCode + if isHTTPRedirect(status) { // 3xx + code = twirp.Internal + } else { + switch status { + case 400: // Bad Request + code = twirp.Internal + case 401: // Unauthorized + code = twirp.Unauthenticated + case 403: // Forbidden + code = twirp.PermissionDenied + case 404: // Not Found + code = twirp.BadRoute + case 429: // Too Many Requests + code = twirp.ResourceExhausted + case 502, 503, 504: // Bad Gateway, Service Unavailable, Gateway Timeout + code = twirp.Unavailable + default: // All other codes + code = twirp.Unknown + } + } + + twerr := twirp.NewError(code, msg) + twerr = twerr.WithMeta("http_error_from_intermediary", "true") // to easily know if this error was from intermediary + twerr = twerr.WithMeta("status_code", strconv.Itoa(status)) + if isHTTPRedirect(status) { + twerr = twerr.WithMeta("location", bodyOrLocation) + } else { + twerr = twerr.WithMeta("body", bodyOrLocation) + } + return twerr +} + +func isHTTPRedirect(status int) bool { + return status >= 300 && status <= 399 +} + +// wrapInternal wraps an error with a prefix as an Internal error. +// The original error cause is accessible by github.com/pkg/errors.Cause. +func wrapInternal(err error, prefix string) twirp.Error { + return twirp.InternalErrorWith(&wrappedError{prefix: prefix, cause: err}) +} + +type wrappedError struct { + prefix string + cause error +} + +func (e *wrappedError) Error() string { return e.prefix + ": " + e.cause.Error() } +func (e *wrappedError) Unwrap() error { return e.cause } // for go1.13 + errors.Is/As +func (e *wrappedError) Cause() error { return e.cause } // for github.com/pkg/errors + +// ensurePanicResponses makes sure that rpc methods causing a panic still result in a Twirp Internal +// error response (status 500), and error hooks are properly called with the panic wrapped as an error. +// The panic is re-raised so it can be handled normally with middleware. +func ensurePanicResponses(ctx context.Context, resp http.ResponseWriter, hooks *twirp.ServerHooks) { + if r := recover(); r != nil { + // Wrap the panic as an error so it can be passed to error hooks. + // The original error is accessible from error hooks, but not visible in the response. + err := errFromPanic(r) + twerr := &internalWithCause{msg: "Internal service panic", cause: err} + // Actually write the error + writeError(ctx, resp, twerr, hooks) + // If possible, flush the error to the wire. + f, ok := resp.(http.Flusher) + if ok { + f.Flush() + } + + panic(r) + } +} + +// errFromPanic returns the typed error if the recovered panic is an error, otherwise formats as error. +func errFromPanic(p interface{}) error { + if err, ok := p.(error); ok { + return err + } + return fmt.Errorf("panic: %v", p) +} + +// internalWithCause is a Twirp Internal error wrapping an original error cause, +// but the original error message is not exposed on Msg(). The original error +// can be checked with go1.13+ errors.Is/As, and also by (github.com/pkg/errors).Unwrap +type internalWithCause struct { + msg string + cause error +} + +func (e *internalWithCause) Unwrap() error { return e.cause } // for go1.13 + errors.Is/As +func (e *internalWithCause) Cause() error { return e.cause } // for github.com/pkg/errors +func (e *internalWithCause) Error() string { return e.msg + ": " + e.cause.Error() } +func (e *internalWithCause) Code() twirp.ErrorCode { return twirp.Internal } +func (e *internalWithCause) Msg() string { return e.msg } +func (e *internalWithCause) Meta(key string) string { return "" } +func (e *internalWithCause) MetaMap() map[string]string { return nil } +func (e *internalWithCause) WithMeta(key string, val string) twirp.Error { return e } + +// malformedRequestError is used when the twirp server cannot unmarshal a request +func malformedRequestError(msg string) twirp.Error { + return twirp.NewError(twirp.Malformed, msg) +} + +// badRouteError is used when the twirp server cannot route a request +func badRouteError(msg string, method, url string) twirp.Error { + err := twirp.NewError(twirp.BadRoute, msg) + err = err.WithMeta("twirp_invalid_route", method+" "+url) + return err +} + +// withoutRedirects makes sure that the POST request can not be redirected. +// The standard library will, by default, redirect requests (including POSTs) if it gets a 302 or +// 303 response, and also 301s in go1.8. It redirects by making a second request, changing the +// method to GET and removing the body. This produces very confusing error messages, so instead we +// set a redirect policy that always errors. This stops Go from executing the redirect. +// +// We have to be a little careful in case the user-provided http.Client has its own CheckRedirect +// policy - if so, we'll run through that policy first. +// +// Because this requires modifying the http.Client, we make a new copy of the client and return it. +func withoutRedirects(in *http.Client) *http.Client { + copy := *in + copy.CheckRedirect = func(req *http.Request, via []*http.Request) error { + if in.CheckRedirect != nil { + // Run the input's redirect if it exists, in case it has side effects, but ignore any error it + // returns, since we want to use ErrUseLastResponse. + err := in.CheckRedirect(req, via) + _ = err // Silly, but this makes sure generated code passes errcheck -blank, which some people use. + } + return http.ErrUseLastResponse + } + return © +} + +// doProtobufRequest makes a Protobuf request to the remote Twirp service. +func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.ClientHooks, url string, in, out proto.Message) (_ context.Context, err error) { + reqBodyBytes, err := proto.Marshal(in) + if err != nil { + return ctx, wrapInternal(err, "failed to marshal proto request") + } + reqBody := bytes.NewBuffer(reqBodyBytes) + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + req, err := newRequest(ctx, url, reqBody, "application/protobuf") + if err != nil { + return ctx, wrapInternal(err, "could not build request") + } + ctx, err = callClientRequestPrepared(ctx, hooks, req) + if err != nil { + return ctx, err + } + + req = req.WithContext(ctx) + resp, err := client.Do(req) + if err != nil { + return ctx, wrapInternal(err, "failed to do request") + } + defer func() { _ = resp.Body.Close() }() + + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + if resp.StatusCode != 200 { + return ctx, errorFromResponse(resp) + } + + respBodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + return ctx, wrapInternal(err, "failed to read response body") + } + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + if err = proto.Unmarshal(respBodyBytes, out); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal proto response") + } + return ctx, nil +} + +// doJSONRequest makes a JSON request to the remote Twirp service. +func doJSONRequest(ctx context.Context, client HTTPClient, hooks *twirp.ClientHooks, url string, in, out proto.Message) (_ context.Context, err error) { + marshaler := &protojson.MarshalOptions{UseProtoNames: true} + reqBytes, err := marshaler.Marshal(in) + if err != nil { + return ctx, wrapInternal(err, "failed to marshal json request") + } + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + req, err := newRequest(ctx, url, bytes.NewReader(reqBytes), "application/json") + if err != nil { + return ctx, wrapInternal(err, "could not build request") + } + ctx, err = callClientRequestPrepared(ctx, hooks, req) + if err != nil { + return ctx, err + } + + req = req.WithContext(ctx) + resp, err := client.Do(req) + if err != nil { + return ctx, wrapInternal(err, "failed to do request") + } + + defer func() { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = wrapInternal(cerr, "failed to close response body") + } + }() + + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + if resp.StatusCode != 200 { + return ctx, errorFromResponse(resp) + } + + d := json.NewDecoder(resp.Body) + rawRespBody := json.RawMessage{} + if err := d.Decode(&rawRespBody); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal json response") + } + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawRespBody, out); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal json response") + } + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + return ctx, nil +} + +// Call twirp.ServerHooks.RequestReceived if the hook is available +func callRequestReceived(ctx context.Context, h *twirp.ServerHooks) (context.Context, error) { + if h == nil || h.RequestReceived == nil { + return ctx, nil + } + return h.RequestReceived(ctx) +} + +// Call twirp.ServerHooks.RequestRouted if the hook is available +func callRequestRouted(ctx context.Context, h *twirp.ServerHooks) (context.Context, error) { + if h == nil || h.RequestRouted == nil { + return ctx, nil + } + return h.RequestRouted(ctx) +} + +// Call twirp.ServerHooks.ResponsePrepared if the hook is available +func callResponsePrepared(ctx context.Context, h *twirp.ServerHooks) context.Context { + if h == nil || h.ResponsePrepared == nil { + return ctx + } + return h.ResponsePrepared(ctx) +} + +// Call twirp.ServerHooks.ResponseSent if the hook is available +func callResponseSent(ctx context.Context, h *twirp.ServerHooks) { + if h == nil || h.ResponseSent == nil { + return + } + h.ResponseSent(ctx) +} + +// Call twirp.ServerHooks.Error if the hook is available +func callError(ctx context.Context, h *twirp.ServerHooks, err twirp.Error) context.Context { + if h == nil || h.Error == nil { + return ctx + } + return h.Error(ctx, err) +} + +func callClientResponseReceived(ctx context.Context, h *twirp.ClientHooks) { + if h == nil || h.ResponseReceived == nil { + return + } + h.ResponseReceived(ctx) +} + +func callClientRequestPrepared(ctx context.Context, h *twirp.ClientHooks, req *http.Request) (context.Context, error) { + if h == nil || h.RequestPrepared == nil { + return ctx, nil + } + return h.RequestPrepared(ctx, req) +} + +func callClientError(ctx context.Context, h *twirp.ClientHooks, err twirp.Error) { + if h == nil || h.Error == nil { + return + } + h.Error(ctx, err) +} + +var twirpFileDescriptor0 = []byte{ + // 512 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0xdd, 0x4e, 0x13, 0x41, + 0x14, 0xce, 0xb6, 0xa5, 0x86, 0x53, 0x69, 0xe8, 0x11, 0x64, 0x5a, 0x82, 0x69, 0x06, 0x41, 0xbd, + 0xb0, 0x4d, 0xf0, 0xd2, 0x78, 0x51, 0x35, 0x31, 0x44, 0xaf, 0x8a, 0x44, 0xd4, 0x0b, 0xb2, 0xee, + 0x1c, 0xc9, 0x0a, 0xee, 0xae, 0x33, 0x53, 0x13, 0x1e, 0xc2, 0x17, 0xf1, 0xad, 0x7c, 0x13, 0xd3, + 0xd9, 0x11, 0x66, 0x7f, 0x31, 0x64, 0xef, 0x76, 0xcf, 0xef, 0x37, 0xdf, 0x7e, 0xdf, 0x0e, 0x3c, + 0x90, 0x49, 0x30, 0xf5, 0x93, 0xe4, 0x22, 0x0c, 0x7c, 0x1d, 0xc6, 0x91, 0x9a, 0x2a, 0x92, 0x3f, + 0xc3, 0x80, 0x26, 0x89, 0x8c, 0x75, 0x8c, 0x77, 0xdd, 0x1c, 0xff, 0xed, 0x41, 0x6f, 0x76, 0x1d, + 0xc0, 0x3e, 0xb4, 0x42, 0xc1, 0xbc, 0xb1, 0xf7, 0x78, 0x75, 0xde, 0x0a, 0x05, 0x6e, 0xc1, 0x9d, + 0x85, 0x22, 0x79, 0x1a, 0x0a, 0xd6, 0x32, 0xc1, 0xee, 0xf2, 0xf5, 0x50, 0x20, 0x42, 0x27, 0xf2, + 0xbf, 0x13, 0x6b, 0x9b, 0xa8, 0x79, 0xc6, 0x31, 0xf4, 0x04, 0xa9, 0x40, 0x86, 0xc9, 0x72, 0x16, + 0xeb, 0x98, 0x94, 0x1b, 0xc2, 0x1d, 0x80, 0x40, 0x92, 0xaf, 0x49, 0x9c, 0xfa, 0x9a, 0xad, 0x98, + 0x82, 0x55, 0x1b, 0x99, 0xe9, 0x65, 0x7a, 0x91, 0x88, 0x7f, 0xe9, 0x6e, 0x9a, 0xb6, 0x91, 0x99, + 0xe6, 0x5f, 0x81, 0xbd, 0x32, 0xb5, 0x0e, 0xe2, 0x39, 0xfd, 0x58, 0x90, 0xd2, 0xb8, 0x01, 0x2b, + 0x3a, 0x3e, 0xa7, 0xc8, 0x62, 0x4f, 0x5f, 0xae, 0x50, 0xb6, 0xaa, 0x51, 0xb6, 0x0b, 0x28, 0xf9, + 0x37, 0x18, 0x96, 0xec, 0x51, 0x49, 0x1c, 0x29, 0xc2, 0xe7, 0xd0, 0x73, 0x18, 0x34, 0xeb, 0x7a, + 0x07, 0xc3, 0x89, 0xcb, 0xea, 0xc4, 0xed, 0x73, 0xab, 0x71, 0x1d, 0xda, 0xe7, 0x74, 0x69, 0xe1, + 0x2c, 0x1f, 0xf9, 0x14, 0xb6, 0xde, 0x85, 0x4a, 0x3b, 0x1d, 0xaa, 0xf6, 0x48, 0xfc, 0x23, 0xb0, + 0x62, 0x83, 0xc5, 0xf6, 0x02, 0x32, 0x5f, 0x97, 0x79, 0xe3, 0x76, 0x3d, 0xb8, 0xac, 0x18, 0xde, + 0xc3, 0xe6, 0x1b, 0xd2, 0xff, 0x4d, 0xee, 0x1e, 0xf4, 0x9d, 0xf6, 0x6b, 0x89, 0xac, 0x39, 0xd1, + 0x43, 0xc1, 0x8f, 0xe1, 0x7e, 0x7e, 0x6a, 0x03, 0x54, 0xf2, 0x5f, 0x1e, 0xb0, 0x63, 0x23, 0x8d, + 0x86, 0x01, 0xdf, 0x4e, 0xda, 0xfc, 0x04, 0x86, 0x25, 0x70, 0x9a, 0x38, 0xe9, 0x07, 0x60, 0xaf, + 0xe9, 0x82, 0x1a, 0x3f, 0x28, 0xdf, 0x86, 0x61, 0xc9, 0xe0, 0x14, 0x32, 0x3f, 0x82, 0x8d, 0x39, + 0x9d, 0x51, 0x44, 0xd2, 0xd7, 0xf4, 0x96, 0x2e, 0x1b, 0xd9, 0xf8, 0x04, 0x36, 0x73, 0x43, 0x2d, + 0x41, 0xd6, 0x18, 0xde, 0x95, 0x31, 0x0e, 0xfe, 0x74, 0xe0, 0x9e, 0x2b, 0xf2, 0xa3, 0xf4, 0x2f, + 0x86, 0x02, 0x06, 0x05, 0x73, 0xe2, 0x7e, 0x96, 0xca, 0xaa, 0xbf, 0xc4, 0xe8, 0xd1, 0x8d, 0x75, + 0x16, 0x8f, 0x0f, 0xeb, 0x79, 0x97, 0xe1, 0x5e, 0xb6, 0xb9, 0xc2, 0xb6, 0xa3, 0xfd, 0x9b, 0xca, + 0xec, 0x8a, 0xcf, 0xd0, 0xcf, 0xfa, 0x02, 0x77, 0xb3, 0x9d, 0xa5, 0x5e, 0x1c, 0x3d, 0xac, 0x2f, + 0xb2, 0xc3, 0x05, 0x0c, 0x0a, 0x6a, 0xcc, 0xb3, 0x54, 0xe5, 0x9e, 0x3c, 0x4b, 0xd5, 0xb2, 0x16, + 0x30, 0x28, 0x08, 0x28, 0xbf, 0xa5, 0x4a, 0xba, 0xf9, 0x2d, 0x95, 0x4a, 0xc4, 0x13, 0x58, 0xcb, + 0x88, 0x06, 0x79, 0xb6, 0xb3, 0x4c, 0xa6, 0xa3, 0xdd, 0xda, 0x9a, 0x74, 0xf2, 0xcb, 0x9d, 0x4f, + 0xdb, 0xbe, 0x3c, 0x5b, 0xa8, 0xa7, 0x41, 0x2c, 0x69, 0x9a, 0xbf, 0x38, 0xbf, 0x74, 0xcd, 0x8d, + 0xf9, 0xec, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x88, 0xdd, 0x06, 0xcd, 0x53, 0x07, 0x00, 0x00, +}
A
rpc/auth/service.pb.go
@@ -0,0 +1,501 @@
+// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.35.2 +// protoc v5.29.1 +// source: rpc/auth/service.proto + +package auth + +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) +) + +// Request and Response messages +type RegisterRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` + Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` +} + +func (x *RegisterRequest) Reset() { + *x = RegisterRequest{} + mi := &file_rpc_auth_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RegisterRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegisterRequest) ProtoMessage() {} + +func (x *RegisterRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_auth_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 RegisterRequest.ProtoReflect.Descriptor instead. +func (*RegisterRequest) Descriptor() ([]byte, []int) { + return file_rpc_auth_service_proto_rawDescGZIP(), []int{0} +} + +func (x *RegisterRequest) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +func (x *RegisterRequest) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +type RegisterResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` +} + +func (x *RegisterResponse) Reset() { + *x = RegisterResponse{} + mi := &file_rpc_auth_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RegisterResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RegisterResponse) ProtoMessage() {} + +func (x *RegisterResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_auth_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 RegisterResponse.ProtoReflect.Descriptor instead. +func (*RegisterResponse) Descriptor() ([]byte, []int) { + return file_rpc_auth_service_proto_rawDescGZIP(), []int{1} +} + +func (x *RegisterResponse) GetUser() *User { + if x != nil { + return x.User + } + return nil +} + +type LoginRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Email string `protobuf:"bytes,1,opt,name=email,proto3" json:"email,omitempty"` + Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` +} + +func (x *LoginRequest) Reset() { + *x = LoginRequest{} + mi := &file_rpc_auth_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LoginRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LoginRequest) ProtoMessage() {} + +func (x *LoginRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_auth_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 LoginRequest.ProtoReflect.Descriptor instead. +func (*LoginRequest) Descriptor() ([]byte, []int) { + return file_rpc_auth_service_proto_rawDescGZIP(), []int{2} +} + +func (x *LoginRequest) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +func (x *LoginRequest) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + +type LoginResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + User *User `protobuf:"bytes,2,opt,name=user,proto3" json:"user,omitempty"` +} + +func (x *LoginResponse) Reset() { + *x = LoginResponse{} + mi := &file_rpc_auth_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LoginResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LoginResponse) ProtoMessage() {} + +func (x *LoginResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_auth_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 LoginResponse.ProtoReflect.Descriptor instead. +func (*LoginResponse) Descriptor() ([]byte, []int) { + return file_rpc_auth_service_proto_rawDescGZIP(), []int{3} +} + +func (x *LoginResponse) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *LoginResponse) GetUser() *User { + if x != nil { + return x.User + } + return nil +} + +type ValidateTokenRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` +} + +func (x *ValidateTokenRequest) Reset() { + *x = ValidateTokenRequest{} + mi := &file_rpc_auth_service_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ValidateTokenRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ValidateTokenRequest) ProtoMessage() {} + +func (x *ValidateTokenRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_auth_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 ValidateTokenRequest.ProtoReflect.Descriptor instead. +func (*ValidateTokenRequest) Descriptor() ([]byte, []int) { + return file_rpc_auth_service_proto_rawDescGZIP(), []int{4} +} + +func (x *ValidateTokenRequest) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +type ValidateTokenResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` +} + +func (x *ValidateTokenResponse) Reset() { + *x = ValidateTokenResponse{} + mi := &file_rpc_auth_service_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ValidateTokenResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ValidateTokenResponse) ProtoMessage() {} + +func (x *ValidateTokenResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_auth_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 ValidateTokenResponse.ProtoReflect.Descriptor instead. +func (*ValidateTokenResponse) Descriptor() ([]byte, []int) { + return file_rpc_auth_service_proto_rawDescGZIP(), []int{5} +} + +func (x *ValidateTokenResponse) GetUser() *User { + if x != nil { + return x.User + } + return nil +} + +// Common messages +type User struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"` + CreatedAt string `protobuf:"bytes,3,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + UpdatedAt string `protobuf:"bytes,4,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"` +} + +func (x *User) Reset() { + *x = User{} + mi := &file_rpc_auth_service_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *User) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*User) ProtoMessage() {} + +func (x *User) ProtoReflect() protoreflect.Message { + mi := &file_rpc_auth_service_proto_msgTypes[6] + 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 User.ProtoReflect.Descriptor instead. +func (*User) Descriptor() ([]byte, []int) { + return file_rpc_auth_service_proto_rawDescGZIP(), []int{6} +} + +func (x *User) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *User) GetEmail() string { + if x != nil { + return x.Email + } + return "" +} + +func (x *User) GetCreatedAt() string { + if x != nil { + return x.CreatedAt + } + return "" +} + +func (x *User) GetUpdatedAt() string { + if x != nil { + return x.UpdatedAt + } + return "" +} + +var File_rpc_auth_service_proto protoreflect.FileDescriptor + +var file_rpc_auth_service_proto_rawDesc = []byte{ + 0x0a, 0x16, 0x72, 0x70, 0x63, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x61, 0x75, 0x74, 0x68, 0x22, 0x43, + 0x0a, 0x0f, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, + 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, + 0x6f, 0x72, 0x64, 0x22, 0x32, 0x0a, 0x10, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x55, 0x73, 0x65, + 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x40, 0x0a, 0x0c, 0x4c, 0x6f, 0x67, 0x69, 0x6e, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1a, 0x0a, + 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x45, 0x0a, 0x0d, 0x4c, 0x6f, 0x67, + 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, + 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, + 0x12, 0x1e, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, + 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, + 0x22, 0x2c, 0x0a, 0x14, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x54, 0x6f, 0x6b, 0x65, + 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, + 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x37, + 0x0a, 0x15, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x55, 0x73, 0x65, + 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x6a, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, + 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, + 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, + 0x5f, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x64, 0x41, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, + 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x64, 0x41, 0x74, 0x32, 0xc4, 0x01, 0x0a, 0x0b, 0x41, 0x75, 0x74, 0x68, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x39, 0x0a, 0x08, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x12, + 0x15, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x52, 0x65, + 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x30, + 0x0a, 0x05, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x12, 0x12, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x4c, + 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x61, 0x75, + 0x74, 0x68, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x48, 0x0a, 0x0d, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x54, 0x6f, 0x6b, 0x65, + 0x6e, 0x12, 0x1a, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, + 0x65, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, + 0x61, 0x75, 0x74, 0x68, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x54, 0x6f, 0x6b, + 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x15, 0x5a, 0x13, 0x61, 0x72, + 0x67, 0x75, 0x73, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x61, 0x75, 0x74, + 0x68, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_rpc_auth_service_proto_rawDescOnce sync.Once + file_rpc_auth_service_proto_rawDescData = file_rpc_auth_service_proto_rawDesc +) + +func file_rpc_auth_service_proto_rawDescGZIP() []byte { + file_rpc_auth_service_proto_rawDescOnce.Do(func() { + file_rpc_auth_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_rpc_auth_service_proto_rawDescData) + }) + return file_rpc_auth_service_proto_rawDescData +} + +var file_rpc_auth_service_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_rpc_auth_service_proto_goTypes = []any{ + (*RegisterRequest)(nil), // 0: auth.RegisterRequest + (*RegisterResponse)(nil), // 1: auth.RegisterResponse + (*LoginRequest)(nil), // 2: auth.LoginRequest + (*LoginResponse)(nil), // 3: auth.LoginResponse + (*ValidateTokenRequest)(nil), // 4: auth.ValidateTokenRequest + (*ValidateTokenResponse)(nil), // 5: auth.ValidateTokenResponse + (*User)(nil), // 6: auth.User +} +var file_rpc_auth_service_proto_depIdxs = []int32{ + 6, // 0: auth.RegisterResponse.user:type_name -> auth.User + 6, // 1: auth.LoginResponse.user:type_name -> auth.User + 6, // 2: auth.ValidateTokenResponse.user:type_name -> auth.User + 0, // 3: auth.AuthService.Register:input_type -> auth.RegisterRequest + 2, // 4: auth.AuthService.Login:input_type -> auth.LoginRequest + 4, // 5: auth.AuthService.ValidateToken:input_type -> auth.ValidateTokenRequest + 1, // 6: auth.AuthService.Register:output_type -> auth.RegisterResponse + 3, // 7: auth.AuthService.Login:output_type -> auth.LoginResponse + 5, // 8: auth.AuthService.ValidateToken:output_type -> auth.ValidateTokenResponse + 6, // [6:9] is the sub-list for method output_type + 3, // [3:6] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_rpc_auth_service_proto_init() } +func file_rpc_auth_service_proto_init() { + if File_rpc_auth_service_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_rpc_auth_service_proto_rawDesc, + NumEnums: 0, + NumMessages: 7, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_rpc_auth_service_proto_goTypes, + DependencyIndexes: file_rpc_auth_service_proto_depIdxs, + MessageInfos: file_rpc_auth_service_proto_msgTypes, + }.Build() + File_rpc_auth_service_proto = out.File + file_rpc_auth_service_proto_rawDesc = nil + file_rpc_auth_service_proto_goTypes = nil + file_rpc_auth_service_proto_depIdxs = nil +}
A
rpc/auth/service.proto
@@ -0,0 +1,44 @@
+syntax = "proto3"; + +package auth; +option go_package = "argus-core/rpc/auth"; + +service AuthService { + rpc Register(RegisterRequest) returns (RegisterResponse); + rpc Login(LoginRequest) returns (LoginResponse); + rpc ValidateToken(ValidateTokenRequest) returns (ValidateTokenResponse); +} + +message RegisterRequest { + string email = 1; + string password = 2; +} + +message RegisterResponse { + User user = 1; +} + +message LoginRequest { + string email = 1; + string password = 2; +} + +message LoginResponse { + string token = 1; + User user = 2; +} + +message ValidateTokenRequest { + string token = 1; +} + +message ValidateTokenResponse { + User user = 1; +} + +message User { + string id = 1; + string email = 2; + string created_at = 3; + string updated_at = 4; +}
A
rpc/auth/service.twirp.go
@@ -0,0 +1,1675 @@
+// Code generated by protoc-gen-twirp v8.1.3, DO NOT EDIT. +// source: rpc/auth/service.proto + +package auth + +import context "context" +import fmt "fmt" +import http "net/http" +import io "io" +import json "encoding/json" +import strconv "strconv" +import strings "strings" + +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" +import twirp "github.com/twitchtv/twirp" +import ctxsetters "github.com/twitchtv/twirp/ctxsetters" + +import bytes "bytes" +import errors "errors" +import path "path" +import url "net/url" + +// Version compatibility assertion. +// If the constant is not defined in the package, that likely means +// the package needs to be updated to work with this generated code. +// See https://twitchtv.github.io/twirp/docs/version_matrix.html +const _ = twirp.TwirpPackageMinVersion_8_1_0 + +// ===================== +// AuthService Interface +// ===================== + +// Authentication service handles user registration, login, and token validation. +type AuthService interface { + // Register creates a new user account + Register(context.Context, *RegisterRequest) (*RegisterResponse, error) + + // Login authenticates a user and returns a JWT token + Login(context.Context, *LoginRequest) (*LoginResponse, error) + + // ValidateToken checks if a JWT token is valid and returns user information + ValidateToken(context.Context, *ValidateTokenRequest) (*ValidateTokenResponse, error) +} + +// =========================== +// AuthService Protobuf Client +// =========================== + +type authServiceProtobufClient struct { + client HTTPClient + urls [3]string + interceptor twirp.Interceptor + opts twirp.ClientOptions +} + +// NewAuthServiceProtobufClient creates a Protobuf client that implements the AuthService interface. +// It communicates using Protobuf and can be configured with a custom HTTPClient. +func NewAuthServiceProtobufClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) AuthService { + if c, ok := client.(*http.Client); ok { + client = withoutRedirects(c) + } + + clientOpts := twirp.ClientOptions{} + for _, o := range opts { + o(&clientOpts) + } + + // Using ReadOpt allows backwards and forwards compatibility with new options in the future + literalURLs := false + _ = clientOpts.ReadOpt("literalURLs", &literalURLs) + var pathPrefix string + if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok { + pathPrefix = "/twirp" // default prefix + } + + // Build method URLs: <baseURL>[<prefix>]/<package>.<Service>/<Method> + serviceURL := sanitizeBaseURL(baseURL) + serviceURL += baseServicePath(pathPrefix, "auth", "AuthService") + urls := [3]string{ + serviceURL + "Register", + serviceURL + "Login", + serviceURL + "ValidateToken", + } + + return &authServiceProtobufClient{ + client: client, + urls: urls, + interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...), + opts: clientOpts, + } +} + +func (c *authServiceProtobufClient) Register(ctx context.Context, in *RegisterRequest) (*RegisterResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "auth") + ctx = ctxsetters.WithServiceName(ctx, "AuthService") + ctx = ctxsetters.WithMethodName(ctx, "Register") + caller := c.callRegister + if c.interceptor != nil { + caller = func(ctx context.Context, req *RegisterRequest) (*RegisterResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*RegisterRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*RegisterRequest) when calling interceptor") + } + return c.callRegister(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*RegisterResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*RegisterResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *authServiceProtobufClient) callRegister(ctx context.Context, in *RegisterRequest) (*RegisterResponse, error) { + out := new(RegisterResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[0], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *authServiceProtobufClient) Login(ctx context.Context, in *LoginRequest) (*LoginResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "auth") + ctx = ctxsetters.WithServiceName(ctx, "AuthService") + ctx = ctxsetters.WithMethodName(ctx, "Login") + caller := c.callLogin + if c.interceptor != nil { + caller = func(ctx context.Context, req *LoginRequest) (*LoginResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*LoginRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*LoginRequest) when calling interceptor") + } + return c.callLogin(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*LoginResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*LoginResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *authServiceProtobufClient) callLogin(ctx context.Context, in *LoginRequest) (*LoginResponse, error) { + out := new(LoginResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[1], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *authServiceProtobufClient) ValidateToken(ctx context.Context, in *ValidateTokenRequest) (*ValidateTokenResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "auth") + ctx = ctxsetters.WithServiceName(ctx, "AuthService") + ctx = ctxsetters.WithMethodName(ctx, "ValidateToken") + caller := c.callValidateToken + if c.interceptor != nil { + caller = func(ctx context.Context, req *ValidateTokenRequest) (*ValidateTokenResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*ValidateTokenRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*ValidateTokenRequest) when calling interceptor") + } + return c.callValidateToken(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*ValidateTokenResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*ValidateTokenResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *authServiceProtobufClient) callValidateToken(ctx context.Context, in *ValidateTokenRequest) (*ValidateTokenResponse, error) { + out := new(ValidateTokenResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[2], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +// ======================= +// AuthService JSON Client +// ======================= + +type authServiceJSONClient struct { + client HTTPClient + urls [3]string + interceptor twirp.Interceptor + opts twirp.ClientOptions +} + +// NewAuthServiceJSONClient creates a JSON client that implements the AuthService interface. +// It communicates using JSON and can be configured with a custom HTTPClient. +func NewAuthServiceJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) AuthService { + if c, ok := client.(*http.Client); ok { + client = withoutRedirects(c) + } + + clientOpts := twirp.ClientOptions{} + for _, o := range opts { + o(&clientOpts) + } + + // Using ReadOpt allows backwards and forwards compatibility with new options in the future + literalURLs := false + _ = clientOpts.ReadOpt("literalURLs", &literalURLs) + var pathPrefix string + if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok { + pathPrefix = "/twirp" // default prefix + } + + // Build method URLs: <baseURL>[<prefix>]/<package>.<Service>/<Method> + serviceURL := sanitizeBaseURL(baseURL) + serviceURL += baseServicePath(pathPrefix, "auth", "AuthService") + urls := [3]string{ + serviceURL + "Register", + serviceURL + "Login", + serviceURL + "ValidateToken", + } + + return &authServiceJSONClient{ + client: client, + urls: urls, + interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...), + opts: clientOpts, + } +} + +func (c *authServiceJSONClient) Register(ctx context.Context, in *RegisterRequest) (*RegisterResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "auth") + ctx = ctxsetters.WithServiceName(ctx, "AuthService") + ctx = ctxsetters.WithMethodName(ctx, "Register") + caller := c.callRegister + if c.interceptor != nil { + caller = func(ctx context.Context, req *RegisterRequest) (*RegisterResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*RegisterRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*RegisterRequest) when calling interceptor") + } + return c.callRegister(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*RegisterResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*RegisterResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *authServiceJSONClient) callRegister(ctx context.Context, in *RegisterRequest) (*RegisterResponse, error) { + out := new(RegisterResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[0], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *authServiceJSONClient) Login(ctx context.Context, in *LoginRequest) (*LoginResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "auth") + ctx = ctxsetters.WithServiceName(ctx, "AuthService") + ctx = ctxsetters.WithMethodName(ctx, "Login") + caller := c.callLogin + if c.interceptor != nil { + caller = func(ctx context.Context, req *LoginRequest) (*LoginResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*LoginRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*LoginRequest) when calling interceptor") + } + return c.callLogin(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*LoginResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*LoginResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *authServiceJSONClient) callLogin(ctx context.Context, in *LoginRequest) (*LoginResponse, error) { + out := new(LoginResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[1], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *authServiceJSONClient) ValidateToken(ctx context.Context, in *ValidateTokenRequest) (*ValidateTokenResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "auth") + ctx = ctxsetters.WithServiceName(ctx, "AuthService") + ctx = ctxsetters.WithMethodName(ctx, "ValidateToken") + caller := c.callValidateToken + if c.interceptor != nil { + caller = func(ctx context.Context, req *ValidateTokenRequest) (*ValidateTokenResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*ValidateTokenRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*ValidateTokenRequest) when calling interceptor") + } + return c.callValidateToken(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*ValidateTokenResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*ValidateTokenResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *authServiceJSONClient) callValidateToken(ctx context.Context, in *ValidateTokenRequest) (*ValidateTokenResponse, error) { + out := new(ValidateTokenResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[2], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +// ========================== +// AuthService Server Handler +// ========================== + +type authServiceServer struct { + AuthService + interceptor twirp.Interceptor + hooks *twirp.ServerHooks + pathPrefix string // prefix for routing + jsonSkipDefaults bool // do not include unpopulated fields (default values) in the response + jsonCamelCase bool // JSON fields are serialized as lowerCamelCase rather than keeping the original proto names +} + +// NewAuthServiceServer builds a TwirpServer that can be used as an http.Handler to handle +// HTTP requests that are routed to the right method in the provided svc implementation. +// The opts are twirp.ServerOption modifiers, for example twirp.WithServerHooks(hooks). +func NewAuthServiceServer(svc AuthService, opts ...interface{}) TwirpServer { + serverOpts := newServerOpts(opts) + + // Using ReadOpt allows backwards and forwards compatibility with new options in the future + jsonSkipDefaults := false + _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) + jsonCamelCase := false + _ = serverOpts.ReadOpt("jsonCamelCase", &jsonCamelCase) + var pathPrefix string + if ok := serverOpts.ReadOpt("pathPrefix", &pathPrefix); !ok { + pathPrefix = "/twirp" // default prefix + } + + return &authServiceServer{ + AuthService: svc, + hooks: serverOpts.Hooks, + interceptor: twirp.ChainInterceptors(serverOpts.Interceptors...), + pathPrefix: pathPrefix, + jsonSkipDefaults: jsonSkipDefaults, + jsonCamelCase: jsonCamelCase, + } +} + +// writeError writes an HTTP response with a valid Twirp error format, and triggers hooks. +// If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err) +func (s *authServiceServer) writeError(ctx context.Context, resp http.ResponseWriter, err error) { + writeError(ctx, resp, err, s.hooks) +} + +// handleRequestBodyError is used to handle error when the twirp server cannot read request +func (s *authServiceServer) handleRequestBodyError(ctx context.Context, resp http.ResponseWriter, msg string, err error) { + if context.Canceled == ctx.Err() { + s.writeError(ctx, resp, twirp.NewError(twirp.Canceled, "failed to read request: context canceled")) + return + } + if context.DeadlineExceeded == ctx.Err() { + s.writeError(ctx, resp, twirp.NewError(twirp.DeadlineExceeded, "failed to read request: deadline exceeded")) + return + } + s.writeError(ctx, resp, twirp.WrapError(malformedRequestError(msg), err)) +} + +// AuthServicePathPrefix is a convenience constant that may identify URL paths. +// Should be used with caution, it only matches routes generated by Twirp Go clients, +// with the default "/twirp" prefix and default CamelCase service and method names. +// More info: https://twitchtv.github.io/twirp/docs/routing.html +const AuthServicePathPrefix = "/twirp/auth.AuthService/" + +func (s *authServiceServer) ServeHTTP(resp http.ResponseWriter, req *http.Request) { + ctx := req.Context() + ctx = ctxsetters.WithPackageName(ctx, "auth") + ctx = ctxsetters.WithServiceName(ctx, "AuthService") + ctx = ctxsetters.WithResponseWriter(ctx, resp) + + var err error + ctx, err = callRequestReceived(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + if req.Method != "POST" { + msg := fmt.Sprintf("unsupported method %q (only POST is allowed)", req.Method) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } + + // Verify path format: [<prefix>]/<package>.<Service>/<Method> + prefix, pkgService, method := parseTwirpPath(req.URL.Path) + if pkgService != "auth.AuthService" { + msg := fmt.Sprintf("no handler for path %q", req.URL.Path) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } + if prefix != s.pathPrefix { + msg := fmt.Sprintf("invalid path prefix %q, expected %q, on path %q", prefix, s.pathPrefix, req.URL.Path) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } + + switch method { + case "Register": + s.serveRegister(ctx, resp, req) + return + case "Login": + s.serveLogin(ctx, resp, req) + return + case "ValidateToken": + s.serveValidateToken(ctx, resp, req) + return + default: + msg := fmt.Sprintf("no handler for path %q", req.URL.Path) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } +} + +func (s *authServiceServer) serveRegister(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveRegisterJSON(ctx, resp, req) + case "application/protobuf": + s.serveRegisterProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *authServiceServer) serveRegisterJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "Register") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(RegisterRequest) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.AuthService.Register + if s.interceptor != nil { + handler = func(ctx context.Context, req *RegisterRequest) (*RegisterResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*RegisterRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*RegisterRequest) when calling interceptor") + } + return s.AuthService.Register(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*RegisterResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*RegisterResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *RegisterResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *RegisterResponse and nil error while calling Register. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *authServiceServer) serveRegisterProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "Register") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := io.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(RegisterRequest) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.AuthService.Register + if s.interceptor != nil { + handler = func(ctx context.Context, req *RegisterRequest) (*RegisterResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*RegisterRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*RegisterRequest) when calling interceptor") + } + return s.AuthService.Register(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*RegisterResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*RegisterResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *RegisterResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *RegisterResponse and nil error while calling Register. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *authServiceServer) serveLogin(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveLoginJSON(ctx, resp, req) + case "application/protobuf": + s.serveLoginProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *authServiceServer) serveLoginJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "Login") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(LoginRequest) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.AuthService.Login + if s.interceptor != nil { + handler = func(ctx context.Context, req *LoginRequest) (*LoginResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*LoginRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*LoginRequest) when calling interceptor") + } + return s.AuthService.Login(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*LoginResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*LoginResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *LoginResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *LoginResponse and nil error while calling Login. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *authServiceServer) serveLoginProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "Login") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := io.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(LoginRequest) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.AuthService.Login + if s.interceptor != nil { + handler = func(ctx context.Context, req *LoginRequest) (*LoginResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*LoginRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*LoginRequest) when calling interceptor") + } + return s.AuthService.Login(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*LoginResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*LoginResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *LoginResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *LoginResponse and nil error while calling Login. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *authServiceServer) serveValidateToken(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveValidateTokenJSON(ctx, resp, req) + case "application/protobuf": + s.serveValidateTokenProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *authServiceServer) serveValidateTokenJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "ValidateToken") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(ValidateTokenRequest) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.AuthService.ValidateToken + if s.interceptor != nil { + handler = func(ctx context.Context, req *ValidateTokenRequest) (*ValidateTokenResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*ValidateTokenRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*ValidateTokenRequest) when calling interceptor") + } + return s.AuthService.ValidateToken(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*ValidateTokenResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*ValidateTokenResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *ValidateTokenResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *ValidateTokenResponse and nil error while calling ValidateToken. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *authServiceServer) serveValidateTokenProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "ValidateToken") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := io.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(ValidateTokenRequest) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.AuthService.ValidateToken + if s.interceptor != nil { + handler = func(ctx context.Context, req *ValidateTokenRequest) (*ValidateTokenResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*ValidateTokenRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*ValidateTokenRequest) when calling interceptor") + } + return s.AuthService.ValidateToken(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*ValidateTokenResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*ValidateTokenResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *ValidateTokenResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *ValidateTokenResponse and nil error while calling ValidateToken. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *authServiceServer) ServiceDescriptor() ([]byte, int) { + return twirpFileDescriptor0, 0 +} + +func (s *authServiceServer) ProtocGenTwirpVersion() string { + return "v8.1.3" +} + +// PathPrefix returns the base service path, in the form: "/<prefix>/<package>.<Service>/" +// that is everything in a Twirp route except for the <Method>. This can be used for routing, +// for example to identify the requests that are targeted to this service in a mux. +func (s *authServiceServer) PathPrefix() string { + return baseServicePath(s.pathPrefix, "auth", "AuthService") +} + +// ===== +// Utils +// ===== + +// HTTPClient is the interface used by generated clients to send HTTP requests. +// It is fulfilled by *(net/http).Client, which is sufficient for most users. +// Users can provide their own implementation for special retry policies. +// +// HTTPClient implementations should not follow redirects. Redirects are +// automatically disabled if *(net/http).Client is passed to client +// constructors. See the withoutRedirects function in this file for more +// details. +type HTTPClient interface { + Do(req *http.Request) (*http.Response, error) +} + +// TwirpServer is the interface generated server structs will support: they're +// HTTP handlers with additional methods for accessing metadata about the +// service. Those accessors are a low-level API for building reflection tools. +// Most people can think of TwirpServers as just http.Handlers. +type TwirpServer interface { + http.Handler + + // ServiceDescriptor returns gzipped bytes describing the .proto file that + // this service was generated from. Once unzipped, the bytes can be + // unmarshalled as a + // google.golang.org/protobuf/types/descriptorpb.FileDescriptorProto. + // + // The returned integer is the index of this particular service within that + // FileDescriptorProto's 'Service' slice of ServiceDescriptorProtos. This is a + // low-level field, expected to be used for reflection. + ServiceDescriptor() ([]byte, int) + + // ProtocGenTwirpVersion is the semantic version string of the version of + // twirp used to generate this file. + ProtocGenTwirpVersion() string + + // PathPrefix returns the HTTP URL path prefix for all methods handled by this + // service. This can be used with an HTTP mux to route Twirp requests. + // The path prefix is in the form: "/<prefix>/<package>.<Service>/" + // that is, everything in a Twirp route except for the <Method> at the end. + PathPrefix() string +} + +func newServerOpts(opts []interface{}) *twirp.ServerOptions { + serverOpts := &twirp.ServerOptions{} + for _, opt := range opts { + switch o := opt.(type) { + case twirp.ServerOption: + o(serverOpts) + case *twirp.ServerHooks: // backwards compatibility, allow to specify hooks as an argument + twirp.WithServerHooks(o)(serverOpts) + case nil: // backwards compatibility, allow nil value for the argument + continue + default: + panic(fmt.Sprintf("Invalid option type %T, please use a twirp.ServerOption", o)) + } + } + return serverOpts +} + +// WriteError writes an HTTP response with a valid Twirp error format (code, msg, meta). +// Useful outside of the Twirp server (e.g. http middleware), but does not trigger hooks. +// If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err) +func WriteError(resp http.ResponseWriter, err error) { + writeError(context.Background(), resp, err, nil) +} + +// writeError writes Twirp errors in the response and triggers hooks. +func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks *twirp.ServerHooks) { + // Convert to a twirp.Error. Non-twirp errors are converted to internal errors. + var twerr twirp.Error + if !errors.As(err, &twerr) { + twerr = twirp.InternalErrorWith(err) + } + + statusCode := twirp.ServerHTTPStatusFromErrorCode(twerr.Code()) + ctx = ctxsetters.WithStatusCode(ctx, statusCode) + ctx = callError(ctx, hooks, twerr) + + respBody := marshalErrorToJSON(twerr) + + resp.Header().Set("Content-Type", "application/json") // Error responses are always JSON + resp.Header().Set("Content-Length", strconv.Itoa(len(respBody))) + resp.WriteHeader(statusCode) // set HTTP status code and send response + + _, writeErr := resp.Write(respBody) + if writeErr != nil { + // We have three options here. We could log the error, call the Error + // hook, or just silently ignore the error. + // + // Logging is unacceptable because we don't have a user-controlled + // logger; writing out to stderr without permission is too rude. + // + // Calling the Error hook would confuse users: it would mean the Error + // hook got called twice for one request, which is likely to lead to + // duplicated log messages and metrics, no matter how well we document + // the behavior. + // + // Silently ignoring the error is our least-bad option. It's highly + // likely that the connection is broken and the original 'err' says + // so anyway. + _ = writeErr + } + + callResponseSent(ctx, hooks) +} + +// sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. +// If the URL is unparsable, the baseURL is returned unchanged. +func sanitizeBaseURL(baseURL string) string { + u, err := url.Parse(baseURL) + if err != nil { + return baseURL // invalid URL will fail later when making requests + } + if u.Scheme == "" { + u.Scheme = "http" + } + return u.String() +} + +// baseServicePath composes the path prefix for the service (without <Method>). +// e.g.: baseServicePath("/twirp", "my.pkg", "MyService") +// +// returns => "/twirp/my.pkg.MyService/" +// +// e.g.: baseServicePath("", "", "MyService") +// +// returns => "/MyService/" +func baseServicePath(prefix, pkg, service string) string { + fullServiceName := service + if pkg != "" { + fullServiceName = pkg + "." + service + } + return path.Join("/", prefix, fullServiceName) + "/" +} + +// parseTwirpPath extracts path components form a valid Twirp route. +// Expected format: "[<prefix>]/<package>.<Service>/<Method>" +// e.g.: prefix, pkgService, method := parseTwirpPath("/twirp/pkg.Svc/MakeHat") +func parseTwirpPath(path string) (string, string, string) { + parts := strings.Split(path, "/") + if len(parts) < 2 { + return "", "", "" + } + method := parts[len(parts)-1] + pkgService := parts[len(parts)-2] + prefix := strings.Join(parts[0:len(parts)-2], "/") + return prefix, pkgService, method +} + +// getCustomHTTPReqHeaders retrieves a copy of any headers that are set in +// a context through the twirp.WithHTTPRequestHeaders function. +// If there are no headers set, or if they have the wrong type, nil is returned. +func getCustomHTTPReqHeaders(ctx context.Context) http.Header { + header, ok := twirp.HTTPRequestHeaders(ctx) + if !ok || header == nil { + return nil + } + copied := make(http.Header) + for k, vv := range header { + if vv == nil { + copied[k] = nil + continue + } + copied[k] = make([]string, len(vv)) + copy(copied[k], vv) + } + return copied +} + +// newRequest makes an http.Request from a client, adding common headers. +func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType string) (*http.Request, error) { + req, err := http.NewRequest("POST", url, reqBody) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if customHeader := getCustomHTTPReqHeaders(ctx); customHeader != nil { + req.Header = customHeader + } + req.Header.Set("Accept", contentType) + req.Header.Set("Content-Type", contentType) + req.Header.Set("Twirp-Version", "v8.1.3") + return req, nil +} + +// JSON serialization for errors +type twerrJSON struct { + Code string `json:"code"` + Msg string `json:"msg"` + Meta map[string]string `json:"meta,omitempty"` +} + +// marshalErrorToJSON returns JSON from a twirp.Error, that can be used as HTTP error response body. +// If serialization fails, it will use a descriptive Internal error instead. +func marshalErrorToJSON(twerr twirp.Error) []byte { + // make sure that msg is not too large + msg := twerr.Msg() + if len(msg) > 1e6 { + msg = msg[:1e6] + } + + tj := twerrJSON{ + Code: string(twerr.Code()), + Msg: msg, + Meta: twerr.MetaMap(), + } + + buf, err := json.Marshal(&tj) + if err != nil { + buf = []byte("{\"type\": \"" + twirp.Internal + "\", \"msg\": \"There was an error but it could not be serialized into JSON\"}") // fallback + } + + return buf +} + +// errorFromResponse builds a twirp.Error from a non-200 HTTP response. +// If the response has a valid serialized Twirp error, then it's returned. +// If not, the response status code is used to generate a similar twirp +// error. See twirpErrorFromIntermediary for more info on intermediary errors. +func errorFromResponse(resp *http.Response) twirp.Error { + statusCode := resp.StatusCode + statusText := http.StatusText(statusCode) + + if isHTTPRedirect(statusCode) { + // Unexpected redirect: it must be an error from an intermediary. + // Twirp clients don't follow redirects automatically, Twirp only handles + // POST requests, redirects should only happen on GET and HEAD requests. + location := resp.Header.Get("Location") + msg := fmt.Sprintf("unexpected HTTP status code %d %q received, Location=%q", statusCode, statusText, location) + return twirpErrorFromIntermediary(statusCode, msg, location) + } + + respBodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + return wrapInternal(err, "failed to read server error response body") + } + + var tj twerrJSON + dec := json.NewDecoder(bytes.NewReader(respBodyBytes)) + dec.DisallowUnknownFields() + if err := dec.Decode(&tj); err != nil || tj.Code == "" { + // Invalid JSON response; it must be an error from an intermediary. + msg := fmt.Sprintf("Error from intermediary with HTTP status code %d %q", statusCode, statusText) + return twirpErrorFromIntermediary(statusCode, msg, string(respBodyBytes)) + } + + errorCode := twirp.ErrorCode(tj.Code) + if !twirp.IsValidErrorCode(errorCode) { + msg := "invalid type returned from server error response: " + tj.Code + return twirp.InternalError(msg).WithMeta("body", string(respBodyBytes)) + } + + twerr := twirp.NewError(errorCode, tj.Msg) + for k, v := range tj.Meta { + twerr = twerr.WithMeta(k, v) + } + return twerr +} + +// twirpErrorFromIntermediary maps HTTP errors from non-twirp sources to twirp errors. +// The mapping is similar to gRPC: https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md. +// Returned twirp Errors have some additional metadata for inspection. +func twirpErrorFromIntermediary(status int, msg string, bodyOrLocation string) twirp.Error { + var code twirp.ErrorCode + if isHTTPRedirect(status) { // 3xx + code = twirp.Internal + } else { + switch status { + case 400: // Bad Request + code = twirp.Internal + case 401: // Unauthorized + code = twirp.Unauthenticated + case 403: // Forbidden + code = twirp.PermissionDenied + case 404: // Not Found + code = twirp.BadRoute + case 429: // Too Many Requests + code = twirp.ResourceExhausted + case 502, 503, 504: // Bad Gateway, Service Unavailable, Gateway Timeout + code = twirp.Unavailable + default: // All other codes + code = twirp.Unknown + } + } + + twerr := twirp.NewError(code, msg) + twerr = twerr.WithMeta("http_error_from_intermediary", "true") // to easily know if this error was from intermediary + twerr = twerr.WithMeta("status_code", strconv.Itoa(status)) + if isHTTPRedirect(status) { + twerr = twerr.WithMeta("location", bodyOrLocation) + } else { + twerr = twerr.WithMeta("body", bodyOrLocation) + } + return twerr +} + +func isHTTPRedirect(status int) bool { + return status >= 300 && status <= 399 +} + +// wrapInternal wraps an error with a prefix as an Internal error. +// The original error cause is accessible by github.com/pkg/errors.Cause. +func wrapInternal(err error, prefix string) twirp.Error { + return twirp.InternalErrorWith(&wrappedError{prefix: prefix, cause: err}) +} + +type wrappedError struct { + prefix string + cause error +} + +func (e *wrappedError) Error() string { return e.prefix + ": " + e.cause.Error() } +func (e *wrappedError) Unwrap() error { return e.cause } // for go1.13 + errors.Is/As +func (e *wrappedError) Cause() error { return e.cause } // for github.com/pkg/errors + +// ensurePanicResponses makes sure that rpc methods causing a panic still result in a Twirp Internal +// error response (status 500), and error hooks are properly called with the panic wrapped as an error. +// The panic is re-raised so it can be handled normally with middleware. +func ensurePanicResponses(ctx context.Context, resp http.ResponseWriter, hooks *twirp.ServerHooks) { + if r := recover(); r != nil { + // Wrap the panic as an error so it can be passed to error hooks. + // The original error is accessible from error hooks, but not visible in the response. + err := errFromPanic(r) + twerr := &internalWithCause{msg: "Internal service panic", cause: err} + // Actually write the error + writeError(ctx, resp, twerr, hooks) + // If possible, flush the error to the wire. + f, ok := resp.(http.Flusher) + if ok { + f.Flush() + } + + panic(r) + } +} + +// errFromPanic returns the typed error if the recovered panic is an error, otherwise formats as error. +func errFromPanic(p interface{}) error { + if err, ok := p.(error); ok { + return err + } + return fmt.Errorf("panic: %v", p) +} + +// internalWithCause is a Twirp Internal error wrapping an original error cause, +// but the original error message is not exposed on Msg(). The original error +// can be checked with go1.13+ errors.Is/As, and also by (github.com/pkg/errors).Unwrap +type internalWithCause struct { + msg string + cause error +} + +func (e *internalWithCause) Unwrap() error { return e.cause } // for go1.13 + errors.Is/As +func (e *internalWithCause) Cause() error { return e.cause } // for github.com/pkg/errors +func (e *internalWithCause) Error() string { return e.msg + ": " + e.cause.Error() } +func (e *internalWithCause) Code() twirp.ErrorCode { return twirp.Internal } +func (e *internalWithCause) Msg() string { return e.msg } +func (e *internalWithCause) Meta(key string) string { return "" } +func (e *internalWithCause) MetaMap() map[string]string { return nil } +func (e *internalWithCause) WithMeta(key string, val string) twirp.Error { return e } + +// malformedRequestError is used when the twirp server cannot unmarshal a request +func malformedRequestError(msg string) twirp.Error { + return twirp.NewError(twirp.Malformed, msg) +} + +// badRouteError is used when the twirp server cannot route a request +func badRouteError(msg string, method, url string) twirp.Error { + err := twirp.NewError(twirp.BadRoute, msg) + err = err.WithMeta("twirp_invalid_route", method+" "+url) + return err +} + +// withoutRedirects makes sure that the POST request can not be redirected. +// The standard library will, by default, redirect requests (including POSTs) if it gets a 302 or +// 303 response, and also 301s in go1.8. It redirects by making a second request, changing the +// method to GET and removing the body. This produces very confusing error messages, so instead we +// set a redirect policy that always errors. This stops Go from executing the redirect. +// +// We have to be a little careful in case the user-provided http.Client has its own CheckRedirect +// policy - if so, we'll run through that policy first. +// +// Because this requires modifying the http.Client, we make a new copy of the client and return it. +func withoutRedirects(in *http.Client) *http.Client { + copy := *in + copy.CheckRedirect = func(req *http.Request, via []*http.Request) error { + if in.CheckRedirect != nil { + // Run the input's redirect if it exists, in case it has side effects, but ignore any error it + // returns, since we want to use ErrUseLastResponse. + err := in.CheckRedirect(req, via) + _ = err // Silly, but this makes sure generated code passes errcheck -blank, which some people use. + } + return http.ErrUseLastResponse + } + return © +} + +// doProtobufRequest makes a Protobuf request to the remote Twirp service. +func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.ClientHooks, url string, in, out proto.Message) (_ context.Context, err error) { + reqBodyBytes, err := proto.Marshal(in) + if err != nil { + return ctx, wrapInternal(err, "failed to marshal proto request") + } + reqBody := bytes.NewBuffer(reqBodyBytes) + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + req, err := newRequest(ctx, url, reqBody, "application/protobuf") + if err != nil { + return ctx, wrapInternal(err, "could not build request") + } + ctx, err = callClientRequestPrepared(ctx, hooks, req) + if err != nil { + return ctx, err + } + + req = req.WithContext(ctx) + resp, err := client.Do(req) + if err != nil { + return ctx, wrapInternal(err, "failed to do request") + } + defer func() { _ = resp.Body.Close() }() + + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + if resp.StatusCode != 200 { + return ctx, errorFromResponse(resp) + } + + respBodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + return ctx, wrapInternal(err, "failed to read response body") + } + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + if err = proto.Unmarshal(respBodyBytes, out); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal proto response") + } + return ctx, nil +} + +// doJSONRequest makes a JSON request to the remote Twirp service. +func doJSONRequest(ctx context.Context, client HTTPClient, hooks *twirp.ClientHooks, url string, in, out proto.Message) (_ context.Context, err error) { + marshaler := &protojson.MarshalOptions{UseProtoNames: true} + reqBytes, err := marshaler.Marshal(in) + if err != nil { + return ctx, wrapInternal(err, "failed to marshal json request") + } + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + req, err := newRequest(ctx, url, bytes.NewReader(reqBytes), "application/json") + if err != nil { + return ctx, wrapInternal(err, "could not build request") + } + ctx, err = callClientRequestPrepared(ctx, hooks, req) + if err != nil { + return ctx, err + } + + req = req.WithContext(ctx) + resp, err := client.Do(req) + if err != nil { + return ctx, wrapInternal(err, "failed to do request") + } + + defer func() { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = wrapInternal(cerr, "failed to close response body") + } + }() + + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + if resp.StatusCode != 200 { + return ctx, errorFromResponse(resp) + } + + d := json.NewDecoder(resp.Body) + rawRespBody := json.RawMessage{} + if err := d.Decode(&rawRespBody); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal json response") + } + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawRespBody, out); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal json response") + } + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + return ctx, nil +} + +// Call twirp.ServerHooks.RequestReceived if the hook is available +func callRequestReceived(ctx context.Context, h *twirp.ServerHooks) (context.Context, error) { + if h == nil || h.RequestReceived == nil { + return ctx, nil + } + return h.RequestReceived(ctx) +} + +// Call twirp.ServerHooks.RequestRouted if the hook is available +func callRequestRouted(ctx context.Context, h *twirp.ServerHooks) (context.Context, error) { + if h == nil || h.RequestRouted == nil { + return ctx, nil + } + return h.RequestRouted(ctx) +} + +// Call twirp.ServerHooks.ResponsePrepared if the hook is available +func callResponsePrepared(ctx context.Context, h *twirp.ServerHooks) context.Context { + if h == nil || h.ResponsePrepared == nil { + return ctx + } + return h.ResponsePrepared(ctx) +} + +// Call twirp.ServerHooks.ResponseSent if the hook is available +func callResponseSent(ctx context.Context, h *twirp.ServerHooks) { + if h == nil || h.ResponseSent == nil { + return + } + h.ResponseSent(ctx) +} + +// Call twirp.ServerHooks.Error if the hook is available +func callError(ctx context.Context, h *twirp.ServerHooks, err twirp.Error) context.Context { + if h == nil || h.Error == nil { + return ctx + } + return h.Error(ctx, err) +} + +func callClientResponseReceived(ctx context.Context, h *twirp.ClientHooks) { + if h == nil || h.ResponseReceived == nil { + return + } + h.ResponseReceived(ctx) +} + +func callClientRequestPrepared(ctx context.Context, h *twirp.ClientHooks, req *http.Request) (context.Context, error) { + if h == nil || h.RequestPrepared == nil { + return ctx, nil + } + return h.RequestPrepared(ctx, req) +} + +func callClientError(ctx context.Context, h *twirp.ClientHooks, err twirp.Error) { + if h == nil || h.Error == nil { + return + } + h.Error(ctx, err) +} + +var twirpFileDescriptor0 = []byte{ + // 338 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0xbb, 0x4e, 0x03, 0x31, + 0x10, 0x54, 0x8e, 0x0b, 0x4a, 0x36, 0x04, 0x90, 0xf3, 0x50, 0x74, 0x08, 0x84, 0xae, 0xa2, 0x80, + 0x04, 0x85, 0x02, 0xd1, 0x11, 0x10, 0x12, 0x05, 0xd5, 0xf1, 0x28, 0x68, 0x90, 0x39, 0xaf, 0x12, + 0x43, 0x88, 0x0f, 0x3f, 0xe0, 0x07, 0xf9, 0x30, 0x74, 0xb6, 0x2f, 0x2f, 0x82, 0x84, 0x28, 0x77, + 0x66, 0x3d, 0xbb, 0xb3, 0x63, 0x68, 0xcb, 0x2c, 0xed, 0x51, 0xa3, 0x47, 0x3d, 0x85, 0xf2, 0x83, + 0xa7, 0xd8, 0xcd, 0xa4, 0xd0, 0x82, 0x84, 0x39, 0x16, 0x5f, 0xc2, 0x56, 0x82, 0x43, 0xae, 0x34, + 0xca, 0x04, 0xdf, 0x0d, 0x2a, 0x4d, 0x9a, 0x50, 0xc6, 0x37, 0xca, 0xc7, 0x9d, 0xd2, 0x7e, 0xe9, + 0xa0, 0x9a, 0xb8, 0x82, 0x44, 0x50, 0xc9, 0xa8, 0x52, 0x9f, 0x42, 0xb2, 0x4e, 0x60, 0x89, 0x69, + 0x1d, 0xf7, 0x61, 0x7b, 0x26, 0xa2, 0x32, 0x31, 0x51, 0x48, 0xf6, 0x20, 0x34, 0x0a, 0xa5, 0x15, + 0xa9, 0xf5, 0xa1, 0x9b, 0x4f, 0xeb, 0xde, 0x2b, 0x94, 0x89, 0xc5, 0xe3, 0x73, 0xd8, 0xb8, 0x11, + 0x43, 0x3e, 0xf9, 0xff, 0xd4, 0x2b, 0xa8, 0x7b, 0x05, 0x3f, 0xb2, 0x09, 0x65, 0x2d, 0x5e, 0x71, + 0x52, 0x48, 0xd8, 0x62, 0xba, 0x48, 0xf0, 0xcb, 0x22, 0x87, 0xd0, 0x7c, 0xa0, 0x63, 0xce, 0xa8, + 0xc6, 0xbb, 0xfc, 0xc1, 0xdc, 0x42, 0x3f, 0xd5, 0xe2, 0x53, 0x68, 0x2d, 0x75, 0xff, 0xd1, 0xef, + 0x0b, 0x84, 0x79, 0x45, 0x36, 0x21, 0xe0, 0xcc, 0x6b, 0x06, 0x9c, 0xcd, 0x7c, 0x07, 0xf3, 0xbe, + 0x77, 0x01, 0x52, 0x89, 0x54, 0x23, 0x7b, 0xa2, 0xba, 0xb3, 0x66, 0xa9, 0xaa, 0x47, 0x06, 0x3a, + 0xa7, 0x4d, 0xc6, 0x0a, 0x3a, 0x74, 0xb4, 0x47, 0x06, 0xba, 0xff, 0x55, 0x82, 0xda, 0xc0, 0xe8, + 0xd1, 0xad, 0x0b, 0x9c, 0x9c, 0x41, 0xa5, 0xc8, 0x87, 0xb4, 0xdc, 0x66, 0x4b, 0xa1, 0x47, 0xed, + 0x65, 0xd8, 0xdb, 0x3a, 0x86, 0xb2, 0x3d, 0x32, 0x21, 0xae, 0x61, 0x3e, 0xb3, 0xa8, 0xb1, 0x80, + 0xf9, 0x17, 0xd7, 0x50, 0x5f, 0xb8, 0x10, 0x89, 0x5c, 0xd7, 0xaa, 0x23, 0x47, 0x3b, 0x2b, 0x39, + 0xa7, 0x74, 0xd1, 0x7a, 0x6c, 0x50, 0x39, 0x34, 0xea, 0x28, 0x15, 0x12, 0x7b, 0xc5, 0x37, 0x7e, + 0x5e, 0xb7, 0xff, 0xf7, 0xe4, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xc8, 0xd4, 0x3c, 0xb4, 0xd9, 0x02, + 0x00, 0x00, +}
A
rpc/logs/service.pb.go
@@ -0,0 +1,663 @@
+// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.35.2 +// protoc v5.29.1 +// source: rpc/logs/service.proto + +package logs + +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) +) + +// Log level enum +type LogLevel int32 + +const ( + LogLevel_UNKNOWN LogLevel = 0 + LogLevel_DEBUG LogLevel = 1 + LogLevel_INFO LogLevel = 2 + LogLevel_WARN LogLevel = 3 + LogLevel_ERROR LogLevel = 4 + LogLevel_FATAL LogLevel = 5 +) + +// Enum value maps for LogLevel. +var ( + LogLevel_name = map[int32]string{ + 0: "UNKNOWN", + 1: "DEBUG", + 2: "INFO", + 3: "WARN", + 4: "ERROR", + 5: "FATAL", + } + LogLevel_value = map[string]int32{ + "UNKNOWN": 0, + "DEBUG": 1, + "INFO": 2, + "WARN": 3, + "ERROR": 4, + "FATAL": 5, + } +) + +func (x LogLevel) Enum() *LogLevel { + p := new(LogLevel) + *p = x + return p +} + +func (x LogLevel) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (LogLevel) Descriptor() protoreflect.EnumDescriptor { + return file_rpc_logs_service_proto_enumTypes[0].Descriptor() +} + +func (LogLevel) Type() protoreflect.EnumType { + return &file_rpc_logs_service_proto_enumTypes[0] +} + +func (x LogLevel) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use LogLevel.Descriptor instead. +func (LogLevel) EnumDescriptor() ([]byte, []int) { + return file_rpc_logs_service_proto_rawDescGZIP(), []int{0} +} + +// Individual log entry +type LogEntry struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + LogId string `protobuf:"bytes,1,opt,name=log_id,json=logId,proto3" json:"log_id,omitempty"` + Timestamp string `protobuf:"bytes,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Level LogLevel `protobuf:"varint,3,opt,name=level,proto3,enum=logs.LogLevel" json:"level,omitempty"` + Message string `protobuf:"bytes,4,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *LogEntry) Reset() { + *x = LogEntry{} + mi := &file_rpc_logs_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LogEntry) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LogEntry) ProtoMessage() {} + +func (x *LogEntry) ProtoReflect() protoreflect.Message { + mi := &file_rpc_logs_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 LogEntry.ProtoReflect.Descriptor instead. +func (*LogEntry) Descriptor() ([]byte, []int) { + return file_rpc_logs_service_proto_rawDescGZIP(), []int{0} +} + +func (x *LogEntry) GetLogId() string { + if x != nil { + return x.LogId + } + return "" +} + +func (x *LogEntry) GetTimestamp() string { + if x != nil { + return x.Timestamp + } + return "" +} + +func (x *LogEntry) GetLevel() LogLevel { + if x != nil { + return x.Level + } + return LogLevel_UNKNOWN +} + +func (x *LogEntry) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type SendLogsRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ApiKey string `protobuf:"bytes,1,opt,name=api_key,json=apiKey,proto3" json:"api_key,omitempty"` // Application API key for authentication + Logs []*LogEntry `protobuf:"bytes,2,rep,name=logs,proto3" json:"logs,omitempty"` +} + +func (x *SendLogsRequest) Reset() { + *x = SendLogsRequest{} + mi := &file_rpc_logs_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SendLogsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SendLogsRequest) ProtoMessage() {} + +func (x *SendLogsRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_logs_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 SendLogsRequest.ProtoReflect.Descriptor instead. +func (*SendLogsRequest) Descriptor() ([]byte, []int) { + return file_rpc_logs_service_proto_rawDescGZIP(), []int{1} +} + +func (x *SendLogsRequest) GetApiKey() string { + if x != nil { + return x.ApiKey + } + return "" +} + +func (x *SendLogsRequest) GetLogs() []*LogEntry { + if x != nil { + return x.Logs + } + return nil +} + +type SendLogsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + AcceptedCount int32 `protobuf:"varint,1,opt,name=accepted_count,json=acceptedCount,proto3" json:"accepted_count,omitempty"` // Number of logs successfully stored +} + +func (x *SendLogsResponse) Reset() { + *x = SendLogsResponse{} + mi := &file_rpc_logs_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SendLogsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SendLogsResponse) ProtoMessage() {} + +func (x *SendLogsResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_logs_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 SendLogsResponse.ProtoReflect.Descriptor instead. +func (*SendLogsResponse) Descriptor() ([]byte, []int) { + return file_rpc_logs_service_proto_rawDescGZIP(), []int{2} +} + +func (x *SendLogsResponse) GetAcceptedCount() int32 { + if x != nil { + return x.AcceptedCount + } + return 0 +} + +type GetLogsRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` // User JWT token for authentication + ApplicationId string `protobuf:"bytes,2,opt,name=application_id,json=applicationId,proto3" json:"application_id,omitempty"` + PageSize int32 `protobuf:"varint,3,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"` // Number of logs per page (default/max: 100) + Cursor string `protobuf:"bytes,4,opt,name=cursor,proto3" json:"cursor,omitempty"` // Timestamp of the last log from previous page + LogLevel string `protobuf:"bytes,5,opt,name=log_level,json=logLevel,proto3" json:"log_level,omitempty"` // Optional: Filter by log level + StartTime string `protobuf:"bytes,6,opt,name=start_time,json=startTime,proto3" json:"start_time,omitempty"` // Optional: Start timestamp (RFC3339) + EndTime string `protobuf:"bytes,7,opt,name=end_time,json=endTime,proto3" json:"end_time,omitempty"` // Optional: End timestamp (RFC3339) +} + +func (x *GetLogsRequest) Reset() { + *x = GetLogsRequest{} + mi := &file_rpc_logs_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetLogsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetLogsRequest) ProtoMessage() {} + +func (x *GetLogsRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_logs_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 GetLogsRequest.ProtoReflect.Descriptor instead. +func (*GetLogsRequest) Descriptor() ([]byte, []int) { + return file_rpc_logs_service_proto_rawDescGZIP(), []int{3} +} + +func (x *GetLogsRequest) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *GetLogsRequest) GetApplicationId() string { + if x != nil { + return x.ApplicationId + } + return "" +} + +func (x *GetLogsRequest) GetPageSize() int32 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *GetLogsRequest) GetCursor() string { + if x != nil { + return x.Cursor + } + return "" +} + +func (x *GetLogsRequest) GetLogLevel() string { + if x != nil { + return x.LogLevel + } + return "" +} + +func (x *GetLogsRequest) GetStartTime() string { + if x != nil { + return x.StartTime + } + return "" +} + +func (x *GetLogsRequest) GetEndTime() string { + if x != nil { + return x.EndTime + } + return "" +} + +type GetLogsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Logs []*LogEntry `protobuf:"bytes,1,rep,name=logs,proto3" json:"logs,omitempty"` + HasMore bool `protobuf:"varint,2,opt,name=has_more,json=hasMore,proto3" json:"has_more,omitempty"` + NextCursor string `protobuf:"bytes,3,opt,name=next_cursor,json=nextCursor,proto3" json:"next_cursor,omitempty"` // Timestamp to use for the next page + TotalCount int32 `protobuf:"varint,4,opt,name=total_count,json=totalCount,proto3" json:"total_count,omitempty"` // Total number of logs matching the filter + ApplicationName string `protobuf:"bytes,5,opt,name=application_name,json=applicationName,proto3" json:"application_name,omitempty"` +} + +func (x *GetLogsResponse) Reset() { + *x = GetLogsResponse{} + mi := &file_rpc_logs_service_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetLogsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetLogsResponse) ProtoMessage() {} + +func (x *GetLogsResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_logs_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 GetLogsResponse.ProtoReflect.Descriptor instead. +func (*GetLogsResponse) Descriptor() ([]byte, []int) { + return file_rpc_logs_service_proto_rawDescGZIP(), []int{4} +} + +func (x *GetLogsResponse) GetLogs() []*LogEntry { + if x != nil { + return x.Logs + } + return nil +} + +func (x *GetLogsResponse) GetHasMore() bool { + if x != nil { + return x.HasMore + } + return false +} + +func (x *GetLogsResponse) GetNextCursor() string { + if x != nil { + return x.NextCursor + } + return "" +} + +func (x *GetLogsResponse) GetTotalCount() int32 { + if x != nil { + return x.TotalCount + } + return 0 +} + +func (x *GetLogsResponse) GetApplicationName() string { + if x != nil { + return x.ApplicationName + } + return "" +} + +type GenerateDummyLogsRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + ApplicationId string `protobuf:"bytes,2,opt,name=application_id,json=applicationId,proto3" json:"application_id,omitempty"` +} + +func (x *GenerateDummyLogsRequest) Reset() { + *x = GenerateDummyLogsRequest{} + mi := &file_rpc_logs_service_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GenerateDummyLogsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GenerateDummyLogsRequest) ProtoMessage() {} + +func (x *GenerateDummyLogsRequest) ProtoReflect() protoreflect.Message { + mi := &file_rpc_logs_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 GenerateDummyLogsRequest.ProtoReflect.Descriptor instead. +func (*GenerateDummyLogsRequest) Descriptor() ([]byte, []int) { + return file_rpc_logs_service_proto_rawDescGZIP(), []int{5} +} + +func (x *GenerateDummyLogsRequest) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *GenerateDummyLogsRequest) GetApplicationId() string { + if x != nil { + return x.ApplicationId + } + return "" +} + +type GenerateDummyLogsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + GeneratedCount int32 `protobuf:"varint,1,opt,name=generated_count,json=generatedCount,proto3" json:"generated_count,omitempty"` +} + +func (x *GenerateDummyLogsResponse) Reset() { + *x = GenerateDummyLogsResponse{} + mi := &file_rpc_logs_service_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GenerateDummyLogsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GenerateDummyLogsResponse) ProtoMessage() {} + +func (x *GenerateDummyLogsResponse) ProtoReflect() protoreflect.Message { + mi := &file_rpc_logs_service_proto_msgTypes[6] + 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 GenerateDummyLogsResponse.ProtoReflect.Descriptor instead. +func (*GenerateDummyLogsResponse) Descriptor() ([]byte, []int) { + return file_rpc_logs_service_proto_rawDescGZIP(), []int{6} +} + +func (x *GenerateDummyLogsResponse) GetGeneratedCount() int32 { + if x != nil { + return x.GeneratedCount + } + return 0 +} + +var File_rpc_logs_service_proto protoreflect.FileDescriptor + +var file_rpc_logs_service_proto_rawDesc = []byte{ + 0x0a, 0x16, 0x72, 0x70, 0x63, 0x2f, 0x6c, 0x6f, 0x67, 0x73, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x6c, 0x6f, 0x67, 0x73, 0x22, 0x7f, + 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x15, 0x0a, 0x06, 0x6c, 0x6f, + 0x67, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6c, 0x6f, 0x67, 0x49, + 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, + 0x24, 0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0e, + 0x2e, 0x6c, 0x6f, 0x67, 0x73, 0x2e, 0x4c, 0x6f, 0x67, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x52, 0x05, + 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, + 0x4e, 0x0a, 0x0f, 0x53, 0x65, 0x6e, 0x64, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x61, 0x70, 0x69, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x12, 0x22, 0x0a, 0x04, 0x6c, + 0x6f, 0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6c, 0x6f, 0x67, 0x73, + 0x2e, 0x4c, 0x6f, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, 0x6c, 0x6f, 0x67, 0x73, 0x22, + 0x39, 0x0a, 0x10, 0x53, 0x65, 0x6e, 0x64, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x5f, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x61, 0x63, 0x63, + 0x65, 0x70, 0x74, 0x65, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xd9, 0x01, 0x0a, 0x0e, 0x47, + 0x65, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, + 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, + 0x6b, 0x65, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x61, 0x70, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x61, + 0x67, 0x65, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, + 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x75, 0x72, 0x73, 0x6f, + 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x12, + 0x1b, 0x0a, 0x09, 0x6c, 0x6f, 0x67, 0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x6c, 0x6f, 0x67, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x1d, 0x0a, 0x0a, + 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x65, + 0x6e, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, + 0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x22, 0xbd, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x4c, 0x6f, + 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x04, 0x6c, 0x6f, + 0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6c, 0x6f, 0x67, 0x73, 0x2e, + 0x4c, 0x6f, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, 0x6c, 0x6f, 0x67, 0x73, 0x12, 0x19, + 0x0a, 0x08, 0x68, 0x61, 0x73, 0x5f, 0x6d, 0x6f, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x07, 0x68, 0x61, 0x73, 0x4d, 0x6f, 0x72, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x6e, 0x65, 0x78, + 0x74, 0x5f, 0x63, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x6e, 0x65, 0x78, 0x74, 0x43, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x74, 0x6f, + 0x74, 0x61, 0x6c, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x29, 0x0a, 0x10, 0x61, + 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x57, 0x0a, 0x18, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, + 0x74, 0x65, 0x44, 0x75, 0x6d, 0x6d, 0x79, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x70, 0x70, 0x6c, + 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0d, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, + 0x44, 0x0a, 0x19, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x44, 0x75, 0x6d, 0x6d, 0x79, + 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27, 0x0a, 0x0f, + 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, + 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x2a, 0x4c, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x4c, 0x65, 0x76, 0x65, + 0x6c, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x09, + 0x0a, 0x05, 0x44, 0x45, 0x42, 0x55, 0x47, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x49, 0x4e, 0x46, + 0x4f, 0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x57, 0x41, 0x52, 0x4e, 0x10, 0x03, 0x12, 0x09, 0x0a, + 0x05, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x04, 0x12, 0x09, 0x0a, 0x05, 0x46, 0x41, 0x54, 0x41, + 0x4c, 0x10, 0x05, 0x32, 0xd6, 0x01, 0x0a, 0x0b, 0x4c, 0x6f, 0x67, 0x73, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x39, 0x0a, 0x08, 0x53, 0x65, 0x6e, 0x64, 0x4c, 0x6f, 0x67, 0x73, 0x12, + 0x15, 0x2e, 0x6c, 0x6f, 0x67, 0x73, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x4c, 0x6f, 0x67, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x6c, 0x6f, 0x67, 0x73, 0x2e, 0x53, 0x65, + 0x6e, 0x64, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x36, + 0x0a, 0x07, 0x47, 0x65, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x12, 0x14, 0x2e, 0x6c, 0x6f, 0x67, 0x73, + 0x2e, 0x47, 0x65, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x15, 0x2e, 0x6c, 0x6f, 0x67, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x54, 0x0a, 0x11, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, + 0x74, 0x65, 0x44, 0x75, 0x6d, 0x6d, 0x79, 0x4c, 0x6f, 0x67, 0x73, 0x12, 0x1e, 0x2e, 0x6c, 0x6f, + 0x67, 0x73, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x44, 0x75, 0x6d, 0x6d, 0x79, + 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6c, 0x6f, + 0x67, 0x73, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x44, 0x75, 0x6d, 0x6d, 0x79, + 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x15, 0x5a, 0x13, + 0x61, 0x72, 0x67, 0x75, 0x73, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x6c, + 0x6f, 0x67, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_rpc_logs_service_proto_rawDescOnce sync.Once + file_rpc_logs_service_proto_rawDescData = file_rpc_logs_service_proto_rawDesc +) + +func file_rpc_logs_service_proto_rawDescGZIP() []byte { + file_rpc_logs_service_proto_rawDescOnce.Do(func() { + file_rpc_logs_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_rpc_logs_service_proto_rawDescData) + }) + return file_rpc_logs_service_proto_rawDescData +} + +var file_rpc_logs_service_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_rpc_logs_service_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_rpc_logs_service_proto_goTypes = []any{ + (LogLevel)(0), // 0: logs.LogLevel + (*LogEntry)(nil), // 1: logs.LogEntry + (*SendLogsRequest)(nil), // 2: logs.SendLogsRequest + (*SendLogsResponse)(nil), // 3: logs.SendLogsResponse + (*GetLogsRequest)(nil), // 4: logs.GetLogsRequest + (*GetLogsResponse)(nil), // 5: logs.GetLogsResponse + (*GenerateDummyLogsRequest)(nil), // 6: logs.GenerateDummyLogsRequest + (*GenerateDummyLogsResponse)(nil), // 7: logs.GenerateDummyLogsResponse +} +var file_rpc_logs_service_proto_depIdxs = []int32{ + 0, // 0: logs.LogEntry.level:type_name -> logs.LogLevel + 1, // 1: logs.SendLogsRequest.logs:type_name -> logs.LogEntry + 1, // 2: logs.GetLogsResponse.logs:type_name -> logs.LogEntry + 2, // 3: logs.LogsService.SendLogs:input_type -> logs.SendLogsRequest + 4, // 4: logs.LogsService.GetLogs:input_type -> logs.GetLogsRequest + 6, // 5: logs.LogsService.GenerateDummyLogs:input_type -> logs.GenerateDummyLogsRequest + 3, // 6: logs.LogsService.SendLogs:output_type -> logs.SendLogsResponse + 5, // 7: logs.LogsService.GetLogs:output_type -> logs.GetLogsResponse + 7, // 8: logs.LogsService.GenerateDummyLogs:output_type -> logs.GenerateDummyLogsResponse + 6, // [6:9] is the sub-list for method output_type + 3, // [3:6] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_rpc_logs_service_proto_init() } +func file_rpc_logs_service_proto_init() { + if File_rpc_logs_service_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_rpc_logs_service_proto_rawDesc, + NumEnums: 1, + NumMessages: 7, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_rpc_logs_service_proto_goTypes, + DependencyIndexes: file_rpc_logs_service_proto_depIdxs, + EnumInfos: file_rpc_logs_service_proto_enumTypes, + MessageInfos: file_rpc_logs_service_proto_msgTypes, + }.Build() + File_rpc_logs_service_proto = out.File + file_rpc_logs_service_proto_rawDesc = nil + file_rpc_logs_service_proto_goTypes = nil + file_rpc_logs_service_proto_depIdxs = nil +}
A
rpc/logs/service.proto
@@ -0,0 +1,64 @@
+syntax = "proto3"; + +package logs; +option go_package = "argus-core/rpc/logs"; + +service LogsService { + rpc SendLogs(SendLogsRequest) returns (SendLogsResponse); + rpc GetLogs(GetLogsRequest) returns (GetLogsResponse); + rpc GenerateDummyLogs(GenerateDummyLogsRequest) returns (GenerateDummyLogsResponse); +} + +// Log level enum +enum LogLevel { + UNKNOWN = 0; + DEBUG = 1; + INFO = 2; + WARN = 3; + ERROR = 4; + FATAL = 5; +} + +// Individual log entry +message LogEntry { + string log_id = 1; + string timestamp = 2; + LogLevel level = 3; + string message = 4; +} + +message SendLogsRequest { + string api_key = 1; // Application API key for authentication + repeated LogEntry logs = 2; +} + +message SendLogsResponse { + int32 accepted_count = 1; // Number of logs successfully stored +} + +message GetLogsRequest { + string token = 1; // User JWT token for authentication + string application_id = 2; + int32 page_size = 3; // Number of logs per page (default/max: 100) + string cursor = 4; // Timestamp of the last log from previous page + string log_level = 5; // Optional: Filter by log level + string start_time = 6; // Optional: Start timestamp (RFC3339) + string end_time = 7; // Optional: End timestamp (RFC3339) +} + +message GetLogsResponse { + repeated LogEntry logs = 1; + bool has_more = 2; + string next_cursor = 3; // Timestamp to use for the next page + int32 total_count = 4; // Total number of logs matching the filter + string application_name = 5; +} + +message GenerateDummyLogsRequest { + string token = 1; + string application_id = 2; +} + +message GenerateDummyLogsResponse { + int32 generated_count = 1; +}
A
rpc/logs/service.twirp.go
@@ -0,0 +1,1691 @@
+// Code generated by protoc-gen-twirp v8.1.3, DO NOT EDIT. +// source: rpc/logs/service.proto + +package logs + +import context "context" +import fmt "fmt" +import http "net/http" +import io "io" +import json "encoding/json" +import strconv "strconv" +import strings "strings" + +import protojson "google.golang.org/protobuf/encoding/protojson" +import proto "google.golang.org/protobuf/proto" +import twirp "github.com/twitchtv/twirp" +import ctxsetters "github.com/twitchtv/twirp/ctxsetters" + +import bytes "bytes" +import errors "errors" +import path "path" +import url "net/url" + +// Version compatibility assertion. +// If the constant is not defined in the package, that likely means +// the package needs to be updated to work with this generated code. +// See https://twitchtv.github.io/twirp/docs/version_matrix.html +const _ = twirp.TwirpPackageMinVersion_8_1_0 + +// ===================== +// LogsService Interface +// ===================== + +type LogsService interface { + // SendLogs allows batch insertion of logs for an application + SendLogs(context.Context, *SendLogsRequest) (*SendLogsResponse, error) + + // GetLogs retrieves recent logs for an application + GetLogs(context.Context, *GetLogsRequest) (*GetLogsResponse, error) + + // GenerateDummyLogs creates sample logs for testing + GenerateDummyLogs(context.Context, *GenerateDummyLogsRequest) (*GenerateDummyLogsResponse, error) +} + +// =========================== +// LogsService Protobuf Client +// =========================== + +type logsServiceProtobufClient struct { + client HTTPClient + urls [3]string + interceptor twirp.Interceptor + opts twirp.ClientOptions +} + +// NewLogsServiceProtobufClient creates a Protobuf client that implements the LogsService interface. +// It communicates using Protobuf and can be configured with a custom HTTPClient. +func NewLogsServiceProtobufClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) LogsService { + if c, ok := client.(*http.Client); ok { + client = withoutRedirects(c) + } + + clientOpts := twirp.ClientOptions{} + for _, o := range opts { + o(&clientOpts) + } + + // Using ReadOpt allows backwards and forwards compatibility with new options in the future + literalURLs := false + _ = clientOpts.ReadOpt("literalURLs", &literalURLs) + var pathPrefix string + if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok { + pathPrefix = "/twirp" // default prefix + } + + // Build method URLs: <baseURL>[<prefix>]/<package>.<Service>/<Method> + serviceURL := sanitizeBaseURL(baseURL) + serviceURL += baseServicePath(pathPrefix, "logs", "LogsService") + urls := [3]string{ + serviceURL + "SendLogs", + serviceURL + "GetLogs", + serviceURL + "GenerateDummyLogs", + } + + return &logsServiceProtobufClient{ + client: client, + urls: urls, + interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...), + opts: clientOpts, + } +} + +func (c *logsServiceProtobufClient) SendLogs(ctx context.Context, in *SendLogsRequest) (*SendLogsResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "logs") + ctx = ctxsetters.WithServiceName(ctx, "LogsService") + ctx = ctxsetters.WithMethodName(ctx, "SendLogs") + caller := c.callSendLogs + if c.interceptor != nil { + caller = func(ctx context.Context, req *SendLogsRequest) (*SendLogsResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*SendLogsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*SendLogsRequest) when calling interceptor") + } + return c.callSendLogs(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*SendLogsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*SendLogsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *logsServiceProtobufClient) callSendLogs(ctx context.Context, in *SendLogsRequest) (*SendLogsResponse, error) { + out := new(SendLogsResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[0], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *logsServiceProtobufClient) GetLogs(ctx context.Context, in *GetLogsRequest) (*GetLogsResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "logs") + ctx = ctxsetters.WithServiceName(ctx, "LogsService") + ctx = ctxsetters.WithMethodName(ctx, "GetLogs") + caller := c.callGetLogs + if c.interceptor != nil { + caller = func(ctx context.Context, req *GetLogsRequest) (*GetLogsResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*GetLogsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*GetLogsRequest) when calling interceptor") + } + return c.callGetLogs(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*GetLogsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*GetLogsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *logsServiceProtobufClient) callGetLogs(ctx context.Context, in *GetLogsRequest) (*GetLogsResponse, error) { + out := new(GetLogsResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[1], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *logsServiceProtobufClient) GenerateDummyLogs(ctx context.Context, in *GenerateDummyLogsRequest) (*GenerateDummyLogsResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "logs") + ctx = ctxsetters.WithServiceName(ctx, "LogsService") + ctx = ctxsetters.WithMethodName(ctx, "GenerateDummyLogs") + caller := c.callGenerateDummyLogs + if c.interceptor != nil { + caller = func(ctx context.Context, req *GenerateDummyLogsRequest) (*GenerateDummyLogsResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*GenerateDummyLogsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*GenerateDummyLogsRequest) when calling interceptor") + } + return c.callGenerateDummyLogs(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*GenerateDummyLogsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*GenerateDummyLogsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *logsServiceProtobufClient) callGenerateDummyLogs(ctx context.Context, in *GenerateDummyLogsRequest) (*GenerateDummyLogsResponse, error) { + out := new(GenerateDummyLogsResponse) + ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[2], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +// ======================= +// LogsService JSON Client +// ======================= + +type logsServiceJSONClient struct { + client HTTPClient + urls [3]string + interceptor twirp.Interceptor + opts twirp.ClientOptions +} + +// NewLogsServiceJSONClient creates a JSON client that implements the LogsService interface. +// It communicates using JSON and can be configured with a custom HTTPClient. +func NewLogsServiceJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) LogsService { + if c, ok := client.(*http.Client); ok { + client = withoutRedirects(c) + } + + clientOpts := twirp.ClientOptions{} + for _, o := range opts { + o(&clientOpts) + } + + // Using ReadOpt allows backwards and forwards compatibility with new options in the future + literalURLs := false + _ = clientOpts.ReadOpt("literalURLs", &literalURLs) + var pathPrefix string + if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok { + pathPrefix = "/twirp" // default prefix + } + + // Build method URLs: <baseURL>[<prefix>]/<package>.<Service>/<Method> + serviceURL := sanitizeBaseURL(baseURL) + serviceURL += baseServicePath(pathPrefix, "logs", "LogsService") + urls := [3]string{ + serviceURL + "SendLogs", + serviceURL + "GetLogs", + serviceURL + "GenerateDummyLogs", + } + + return &logsServiceJSONClient{ + client: client, + urls: urls, + interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...), + opts: clientOpts, + } +} + +func (c *logsServiceJSONClient) SendLogs(ctx context.Context, in *SendLogsRequest) (*SendLogsResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "logs") + ctx = ctxsetters.WithServiceName(ctx, "LogsService") + ctx = ctxsetters.WithMethodName(ctx, "SendLogs") + caller := c.callSendLogs + if c.interceptor != nil { + caller = func(ctx context.Context, req *SendLogsRequest) (*SendLogsResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*SendLogsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*SendLogsRequest) when calling interceptor") + } + return c.callSendLogs(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*SendLogsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*SendLogsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *logsServiceJSONClient) callSendLogs(ctx context.Context, in *SendLogsRequest) (*SendLogsResponse, error) { + out := new(SendLogsResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[0], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *logsServiceJSONClient) GetLogs(ctx context.Context, in *GetLogsRequest) (*GetLogsResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "logs") + ctx = ctxsetters.WithServiceName(ctx, "LogsService") + ctx = ctxsetters.WithMethodName(ctx, "GetLogs") + caller := c.callGetLogs + if c.interceptor != nil { + caller = func(ctx context.Context, req *GetLogsRequest) (*GetLogsResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*GetLogsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*GetLogsRequest) when calling interceptor") + } + return c.callGetLogs(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*GetLogsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*GetLogsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *logsServiceJSONClient) callGetLogs(ctx context.Context, in *GetLogsRequest) (*GetLogsResponse, error) { + out := new(GetLogsResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[1], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +func (c *logsServiceJSONClient) GenerateDummyLogs(ctx context.Context, in *GenerateDummyLogsRequest) (*GenerateDummyLogsResponse, error) { + ctx = ctxsetters.WithPackageName(ctx, "logs") + ctx = ctxsetters.WithServiceName(ctx, "LogsService") + ctx = ctxsetters.WithMethodName(ctx, "GenerateDummyLogs") + caller := c.callGenerateDummyLogs + if c.interceptor != nil { + caller = func(ctx context.Context, req *GenerateDummyLogsRequest) (*GenerateDummyLogsResponse, error) { + resp, err := c.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*GenerateDummyLogsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*GenerateDummyLogsRequest) when calling interceptor") + } + return c.callGenerateDummyLogs(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*GenerateDummyLogsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*GenerateDummyLogsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + return caller(ctx, in) +} + +func (c *logsServiceJSONClient) callGenerateDummyLogs(ctx context.Context, in *GenerateDummyLogsRequest) (*GenerateDummyLogsResponse, error) { + out := new(GenerateDummyLogsResponse) + ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[2], in, out) + if err != nil { + twerr, ok := err.(twirp.Error) + if !ok { + twerr = twirp.InternalErrorWith(err) + } + callClientError(ctx, c.opts.Hooks, twerr) + return nil, err + } + + callClientResponseReceived(ctx, c.opts.Hooks) + + return out, nil +} + +// ========================== +// LogsService Server Handler +// ========================== + +type logsServiceServer struct { + LogsService + interceptor twirp.Interceptor + hooks *twirp.ServerHooks + pathPrefix string // prefix for routing + jsonSkipDefaults bool // do not include unpopulated fields (default values) in the response + jsonCamelCase bool // JSON fields are serialized as lowerCamelCase rather than keeping the original proto names +} + +// NewLogsServiceServer builds a TwirpServer that can be used as an http.Handler to handle +// HTTP requests that are routed to the right method in the provided svc implementation. +// The opts are twirp.ServerOption modifiers, for example twirp.WithServerHooks(hooks). +func NewLogsServiceServer(svc LogsService, opts ...interface{}) TwirpServer { + serverOpts := newServerOpts(opts) + + // Using ReadOpt allows backwards and forwards compatibility with new options in the future + jsonSkipDefaults := false + _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) + jsonCamelCase := false + _ = serverOpts.ReadOpt("jsonCamelCase", &jsonCamelCase) + var pathPrefix string + if ok := serverOpts.ReadOpt("pathPrefix", &pathPrefix); !ok { + pathPrefix = "/twirp" // default prefix + } + + return &logsServiceServer{ + LogsService: svc, + hooks: serverOpts.Hooks, + interceptor: twirp.ChainInterceptors(serverOpts.Interceptors...), + pathPrefix: pathPrefix, + jsonSkipDefaults: jsonSkipDefaults, + jsonCamelCase: jsonCamelCase, + } +} + +// writeError writes an HTTP response with a valid Twirp error format, and triggers hooks. +// If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err) +func (s *logsServiceServer) writeError(ctx context.Context, resp http.ResponseWriter, err error) { + writeError(ctx, resp, err, s.hooks) +} + +// handleRequestBodyError is used to handle error when the twirp server cannot read request +func (s *logsServiceServer) handleRequestBodyError(ctx context.Context, resp http.ResponseWriter, msg string, err error) { + if context.Canceled == ctx.Err() { + s.writeError(ctx, resp, twirp.NewError(twirp.Canceled, "failed to read request: context canceled")) + return + } + if context.DeadlineExceeded == ctx.Err() { + s.writeError(ctx, resp, twirp.NewError(twirp.DeadlineExceeded, "failed to read request: deadline exceeded")) + return + } + s.writeError(ctx, resp, twirp.WrapError(malformedRequestError(msg), err)) +} + +// LogsServicePathPrefix is a convenience constant that may identify URL paths. +// Should be used with caution, it only matches routes generated by Twirp Go clients, +// with the default "/twirp" prefix and default CamelCase service and method names. +// More info: https://twitchtv.github.io/twirp/docs/routing.html +const LogsServicePathPrefix = "/twirp/logs.LogsService/" + +func (s *logsServiceServer) ServeHTTP(resp http.ResponseWriter, req *http.Request) { + ctx := req.Context() + ctx = ctxsetters.WithPackageName(ctx, "logs") + ctx = ctxsetters.WithServiceName(ctx, "LogsService") + ctx = ctxsetters.WithResponseWriter(ctx, resp) + + var err error + ctx, err = callRequestReceived(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + if req.Method != "POST" { + msg := fmt.Sprintf("unsupported method %q (only POST is allowed)", req.Method) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } + + // Verify path format: [<prefix>]/<package>.<Service>/<Method> + prefix, pkgService, method := parseTwirpPath(req.URL.Path) + if pkgService != "logs.LogsService" { + msg := fmt.Sprintf("no handler for path %q", req.URL.Path) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } + if prefix != s.pathPrefix { + msg := fmt.Sprintf("invalid path prefix %q, expected %q, on path %q", prefix, s.pathPrefix, req.URL.Path) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } + + switch method { + case "SendLogs": + s.serveSendLogs(ctx, resp, req) + return + case "GetLogs": + s.serveGetLogs(ctx, resp, req) + return + case "GenerateDummyLogs": + s.serveGenerateDummyLogs(ctx, resp, req) + return + default: + msg := fmt.Sprintf("no handler for path %q", req.URL.Path) + s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path)) + return + } +} + +func (s *logsServiceServer) serveSendLogs(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveSendLogsJSON(ctx, resp, req) + case "application/protobuf": + s.serveSendLogsProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *logsServiceServer) serveSendLogsJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "SendLogs") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(SendLogsRequest) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.LogsService.SendLogs + if s.interceptor != nil { + handler = func(ctx context.Context, req *SendLogsRequest) (*SendLogsResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*SendLogsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*SendLogsRequest) when calling interceptor") + } + return s.LogsService.SendLogs(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*SendLogsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*SendLogsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *SendLogsResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *SendLogsResponse and nil error while calling SendLogs. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *logsServiceServer) serveSendLogsProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "SendLogs") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := io.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(SendLogsRequest) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.LogsService.SendLogs + if s.interceptor != nil { + handler = func(ctx context.Context, req *SendLogsRequest) (*SendLogsResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*SendLogsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*SendLogsRequest) when calling interceptor") + } + return s.LogsService.SendLogs(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*SendLogsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*SendLogsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *SendLogsResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *SendLogsResponse and nil error while calling SendLogs. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *logsServiceServer) serveGetLogs(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveGetLogsJSON(ctx, resp, req) + case "application/protobuf": + s.serveGetLogsProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *logsServiceServer) serveGetLogsJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "GetLogs") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(GetLogsRequest) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.LogsService.GetLogs + if s.interceptor != nil { + handler = func(ctx context.Context, req *GetLogsRequest) (*GetLogsResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*GetLogsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*GetLogsRequest) when calling interceptor") + } + return s.LogsService.GetLogs(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*GetLogsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*GetLogsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *GetLogsResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *GetLogsResponse and nil error while calling GetLogs. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *logsServiceServer) serveGetLogsProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "GetLogs") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := io.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(GetLogsRequest) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.LogsService.GetLogs + if s.interceptor != nil { + handler = func(ctx context.Context, req *GetLogsRequest) (*GetLogsResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*GetLogsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*GetLogsRequest) when calling interceptor") + } + return s.LogsService.GetLogs(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*GetLogsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*GetLogsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *GetLogsResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *GetLogsResponse and nil error while calling GetLogs. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *logsServiceServer) serveGenerateDummyLogs(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + header := req.Header.Get("Content-Type") + i := strings.Index(header, ";") + if i == -1 { + i = len(header) + } + switch strings.TrimSpace(strings.ToLower(header[:i])) { + case "application/json": + s.serveGenerateDummyLogsJSON(ctx, resp, req) + case "application/protobuf": + s.serveGenerateDummyLogsProtobuf(ctx, resp, req) + default: + msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type")) + twerr := badRouteError(msg, req.Method, req.URL.Path) + s.writeError(ctx, resp, twerr) + } +} + +func (s *logsServiceServer) serveGenerateDummyLogsJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "GenerateDummyLogs") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + d := json.NewDecoder(req.Body) + rawReqBody := json.RawMessage{} + if err := d.Decode(&rawReqBody); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + reqContent := new(GenerateDummyLogsRequest) + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil { + s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err) + return + } + + handler := s.LogsService.GenerateDummyLogs + if s.interceptor != nil { + handler = func(ctx context.Context, req *GenerateDummyLogsRequest) (*GenerateDummyLogsResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*GenerateDummyLogsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*GenerateDummyLogsRequest) when calling interceptor") + } + return s.LogsService.GenerateDummyLogs(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*GenerateDummyLogsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*GenerateDummyLogsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *GenerateDummyLogsResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *GenerateDummyLogsResponse and nil error while calling GenerateDummyLogs. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults} + respBytes, err := marshaler.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/json") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *logsServiceServer) serveGenerateDummyLogsProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) { + var err error + ctx = ctxsetters.WithMethodName(ctx, "GenerateDummyLogs") + ctx, err = callRequestRouted(ctx, s.hooks) + if err != nil { + s.writeError(ctx, resp, err) + return + } + + buf, err := io.ReadAll(req.Body) + if err != nil { + s.handleRequestBodyError(ctx, resp, "failed to read request body", err) + return + } + reqContent := new(GenerateDummyLogsRequest) + if err = proto.Unmarshal(buf, reqContent); err != nil { + s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded")) + return + } + + handler := s.LogsService.GenerateDummyLogs + if s.interceptor != nil { + handler = func(ctx context.Context, req *GenerateDummyLogsRequest) (*GenerateDummyLogsResponse, error) { + resp, err := s.interceptor( + func(ctx context.Context, req interface{}) (interface{}, error) { + typedReq, ok := req.(*GenerateDummyLogsRequest) + if !ok { + return nil, twirp.InternalError("failed type assertion req.(*GenerateDummyLogsRequest) when calling interceptor") + } + return s.LogsService.GenerateDummyLogs(ctx, typedReq) + }, + )(ctx, req) + if resp != nil { + typedResp, ok := resp.(*GenerateDummyLogsResponse) + if !ok { + return nil, twirp.InternalError("failed type assertion resp.(*GenerateDummyLogsResponse) when calling interceptor") + } + return typedResp, err + } + return nil, err + } + } + + // Call service method + var respContent *GenerateDummyLogsResponse + func() { + defer ensurePanicResponses(ctx, resp, s.hooks) + respContent, err = handler(ctx, reqContent) + }() + + if err != nil { + s.writeError(ctx, resp, err) + return + } + if respContent == nil { + s.writeError(ctx, resp, twirp.InternalError("received a nil *GenerateDummyLogsResponse and nil error while calling GenerateDummyLogs. nil responses are not supported")) + return + } + + ctx = callResponsePrepared(ctx, s.hooks) + + respBytes, err := proto.Marshal(respContent) + if err != nil { + s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response")) + return + } + + ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK) + resp.Header().Set("Content-Type", "application/protobuf") + resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes))) + resp.WriteHeader(http.StatusOK) + if n, err := resp.Write(respBytes); err != nil { + msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error()) + twerr := twirp.NewError(twirp.Unknown, msg) + ctx = callError(ctx, s.hooks, twerr) + } + callResponseSent(ctx, s.hooks) +} + +func (s *logsServiceServer) ServiceDescriptor() ([]byte, int) { + return twirpFileDescriptor0, 0 +} + +func (s *logsServiceServer) ProtocGenTwirpVersion() string { + return "v8.1.3" +} + +// PathPrefix returns the base service path, in the form: "/<prefix>/<package>.<Service>/" +// that is everything in a Twirp route except for the <Method>. This can be used for routing, +// for example to identify the requests that are targeted to this service in a mux. +func (s *logsServiceServer) PathPrefix() string { + return baseServicePath(s.pathPrefix, "logs", "LogsService") +} + +// ===== +// Utils +// ===== + +// HTTPClient is the interface used by generated clients to send HTTP requests. +// It is fulfilled by *(net/http).Client, which is sufficient for most users. +// Users can provide their own implementation for special retry policies. +// +// HTTPClient implementations should not follow redirects. Redirects are +// automatically disabled if *(net/http).Client is passed to client +// constructors. See the withoutRedirects function in this file for more +// details. +type HTTPClient interface { + Do(req *http.Request) (*http.Response, error) +} + +// TwirpServer is the interface generated server structs will support: they're +// HTTP handlers with additional methods for accessing metadata about the +// service. Those accessors are a low-level API for building reflection tools. +// Most people can think of TwirpServers as just http.Handlers. +type TwirpServer interface { + http.Handler + + // ServiceDescriptor returns gzipped bytes describing the .proto file that + // this service was generated from. Once unzipped, the bytes can be + // unmarshalled as a + // google.golang.org/protobuf/types/descriptorpb.FileDescriptorProto. + // + // The returned integer is the index of this particular service within that + // FileDescriptorProto's 'Service' slice of ServiceDescriptorProtos. This is a + // low-level field, expected to be used for reflection. + ServiceDescriptor() ([]byte, int) + + // ProtocGenTwirpVersion is the semantic version string of the version of + // twirp used to generate this file. + ProtocGenTwirpVersion() string + + // PathPrefix returns the HTTP URL path prefix for all methods handled by this + // service. This can be used with an HTTP mux to route Twirp requests. + // The path prefix is in the form: "/<prefix>/<package>.<Service>/" + // that is, everything in a Twirp route except for the <Method> at the end. + PathPrefix() string +} + +func newServerOpts(opts []interface{}) *twirp.ServerOptions { + serverOpts := &twirp.ServerOptions{} + for _, opt := range opts { + switch o := opt.(type) { + case twirp.ServerOption: + o(serverOpts) + case *twirp.ServerHooks: // backwards compatibility, allow to specify hooks as an argument + twirp.WithServerHooks(o)(serverOpts) + case nil: // backwards compatibility, allow nil value for the argument + continue + default: + panic(fmt.Sprintf("Invalid option type %T, please use a twirp.ServerOption", o)) + } + } + return serverOpts +} + +// WriteError writes an HTTP response with a valid Twirp error format (code, msg, meta). +// Useful outside of the Twirp server (e.g. http middleware), but does not trigger hooks. +// If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err) +func WriteError(resp http.ResponseWriter, err error) { + writeError(context.Background(), resp, err, nil) +} + +// writeError writes Twirp errors in the response and triggers hooks. +func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks *twirp.ServerHooks) { + // Convert to a twirp.Error. Non-twirp errors are converted to internal errors. + var twerr twirp.Error + if !errors.As(err, &twerr) { + twerr = twirp.InternalErrorWith(err) + } + + statusCode := twirp.ServerHTTPStatusFromErrorCode(twerr.Code()) + ctx = ctxsetters.WithStatusCode(ctx, statusCode) + ctx = callError(ctx, hooks, twerr) + + respBody := marshalErrorToJSON(twerr) + + resp.Header().Set("Content-Type", "application/json") // Error responses are always JSON + resp.Header().Set("Content-Length", strconv.Itoa(len(respBody))) + resp.WriteHeader(statusCode) // set HTTP status code and send response + + _, writeErr := resp.Write(respBody) + if writeErr != nil { + // We have three options here. We could log the error, call the Error + // hook, or just silently ignore the error. + // + // Logging is unacceptable because we don't have a user-controlled + // logger; writing out to stderr without permission is too rude. + // + // Calling the Error hook would confuse users: it would mean the Error + // hook got called twice for one request, which is likely to lead to + // duplicated log messages and metrics, no matter how well we document + // the behavior. + // + // Silently ignoring the error is our least-bad option. It's highly + // likely that the connection is broken and the original 'err' says + // so anyway. + _ = writeErr + } + + callResponseSent(ctx, hooks) +} + +// sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. +// If the URL is unparsable, the baseURL is returned unchanged. +func sanitizeBaseURL(baseURL string) string { + u, err := url.Parse(baseURL) + if err != nil { + return baseURL // invalid URL will fail later when making requests + } + if u.Scheme == "" { + u.Scheme = "http" + } + return u.String() +} + +// baseServicePath composes the path prefix for the service (without <Method>). +// e.g.: baseServicePath("/twirp", "my.pkg", "MyService") +// +// returns => "/twirp/my.pkg.MyService/" +// +// e.g.: baseServicePath("", "", "MyService") +// +// returns => "/MyService/" +func baseServicePath(prefix, pkg, service string) string { + fullServiceName := service + if pkg != "" { + fullServiceName = pkg + "." + service + } + return path.Join("/", prefix, fullServiceName) + "/" +} + +// parseTwirpPath extracts path components form a valid Twirp route. +// Expected format: "[<prefix>]/<package>.<Service>/<Method>" +// e.g.: prefix, pkgService, method := parseTwirpPath("/twirp/pkg.Svc/MakeHat") +func parseTwirpPath(path string) (string, string, string) { + parts := strings.Split(path, "/") + if len(parts) < 2 { + return "", "", "" + } + method := parts[len(parts)-1] + pkgService := parts[len(parts)-2] + prefix := strings.Join(parts[0:len(parts)-2], "/") + return prefix, pkgService, method +} + +// getCustomHTTPReqHeaders retrieves a copy of any headers that are set in +// a context through the twirp.WithHTTPRequestHeaders function. +// If there are no headers set, or if they have the wrong type, nil is returned. +func getCustomHTTPReqHeaders(ctx context.Context) http.Header { + header, ok := twirp.HTTPRequestHeaders(ctx) + if !ok || header == nil { + return nil + } + copied := make(http.Header) + for k, vv := range header { + if vv == nil { + copied[k] = nil + continue + } + copied[k] = make([]string, len(vv)) + copy(copied[k], vv) + } + return copied +} + +// newRequest makes an http.Request from a client, adding common headers. +func newRequest(ctx context.Context, url string, reqBody io.Reader, contentType string) (*http.Request, error) { + req, err := http.NewRequest("POST", url, reqBody) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if customHeader := getCustomHTTPReqHeaders(ctx); customHeader != nil { + req.Header = customHeader + } + req.Header.Set("Accept", contentType) + req.Header.Set("Content-Type", contentType) + req.Header.Set("Twirp-Version", "v8.1.3") + return req, nil +} + +// JSON serialization for errors +type twerrJSON struct { + Code string `json:"code"` + Msg string `json:"msg"` + Meta map[string]string `json:"meta,omitempty"` +} + +// marshalErrorToJSON returns JSON from a twirp.Error, that can be used as HTTP error response body. +// If serialization fails, it will use a descriptive Internal error instead. +func marshalErrorToJSON(twerr twirp.Error) []byte { + // make sure that msg is not too large + msg := twerr.Msg() + if len(msg) > 1e6 { + msg = msg[:1e6] + } + + tj := twerrJSON{ + Code: string(twerr.Code()), + Msg: msg, + Meta: twerr.MetaMap(), + } + + buf, err := json.Marshal(&tj) + if err != nil { + buf = []byte("{\"type\": \"" + twirp.Internal + "\", \"msg\": \"There was an error but it could not be serialized into JSON\"}") // fallback + } + + return buf +} + +// errorFromResponse builds a twirp.Error from a non-200 HTTP response. +// If the response has a valid serialized Twirp error, then it's returned. +// If not, the response status code is used to generate a similar twirp +// error. See twirpErrorFromIntermediary for more info on intermediary errors. +func errorFromResponse(resp *http.Response) twirp.Error { + statusCode := resp.StatusCode + statusText := http.StatusText(statusCode) + + if isHTTPRedirect(statusCode) { + // Unexpected redirect: it must be an error from an intermediary. + // Twirp clients don't follow redirects automatically, Twirp only handles + // POST requests, redirects should only happen on GET and HEAD requests. + location := resp.Header.Get("Location") + msg := fmt.Sprintf("unexpected HTTP status code %d %q received, Location=%q", statusCode, statusText, location) + return twirpErrorFromIntermediary(statusCode, msg, location) + } + + respBodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + return wrapInternal(err, "failed to read server error response body") + } + + var tj twerrJSON + dec := json.NewDecoder(bytes.NewReader(respBodyBytes)) + dec.DisallowUnknownFields() + if err := dec.Decode(&tj); err != nil || tj.Code == "" { + // Invalid JSON response; it must be an error from an intermediary. + msg := fmt.Sprintf("Error from intermediary with HTTP status code %d %q", statusCode, statusText) + return twirpErrorFromIntermediary(statusCode, msg, string(respBodyBytes)) + } + + errorCode := twirp.ErrorCode(tj.Code) + if !twirp.IsValidErrorCode(errorCode) { + msg := "invalid type returned from server error response: " + tj.Code + return twirp.InternalError(msg).WithMeta("body", string(respBodyBytes)) + } + + twerr := twirp.NewError(errorCode, tj.Msg) + for k, v := range tj.Meta { + twerr = twerr.WithMeta(k, v) + } + return twerr +} + +// twirpErrorFromIntermediary maps HTTP errors from non-twirp sources to twirp errors. +// The mapping is similar to gRPC: https://github.com/grpc/grpc/blob/master/doc/http-grpc-status-mapping.md. +// Returned twirp Errors have some additional metadata for inspection. +func twirpErrorFromIntermediary(status int, msg string, bodyOrLocation string) twirp.Error { + var code twirp.ErrorCode + if isHTTPRedirect(status) { // 3xx + code = twirp.Internal + } else { + switch status { + case 400: // Bad Request + code = twirp.Internal + case 401: // Unauthorized + code = twirp.Unauthenticated + case 403: // Forbidden + code = twirp.PermissionDenied + case 404: // Not Found + code = twirp.BadRoute + case 429: // Too Many Requests + code = twirp.ResourceExhausted + case 502, 503, 504: // Bad Gateway, Service Unavailable, Gateway Timeout + code = twirp.Unavailable + default: // All other codes + code = twirp.Unknown + } + } + + twerr := twirp.NewError(code, msg) + twerr = twerr.WithMeta("http_error_from_intermediary", "true") // to easily know if this error was from intermediary + twerr = twerr.WithMeta("status_code", strconv.Itoa(status)) + if isHTTPRedirect(status) { + twerr = twerr.WithMeta("location", bodyOrLocation) + } else { + twerr = twerr.WithMeta("body", bodyOrLocation) + } + return twerr +} + +func isHTTPRedirect(status int) bool { + return status >= 300 && status <= 399 +} + +// wrapInternal wraps an error with a prefix as an Internal error. +// The original error cause is accessible by github.com/pkg/errors.Cause. +func wrapInternal(err error, prefix string) twirp.Error { + return twirp.InternalErrorWith(&wrappedError{prefix: prefix, cause: err}) +} + +type wrappedError struct { + prefix string + cause error +} + +func (e *wrappedError) Error() string { return e.prefix + ": " + e.cause.Error() } +func (e *wrappedError) Unwrap() error { return e.cause } // for go1.13 + errors.Is/As +func (e *wrappedError) Cause() error { return e.cause } // for github.com/pkg/errors + +// ensurePanicResponses makes sure that rpc methods causing a panic still result in a Twirp Internal +// error response (status 500), and error hooks are properly called with the panic wrapped as an error. +// The panic is re-raised so it can be handled normally with middleware. +func ensurePanicResponses(ctx context.Context, resp http.ResponseWriter, hooks *twirp.ServerHooks) { + if r := recover(); r != nil { + // Wrap the panic as an error so it can be passed to error hooks. + // The original error is accessible from error hooks, but not visible in the response. + err := errFromPanic(r) + twerr := &internalWithCause{msg: "Internal service panic", cause: err} + // Actually write the error + writeError(ctx, resp, twerr, hooks) + // If possible, flush the error to the wire. + f, ok := resp.(http.Flusher) + if ok { + f.Flush() + } + + panic(r) + } +} + +// errFromPanic returns the typed error if the recovered panic is an error, otherwise formats as error. +func errFromPanic(p interface{}) error { + if err, ok := p.(error); ok { + return err + } + return fmt.Errorf("panic: %v", p) +} + +// internalWithCause is a Twirp Internal error wrapping an original error cause, +// but the original error message is not exposed on Msg(). The original error +// can be checked with go1.13+ errors.Is/As, and also by (github.com/pkg/errors).Unwrap +type internalWithCause struct { + msg string + cause error +} + +func (e *internalWithCause) Unwrap() error { return e.cause } // for go1.13 + errors.Is/As +func (e *internalWithCause) Cause() error { return e.cause } // for github.com/pkg/errors +func (e *internalWithCause) Error() string { return e.msg + ": " + e.cause.Error() } +func (e *internalWithCause) Code() twirp.ErrorCode { return twirp.Internal } +func (e *internalWithCause) Msg() string { return e.msg } +func (e *internalWithCause) Meta(key string) string { return "" } +func (e *internalWithCause) MetaMap() map[string]string { return nil } +func (e *internalWithCause) WithMeta(key string, val string) twirp.Error { return e } + +// malformedRequestError is used when the twirp server cannot unmarshal a request +func malformedRequestError(msg string) twirp.Error { + return twirp.NewError(twirp.Malformed, msg) +} + +// badRouteError is used when the twirp server cannot route a request +func badRouteError(msg string, method, url string) twirp.Error { + err := twirp.NewError(twirp.BadRoute, msg) + err = err.WithMeta("twirp_invalid_route", method+" "+url) + return err +} + +// withoutRedirects makes sure that the POST request can not be redirected. +// The standard library will, by default, redirect requests (including POSTs) if it gets a 302 or +// 303 response, and also 301s in go1.8. It redirects by making a second request, changing the +// method to GET and removing the body. This produces very confusing error messages, so instead we +// set a redirect policy that always errors. This stops Go from executing the redirect. +// +// We have to be a little careful in case the user-provided http.Client has its own CheckRedirect +// policy - if so, we'll run through that policy first. +// +// Because this requires modifying the http.Client, we make a new copy of the client and return it. +func withoutRedirects(in *http.Client) *http.Client { + copy := *in + copy.CheckRedirect = func(req *http.Request, via []*http.Request) error { + if in.CheckRedirect != nil { + // Run the input's redirect if it exists, in case it has side effects, but ignore any error it + // returns, since we want to use ErrUseLastResponse. + err := in.CheckRedirect(req, via) + _ = err // Silly, but this makes sure generated code passes errcheck -blank, which some people use. + } + return http.ErrUseLastResponse + } + return © +} + +// doProtobufRequest makes a Protobuf request to the remote Twirp service. +func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.ClientHooks, url string, in, out proto.Message) (_ context.Context, err error) { + reqBodyBytes, err := proto.Marshal(in) + if err != nil { + return ctx, wrapInternal(err, "failed to marshal proto request") + } + reqBody := bytes.NewBuffer(reqBodyBytes) + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + req, err := newRequest(ctx, url, reqBody, "application/protobuf") + if err != nil { + return ctx, wrapInternal(err, "could not build request") + } + ctx, err = callClientRequestPrepared(ctx, hooks, req) + if err != nil { + return ctx, err + } + + req = req.WithContext(ctx) + resp, err := client.Do(req) + if err != nil { + return ctx, wrapInternal(err, "failed to do request") + } + defer func() { _ = resp.Body.Close() }() + + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + if resp.StatusCode != 200 { + return ctx, errorFromResponse(resp) + } + + respBodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + return ctx, wrapInternal(err, "failed to read response body") + } + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + if err = proto.Unmarshal(respBodyBytes, out); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal proto response") + } + return ctx, nil +} + +// doJSONRequest makes a JSON request to the remote Twirp service. +func doJSONRequest(ctx context.Context, client HTTPClient, hooks *twirp.ClientHooks, url string, in, out proto.Message) (_ context.Context, err error) { + marshaler := &protojson.MarshalOptions{UseProtoNames: true} + reqBytes, err := marshaler.Marshal(in) + if err != nil { + return ctx, wrapInternal(err, "failed to marshal json request") + } + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + req, err := newRequest(ctx, url, bytes.NewReader(reqBytes), "application/json") + if err != nil { + return ctx, wrapInternal(err, "could not build request") + } + ctx, err = callClientRequestPrepared(ctx, hooks, req) + if err != nil { + return ctx, err + } + + req = req.WithContext(ctx) + resp, err := client.Do(req) + if err != nil { + return ctx, wrapInternal(err, "failed to do request") + } + + defer func() { + cerr := resp.Body.Close() + if err == nil && cerr != nil { + err = wrapInternal(cerr, "failed to close response body") + } + }() + + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + + if resp.StatusCode != 200 { + return ctx, errorFromResponse(resp) + } + + d := json.NewDecoder(resp.Body) + rawRespBody := json.RawMessage{} + if err := d.Decode(&rawRespBody); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal json response") + } + unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true} + if err = unmarshaler.Unmarshal(rawRespBody, out); err != nil { + return ctx, wrapInternal(err, "failed to unmarshal json response") + } + if err = ctx.Err(); err != nil { + return ctx, wrapInternal(err, "aborted because context was done") + } + return ctx, nil +} + +// Call twirp.ServerHooks.RequestReceived if the hook is available +func callRequestReceived(ctx context.Context, h *twirp.ServerHooks) (context.Context, error) { + if h == nil || h.RequestReceived == nil { + return ctx, nil + } + return h.RequestReceived(ctx) +} + +// Call twirp.ServerHooks.RequestRouted if the hook is available +func callRequestRouted(ctx context.Context, h *twirp.ServerHooks) (context.Context, error) { + if h == nil || h.RequestRouted == nil { + return ctx, nil + } + return h.RequestRouted(ctx) +} + +// Call twirp.ServerHooks.ResponsePrepared if the hook is available +func callResponsePrepared(ctx context.Context, h *twirp.ServerHooks) context.Context { + if h == nil || h.ResponsePrepared == nil { + return ctx + } + return h.ResponsePrepared(ctx) +} + +// Call twirp.ServerHooks.ResponseSent if the hook is available +func callResponseSent(ctx context.Context, h *twirp.ServerHooks) { + if h == nil || h.ResponseSent == nil { + return + } + h.ResponseSent(ctx) +} + +// Call twirp.ServerHooks.Error if the hook is available +func callError(ctx context.Context, h *twirp.ServerHooks, err twirp.Error) context.Context { + if h == nil || h.Error == nil { + return ctx + } + return h.Error(ctx, err) +} + +func callClientResponseReceived(ctx context.Context, h *twirp.ClientHooks) { + if h == nil || h.ResponseReceived == nil { + return + } + h.ResponseReceived(ctx) +} + +func callClientRequestPrepared(ctx context.Context, h *twirp.ClientHooks, req *http.Request) (context.Context, error) { + if h == nil || h.RequestPrepared == nil { + return ctx, nil + } + return h.RequestPrepared(ctx, req) +} + +func callClientError(ctx context.Context, h *twirp.ClientHooks, err twirp.Error) { + if h == nil || h.Error == nil { + return + } + h.Error(ctx, err) +} + +var twirpFileDescriptor0 = []byte{ + // 618 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0xdb, 0x4e, 0xdb, 0x4a, + 0x14, 0x86, 0xb7, 0x49, 0x9c, 0x38, 0x2b, 0x22, 0xf1, 0x9e, 0x4d, 0xd8, 0x86, 0x1e, 0x40, 0x56, + 0xab, 0xd2, 0x4a, 0x05, 0x89, 0x4a, 0x95, 0xb8, 0xe4, 0x2c, 0x44, 0x6a, 0x24, 0x03, 0x42, 0xea, + 0x8d, 0x35, 0xb5, 0x97, 0x8c, 0x85, 0xed, 0x71, 0x3d, 0x13, 0xd4, 0x70, 0xd3, 0x27, 0xeb, 0x6b, + 0x54, 0xea, 0xdb, 0x54, 0x73, 0x30, 0x04, 0x0a, 0x77, 0xbd, 0xf3, 0xfc, 0xcb, 0xfe, 0xbd, 0xfe, + 0x6f, 0xcd, 0x0c, 0x2c, 0xd6, 0x55, 0xbc, 0x91, 0xb3, 0x94, 0x6f, 0x70, 0xac, 0xaf, 0xb3, 0x18, + 0xd7, 0xab, 0x9a, 0x09, 0x46, 0xda, 0x52, 0xf3, 0xbf, 0x83, 0x33, 0x66, 0xe9, 0x7e, 0x29, 0xea, + 0x29, 0x19, 0x41, 0x27, 0x67, 0x69, 0x94, 0x25, 0x9e, 0xb5, 0x6a, 0xad, 0xf5, 0x42, 0x3b, 0x67, + 0xe9, 0x51, 0x42, 0x9e, 0x43, 0x4f, 0x64, 0x05, 0x72, 0x41, 0x8b, 0xca, 0x9b, 0x53, 0x95, 0x3b, + 0x81, 0xbc, 0x02, 0x3b, 0xc7, 0x6b, 0xcc, 0xbd, 0xd6, 0xaa, 0xb5, 0x36, 0xd8, 0x1c, 0xac, 0x4b, + 0xdb, 0xf5, 0x31, 0x4b, 0xc7, 0x52, 0x0d, 0x75, 0x91, 0x78, 0xd0, 0x2d, 0x90, 0x73, 0x9a, 0xa2, + 0xd7, 0x56, 0x0e, 0xcd, 0xd2, 0x0f, 0x60, 0x78, 0x8a, 0x65, 0x32, 0x66, 0x29, 0x0f, 0xf1, 0xeb, + 0x04, 0xb9, 0x20, 0xff, 0x43, 0x97, 0x56, 0x59, 0x74, 0x85, 0x53, 0xd3, 0x48, 0x87, 0x56, 0xd9, + 0x31, 0x4e, 0x89, 0x0f, 0xaa, 0x69, 0x6f, 0x6e, 0xb5, 0xb5, 0xd6, 0x9f, 0xf9, 0x95, 0x6a, 0x3f, + 0xd4, 0x81, 0xb6, 0xc0, 0xbd, 0xf3, 0xe3, 0x15, 0x2b, 0x39, 0x92, 0xd7, 0x30, 0xa0, 0x71, 0x8c, + 0x95, 0xc0, 0x24, 0x8a, 0xd9, 0xa4, 0x14, 0xca, 0xd7, 0x0e, 0xe7, 0x1b, 0x75, 0x57, 0x8a, 0xfe, + 0x2f, 0x0b, 0x06, 0x87, 0x28, 0x66, 0x5b, 0x59, 0x00, 0x5b, 0xb0, 0x2b, 0x2c, 0x1b, 0x22, 0x6a, + 0xa1, 0xfc, 0xaa, 0x2a, 0xcf, 0x62, 0x2a, 0x32, 0x56, 0x4a, 0x60, 0x1a, 0xcb, 0xfc, 0x8c, 0x7a, + 0x94, 0x90, 0x67, 0xd0, 0xab, 0x68, 0x8a, 0x11, 0xcf, 0x6e, 0x50, 0xe1, 0xb1, 0x43, 0x47, 0x0a, + 0xa7, 0xd9, 0x0d, 0x92, 0x45, 0xe8, 0xc4, 0x93, 0x9a, 0xb3, 0xda, 0x00, 0x31, 0x2b, 0xf9, 0x91, + 0x1c, 0x82, 0x66, 0x6a, 0xab, 0x92, 0x93, 0x1b, 0x9a, 0xe4, 0x05, 0x00, 0x17, 0xb4, 0x16, 0x91, + 0xe4, 0xef, 0x75, 0xf4, 0x2c, 0x94, 0x72, 0x96, 0x15, 0x48, 0x96, 0xc0, 0xc1, 0x32, 0xd1, 0xc5, + 0xae, 0xc6, 0x8c, 0x65, 0x22, 0x4b, 0xfe, 0x0f, 0x0b, 0x86, 0xb7, 0xd9, 0x0c, 0x96, 0x06, 0xa7, + 0xf5, 0x34, 0x4e, 0x69, 0x79, 0x49, 0x79, 0x54, 0xb0, 0x1a, 0x55, 0x48, 0x27, 0xec, 0x5e, 0x52, + 0xfe, 0x89, 0xd5, 0x48, 0x56, 0xa0, 0x5f, 0xe2, 0x37, 0x11, 0x99, 0x18, 0x2d, 0xf5, 0x43, 0x90, + 0xd2, 0xae, 0x8e, 0xb2, 0x02, 0x7d, 0xc1, 0x04, 0xcd, 0x0d, 0xf3, 0xb6, 0x22, 0x00, 0x4a, 0x52, + 0xc0, 0xc9, 0x5b, 0x70, 0x67, 0x39, 0x96, 0xb4, 0x40, 0x13, 0x79, 0x38, 0xa3, 0x07, 0xb4, 0x40, + 0xff, 0x02, 0xbc, 0x43, 0x2c, 0xb1, 0xa6, 0x02, 0xf7, 0x26, 0x45, 0x31, 0xfd, 0x5b, 0x43, 0xf2, + 0xf7, 0x60, 0xe9, 0x11, 0x63, 0x43, 0xe8, 0x0d, 0x0c, 0x53, 0x53, 0xbc, 0xbf, 0x73, 0x06, 0xb7, + 0xb2, 0x4a, 0xf2, 0x6e, 0xac, 0x8e, 0x91, 0x1e, 0x52, 0x1f, 0xba, 0xe7, 0xc1, 0x71, 0x70, 0x72, + 0x11, 0xb8, 0xff, 0x90, 0x1e, 0xd8, 0x7b, 0xfb, 0x3b, 0xe7, 0x87, 0xae, 0x45, 0x1c, 0x68, 0x1f, + 0x05, 0x07, 0x27, 0xee, 0x9c, 0x7c, 0xba, 0xd8, 0x0e, 0x03, 0xb7, 0x25, 0xcb, 0xfb, 0x61, 0x78, + 0x12, 0xba, 0x6d, 0xf9, 0x78, 0xb0, 0x7d, 0xb6, 0x3d, 0x76, 0xed, 0xcd, 0x9f, 0x16, 0xf4, 0x65, + 0x1f, 0xa7, 0xfa, 0xc0, 0x92, 0x2d, 0x70, 0x9a, 0x3d, 0x4d, 0x46, 0x7a, 0x4c, 0x0f, 0xce, 0xcc, + 0xf2, 0xe2, 0x43, 0xd9, 0x24, 0xf8, 0x08, 0x5d, 0x33, 0x76, 0xb2, 0xa0, 0x5f, 0xb9, 0xbf, 0xc3, + 0x97, 0x47, 0x0f, 0x54, 0xf3, 0xdd, 0x19, 0xfc, 0xfb, 0x07, 0x16, 0xf2, 0xb2, 0x79, 0xf7, 0xf1, + 0x41, 0x2c, 0xaf, 0x3c, 0x59, 0xd7, 0xae, 0x3b, 0xa3, 0xcf, 0xff, 0xd1, 0x3a, 0x9d, 0xf0, 0xf7, + 0x31, 0xab, 0x71, 0xa3, 0xb9, 0x98, 0xbe, 0x74, 0xd4, 0x8d, 0xf4, 0xe1, 0x77, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x20, 0x71, 0xf5, 0x26, 0xab, 0x04, 0x00, 0x00, +}