Getting Started
Request handling
- Routing
- Action Controller
- Resources
- Context
- Request Binding
- Middleware
- Error Handling
- Sessions
- Cookies
Frontend
Database
- Getting started with Pop
- Soda CLI
- Database Configuration
- Buffalo Integration
- Models
- Generators
- Migrations
- Fizz
- Mutations
- Querying
- Raw Queries
- Callbacks
- Scoping
- Associations and Relationships
- One to one associations
- One to many associations
Guides
- API Applications
- File Uploads
- Background Job Workers
- Mailers
- Tasks
- Plugins
- Local Authentication
- Third Party Authentication
- Events
- Go Modules
- Localization
- Logging
- Template Engines
- Testing
- Videos
Deploy
Tasks
Guides
Tasks
Tasks are small scripts that are often needed when writing an application. These tasks might be along the lines of seeding a database, parsing a log file, or even a release script. Buffalo uses the grift package to make writing these tasks simple.
Writing Tasks
Tasks must all be in the grifts
package. A simple task would look like following:
var _ = grift.Add("hello", func(c *grift.Context) error {
fmt.Println("Hello!")
return nil
})
Tasks Generator
$ buffalo g task foo:bar
--> grifts/bar.go
// grifts/bar.go
package grifts
import (
. "github.com/markbates/grift/grift"
)
var _ = Namespace("foo", func() {
Desc("bar", "TODO")
Add("bar", func(c *Context) error {
return nil
})
})
Listing Available Tasks
$ buffalo task list
Available grifts
================
buffalo task db:seed # Seeds a database
buffalo task middleware # Prints out your middleware stack
buffalo task routes # Print out all defined routes
buffalo task secret # Generate a cryptographically secure secret key
Running Tasks
Development
Tasks can be run in development using the buffalo task
command.
$ buffalo task hello
From a Built Binary
After a binary has been built, the tasks can be run with the task
subcommand:
$ myapp task hello