ftx

package module
v0.11.20 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2025 License: Unlicense Imports: 75 Imported by: 1

README

ftx

Documentation

Index

Constants

View Source
const (
	// RequestMaxBodySize limits the amount of data read from the request body to prevent memory exhaustion
	RequestMaxBodySize = 2 * 1024 * 1024 // 2 MB
)

Variables

View Source
var (
	OTPRequestedTopic = Topic("auth.otp.requested")
)

Functions

func AdminKeyFromContext

func AdminKeyFromContext(ctx context.Context) (value string, found bool)

func BaseType

func BaseType(elem any) reflect.Type

BaseType returns the base type of the given element

func Broadcast added in v0.11.0

func Broadcast[T comparable](observer Observer[T], payload protoreflect.ProtoMessage, topics ...T)

func Collection

func Collection[T any]() string

Collection returns the name of the collection for the given element

func CompositeMiddleware

func CompositeMiddleware(middleware ...mux.MiddlewareFunc) mux.MiddlewareFunc

CompositeMiddleware composes multiple mux.MiddlewareFunc into a single one, applying them in the order provided (first to last).

func ConfigFromEnv

func ConfigFromEnv[T proto.Message](defaultConf T) T

func ConnectionClosed added in v0.11.0

func ConnectionClosed(conn *websocket.Conn) <-chan struct{}

ConnectionClosed returns a channel that is closed when the connection is closed

func ContextWithAdminKey

func ContextWithAdminKey(parent context.Context, key string) context.Context

func ContextWithDirectives

func ContextWithDirectives(parent context.Context, directives []string) context.Context

func ContextWithSession

func ContextWithSession(parent context.Context, session *authv1.Session) context.Context

func CreateAdminAccount added in v0.11.12

func CreateAdminAccount(ctx context.Context, access Access, req *dashboardv1.RegisterAccountRequest) (key string, err error)

func DirectivesFromContext

func DirectivesFromContext(ctx context.Context) (directives []string, found bool)

func Dot

func Dot(parts ...string) string

Dot joins a slice of strings with a dot

func DoubleQuote

func DoubleQuote(s string) string

DoubleQuote ...

func Enforce

func Enforce[T proto.Message](ctx context.Context, enforcer casbin.IEnforcer, subjectFn SubjectFn[T], enforceFn EnforceFn[T]) (subject T, authorized bool)

Enforce is a helper function to enforce a policy

func Enforcer

func Enforcer(conf, policy string) func() (*casbin.Enforcer, error)

Enforcer is a helper function to provide a casbin enforcer

func Expose

func Expose[T proto.Message]() exposed

Expose ...

func GraphqlMiddleware

func GraphqlMiddleware(next http.Handler) http.Handler

GraphqlMiddleware injects the directives into the context

func HandleDownloadFile

func HandleDownloadFile[T FileStorage](fs T) runtime.HandlerFunc

func HandleUploadFile

func HandleUploadFile[T FileStorage](fs T) runtime.HandlerFunc

func HashFile

func HashFile(file []byte) (string, error)

HashFile ...

func HttpHandler

func HttpHandler(hf grpc_runtime.HandlerFunc) http.HandlerFunc

HttpHandler converts a runtime.HandlerFunc to a http.HandlerFunc

func ID

func ID[T any](key string) string

NODE HELPERS

func JSONName

func JSONName(f reflect.StructField) string

JSONName returns the name of the field in the JSON tag

func Join

func Join(parts ...string) string

Join joins a slice of strings

func Map

func Map[T any](size int, fn func(int) T) (result []T)

Map converts a slice of values to a slice of values using a function

func Match

Match applies a single mux.MiddlewareFunc only if the request path matches the given regexp.

func Mutation

func Mutation[Arg, Out proto.Message](fn func(context.Context, Arg) (Out, error)) mutation

Mutation ...

func NewBitcoinCore added in v0.11.0

func NewBitcoinCore(ctx context.Context, config *configv1.Bitcoin, observer Observer[Topic], invoices ...*paymentv1.Invoice) *bitcoinCore

func NewConnection

func NewConnection(ctx context.Context, conf *configv1.Connection) (*connection, error)

NewConnection ...

func NewDbFileStorage

func NewDbFileStorage(access Access) (*dbFileStorage, error)

NewDbFileStorage ...

func NewFilesystemStorage

func NewFilesystemStorage(config *configv1.FilesystemStorage) *filesystemStorage

NewFilesystemStorage ...

func NewGraph

func NewGraph() *graph

NewGraph ...

func NewObserver

func NewObserver[T comparable]() *observer[T]

NewObserver ...

func OTPMailSubscriber

func OTPMailSubscriber(ctx context.Context, config *configv1.Mail, message OTPMailTemplate) (Topic, Processor[Topic])

OTPMailSubscriber is a function that sends an email to the user with the OTP code

func ProtoMarshal

func ProtoMarshal(v any, out proto.Message) error

func Provide

func Provide[T any](val any) fx.Option

Provide provides a value annotated with a specific type

func Pure

func Pure[T any](v T) (result T)

Pure converts a value to a pure JSON value

func Query

func Query[Arg, Out proto.Message](fn func(context.Context, Arg) (Out, error)) query

Query ...

func QueryFilter added in v0.11.0

func QueryFilter(parts ...string) string

func QueryJoin

func QueryJoin(parts ...string) string

QueryJoin joins a slice of strings with a space

func Quote

func Quote(s string) string

Quote ...

func ReadRequestBody

func ReadRequestBody(r *http.Request) ([]byte, error)

ReadRequestBody reads and returns the full body of the request without consuming it permanently. It restores the body so it can be read again later. Returns an error if reading fails or body exceeds MaxBodySize.

func ResourceID

func ResourceID(resource, key string) string

func RuntimeHandler

func RuntimeHandler(hf http.HandlerFunc) grpc_runtime.HandlerFunc

RuntimeHandler converts a http.HandlerFunc to a runtime.HandlerFunc

func Select

func Select[T any](v T) selector[T]

Select returns a new selector with the given value

func SessionFromContext

func SessionFromContext(ctx context.Context) (session *authv1.Session, found bool)

func Should

func Should[T any](v T, _ error) T

Should returns a value and ignores the error

func Subject

func Subject[T proto.Message](ctx context.Context, subject SubjectFn[T]) (val T, err error)

Subject returns a value and an error from a SubjectFn

func ToMap

func ToMap(v any) (result map[string]any)

ToMap converts a value to a map[string]any

func ValueOfEnum added in v0.10.11

func ValueOfEnum(enum protoreflect.EnumDescriptor, name string) protoreflect.Value

func Vars

func Vars() bindVars

Vars ...

func VarsFor

func VarsFor[T proto.Message](elem T) bindVars

Types

type Access

type Access interface {
	// AutoMigrate ...
	AutoMigrate(ctx context.Context, graph Graph) error

	// Collection ...
	Collection(ctx context.Context, elem any, callbacks ...CollectionCallback) (driver.Collection, error)

	// Query returns a list of elements
	Query(ctx context.Context, query string, bindVars map[string]any, out any) error

	// Fetch returns a single element
	Fetch(ctx context.Context, query string, bindVars map[string]any, out any) error

	// List ...
	List(ctx context.Context, bindVars BindVars, out any) (int64, error)

	// Find ...
	Find(ctx context.Context, bindVars BindVars, out any) error

	// Create ...
	Create(ctx context.Context, val any) ([]string, error)

	// Update ...
	Update(ctx context.Context, key string, item any) error

	// Replace ...
	Replace(ctx context.Context, key string, item any) error

	// Delete ...
	Delete(ctx context.Context, item any) error

	// Relations ...
	Relations(ctx context.Context, id string, bindVars BindVars, direction Direction, out any) (int64, error)
}

Access ...

type ArangoAccess

type ArangoAccess struct {
	// contains filtered or unexported fields
}

func NewArangoAccess

func NewArangoAccess(conn Connection, observer Observer[Topic]) (*ArangoAccess, error)

func (*ArangoAccess) AutoMigrate

func (e *ArangoAccess) AutoMigrate(ctx context.Context, graph Graph) error

AutoMigrate ...

func (*ArangoAccess) Collection

func (e *ArangoAccess) Collection(ctx context.Context, elem any, callbacks ...CollectionCallback) (col driver.Collection, err error)

Collection ...

func (*ArangoAccess) Create

func (e *ArangoAccess) Create(ctx context.Context, val any) ([]string, error)

Create ...

func (*ArangoAccess) Delete

func (e *ArangoAccess) Delete(ctx context.Context, item any) error

Delete ...

func (*ArangoAccess) Fetch

func (e *ArangoAccess) Fetch(ctx context.Context, query string, bindVars map[string]any, out any) error

Fetch ...

func (*ArangoAccess) Find

func (e *ArangoAccess) Find(ctx context.Context, bindVars BindVars, out any) error

Find ...

func (*ArangoAccess) List

func (e *ArangoAccess) List(ctx context.Context, bindVars BindVars, out any) (int64, error)

List ...

func (*ArangoAccess) Query

func (e *ArangoAccess) Query(ctx context.Context, query string, bindVars map[string]any, out any) error

Query ...

func (*ArangoAccess) Relations

func (e *ArangoAccess) Relations(ctx context.Context, id string, bindVars BindVars, direction Direction, out any) (int64, error)

Relations ...

func (*ArangoAccess) Replace

func (e *ArangoAccess) Replace(ctx context.Context, key string, item any) error

Replace ...

func (*ArangoAccess) Update

func (e *ArangoAccess) Update(ctx context.Context, key string, item any) error

Update ...

type AuthHandler

type AuthHandler struct {
	authv1.UnsafeAuthenticationServiceServer
	// contains filtered or unexported fields
}

func NewAuthHandler

func NewAuthHandler(ctx context.Context, config *configv1.Auth, params AuthHandlerParams) (*AuthHandler, error)

func (*AuthHandler) Handler

func (h *AuthHandler) Handler(ctx context.Context) http.Handler

func (*AuthHandler) Middleware

func (h *AuthHandler) Middleware(next http.Handler) http.Handler

func (*AuthHandler) RefreshToken

func (h *AuthHandler) RefreshToken(ctx context.Context, req *emptypb.Empty) (*authv1.RefreshTokenResponse, error)

func (*AuthHandler) RequestOTP

func (*AuthHandler) ValidateSSOToken

func (h *AuthHandler) ValidateSSOToken(ctx context.Context, req *emptypb.Empty) (*authv1.ValidateSSOTokenResponse, error)

func (*AuthHandler) VerifyOTP

type AuthHandlerParams

type AuthHandlerParams struct {
	fx.In

	Access   Access
	Observer Observer[Topic]
}

type BindVars

type BindVars interface {
	// LimitString ...
	LimitString() string

	// FiltersFor ...
	FiltersFor(doc string) string

	// Values ...
	Values() map[string]interface{}
}

BindVars ...

type BitcoinPaymentGateway added in v0.11.0

type BitcoinPaymentGateway struct {
	bitcoinv1.UnsafeBitcoinPaymentServiceServer
	// contains filtered or unexported fields
}

func NewBitcoinPaymentGateway added in v0.11.0

func NewBitcoinPaymentGateway(ctx context.Context, config *configv1.Bitcoin, params BitcoinPaymentGatewayParams) (*BitcoinPaymentGateway, error)

func (*BitcoinPaymentGateway) CreateInvoice added in v0.11.0

func (*BitcoinPaymentGateway) Export added in v0.11.0

func (*BitcoinPaymentGateway) GetInvoice added in v0.11.0

func (*BitcoinPaymentGateway) Handler added in v0.11.0

func (h *BitcoinPaymentGateway) Handler(ctx context.Context, middlewares ...runtime.Middleware) http.Handler

func (*BitcoinPaymentGateway) ListInvoices added in v0.11.0

func (*BitcoinPaymentGateway) Ping added in v0.11.6

func (*BitcoinPaymentGateway) RefreshInvoice added in v0.11.0

func (*BitcoinPaymentGateway) Subscribe added in v0.11.0

func (h *BitcoinPaymentGateway) Subscribe(w http.ResponseWriter, r *http.Request, pathParams map[string]string)

type BitcoinPaymentGatewayParams added in v0.11.0

type BitcoinPaymentGatewayParams struct {
	fx.In

	Access   Access
	Observer Observer[Topic]
}

type CasbinAdapter

type CasbinAdapter[T proto.Message] struct {
	// contains filtered or unexported fields
}

CasbinAdapter ...

func Unsafe_NewCasbinAdapter

func Unsafe_NewCasbinAdapter[T proto.Message](ctx context.Context, access Access) (*CasbinAdapter[T], error)

Unsafe_NewCasbinAdapter ... TODO: finish this

func (*CasbinAdapter[T]) AddPolicy

func (a *CasbinAdapter[T]) AddPolicy(sec string, ptype string, rule []string) error

AddPolicy implements persist.Adapter.

func (*CasbinAdapter[T]) ExtraFields added in v0.10.11

func (a *CasbinAdapter[T]) ExtraFields() (result []protoreflect.FieldDescriptor)

func (*CasbinAdapter[T]) LoadPolicy

func (a *CasbinAdapter[T]) LoadPolicy(model model.Model) error

LoadPolicy implements persist.Adapter.

func (*CasbinAdapter[T]) Marshal

func (a *CasbinAdapter[T]) Marshal(elem T) (sec string, ptype string, rule []string)

func (*CasbinAdapter[T]) RemoveFilteredPolicy

func (a *CasbinAdapter[T]) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error

RemoveFilteredPolicy implements persist.Adapter.

func (*CasbinAdapter[T]) RemovePolicy

func (a *CasbinAdapter[T]) RemovePolicy(sec string, ptype string, rule []string) error

RemovePolicy implements persist.Adapter.

func (*CasbinAdapter[T]) SavePolicy

func (a *CasbinAdapter[T]) SavePolicy(model model.Model) error

SavePolicy implements persist.Adapter.

func (*CasbinAdapter[T]) Unmarshal

func (a *CasbinAdapter[T]) Unmarshal(sec string, ptype string, rule []string) (out T, err error)

type CollectionCallback

type CollectionCallback func(context.Context, driver.Collection)

CollectionCallback ...

type Connection

type Connection interface {
	// Database ...
	Database(ctx context.Context) (driver.Database, error)
	// Collection ...
	Collection(ctx context.Context, elem any) (driver.Collection, error)
	// Reflect ...
	Reflect(ctx context.Context, elem reflect.Type) (driver.Collection, error)
}

Connection ...

type DashboardHandler

DashboardHandler ...

func NewDashboard

func NewDashboard(ctx context.Context, config *configv1.Dashboard, params DashboardParams) (*DashboardHandler, error)

NewDashboard ...

func (*DashboardHandler) AuthorizeMiddleware added in v0.10.11

func (h *DashboardHandler) AuthorizeMiddleware(skip *regexp.Regexp) runtime.Middleware

func (*DashboardHandler) DeleteAccount added in v0.11.12

func (*DashboardHandler) DeleteResource

func (*DashboardHandler) GetAccount

func (*DashboardHandler) GetResource

func (*DashboardHandler) GetSchema

func (*DashboardHandler) GetSession added in v0.11.12

func (*DashboardHandler) Handler

func (h *DashboardHandler) Handler(ctx context.Context) http.Handler

func (*DashboardHandler) ListAccounts added in v0.11.12

func (*DashboardHandler) ListResources

RESOURCES

func (*DashboardHandler) Login

AUTHENTICATION

func (*DashboardHandler) RegisterAccount added in v0.11.12

func (*DashboardHandler) UpdateDetails added in v0.11.12

func (*DashboardHandler) UpdateNotes added in v0.11.12

func (*DashboardHandler) UpdatePassword added in v0.11.14

func (*DashboardHandler) UpdateScopes added in v0.11.12

func (*DashboardHandler) UpdateStatus added in v0.11.12

type DashboardParams

type DashboardParams struct {
	fx.In

	Access
	Graph
	FileStorage
	Observer[Topic]
}

DashboardParams ...

type Direction

type Direction string
const (
	DirectionInbound  Direction = "INBOUND"
	DirectionOutbound Direction = "OUTBOUND"
	DirectionAny      Direction = "ANY"
)

func (Direction) String

func (d Direction) String() string

type EnforceFn

type EnforceFn[T proto.Message] func(ctx context.Context, subject T) (Rules, error)

EnforceFn is a function that returns a slice of any and an error

type Event

type Event[T comparable] struct {
	// Topic ...
	Topic T
	// Payload ...
	Payload protoreflect.ProtoMessage
	// Timestamp ...
	Timestamp time.Time
}

Event ...

type FileStorage

type FileStorage interface {
	// StoreFile ...
	StoreFile(name string, file []byte) (id string, err error)

	// StoreByHash ...
	StoreByHash(file []byte) (id string, err error)

	// ReadFile ...
	ReadFile(id string) (fileContent []byte, errr error)

	// MaxMemory ...
	MaxMemory() int64
}

FileStorage ...

type Graph

type Graph interface {
	// Node ...
	Node(node any)
	// Edge ...
	Edge(from, to, edge any)

	// Nodes ...
	Nodes() []reflect.Type
	// Edges ...
	Edges() []reflect.Type
	// Relation ...
	Relation(edge reflect.Type) *Relation

	// CollectionFor ...
	CollectionFor(elem reflect.Type) string
	// TypeOf ...
	TypeOf(name string) reflect.Type
}

Graph ...

type GraphqlHandler

type GraphqlHandler struct {
	Access Access
	Graph  Graph

	fx.In
}

GraphqlHandler ...

func (*GraphqlHandler) Handler

func (e *GraphqlHandler) Handler(ctx context.Context, handlers ...interface{}) *handler.Handler

Handler ...

type OTPMailTemplate

type OTPMailTemplate func(email, code string) []byte

OTPMailTemplate is a function that returns the message to send to the user

type Observer

type Observer[T comparable] interface {
	// Subscribe ...
	Subscribe(t T, p Processor[T]) SourceID
	// Unsubscribe ...
	Unsubscribe(s SourceID)
	// Emit ...
	Emit(e *Event[T]) error
}

Observer ...

type Processor

type Processor[T comparable] func(e *Event[T]) error

Processor ...

type Relation

type Relation struct {
	From reflect.Type `json:"_from"`
	To   reflect.Type `json:"_to"`
}

Relation

type Rule

type Rule []interface{}

Rule is a slice of any

type Rules

type Rules []Rule

Rules is a slice of Rule

func EnforceDirectives

func EnforceDirectives(ctx context.Context, role fmt.Stringer) Rules

EnforceDirectives returns the rules for the given role for each directive

type SourceID

type SourceID int64

SourceID ...

type SubjectFn

type SubjectFn[T proto.Message] func(ctx context.Context, session *domainv1.Session) (T, error)

SubjectFn is a function that returns a value and an error

type Topic

type Topic string
var (
	CreatedTopic  Topic = "document.created"
	UpdatedTopic  Topic = "document.updated"
	ReplacedTopic Topic = "document.replaced"
	DeletedTopic  Topic = "document.deleted"
)
var (
	DashboardCreatedTopic  Topic = "dashboard.created"
	DashboardReplacedTopic Topic = "dashboard.replaced"
	DashboardDeletedTopic  Topic = "dashboard.deleted"
)
var (
	CreateInvoiceTopic Topic = "invoice.create"
	UpdateInvoiceTopic Topic = "invoice.update"
)

func (Topic) For

func (t Topic) For(elem any) Topic

func (Topic) Tag added in v0.11.0

func (t Topic) Tag(tag, val string) Topic

Directories

Path Synopsis
examples
library command
ftx
cmd
internal
pkg
auth/domain/auth/v1
Package authv1 is a reverse proxy.
Package authv1 is a reverse proxy.
dashboard/domain/dashboard/v1
Package dashboardv1 is a reverse proxy.
Package dashboardv1 is a reverse proxy.
payment/domain/bitcoin/v1
Package bitcoinv1 is a reverse proxy.
Package bitcoinv1 is a reverse proxy.

Jump to

Keyboard shortcuts

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