gocli

package module
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: BSD-2-Clause Imports: 18 Imported by: 12

README

gocli

Entry point for application

Features

  1. Support environment configs with dependencies. Each yaml config file may contain depends key to preload configs from parent environment config files
  2. Support argument customization via config You can define your own flags parsed automatically on application starts
  3. Support processing commands through socket connection You can define your own command passed through socket connection. Command implementation
  4. Logger interface Minimal function set for basic logger
  5. Standard application instance (DNApp) out of the box.

Usage

Documentation

Index

Constants

View Source
const (
	ArgumentTypeString = "string"
	ArgumentTypeInt    = "int"
	ArgumentTypeUint   = "uint"
	ArgumentTypeBool   = "bool"
)
View Source
const (
	CommandPrefix   = "-"
	CommandAssignee = "="
)
View Source
const (
	LogLevelDebug = 1 << iota
	LogLevelInfo
	LogLevelWarn
	LogLevelErr
)
View Source
const (
	CommandSessionHost = "localhost"
	CommandSessionPort = "8080"
	CommandSessionType = "tcp"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application interface {
	// Get config struct
	GetConfig() interface{}
	// Get full path to config
	GetConfigPath(env string) string
	// Get absolute path
	GetAbsolutePath(path string, dir string) (string, porterr.IError)
	// Set config struct
	SetConfig(cfg interface{}) Application
	// Parse config
	ParseConfig(env string) Application
	// Start application
	Start(port string, callback func(command *Command)) porterr.IError
	// Behaviour for fatal errors
	FatalError(err error)
	// Get Logger
	GetLogger(level int) Logger
	// Success log message with command repeat
	SuccessMessage(message string, command ...*Command)
	// Warning log message with command repeat
	AttentionMessage(message string, command ...*Command)
	// Fail log message with command repeat
	FailMessage(message string, command ...*Command)
	// Parse console flags
	ParseFlags(args *Arguments)
}

Application class

func NewApplication added in v0.5.0

func NewApplication(env string, configPath string, values interface{}) Application

Create new Application

type Argument

type Argument struct {
	// Type of argument
	Type string
	// Value of argument
	Value interface{}
	// Label of argument
	Label string
	// Name of argument
	Name string
}

Argument struct

func (Argument) GetBool added in v0.3.1

func (a Argument) GetBool() bool

Get bool value of argument

func (Argument) GetInt added in v0.1.3

func (a Argument) GetInt() int64

Get int value of argument

func (Argument) GetString added in v0.1.3

func (a Argument) GetString() string

Get string value of argument

func (Argument) GetUnit added in v0.3.1

func (a Argument) GetUnit() uint64

Get int value of argument

type Arguments

type Arguments map[string]Argument

Console app arguments

type Command added in v0.4.0

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

Command is an argument list

func ParseCommand added in v0.4.0

func ParseCommand(command []byte) *Command

Parse command

func (*Command) Arguments added in v0.4.0

func (c *Command) Arguments() []Argument

UnBind connection

func (*Command) BindConnection added in v0.4.0

func (c *Command) BindConnection(conn net.Conn)

Bind connection to command

func (*Command) GetOrigin added in v0.4.0

func (c *Command) GetOrigin() string

Get origin command

func (*Command) Result added in v0.4.0

func (c *Command) Result(result []byte) porterr.IError

Result of command to connection

func (*Command) String added in v0.4.1

func (c *Command) String() string

Render command

func (*Command) UnbindConnection added in v0.4.0

func (c *Command) UnbindConnection()

UnBind connection

type DNApp

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

Dynamic Name Application Implements Application interface

func (DNApp) AttentionMessage added in v0.6.0

func (a DNApp) AttentionMessage(message string, command ...*Command)

Attention message

func (DNApp) FailMessage added in v0.6.0

func (a DNApp) FailMessage(message string, command ...*Command)

Fail message

func (DNApp) FatalError

func (a DNApp) FatalError(err error)

Fatal error

func (DNApp) GetAbsolutePath added in v0.5.0

func (a DNApp) GetAbsolutePath(path string, dir string) (string, porterr.IError)

Get absolute path to application

func (DNApp) GetConfig

func (a DNApp) GetConfig() interface{}

Get config struct

func (DNApp) GetConfigPath

func (a DNApp) GetConfigPath(env string) string

Get full path to config

func (*DNApp) GetLogger

func (a *DNApp) GetLogger(level int) Logger

Get logger

func (*DNApp) ParseConfig added in v0.5.0

func (a *DNApp) ParseConfig(env string) Application

Config parser

func (DNApp) ParseFlags

func (a DNApp) ParseFlags(args *Arguments)

Parse console arguments

func (*DNApp) SetConfig

func (a *DNApp) SetConfig(cfg interface{}) Application

Set config struct

func (DNApp) Start

func (a DNApp) Start(address string, callback func(command *Command)) porterr.IError

Start application

func (DNApp) SuccessMessage added in v0.6.0

func (a DNApp) SuccessMessage(message string, command ...*Command)

Success message

type Logger added in v0.0.7

type Logger interface {
	GetLevel() int

	Print(v ...interface{})
	Println(v ...interface{})
	Printf(format string, v ...interface{})

	Info(v ...interface{})
	Infoln(v ...interface{})
	Infof(format string, v ...interface{})

	Warn(v ...interface{})
	Warnln(v ...interface{})
	Warnf(format string, v ...interface{})

	Error(v ...interface{})
	Errorln(v ...interface{})
	Errorf(format string, v ...interface{})
}

func NewLogger

func NewLogger(level int, prefix string, flags int) Logger

New logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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