-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect_go.go
36 lines (30 loc) · 947 Bytes
/
connect_go.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Package service implements the RPCs for neutral-diet services
package service
import (
"firebase.google.com/go/auth"
"firebase.google.com/go/messaging"
"github.com/bufbuild/connect-go"
"github.com/ram02z/neutral_diet/internal/service/db"
)
// A ConnectWrapper represents the PostgreSQL database, Firebase Authentication and Firebase
// messaging clients.
type ConnectWrapper struct {
s *db.Store
a *auth.Client
m *messaging.Client
}
// RequestWithValidator is an abstract interface used for connect-go requests.
type RequestWithValidator interface {
Validate() error
}
// NewConnectWrapper creates a new instance of [ConnectWrapper].
func NewConnectWrapper(s *db.Store, a *auth.Client, m *messaging.Client) *ConnectWrapper {
return &ConnectWrapper{s: s, a: a, m: m}
}
func validate(r RequestWithValidator) error {
err := r.Validate()
if err != nil {
return connect.NewError(connect.CodeInvalidArgument, err)
}
return nil
}