cmd

package module
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

README

KrakenD Cobra

An adapter of the cobra lib for the KrakenD framework

Package cmd defines the cobra command structs and an execution method for adding an improved CLI to KrakenD based api gateways

Basic example

package main

import (
	"os"

	"github.com/devopsfaith/krakend-cobra/v2"
	"github.com/devopsfaith/krakend-viper/v2"
	"github.com/luraproject/lura/v2/config"
	"github.com/luraproject/lura/v2/logging"
	"github.com/luraproject/lura/v2/proxy"
	krakendgin "github.com/luraproject/lura/v2/router/gin"
)

func main() {

	cmd.Execute(viper.New(), func(serviceConfig config.ServiceConfig) {
		logger, _ := logging.NewLogger("DEBUG", os.Stdout, "")
		krakendgin.DefaultFactory(proxy.DefaultFactory(logger), logger).New().Run(serviceConfig)
	})

}

Available commands

The cmd package includes two commands: check and run.

  1. check validates the received config file.
  2. run executes the passed executor once the received flags overwrite the parsed config.
$ ./krakend

`7MMF' `YMM'                  `7MM                         `7MM"""Yb.
  MM   .M'                      MM                           MM    `Yb.
  MM .d"     `7Mb,od8 ,6"Yb.    MM  ,MP'.gP"Ya `7MMpMMMb.    MM     `Mb
  MMMMM.       MM' "'8)   MM    MM ;Y  ,M'   Yb  MM    MM    MM      MM
  MM  VMA      MM     ,pm9MM    MM;Mm  8M""""""  MM    MM    MM     ,MP
  MM   `MM.    MM    8M   MM    MM `Mb.YM.    ,  MM    MM    MM    ,dP'
.JMML.   MMb..JMML.  `Moo9^Yo..JMML. YA.`Mbmmd'.JMML  JMML..JMMmmmdP'
_______________________________________________________________________

Version: undefined

The API Gateway builder

Usage:
  krakend [command]

Available Commands:
  check       Validates that the configuration file is valid.
  run         Run the KrakenD server.

Flags:
  -c, --config string   Path to the configuration filename
  -d, --debug           Enable the debug

Use "krakend [command] --help" for more information about a command.

Documentation

Overview

Package cmd defines the cobra command structs and an execution method for adding an improved CLI to KrakenD based api gateways

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultRoot   Root
	RootCommand   Command
	RunCommand    Command
	CheckCommand  Command
	PluginCommand Command
)
View Source
var SchemaURL = "https://www.krakend.io/schema/v3.json"

Functions

func Execute

func Execute(configParser config.Parser, f Executor)

Execute sets up the cmd package with the received configuration parser and executor and delegates the CLI execution to the cobra lib

func ExecuteRoot

func ExecuteRoot(configParser config.Parser, f Executor, root Root)

func GetConfigFlag

func GetConfigFlag() string

func GetConfigParser added in v2.0.1

func GetConfigParser() config.Parser

func GetDebugFlag

func GetDebugFlag() bool

Types

type Command

type Command struct {
	Cmd   *cobra.Command
	Flags []FlagBuilder
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(command *cobra.Command, flags ...FlagBuilder) Command

func (*Command) AddFlag

func (c *Command) AddFlag(f FlagBuilder)

func (*Command) AddSubCommand

func (c *Command) AddSubCommand(cmd *cobra.Command)

func (*Command) BuildFlags

func (c *Command) BuildFlags()

type Executor

type Executor func(config.ServiceConfig)

Executor defines the function that requires a service description

type FlagBuilder

type FlagBuilder func(*cobra.Command)

func BoolFlagBuilder

func BoolFlagBuilder(dst *bool, long, short string, defaultValue bool, help string) FlagBuilder

func CountFlagBuilder

func CountFlagBuilder(dst *int, long, short string, help string) FlagBuilder

func DurationFlagBuilder

func DurationFlagBuilder(dst *time.Duration, long, short string, defaultValue time.Duration, help string) FlagBuilder

func Float64FlagBuilder

func Float64FlagBuilder(dst *float64, long, short string, defaultValue float64, help string) FlagBuilder

func IntFlagBuilder

func IntFlagBuilder(dst *int, long, short string, defaultValue int, help string) FlagBuilder

func StringFlagBuilder

func StringFlagBuilder(dst *string, long, short, defaultValue, help string) FlagBuilder

type Root

type Root struct {
	Command
	SubCommands []Command
	// contains filtered or unexported fields
}

func NewRoot

func NewRoot(root Command, subCommands ...Command) Root

func (*Root) Build

func (r *Root) Build()

func (Root) Execute

func (r Root) Execute(configParser config.Parser, f Executor)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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