MCPcopy Create free account
hub / github.com/google/go-cloud / processOrder

Method processOrder

samples/order/processor.go:163–195  ·  view source on GitHub ↗

processOrder processes the order request.

(ctx context.Context, order *Order)

Source from the content-addressed store, hash-verified

161
162// processOrder processes the order request.
163func (p *processor) processOrder(ctx context.Context, order *Order) error {
164 // Read the input image from the bucket.
165 r, err := p.bucket.NewReader(ctx, order.InImage, nil)
166 if err != nil {
167 return err
168 }
169
170 defer r.Close()
171 img, format, err := image.Decode(r)
172 if err != nil {
173 return err
174 }
175
176 // Process and write the output image.
177 order.OutImage = fmt.Sprintf("%s-out.png", strings.TrimSuffix(order.InImage, "-in"))
178 w, err := p.bucket.NewWriter(ctx, order.OutImage, nil)
179 if err != nil {
180 return err
181 }
182 if err := png.Encode(w, img); err != nil {
183 w.Close()
184 return err
185 }
186 if err := w.Close(); err != nil {
187 return err
188 }
189
190 // Pretend that the conversion takes some time.
191 time.Sleep(time.Duration(rand.Intn(5)+2) * time.Second)
192
193 order.Note = fmt.Sprintf("converted from %s to png", format)
194 return nil
195}

Callers 2

handleRequestMethod · 0.95
TestProcessOrderFunction · 0.80

Calls 6

CloseMethod · 0.95
CloseMethod · 0.95
NewReaderMethod · 0.80
NewWriterMethod · 0.80
DecodeMethod · 0.45
EncodeMethod · 0.45

Tested by 1

TestProcessOrderFunction · 0.64