-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.go
91 lines (75 loc) · 3.19 KB
/
common.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package page
import (
"context"
"io"
"net/http"
"strings"
"time"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/date"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
"github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
)
const FormUrlEncoded = "application/x-www-form-urlencoded"
type Template func(io.Writer, interface{}) error
type Logger interface {
InfoContext(ctx context.Context, msg string, args ...any)
ErrorContext(ctx context.Context, msg string, args ...any)
}
type ShareCodeStore interface {
Get(ctx context.Context, actorType actor.Type, shareCode string) (actor.ShareCodeData, error)
Put(ctx context.Context, actorType actor.Type, shareCode string, data actor.ShareCodeData) error
}
type NotifyClient interface {
SendActorEmail(context context.Context, to, lpaUID string, email notify.Email) error
SendActorSMS(context context.Context, to, lpaUID string, sms notify.SMS) error
}
type OneLoginClient interface {
AuthCodeURL(state, nonce, locale string, identity bool) (string, error)
EndSessionURL(idToken, postLogoutURL string) (string, error)
Exchange(ctx context.Context, code, nonce string) (idToken, accessToken string, err error)
UserInfo(ctx context.Context, accessToken string) (onelogin.UserInfo, error)
}
type DonorStore interface {
Create(context.Context) (*actor.DonorProvidedDetails, error)
Put(context.Context, *actor.DonorProvidedDetails) error
}
type Bundle interface {
For(lang localize.Lang) *localize.Localizer
}
type Localizer interface {
Concat([]string, string) string
Count(string, int) string
Format(string, map[string]any) string
FormatCount(string, int, map[string]interface{}) string
FormatDate(date.TimeOrDate) string
FormatTime(time.Time) string
FormatDateTime(time.Time) string
Possessive(string) string
SetShowTranslationKeys(bool)
ShowTranslationKeys() bool
T(string) string
}
func PostFormString(r *http.Request, name string) string {
return strings.TrimSpace(r.PostFormValue(name))
}
func PostFormReferenceNumber(r *http.Request, name string) string {
return strings.ReplaceAll(strings.ReplaceAll(r.PostFormValue(name), " ", ""), "-", "")
}
type Handler func(data AppData, w http.ResponseWriter, r *http.Request) error
type EventClient interface {
SendNotificationSent(ctx context.Context, notificationSentEvent event.NotificationSent) error
SendPaperFormRequested(ctx context.Context, paperFormRequestedEvent event.PaperFormRequested) error
}
type SessionStore interface {
Csrf(r *http.Request) (*sesh.CsrfSession, error)
SetCsrf(r *http.Request, w http.ResponseWriter, session *sesh.CsrfSession) error
Login(r *http.Request) (*sesh.LoginSession, error)
SetLogin(r *http.Request, w http.ResponseWriter, session *sesh.LoginSession) error
ClearLogin(r *http.Request, w http.ResponseWriter) error
OneLogin(r *http.Request) (*sesh.OneLoginSession, error)
SetOneLogin(r *http.Request, w http.ResponseWriter, session *sesh.OneLoginSession) error
}