Documentation ¶
Overview ¶
Package cmd provides an opiniated interface for implementing Axiom based tools and utilities. Those tools share the same configuration, logging and application lifecycle behaviour. This results in an easy to use and understandable set of application.
In the most basic case, applications should pass their name and an implementation of `cmd.RunFunc` to `cmd.Run()`:
package main import ( "context" "github.com/axiomhq/pkg/cmd" ) func main() { cmd.Run("my-app", Run) } func Run(_ context.Context, log *zap.Logger, _ *axiom.Client) error { log.Info("hello, world!") return nil }
Example ¶
package main import ( "context" "fmt" "os" "github.com/axiomhq/axiom-go/axiom" "go.uber.org/zap" "github.com/axiomhq/pkg/cmd" ) func main() { os.Clearenv() os.Setenv("DEBUG", "1") mainFunc := func(_ context.Context, _ *zap.Logger, _ *axiom.Client) error { // All your actual application code goes here! See doc.go for more info. fmt.Print("Hello World!") return nil } cmd.Run("example", mainFunc, cmd.WithAxiomOptions( axiom.SetNoEnv(), axiom.SetURL("http://axiom.local"), axiom.SetAccessToken("xapt-1234"), ), ) }
Output: Hello World!
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultExitSignals ¶
DefaultExitSignals are the default signals to catch and exit upon.
func DefaultLoggerOptions ¶
DefaultLoggerOptions are the default logger options to use
Types ¶
type Option ¶
type Option func(c *config) error
An Option modifies the behaviour of the `Run()` function.
func WithAxiomOptions ¶
WithAxiomOptions sets the options used for creating the Axiom client.
func WithExitSignals ¶
WithExitSignals sets the signals that will cause the program to exit gracefully. If this option is not specified, the default signals are specified by the `DefaultExitSignals()` function.
func WithLoggerOptions ¶
WithLoggerOptions sets the options used for creating the logger. If this option is not specified, the default logger options are specified by the `DefaultLoggerOptions()` function.
func WithRequiredEnvVars ¶
WithRequiredEnvVars sets the environment variables that are required to be set at application startup. Required environment variables must be set and not be empty. "AXIOM_URL", "AXIOM_TOKEN", "AXIOM_ORG_ID" and "DEBUG" are reserved.
func WithValidateAxiomCredentials ¶
func WithValidateAxiomCredentials() Option
WithValidateAxiomCredentials will validate the Axiom credentials at startup and fail the execution gracefully, if they are invalid.
type RunFunc ¶
RunFunc is implemented by the main packages and passed to the `Run` function which takes care of signal handling, loading the runtime configuration and setting up logging, the Axiom client, etc. It must block until the context is marked done. Errors returned from the `RunFunc` should be created using the `Error()` function.