potto

package module
v0.0.0-...-a39c6e4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2018 License: MIT Imports: 6 Imported by: 1

README

potto

GoDoc

a tiny framework to handle Slack Outgoing WebHooks for golang

Example

package main

import (
	"strings"

	"github.com/m0t0k1ch1/potto"
)

func Ping(ctx potto.Ctx, args potto.ActionArgs) (*potto.Response, error) {
	return potto.NewResponse("pong"), nil
}

func Say(ctx potto.Ctx, args potto.ActionArgs) (*potto.Response, error) {
	text := strings.Join(args, " ")
	return potto.NewResponse(text), nil
}

func main() {
	p := potto.New()
	p.AddAction("ping", Ping)
	p.AddAction("say", Say)
	p.Run(":8080")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActionHandler

func ActionHandler(ctx Ctx)

Types

type Action

type Action func(Ctx, ActionArgs) (*Response, error)

type ActionArgs

type ActionArgs []string

type Args

type Args struct {
	ksatriya.Args
}

type Command

type Command struct {
	Name string
	Args ActionArgs
}

func NewCommand

func NewCommand(text, trigger string) *Command

type Context

type Context struct {
	*ksatriya.Context
	// contains filtered or unexported fields
}

func (*Context) Actions

func (ctx *Context) Actions() map[string]Action

type Ctx

type Ctx interface {
	ksatriya.Ctx
	Actions() map[string]Action
}

type CtxBuilder

type CtxBuilder func(w http.ResponseWriter, req *http.Request, args Args) Ctx

type HandlerFunc

type HandlerFunc func(Ctx)

type Potto

type Potto struct {
	*ksatriya.Ksatriya
	// contains filtered or unexported fields
}

func New

func New() *Potto

func (*Potto) Actions

func (p *Potto) Actions() map[string]Action

func (*Potto) AddAction

func (p *Potto) AddAction(name string, action Action)

func (*Potto) AddRoute

func (p *Potto) AddRoute(method, path string, hf HandlerFunc)

func (*Potto) NewContext

func (p *Potto) NewContext(w http.ResponseWriter, req *http.Request, args Args) Ctx

func (*Potto) SetCtxBuilder

func (p *Potto) SetCtxBuilder(f CtxBuilder)

type Response

type Response struct {
	Text string `json:"text"`
}

func NewResponse

func NewResponse(text string) *Response

Jump to

Keyboard shortcuts

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