middleware

package
v0.0.0-...-2c8c8f7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// API key
	CtxApiKey = CtxKey("Web3Pay-Api-Key")
)
View Source
const (
	// billing status context key
	CtxKeyBillingStatus = CtxKey("Web3Pay-Billing-Status")
)
View Source
const (
	// VIP subscription status context key
	CtxKeyVipSubscriptionStatus = CtxKey("Web3Pay-Vip-Subscription-Status")
)

Variables

This section is empty.

Functions

func ApiKeyContextInjector

func ApiKeyContextInjector(kextractor func(r *http.Request) string) httpContextInjector

ApiKeyContextInjector returns context injector by extracting API key from request

func GetApiKeyFromContext

func GetApiKeyFromContext(ctx context.Context) (string, bool)

GetApiKeyFromContext gets API key from context

Types

type BillingMiddlewareOption

type BillingMiddlewareOption struct {
	// we3pay client to request billing gateway (mandatory)
	Client *client.BillingClient
	// provider to get API key from context, use `GetApiKeyFromContext` if not provided
	ApiKeyProvider authKeyProvider
	// whether to propagate internal server errors of the requested billing gateway
	// to the already billed users, default as false which will pretend nothing wrong
	// happened except some error logs will be printed. This is usually used to mitigate
	// side effects such as blocking paid user from access due to internal server errors.
	PropagateInternalServerError bool
}

func NewBillingMiddlewareOptionWithClient

func NewBillingMiddlewareOptionWithClient(client *client.BillingClient) *BillingMiddlewareOption

func (*BillingMiddlewareOption) InitDefault

func (option *BillingMiddlewareOption) InitDefault() *BillingMiddlewareOption

type BillingStatus

type BillingStatus struct {
	Receipt *service.BillingReceipt // billing receipt
	Error   error                   // billing error
	// contains filtered or unexported fields
}

BillingStatus billing result

func BillingStatusFromContext

func BillingStatusFromContext(ctx context.Context) (*BillingStatus, bool)

BillingStatusFromContext returns billing status from context

func NewBillingStatusWithError

func NewBillingStatusWithError(apiKey string, err error) *BillingStatus

create billing status from error

func NewBillingStatusWithReceipt

func NewBillingStatusWithReceipt(apiKey string, receipt *service.BillingReceipt) *BillingStatus

create billing status from receipt

func (*BillingStatus) BusinessError

func (bs *BillingStatus) BusinessError() (error, bool)

BusinessError returns business error as it is otherwise nil

func (*BillingStatus) InternalServerError

func (bs *BillingStatus) InternalServerError() (error, bool)

InternalServerError return internal server error as it is otherwise nil

func (*BillingStatus) Success

func (bs *BillingStatus) Success() bool

Success checks if billing successful

type CtxKey

type CtxKey string

CtxKey context key

type HttpBillingMiddlewareOption

type HttpBillingMiddlewareOption struct {
	*BillingMiddlewareOption
	// gets resource ID from http request
	ResourceIdMapper HttpResourceIdMapper
}

func NewHttpBillingMiddlewareOptionWithClient

func NewHttpBillingMiddlewareOptionWithClient(client *client.BillingClient) *HttpBillingMiddlewareOption

func (*HttpBillingMiddlewareOption) InitDefault

type HttpMiddleware

type HttpMiddleware = func(next http.Handler) http.Handler

net/http middleware

func HttpBillingMiddleware

func HttpBillingMiddleware(option *HttpBillingMiddlewareOption) HttpMiddleware

HttpBillingMiddleware provides billing RPC middleware for net/http.

func HttpInjectContextMiddleware

func HttpInjectContextMiddleware(injectors ...httpContextInjector) HttpMiddleware

HttpInjectContextMiddleware injects contextual data

func HttpVipSubscriptionMiddleware

func HttpVipSubscriptionMiddleware(option *VipSubscriptionMiddlewareOption) HttpMiddleware

HttpVipSubscriptionMiddleware provides VIP subscription RPC middleware for net/http.

type HttpResourceIdMapper

type HttpResourceIdMapper func(req *http.Request) string

type Ow3BillingMiddlewareOption

type Ow3BillingMiddlewareOption struct {
	*BillingMiddlewareOption
	// gets resource ID from json rpc message
	ResourceIdMapper Ow3ResourceIdMapper
}

func NewOw3BillingMiddlewareOptionWithClient

func NewOw3BillingMiddlewareOptionWithClient(client *client.BillingClient) *Ow3BillingMiddlewareOption

type Ow3Middleware

type Ow3Middleware = rpc.HandleCallMsgMiddleware

openweb3 middleware

func Openweb3BillingMiddleware

func Openweb3BillingMiddleware(option *Ow3BillingMiddlewareOption) Ow3Middleware

Openweb3BillingMiddleware provides billing RPC middleware for openweb3.

func Openweb3VipSubscriptionMiddleware

func Openweb3VipSubscriptionMiddleware(option *VipSubscriptionMiddlewareOption) Ow3Middleware

Openweb3VipSubscriptionMiddleware provides VIP subscription RPC middleware for openweb3.

type Ow3ResourceIdMapper

type Ow3ResourceIdMapper func(msg *rpc.JsonRpcMessage) string

type VipSubscriptionMiddlewareOption

type VipSubscriptionMiddlewareOption struct {
	// client to request VIP subscription info from the blockchain network (mandatory)
	Client *client.VipSubscriptionClient
	// provider to get API key from context, use `GetApiKeyFromContext` if not provided
	ApiKeyProvider authKeyProvider
	// whether to propagate non-business error to the already subscribed users, default as
	// false which will pretend nothing wrong happened except some error logs will be printed.
	// This is usually used to mitigate side effects such as blocking paid user from access
	// due to some server errors (such as timeout etc.,)
	PropagateNonBusinessError bool
}

func NewVipSubscriptionMiddlewareOptionWithClient

func NewVipSubscriptionMiddlewareOptionWithClient(client *client.VipSubscriptionClient) *VipSubscriptionMiddlewareOption

func (*VipSubscriptionMiddlewareOption) InitDefault

type VipSubscriptionStatus

type VipSubscriptionStatus struct {
	VipInfo *types.VipInfo // VIP info
	Error   error          // subscription error
	// contains filtered or unexported fields
}

VipSubscriptionStatus VIP subscription status

func NewVipSubscriptionStatusWithError

func NewVipSubscriptionStatusWithError(apiKey string, err error) *VipSubscriptionStatus

create subscription status from error

func NewVipSubscriptionStatusWithInfo

func NewVipSubscriptionStatusWithInfo(apiKey string, vi *types.VipInfo) *VipSubscriptionStatus

create subscription status from subscription VIP info

func VipSubscriptionStatusFromContext

func VipSubscriptionStatusFromContext(ctx context.Context) (*VipSubscriptionStatus, bool)

VipSubscriptionStatusFromContext returns VIP subscription status from context

func (*VipSubscriptionStatus) BusinessError

func (bs *VipSubscriptionStatus) BusinessError() (error, bool)

BusinessError returns business error as it is otherwise nil

func (*VipSubscriptionStatus) GetVipInfo

func (ss *VipSubscriptionStatus) GetVipInfo() (*types.VipInfo, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL