Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/handlers/device_association_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func DeviceShareCodeQR(w http.ResponseWriter, r *http.Request) {
impl,
w,
r,
func(result *model.DeviceShareCodeQRResult) bool {
func(_ *session.ClientSession, result *model.DeviceShareCodeQRResult) bool {
w.Header().Set("Content-Type", "image/png")
w.Write(result.PngBytes)
return true
Expand Down Expand Up @@ -62,7 +62,7 @@ func DeviceAdoptCodeQR(w http.ResponseWriter, r *http.Request) {
impl,
w,
r,
func(result *model.DeviceAdoptCodeQRResult) bool {
func(_ *session.ClientSession, result *model.DeviceAdoptCodeQRResult) bool {
w.Header().Set("Content-Type", "image/png")
w.Write(result.PngBytes)
return true
Expand Down
2 changes: 1 addition & 1 deletion controller/circle_wallet_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func findMostRecentCircleWallet(session *session.ClientSession) (*CircleWalletIn
return mostRecentWalletInfo, nil
}

func VerifyCircleBody(req *http.Request) (io.Reader, error) {
func VerifyCircleBody(clientSession *session.ClientSession, req *http.Request) (io.Reader, error) {

// server.Logger().Println("VerifyCircleBody")

Expand Down
8 changes: 4 additions & 4 deletions controller/subscription_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ func PlaySubscriptionRenewalPost(
return nil
}

func VerifyStripeBody(req *http.Request) (io.Reader, error) {
func VerifyStripeBody(clientSession *session.ClientSession, req *http.Request) (io.Reader, error) {
bodyBytes, err := io.ReadAll(req.Body)
if err != nil {
return nil, err
Expand All @@ -1502,7 +1502,7 @@ func VerifyStripeBody(req *http.Request) (io.Reader, error) {
return bytes.NewReader(bodyBytes), nil
}

func VerifyCoinbaseBody(req *http.Request) (io.Reader, error) {
func VerifyCoinbaseBody(clientSession *session.ClientSession, req *http.Request) (io.Reader, error) {
bodyBytes, err := io.ReadAll(req.Body)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1533,7 +1533,7 @@ func coinbaseSignature(bodyBytes []byte, header string, secret string) error {
return errors.New("Invalid authentication.")
}

func VerifyPlayBody(req *http.Request) (io.Reader, error) {
func VerifyPlayBody(clientSession *session.ClientSession, req *http.Request) (io.Reader, error) {

bodyBytes, err := io.ReadAll(req.Body)
if err != nil {
Expand Down Expand Up @@ -1941,7 +1941,7 @@ var heliusAuthSecret = sync.OnceValue(func() string {
return c["helius"].(map[string]any)["webhook_auth_header"].(string)
})

func VerifyHeliusBody(req *http.Request) (io.Reader, error) {
func VerifyHeliusBody(clientSession *session.ClientSession, req *http.Request) (io.Reader, error) {
bodyBytes, err := io.ReadAll(req.Body)
if err != nil {
return nil, err
Expand Down
20 changes: 9 additions & 11 deletions router/handler_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (

type ImplFunction[R any] func(*session.ClientSession) (R, error)
type ImplWithInputFunction[T any, R any] func(T, *session.ClientSession) (R, error)
type BodyFormatFunction func(*http.Request) (io.Reader, error)
type FormatFunction[R any] func(result R) (complete bool)
type BodyFormatFunction func(*session.ClientSession, *http.Request) (io.Reader, error)
type FormatFunction[R any] func(*session.ClientSession, R) (complete bool)

func JsonFormatter[R any](w http.ResponseWriter) FormatFunction[R] {
formatter := func(result R) bool {
formatter := func(clientSession *session.ClientSession, result R) bool {
responseJson, err := json.Marshal(result)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -70,12 +70,11 @@ func wrap[R any](
}

for _, formatter := range formatters {
if complete := formatter(result); complete {
if complete := formatter(session, result); complete {
return
}
}

JsonFormatter[R](w)(result)
JsonFormatter[R](w)(session, result)
}

func implName[R any](impl ImplFunction[R]) string {
Expand Down Expand Up @@ -208,7 +207,7 @@ func wrapWithInput[T any, R any](
// return
// }

body, err := bodyFormatter(req)
body, err := bodyFormatter(session, req)
if err != nil {
glog.Infof("[h]request body formatter error %s\n", err)
http.Error(w, err.Error(), http.StatusBadRequest)
Expand Down Expand Up @@ -245,12 +244,11 @@ func wrapWithInput[T any, R any](
}

for _, formatter := range formatters {
if complete := formatter(result); complete {
if complete := formatter(session, result); complete {
return
}
}

JsonFormatter[R](w)(result)
JsonFormatter[R](w)(session, result)
}

// guarantees NetworkId+UserId
Expand Down Expand Up @@ -425,6 +423,6 @@ func RaiseHttpError(err error, w http.ResponseWriter) (statusError bool) {
return
}

func RequestBodyFormatter(req *http.Request) (io.Reader, error) {
func RequestBodyFormatter(clientSession *session.ClientSession, req *http.Request) (io.Reader, error) {
return req.Body, nil
}