daemonPkg

package
v6.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: GPL-3.0 Imports: 43 Imported by: 0

README

chifra daemon

chifra daemon manages chifra's API server. Each of the chifra commands along with all of its options, are provided not only by the command line, but also the API server. We call this process the flame server, which is written in Go. chifra serve is an alias for the chifra daemon command.

In the future, this daemon may also manage other long-running processes such as chifra scrape and chifra monitors, but for now, it's only managing the API server.

If the default port for the API server is in use, you may change it with the --url option.

To get help for any command, please see the API documentation on our website. But, you may also run chifra --help or chifra <cmd> --help on your command line to get help.

See below for an example of converting command line options to a call to the API. There's a one-to-one correspondence between the command line tools and options and the API routes and their options.

Purpose:
  Initialize and control long-running processes such as the API and the scrapers.

Usage:
  chifra daemon [flags]

Aliases:
  daemon, serve

Flags:
  -u, --url string   specify the API server's url and optionally its port (default "localhost:8080")
      --silent       disable logging (for use in SDK for example)
  -v, --verbose      enable verbose output
  -h, --help         display this help screen

Notes:
  - To start API open terminal window and run chifra daemon.
  - See the API documentation (https://trueblocks.io/api) for more information.

Data models produced by this tool:

  • none

further information

To convert the options for a command line tool to an API call, do the following:

  1. Any --snake_case argument to the command line should be converted to camelCase. For example, --no_header on the command line should be sent as &noHeader to the API server.
  2. Any switch on the command line, (i.e., options whose presence indicates true and whose absence indicates false) should be sent as a boolean to the API server. For example, --no_header on the command line should be sent as &noHeader=true to the API server. If the option is fales, you do not need to send it to the API server.
  3. Positionals such as the addresses, topics, and four-bytes for chifra export, must be prepended with their positional name. For example, chifra export <address> <topic> should be sent as &addrs=<address>&topics=<topic> to the API server. For some commands (experiment) you may send more than one value for a positional with %20 separating the entries or by sending multiple positionals (i.e., &addrs=<address1>&addrs=<address2>).

Chifra was built for the command line, a fact we purposefully take advantage of to ensure continued operation on small machines. As such, this tool is not intended to serve multiple end users in a cloud-based server environment. This is by design. Be forewarned.

Other Options

All tools accept the following additional flags, although in some cases, they have no meaning.

  -v, --version         display the current version of the tool
      --output string   write the results to file 'fn' and return the filename
      --append          for --output command only append to instead of replace contents of file
      --file string     specify multiple sets of command line options in a file

Note: For the --file string option, you may place a series of valid command lines in a file using any valid flags. In some cases, this may significantly improve performance. A semi-colon at the start of any line makes it a comment.

Note: If you use --output --append option and at the same time the --file option, you may not switch export formats in the command file. For example, a command file with two different commands, one with --fmt csv and the other with --fmt json will produce both invalid CSV and invalid JSON.

Copyright (c) 2024, TrueBlocks, LLC. All rights reserved. Generated with goMaker.

Documentation

Overview

daemonPkg implements the chifra daemon command.

chifra daemon manages chifra's API server. Each of the chifra commands along with all of its options, are provided not only by the command line, but also the API server. We call this process the flame server, which is written in Go. chifra serve is an alias for the chifra daemon command.

In the future, this daemon may also manage other long-running processes such as chifra scrape and chifra monitors, but for now, it's only managing the API server.

If the default port for the API server is in use, you may change it with the --url option.

To get help for any command, please see the API documentation on our website. But, you may also run chifra --help or chifra <cmd> --help on your command line to get help.

See below for an example of converting command line options to a call to the API. There's a one-to-one correspondence between the command line tools and options and the API routes and their options.

Index

Constants

This section is empty.

Variables

View Source
var OptionsHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	_ = r
	addCorsHeaders(w)
})

Functions

func ContentTypeHandler

func ContentTypeHandler(next http.Handler) http.Handler

ContentTypeHandler sets correct Content-Type header on response

func CorsHandler

func CorsHandler(next http.Handler) http.Handler

CorsHandler handles CORS requests

func HandleWebsockets

func HandleWebsockets(pool *ConnectionPool, w http.ResponseWriter, r *http.Request)

HandleWebsockets handles web sockets

func Logger

func Logger(silent bool, inner http.Handler, name string) http.Handler

Logger sends information to the server's console

func NewRouter

func NewRouter(silent bool) *mux.Router

NewRouter Creates a new router given the routes array

func ResetOptions

func ResetOptions(testMode bool)

func RespondWithError

func RespondWithError(w http.ResponseWriter, httpStatus int, err error)

RespondWithError marshals an err into JSON and returns the bytes back to the caller httpStatus HTTP error status code

func RunDaemon

func RunDaemon(cmd *cobra.Command, args []string) error

RunDaemon handles the daemon command for the command line. Returns error only as per cobra.

func RunWebsocketPool

func RunWebsocketPool()

RunWebsocketPool runs the websocket pool

func ServeDaemon

func ServeDaemon(w http.ResponseWriter, r *http.Request) error

ServeDaemon handles the daemon command for the API. Returns an error.

Types

type ConnectionPool

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

ConnectionPool is the collection of all connections

type DaemonOptions

type DaemonOptions struct {
	Url     string                `json:"url,omitempty"`     // Specify the API server's url and optionally its port
	Silent  bool                  `json:"silent,omitempty"`  // Disable logging (for use in SDK for example)
	Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options
	Conn    *rpc.Connection       `json:"conn,omitempty"`    // The connection to the RPC server
	BadFlag error                 `json:"badFlag,omitempty"` // An error flag if needed

}

DaemonOptions provides all command options for the chifra daemon command.

func DaemonFinishParseInternal

func DaemonFinishParseInternal(w io.Writer, values url.Values) *DaemonOptions

func GetDaemonOptions

func GetDaemonOptions(args []string, g *globals.GlobalOptions) *DaemonOptions

GetDaemonOptions returns the options for this tool so other tools may use it.

func GetOptions

func GetOptions() *DaemonOptions

func (*DaemonOptions) DaemonInternal

func (opts *DaemonOptions) DaemonInternal(rCtx *output.RenderCtx) error

DaemonInternal handles the internal workings of the daemon command. Returns an error.

func (*DaemonOptions) String

func (opts *DaemonOptions) String() string

String implements the Stringer interface

type Message

type Message struct {
	Action  MessageType `json:"action"`
	ID      string      `json:"id"`
	Content string      `json:"content"`
}

Message is a structure used to send messages via websockets

type MessageType

type MessageType string

MessageType is a message carried in a string

const (
	// CommandErrorMessage is a message send when the server encounters an error
	CommandErrorMessage MessageType = "command_error"
	// CommandOutputMessage is currently not used, but may in the future carry the actual data
	CommandOutputMessage MessageType = "output"
	// ProgressMessage is a message carried on the stderr stream
	ProgressMessage MessageType = "progress"
)

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

Route A structure to hold the API's routes

Jump to

Keyboard shortcuts

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