13
13
// with it via JSON messages over stdin/stdout. The subprocess's stderr will be
14
14
// connected to the go command's stderr.
15
15
//
16
- // The subprocess should immediately send a [ProgResponse ] with its capabilities.
17
- // After that, the go command will send a stream of [ProgRequest ] messages and the
18
- // subprocess should reply to each [ProgRequest ] with a [ProgResponse ] message.
16
+ // The subprocess should immediately send a [Response ] with its capabilities.
17
+ // After that, the go command will send a stream of [Request ] messages and the
18
+ // subprocess should reply to each [Request ] with a [Response ] message.
19
19
package cacheprog
20
20
21
21
import (
22
22
"io"
23
23
"time"
24
24
)
25
25
26
- // ProgCmd is a command that can be issued to a child process.
26
+ // Cmd is a command that can be issued to a child process.
27
27
//
28
28
// If the interface needs to grow, the go command can add new commands or new
29
- // versioned commands like "get2" in the future. The initial [ProgResponse ] from
29
+ // versioned commands like "get2" in the future. The initial [Response ] from
30
30
// the child process indicates which commands it supports.
31
- type ProgCmd string
31
+ type Cmd string
32
32
33
33
const (
34
34
// CmdPut tells the cache program to store an object in the cache.
35
35
//
36
- // [ProgRequest .ActionID] is the cache key of this object. The cache should
37
- // store [ProgRequest .OutputID] and [ProgRequest .Body] under this key for a
36
+ // [Request .ActionID] is the cache key of this object. The cache should
37
+ // store [Request .OutputID] and [Request .Body] under this key for a
38
38
// later "get" request. It must also store the Body in a file in the local
39
- // file system and return the path to that file in [ProgResponse .DiskPath],
39
+ // file system and return the path to that file in [Response .DiskPath],
40
40
// which must exist at least until a "close" request.
41
- CmdPut = ProgCmd ("put" )
41
+ CmdPut = Cmd ("put" )
42
42
43
43
// CmdGet tells the cache program to retrieve an object from the cache.
44
44
//
45
- // [ProgRequest .ActionID] specifies the key of the object to get. If the
46
- // cache does not contain this object, it should set [ProgResponse .Miss] to
47
- // true. Otherwise, it should populate the fields of [ProgResponse ],
48
- // including setting [ProgResponse .OutputID] to the OutputID of the original
49
- // "put" request and [ProgResponse .DiskPath] to the path of a local file
45
+ // [Request .ActionID] specifies the key of the object to get. If the
46
+ // cache does not contain this object, it should set [Response .Miss] to
47
+ // true. Otherwise, it should populate the fields of [Response ],
48
+ // including setting [Response .OutputID] to the OutputID of the original
49
+ // "put" request and [Response .DiskPath] to the path of a local file
50
50
// containing the Body of the original "put" request. That file must
51
51
// continue to exist at least until a "close" request.
52
- CmdGet = ProgCmd ("get" )
52
+ CmdGet = Cmd ("get" )
53
53
54
54
// CmdClose requests that the cache program exit gracefully.
55
55
//
56
56
// The cache program should reply to this request and then exit
57
57
// (thus closing its stdout).
58
- CmdClose = ProgCmd ("close" )
58
+ CmdClose = Cmd ("close" )
59
59
)
60
60
61
- // ProgRequest is the JSON-encoded message that's sent from the go command to
61
+ // Request is the JSON-encoded message that's sent from the go command to
62
62
// the GOCACHEPROG child process over stdin. Each JSON object is on its own
63
63
// line. A ProgRequest of Type "put" with BodySize > 0 will be followed by a
64
64
// line containing a base64-encoded JSON string literal of the body.
65
- type ProgRequest struct {
65
+ type Request struct {
66
66
// ID is a unique number per process across all requests.
67
- // It must be echoed in the ProgResponse from the child.
67
+ // It must be echoed in the Response from the child.
68
68
ID int64
69
69
70
70
// Command is the type of request.
71
71
// The go command will only send commands that were declared
72
72
// as supported by the child.
73
- Command ProgCmd
73
+ Command Cmd
74
74
75
75
// ActionID is the cache key for "put" and "get" requests.
76
76
ActionID []byte `json:",omitempty"` // or nil if not used
@@ -85,7 +85,7 @@ type ProgRequest struct {
85
85
// as a base64-encoded JSON string when BodySize is non-zero.
86
86
// It's sent as a separate JSON value instead of being a struct field
87
87
// send in this JSON object so large values can be streamed in both directions.
88
- // The base64 string body of a ProgRequest will always be written
88
+ // The base64 string body of a Request will always be written
89
89
// immediately after the JSON object and a newline.
90
90
Body io.Reader `json:"-"`
91
91
@@ -101,26 +101,26 @@ type ProgRequest struct {
101
101
ObjectID []byte `json:",omitempty"`
102
102
}
103
103
104
- // ProgResponse is the JSON response from the child process to the go command.
104
+ // Response is the JSON response from the child process to the go command.
105
105
//
106
106
// With the exception of the first protocol message that the child writes to its
107
107
// stdout with ID==0 and KnownCommands populated, these are only sent in
108
- // response to a ProgRequest from the go command.
108
+ // response to a Request from the go command.
109
109
//
110
- // ProgResponses can be sent in any order. The ID must match the request they're
110
+ // Responses can be sent in any order. The ID must match the request they're
111
111
// replying to.
112
- type ProgResponse struct {
113
- ID int64 // that corresponds to ProgRequest ; they can be answered out of order
112
+ type Response struct {
113
+ ID int64 // that corresponds to Request ; they can be answered out of order
114
114
Err string `json:",omitempty"` // if non-empty, the error
115
115
116
116
// KnownCommands is included in the first message that cache helper program
117
117
// writes to stdout on startup (with ID==0). It includes the
118
- // ProgRequest .Command types that are supported by the program.
118
+ // Request .Command types that are supported by the program.
119
119
//
120
120
// This lets the go command extend the protocol gracefully over time (adding
121
121
// "get2", etc), or fail gracefully when needed. It also lets the go command
122
122
// verify the program wants to be a cache helper.
123
- KnownCommands []ProgCmd `json:",omitempty"`
123
+ KnownCommands []Cmd `json:",omitempty"`
124
124
125
125
// For "get" requests.
126
126
0 commit comments