Multitenant streams api (#72)

This commit is contained in:
Dominic Wong
2021-03-18 17:21:41 +00:00
committed by GitHub
parent 28ad626d91
commit 8dfe49f813
87 changed files with 1890 additions and 1064 deletions

View File

@@ -12,7 +12,7 @@ proto:
.PHONY: docs
docs:
protoc --openapi_out=. --proto_path=. --micro_out=. --go_out=:. proto/invites.proto
@redoc-cli bundle api-invites.json
@redoc-cli bundle api-protobuf.json
.PHONY: build
build:

View File

@@ -2,12 +2,12 @@ package handler_test
import (
"context"
"os"
"testing"
"google.golang.org/protobuf/types/known/wrapperspb"
"github.com/micro/services/invites/handler"
pb "github.com/micro/services/invites/proto"
"google.golang.org/protobuf/types/known/wrapperspb"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
@@ -17,21 +17,25 @@ import (
func testHandler(t *testing.T) *handler.Invites {
// connect to the database
db, err := gorm.Open(postgres.Open("postgresql://postgres@localhost:5432/invites?sslmode=disable"), &gorm.Config{})
addr := os.Getenv("POSTGRES_URL")
if len(addr) == 0 {
addr = "postgresql://postgres@localhost:5432/postgres?sslmode=disable"
}
db, err := gorm.Open(postgres.Open(addr), &gorm.Config{})
if err != nil {
t.Fatalf("Error connecting to database: %v", err)
}
// clean any data from a previous run
if err := db.Exec("DROP TABLE IF EXISTS invites CASCADE").Error; err != nil {
t.Fatalf("Error cleaning database: %v", err)
}
// migrate the database
if err := db.AutoMigrate(&handler.Invite{}); err != nil {
t.Fatalf("Error migrating database: %v", err)
}
// clean any data from a previous run
if err := db.Exec("TRUNCATE TABLE invites CASCADE").Error; err != nil {
t.Fatalf("Error cleaning database: %v", err)
}
return &handler.Invites{DB: db}
}

View File

@@ -1,16 +1,16 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.25.0
// protoc v3.6.1
// protoc v3.15.5
// source: proto/invites.proto
package invites
import (
proto "github.com/golang/protobuf/proto"
wrappers "github.com/golang/protobuf/ptypes/wrappers"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
reflect "reflect"
sync "sync"
)
@@ -204,8 +204,8 @@ type ReadRequest struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id *wrappers.StringValue `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Code *wrappers.StringValue `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"`
Id *wrapperspb.StringValue `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Code *wrapperspb.StringValue `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"`
}
func (x *ReadRequest) Reset() {
@@ -240,14 +240,14 @@ func (*ReadRequest) Descriptor() ([]byte, []int) {
return file_proto_invites_proto_rawDescGZIP(), []int{3}
}
func (x *ReadRequest) GetId() *wrappers.StringValue {
func (x *ReadRequest) GetId() *wrapperspb.StringValue {
if x != nil {
return x.Id
}
return nil
}
func (x *ReadRequest) GetCode() *wrappers.StringValue {
func (x *ReadRequest) GetCode() *wrapperspb.StringValue {
if x != nil {
return x.Code
}
@@ -306,8 +306,8 @@ type ListRequest struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
GroupId *wrappers.StringValue `protobuf:"bytes,1,opt,name=group_id,json=groupId,proto3" json:"group_id,omitempty"`
Email *wrappers.StringValue `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"`
GroupId *wrapperspb.StringValue `protobuf:"bytes,1,opt,name=group_id,json=groupId,proto3" json:"group_id,omitempty"`
Email *wrapperspb.StringValue `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"`
}
func (x *ListRequest) Reset() {
@@ -342,14 +342,14 @@ func (*ListRequest) Descriptor() ([]byte, []int) {
return file_proto_invites_proto_rawDescGZIP(), []int{5}
}
func (x *ListRequest) GetGroupId() *wrappers.StringValue {
func (x *ListRequest) GetGroupId() *wrapperspb.StringValue {
if x != nil {
return x.GroupId
}
return nil
}
func (x *ListRequest) GetEmail() *wrappers.StringValue {
func (x *ListRequest) GetEmail() *wrapperspb.StringValue {
if x != nil {
return x.Email
}
@@ -567,16 +567,16 @@ func file_proto_invites_proto_rawDescGZIP() []byte {
var file_proto_invites_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
var file_proto_invites_proto_goTypes = []interface{}{
(*Invite)(nil), // 0: invites.Invite
(*CreateRequest)(nil), // 1: invites.CreateRequest
(*CreateResponse)(nil), // 2: invites.CreateResponse
(*ReadRequest)(nil), // 3: invites.ReadRequest
(*ReadResponse)(nil), // 4: invites.ReadResponse
(*ListRequest)(nil), // 5: invites.ListRequest
(*ListResponse)(nil), // 6: invites.ListResponse
(*DeleteRequest)(nil), // 7: invites.DeleteRequest
(*DeleteResponse)(nil), // 8: invites.DeleteResponse
(*wrappers.StringValue)(nil), // 9: google.protobuf.StringValue
(*Invite)(nil), // 0: invites.Invite
(*CreateRequest)(nil), // 1: invites.CreateRequest
(*CreateResponse)(nil), // 2: invites.CreateResponse
(*ReadRequest)(nil), // 3: invites.ReadRequest
(*ReadResponse)(nil), // 4: invites.ReadResponse
(*ListRequest)(nil), // 5: invites.ListRequest
(*ListResponse)(nil), // 6: invites.ListResponse
(*DeleteRequest)(nil), // 7: invites.DeleteRequest
(*DeleteResponse)(nil), // 8: invites.DeleteResponse
(*wrapperspb.StringValue)(nil), // 9: google.protobuf.StringValue
}
var file_proto_invites_proto_depIdxs = []int32{
0, // 0: invites.CreateResponse.invite:type_name -> invites.Invite

View File

@@ -6,7 +6,7 @@ package invites
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
_ "github.com/golang/protobuf/ptypes/wrappers"
_ "google.golang.org/protobuf/types/known/wrapperspb"
math "math"
)

View File

@@ -1,7 +1,7 @@
syntax = "proto3";
package invites;
option go_package = "proto;invites";
option go_package = "./proto;invites";
import "google/protobuf/wrappers.proto";
service Invites {
@@ -53,4 +53,4 @@ message DeleteRequest {
string id = 1;
}
message DeleteResponse {}
message DeleteResponse {}