项目作者: autom8ter

项目描述 :
slasher makes it easy to write http servers that respond to slack slash commands
高级语言: Go
项目地址: git://github.com/autom8ter/slasher.git
创建时间: 2020-01-20T02:27:35Z
项目社区:https://github.com/autom8ter/slasher

开源协议:

下载


slasher


import “github.com/autom8ter/slasher”

Usage

func ExampleHandler

  1. func ExampleHandler()

type HandlerFunc

  1. type HandlerFunc func(s *Slasher, client *slack.Client, command *slack.SlashCommand) (interface{}, error)

A handler func is run against an incoming slack slash command. It is up to the
user of this library to define their own handlers

type Slasher

  1. type Slasher struct {
  2. }

Slasher holds a slack client, a map of functions map[string]HandlerFunc and an
array of allowed users

func NewSlasher

  1. func NewSlasher(token string) *Slasher

Creates a newe slasher instance

func (*Slasher) AddHandler

  1. func (s *Slasher) AddHandler(command string, function HandlerFunc)

Adds a slack slash command handler

func (*Slasher) BashScipt

  1. func (s *Slasher) BashScipt(script string) ([]byte, error)

runs exec.Command(“/bin/sh”, “-c”, script)

func (*Slasher) CommandHandlers

  1. func (s *Slasher) CommandHandlers() []string

Names of all supported slash commands

func (*Slasher) DeleteHandler

  1. func (s *Slasher) DeleteHandler(command string)

Deletes a handler delete(s.functions, command)

func (*Slasher) Error

  1. func (s *Slasher) Error(w http.ResponseWriter, err error)

Writes a wrapped Slasher error to the response

func (*Slasher) Exec

  1. func (s *Slasher) Exec(args ...string) ([]byte, error)

runs exec.Command(args[0], args[1:]…)

func (*Slasher) Exists

  1. func (s *Slasher) Exists(command string) bool

Checks if a function exists for the command

func (*Slasher) HandlerFunc

  1. func (s *Slasher) HandlerFunc() http.HandlerFunc

func (*Slasher) JSON

  1. func (s *Slasher) JSON(w http.ResponseWriter, obj interface{})

Writes pretty json to the response

func (*Slasher) Python3Script

  1. func (s *Slasher) Python3Script(cmd string) ([]byte, error)

runs exec.Command(“python3”, “-c”, cmd)

func (*Slasher) ShellScript

  1. func (s *Slasher) ShellScript(script string) ([]byte, error)

exec.Command(“/bin/sh”, “-c”, script)

func (*Slasher) String

  1. func (s *Slasher) String(w http.ResponseWriter, response string)

Writes the string to the response