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/users.proto
@redoc-cli bundle api-users.json
@redoc-cli bundle api-protobuf.json
.PHONY: build
build:

View File

@@ -1,6 +1,7 @@
package handler_test
import (
"os"
"testing"
"time"
@@ -14,21 +15,25 @@ import (
func testHandler(t *testing.T) *handler.Users {
// connect to the database
db, err := gorm.Open(postgres.Open("postgresql://postgres@localhost:5432/users?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 users, tokens CASCADE").Error; err != nil {
t.Fatalf("Error cleaning database: %v", err)
}
// migrate the database
if err := db.AutoMigrate(&handler.User{}, &handler.Token{}); err != nil {
t.Fatalf("Error migrating database: %v", err)
}
// clean any data from a previous run
if err := db.Exec("TRUNCATE TABLE users, tokens CASCADE").Error; err != nil {
t.Fatalf("Error cleaning database: %v", err)
}
return &handler.Users{DB: db, Time: time.Now}
}

View File

@@ -1,16 +1,15 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.23.0
// protoc v3.13.0
// protoc-gen-go v1.26.0
// protoc v3.15.5
// source: proto/users.proto
package users
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"
)
@@ -22,10 +21,6 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4
type User struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -416,11 +411,11 @@ type UpdateRequest struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
FirstName *wrappers.StringValue `protobuf:"bytes,2,opt,name=first_name,json=firstName,proto3" json:"first_name,omitempty"`
LastName *wrappers.StringValue `protobuf:"bytes,3,opt,name=last_name,json=lastName,proto3" json:"last_name,omitempty"`
Email *wrappers.StringValue `protobuf:"bytes,4,opt,name=email,proto3" json:"email,omitempty"`
Password *wrappers.StringValue `protobuf:"bytes,5,opt,name=password,proto3" json:"password,omitempty"`
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
FirstName *wrapperspb.StringValue `protobuf:"bytes,2,opt,name=first_name,json=firstName,proto3" json:"first_name,omitempty"`
LastName *wrapperspb.StringValue `protobuf:"bytes,3,opt,name=last_name,json=lastName,proto3" json:"last_name,omitempty"`
Email *wrapperspb.StringValue `protobuf:"bytes,4,opt,name=email,proto3" json:"email,omitempty"`
Password *wrapperspb.StringValue `protobuf:"bytes,5,opt,name=password,proto3" json:"password,omitempty"`
}
func (x *UpdateRequest) Reset() {
@@ -462,28 +457,28 @@ func (x *UpdateRequest) GetId() string {
return ""
}
func (x *UpdateRequest) GetFirstName() *wrappers.StringValue {
func (x *UpdateRequest) GetFirstName() *wrapperspb.StringValue {
if x != nil {
return x.FirstName
}
return nil
}
func (x *UpdateRequest) GetLastName() *wrappers.StringValue {
func (x *UpdateRequest) GetLastName() *wrapperspb.StringValue {
if x != nil {
return x.LastName
}
return nil
}
func (x *UpdateRequest) GetEmail() *wrappers.StringValue {
func (x *UpdateRequest) GetEmail() *wrapperspb.StringValue {
if x != nil {
return x.Email
}
return nil
}
func (x *UpdateRequest) GetPassword() *wrappers.StringValue {
func (x *UpdateRequest) GetPassword() *wrapperspb.StringValue {
if x != nil {
return x.Password
}
@@ -1123,7 +1118,8 @@ var file_proto_users_proto_rawDesc = []byte{
0x2e, 0x75, 0x73, 0x65, 0x72, 0x73, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x73, 0x2e, 0x56,
0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x00, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x75, 0x73, 0x65,
0x72, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -1140,28 +1136,28 @@ func file_proto_users_proto_rawDescGZIP() []byte {
var file_proto_users_proto_msgTypes = make([]protoimpl.MessageInfo, 21)
var file_proto_users_proto_goTypes = []interface{}{
(*User)(nil), // 0: users.User
(*CreateRequest)(nil), // 1: users.CreateRequest
(*CreateResponse)(nil), // 2: users.CreateResponse
(*ReadRequest)(nil), // 3: users.ReadRequest
(*ReadResponse)(nil), // 4: users.ReadResponse
(*ReadByEmailRequest)(nil), // 5: users.ReadByEmailRequest
(*ReadByEmailResponse)(nil), // 6: users.ReadByEmailResponse
(*UpdateRequest)(nil), // 7: users.UpdateRequest
(*UpdateResponse)(nil), // 8: users.UpdateResponse
(*DeleteRequest)(nil), // 9: users.DeleteRequest
(*DeleteResponse)(nil), // 10: users.DeleteResponse
(*ListRequest)(nil), // 11: users.ListRequest
(*ListResponse)(nil), // 12: users.ListResponse
(*LoginRequest)(nil), // 13: users.LoginRequest
(*LoginResponse)(nil), // 14: users.LoginResponse
(*LogoutRequest)(nil), // 15: users.LogoutRequest
(*LogoutResponse)(nil), // 16: users.LogoutResponse
(*ValidateRequest)(nil), // 17: users.ValidateRequest
(*ValidateResponse)(nil), // 18: users.ValidateResponse
nil, // 19: users.ReadResponse.UsersEntry
nil, // 20: users.ReadByEmailResponse.UsersEntry
(*wrappers.StringValue)(nil), // 21: google.protobuf.StringValue
(*User)(nil), // 0: users.User
(*CreateRequest)(nil), // 1: users.CreateRequest
(*CreateResponse)(nil), // 2: users.CreateResponse
(*ReadRequest)(nil), // 3: users.ReadRequest
(*ReadResponse)(nil), // 4: users.ReadResponse
(*ReadByEmailRequest)(nil), // 5: users.ReadByEmailRequest
(*ReadByEmailResponse)(nil), // 6: users.ReadByEmailResponse
(*UpdateRequest)(nil), // 7: users.UpdateRequest
(*UpdateResponse)(nil), // 8: users.UpdateResponse
(*DeleteRequest)(nil), // 9: users.DeleteRequest
(*DeleteResponse)(nil), // 10: users.DeleteResponse
(*ListRequest)(nil), // 11: users.ListRequest
(*ListResponse)(nil), // 12: users.ListResponse
(*LoginRequest)(nil), // 13: users.LoginRequest
(*LoginResponse)(nil), // 14: users.LoginResponse
(*LogoutRequest)(nil), // 15: users.LogoutRequest
(*LogoutResponse)(nil), // 16: users.LogoutResponse
(*ValidateRequest)(nil), // 17: users.ValidateRequest
(*ValidateResponse)(nil), // 18: users.ValidateResponse
nil, // 19: users.ReadResponse.UsersEntry
nil, // 20: users.ReadByEmailResponse.UsersEntry
(*wrapperspb.StringValue)(nil), // 21: google.protobuf.StringValue
}
var file_proto_users_proto_depIdxs = []int32{
0, // 0: users.CreateResponse.user:type_name -> users.User

View File

@@ -6,7 +6,7 @@ package users
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 users;
option go_package = "proto;users";
option go_package = "./proto;users";
import "google/protobuf/wrappers.proto";
service Users {
@@ -101,4 +101,4 @@ message ValidateRequest {
message ValidateResponse {
User user = 1;
}
}