package module
v0.0.0-...-1f2349a Latest Latest

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

Go to latest
Published: Oct 25, 2016 License: MIT Imports: 5 Imported by: 9


allot MIT License GoDoc Go Report Card allot - Coverage Status Build Status

allot is a small Golang library to match and parse commands with pre-defined strings. For example use allot to define a list of commands your CLI application or Slackbot supports and check if incoming requests are matching your commands.

The allot library supports placeholders and regular expressions for parameter matching and parsing.


cmd := allot.NewCommand("revert <commits:integer> commits on <project:string> at (stage|prod)")
match, err := cmd.Match("revert 12 commits on example at prod")

if (err != nil)
  commits, _ = match.Integer("commits")
  project, _ = match.String("project")
  env, _ = match.Match(2)

  fmt.Printf("Revert \"%d\" on \"%s\" at \"%s\"", commits, project, env)
} else {
  fmt.Println("Request did not match command.")


See the hanu Slackbot framework for a usecase for allot:





This section is empty.


This section is empty.


func Expression

func Expression(data string) *regexp.Regexp

Expression returns the regexp for a data type


type Command

type Command struct {
	// contains filtered or unexported fields

Command is a Command definition

func New

func New(command string) Command

New returns a new command

func (Command) Expression

func (c Command) Expression() *regexp.Regexp

Expression returns the regular expression matching the command text

func (Command) Has

func (c Command) Has(param ParameterInterface) bool

Has checks if the parameter is found in the command

func (Command) Match

func (c Command) Match(req string) (MatchInterface, error)

Match returns the parameter matching the expression at the defined position

func (Command) Matches

func (c Command) Matches(req string) bool

Matches checks if a comand definition matches a request

func (Command) Parameters

func (c Command) Parameters() []Parameter

Parameters returns the list of defined parameters

func (Command) Position

func (c Command) Position(param ParameterInterface) int

Position returns the position of a parameter

func (Command) Text

func (c Command) Text() string

Text returns the command text

type CommandInterface

type CommandInterface interface {
	Expression() *regexp.Regexp
	Has(name ParameterInterface) bool
	Match(req string) (MatchInterface, error)
	Matches(req string) bool
	Parameters() []Parameter
	Position(param ParameterInterface) int
	Text() string

CommandInterface describes how to access a Command

type Match

type Match struct {
	Command CommandInterface
	Request string

Match is the Match definition

func (Match) Integer

func (m Match) Integer(name string) (int, error)

Integer returns the value for an integer parameter

func (Match) Match

func (m Match) Match(position int) (string, error)

Match returns the match at given position

func (Match) Parameter

func (m Match) Parameter(param ParameterInterface) (string, error)

Parameter returns the value for a parameter

func (Match) String

func (m Match) String(name string) (string, error)

String returns the value for a string parameter

type MatchInterface

type MatchInterface interface {
	String(name string) (string, error)
	Integer(name string) (int, error)
	Match(position int) (string, error)

	Parameter(param ParameterInterface) (string, error)

MatchInterface describes how to access a Match

type Parameter

type Parameter struct {
	// contains filtered or unexported fields

Parameter is the Parameter definition

func NewParameterWithType

func NewParameterWithType(name string, data string) Parameter

NewParameterWithType returns

func Parse

func Parse(text string) Parameter

Parse parses parameter info

func (Parameter) Data

func (p Parameter) Data() string

Data returns the Parameter name

func (Parameter) Equals

func (p Parameter) Equals(param ParameterInterface) bool

Equals checks if two parameter are equal

func (Parameter) Expression

func (p Parameter) Expression() *regexp.Regexp

Expression returns the regexp behind the type

func (Parameter) Name

func (p Parameter) Name() string

Name returns the Parameter name

type ParameterInterface

type ParameterInterface interface {
	Equals(param ParameterInterface) bool
	Expression() *regexp.Regexp
	Name() string
	Data() string

ParameterInterface describes how to access a Parameter

Jump to

Keyboard shortcuts

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