-
Notifications
You must be signed in to change notification settings - Fork 1
/
pipeline.go
32 lines (28 loc) · 916 Bytes
/
pipeline.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package service
import (
"bytes"
"encoding/json"
"strconv"
"github.com/shisa-platform/core/httpx"
)
// Pipeline is a chain of handlers to be invoked in order on a
// request. The first non-nil response will be returned to the
// user agent. If no response is produced an Internal Service
// Error handler will be invoked.
type Pipeline struct {
Policy Policy // customizes automated behavior
Handlers []httpx.Handler // the pipline steps, minimum one
QuerySchemas []httpx.ParameterSchema // optional query parameter validation
}
func (p Pipeline) jsonify(buf *bytes.Buffer) {
enc := json.NewEncoder(buf)
buf.WriteString("{\"Policy\":")
enc.Encode(p.Policy)
buf.WriteString(",\"Handlers\":")
buf.WriteString(strconv.Itoa(len(p.Handlers)))
if len(p.QuerySchemas) != 0 {
buf.WriteString(",\"QuerySchemas\":")
enc.Encode(p.QuerySchemas)
}
buf.WriteByte('}')
}