Skip to main content


Introduced in v0.8.0.

default is a directive executor who sets unsetted fields to their default value.


Name: "default"
Args: VAL1 [,VAL2 [,VAL3, ...]]

For an array type of value, you can use comma to separate the items in the array. So the presence of comma in an array item can lead to unexpected behavior.

default will examine if the field was already set by former directives. If not, it will set the field to the given value.


type ListTasksQuery struct {
Page int `in:"query=page;default=1"`
PerPage int `in:"query=per_page;default=20"`
StateList []string `in:"query=state;default=pending,running"`
GET /tasks?page=4&perPage=10&state=failed&state=succeeded
Page: 4,
PerPage: 10,
StateList: []string{"failed", "succeeded"},
GET /tasks
Page: 1,
PerPage: 20,
StateList: []string{"pending", "running"},