ftx

package module
v0.12.12 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 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)

Broadcast emits an event to the observer for the given topics

func COUNT added in v0.12.7

func COUNT[T proto.Message](filter Filters) (q string, bindVars map[string]interface{})

COUNT returns the number of documents in a collection

Example: "RETURN COUNT(FOR doc IN col FILTER doc.name == @name RETURN doc)" {"name": "John"}

func Collection

func Collection[T any]() string

Collection returns the name of the collection for the given element

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, password string, err error)

func DOCUMENT added in v0.12.0

func DOCUMENT(id string) (q string, bindVars map[string]interface{})

DOCUMENT returns a document by its id

Example: "RETURN DOCUMENT(@id)" {"id": "col/123"}

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 FOR added in v0.12.0

func FOR[T proto.Message](filter Filters) (q string, bindVars map[string]interface{})

FOR returns documents from a collection

Example: "FOR doc IN col FILTER doc.name == @name RETURN doc" {"name": "John"}

func Filter added in v0.12.0

func Filter(exprs ...string) filters

Filter ...

func FilterFrom added in v0.12.0

func FilterFrom[T proto.Message](elem T) filters

FilterFrom ...

func GraphqlMiddleware

func GraphqlMiddleware(next http.Handler) http.Handler

GraphqlMiddleware injects the directives into the context

func HandleDownloadFile

func HandleDownloadFile(fs FileStorage) http.HandlerFunc

func HandleUploadFile

func HandleUploadFile(fs FileStorage) http.HandlerFunc

func HashFile

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

HashFile ...

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 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 NewEnforcer added in v0.11.22

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

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 REMOVE added in v0.12.0

func REMOVE[T proto.Message](filter Filters) (q string, bindVars map[string]interface{})

REMOVE removes documents from a collection

Example: "FOR doc IN col FILTER doc.name == @name REMOVE doc IN col" {"name": "John"}

func ReadReset added in v0.12.8

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

ReadReset 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 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

Types

type Access

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

	// Collection ...
	Collection(ctx context.Context, elem any, callbacks ...func(context.Context, driver.Collection)) (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, filters Filters, out any) (int64, error)

	// Get ...
	Get(ctx context.Context, filters Filters, 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, filters Filters, 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 ...func(context.Context, driver.Collection)) (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) Get added in v0.12.4

func (e *ArangoAccess) Get(ctx context.Context, filters Filters, out any) error

Get ...

func (*ArangoAccess) List

func (e *ArangoAccess) List(ctx context.Context, filters Filters, 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, filters Filters, 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 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 Checks added in v0.12.8

type Checks[T any] []func(T) bool

Checks is a collection of functions that can be used to check if a key should be ignored

func (Checks[T]) All added in v0.12.8

func (c Checks[T]) All(key T) bool

All returns true if all of the checks return true

func (Checks[T]) Any added in v0.12.8

func (c Checks[T]) Any(key T) bool

Any returns true if any of the checks return true

type Comparer added in v0.12.0

type Comparer interface {
	Symbol() string
	Value() interface{}
}

Comparer ...

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 int

Direction is a direction of a relation.

INBOUND: the relation is inbound to the node, means the node is the target of the relation.

OUTBOUND: the relation is outbound from the node, means the node is the source of the relation.

ANY: the relation is inbound or outbound from the node, means the node is the source or target of the relation.

const (
	DirectionInbound Direction = iota
	DirectionOutbound
	DirectionAny
)

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 Eq added in v0.11.22

type Eq struct {
	To any
}

Eq supports the == operator

func (Eq) Symbol added in v0.11.22

func (Eq) Symbol() string

func (Eq) Value added in v0.11.22

func (e Eq) Value() interface{}

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 Filters added in v0.12.0

type Filters interface {
	// FilterString ...
	FilterString(doc string) string

	// SortString ...
	SortString(doc string) string

	// LimitString ...
	LimitString() string

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

Filters ...

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 Gt added in v0.11.22

type Gt struct {
	Than any
}

Gt supports the > operator

func (Gt) Symbol added in v0.11.22

func (Gt) Symbol() string

func (Gt) Value added in v0.11.22

func (g Gt) Value() interface{}

type Gte added in v0.11.22

type Gte struct {
	Than any
}

Gte supports the >= operator

func (Gte) Symbol added in v0.11.22

func (Gte) Symbol() string

func (Gte) Value added in v0.11.22

func (g Gte) Value() interface{}

type Lt added in v0.11.22

type Lt struct {
	Than any
}

Lt supports the < operator

func (Lt) Symbol added in v0.11.22

func (Lt) Symbol() string

func (Lt) Value added in v0.11.22

func (l Lt) Value() interface{}

type Lte added in v0.11.22

type Lte struct {
	Than any
}

Lte supports the <= operator

func (Lte) Symbol added in v0.11.22

func (Lte) Symbol() string

func (Lte) Value added in v0.11.22

func (l Lte) Value() interface{}

type Middleware added in v0.12.10

type Middleware func(http.Handler) http.Handler

Middleware is a function that wraps an http.Handler to add functionality before and/or after the handler is executed.

func CreateStack added in v0.12.10

func CreateStack(middleware ...Middleware) Middleware

CreateStack composes multiple Middleware into a single one, applying them in the order provided (first to last).

func Match

func Match(re *regexp.Regexp, mw ...Middleware) Middleware

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

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 (
	ResourceCreatedTopic  Topic = "dashboard.resource.created"
	ResourceReplacedTopic Topic = "dashboard.resource.replaced"
	ResourceDeletedTopic  Topic = "dashboard.resource.deleted"

	AccountCreatedTopic Topic = "dashboard.account.created"
)
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