fx

package
v1.1.35 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2025 License: Unlicense Imports: 16 Imported by: 0

Documentation

Overview

Json i/o Json in: execute & decode http requests Json out: handle & encode http responses, server-side streaming

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Node

func Node(ctx context.Context) (*rpc.Client, *ethclient.Client, error)

Establish geth.ipc connection (http, websocket disabled)

Types

type Data added in v1.1.25

type Data struct {
	Pg  *sql.DB
	RB  *redis.Client
	Ctx context.Context
}

func Source added in v1.1.25

func Source(dbName string, ctx context.Context) (*Data, error)

func (*Data) ConnectPostgres added in v1.1.25

func (d *Data) ConnectPostgres(dbName string) error

func (*Data) ConnectRedis added in v1.1.25

func (d *Data) ConnectRedis(dbNumber int, ctx context.Context) error

type JSON

type JSON struct {
	HTTP *http.Client
	CTX  context.Context
}

func Json

func Json(http http.Client, ctx context.Context) *JSON

Json initializes and returns a new JSON utility instance, using http.Client and context.Context created in NewFactory.

func (*JSON) In

func (j *JSON) In(url, apiKey string) ([]byte, error)

Execute HTTP GET requests, with X-API-KEY headers as needed, and return the response body as bytes.

func (*JSON) Out

func (j *JSON) Out(w http.ResponseWriter, input func() (any, error), locker sync.Locker)

Out writes single response for http requests, using a function to source data and a locker to synchronize access or an HTTP 500 error when the input function fails or JSON encoding fails.

func (*JSON) OutSSE

func (j *JSON) OutSSE(w http.ResponseWriter, r *http.Request, input func() (any, error), interval time.Duration)

OutSSE is Out at a defined interval, streams responses until the client disconnects or the context is canceled.

func (*JSON) Print

func (j *JSON) Print(value any)

Print value as indented JSON to the standard output or logs error when value cannot be marshaled.

func (*JSON) Simplify added in v1.1.0

func (j *JSON) Simplify(input []any, prefix string) []any

Simplify processes a slice of objects ([]any), flattens each object, and removes empty fields.

type Math added in v1.1.13

type Math struct{}

func (*Math) Down added in v1.1.20

func (m *Math) Down(from int64, callback func(int64))

func (*Math) Int added in v1.1.13

func (m *Math) Int(value string) *big.Int

func (*Math) Up added in v1.1.20

func (m *Math) Up(from int64, callback func(int64))

type State added in v1.1.23

type State struct {
	Mu   *sync.Mutex
	Data *Data
	Ctx  context.Context
	Map  map[string]map[string]any
}

func NewState added in v1.1.23

func NewState(data *Data, ctx context.Context) *State

func (*State) AddToPackage added in v1.1.33

func (s *State) AddToPackage(pkg string, key string, value any) error

func (*State) GetFromPackage added in v1.1.33

func (s *State) GetFromPackage(pkg string, key string) (any, error)

func (*State) GetPackage added in v1.1.33

func (s *State) GetPackage(pkg string) (map[string]any, error)

func (*State) LoadState added in v1.1.32

func (s *State) LoadState() error

Jump to

Keyboard shortcuts

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