diff options
| author | mo khan <mo@mokhan.ca> | 2025-05-28 12:14:11 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-05-28 12:14:11 -0600 |
| commit | 591f293c8bcf464ed62701321d3f27de31ceb621 (patch) | |
| tree | 6b9c8c303f9816a3faf7abb9a75c3c59b6a5808a /app/domain | |
| parent | f76542bc846bc77e825055a1a6ea7cd0cb178844 (diff) | |
refactor: parse headers injected by envoy
Diffstat (limited to 'app/domain')
| -rw-r--r-- | app/domain/identifiable.go | 8 | ||||
| -rw-r--r-- | app/domain/user.go | 11 |
2 files changed, 16 insertions, 3 deletions
diff --git a/app/domain/identifiable.go b/app/domain/identifiable.go index 8fbc1e4..06bec07 100644 --- a/app/domain/identifiable.go +++ b/app/domain/identifiable.go @@ -1,7 +1,15 @@ package domain +import "github.com/xlgmokha/x/pkg/x" + type Identifiable interface { GetID() ID SetID(id ID) error ToGID() string } + +func WithID[T Identifiable](id ID) x.Configure[T] { + return func(item T) { + item.SetID(id) + } +} diff --git a/app/domain/user.go b/app/domain/user.go index 02ddd26..a6adfa8 100644 --- a/app/domain/user.go +++ b/app/domain/user.go @@ -1,15 +1,20 @@ package domain +import "github.com/xlgmokha/x/pkg/x" + type User struct { ID ID `json:"id" jsonapi:"primary,users"` Username string `json:"username" jsonapi:"attr,username"` - Email string `json:"email" jsonapi:"attr,email"` ProfileURL string `json:"profile" jsonapi:"attr,profile"` Picture string `json:"picture" jsonapi:"attr,picture"` } -func NewUser() *User { - return &User{} +func NewUser(options ...x.Configure[*User]) *User { + user := &User{} + for _, option := range options { + option(user) + } + return user } func (u *User) GetID() ID { |
