8am's People
Forkers
milossimic biexiang taimoor99 forging2012 itcloudy 321dao xyhp915 isgasho vtansen nattaponra oreza bamoo456 yutaroyutaro pzentenoe raymondzhaoy kavonm alberttokped gunererd dharmatin ddigodavid dreamph chelium cadenvip ryano3000 sector84 lin0xu ryicoh samhwang1990 damianoneill yph136 zyichi wg001 scotty100 enixdark ivannau lingling1420q wandyirawan congphan taeyeonwm cuzzuky87 ductam1987 butterv nelsonken digenaldo smallteeths kyocfe tuanden0 ztp1977 liaokaishan yuta-masano khantwaikyaw mowazzem karolis-arbaciauskas osvaldotcf8am's Issues
Multi-tenancy logic related to repository, usecase or handler layer?
@hatajoe thanks for your amazing work! Go is just a hobby for me and I'm having fun. I'm learning a lot from your project.
I'm trying to understand if multi-tenancy column/table based is something to be "included", if it is "related to" the repository, usecase or handler level.
Example
Adding tenant.go
model like this:
package model
type Tenant struct {
ID int64 `json:"id"`
Name string `json:"name"`
}
to other models like this:
package model
type User struct {
ID string
TenantID int64 `json:"tenant_id"` // <--- here
Tenant *Tenant // <--- here
Email string
}
Question
Let's say my tenant_id
is a field of a User
struct in context
on every request (authenticated by a third party middleware).
Where do you think I should do something like below? In handler, usecase or repository?
tenantID := GetTenantIDFromUserInContext()
article.TenantID = tenantID
Doubts about fetch queries
Today, before I discover the amazing "clean architecture", I'm using a where
clause in my SQL queries (go-pg/pg#1179), like this:
// Used as: "q.Apply(FilterByTenant(ctx))"
func FilterByTenant(ctx context.Context) func(q *orm.Query) (*orm.Query, error) {
user := ctx.Value(auth.CTXKeyUser).(*models.User)
return func(q *orm.Query) (*orm.Query, error) {
q = q.Where("tenant_id = ?", user.TenantID)
return q, nil
}
}
I think maybe the concept of FilterByTenant
in the usecase layer is an unnecessary repetition and should belong to lower levels like repositories?
But I also think that the main multi-tenancy logic does not change with the change of possible repository types (Postgres, Mysql, Mongo, microservices).
What do you think about it?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.