Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: appengine/logdog/coordinator/backend/util.go

Issue 1863973002: LogDog: Update to archival V2. (Closed) Base URL: https://github.com/luci/luci-go@grpcutil-errors
Patch Set: Code review comments, use Pub/Sub, archival staging, quality of life. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package backend 5 package backend
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "net/http" 9 "net/http"
10 "net/url"
11 10
12 "github.com/golang/protobuf/proto"
13 tq "github.com/luci/gae/service/taskqueue"
14 log "github.com/luci/luci-go/common/logging" 11 log "github.com/luci/luci-go/common/logging"
15 "golang.org/x/net/context" 12 "golang.org/x/net/context"
16 ) 13 )
17 14
18 // httpError 15 // httpError
19 type httpError struct { 16 type httpError struct {
20 reason error 17 reason error
21 code int 18 code int
22 } 19 }
23 20
(...skipping 17 matching lines...) Expand all
41 statusCode = e.code 38 statusCode = e.code
42 } 39 }
43 40
44 log.Fields{ 41 log.Fields{
45 log.ErrorKey: err, 42 log.ErrorKey: err,
46 "statusCode": statusCode, 43 "statusCode": statusCode,
47 }.Errorf(c, "Backend handler returned error.") 44 }.Errorf(c, "Backend handler returned error.")
48 w.WriteHeader(statusCode) 45 w.WriteHeader(statusCode)
49 } 46 }
50 } 47 }
51
52 func mkValues(params map[string]string) url.Values {
53 values := make(url.Values, len(params))
54 for k, v := range params {
55 values[k] = []string{v}
56 }
57 return values
58 }
59
60 func createTask(path string, params map[string]string) *tq.Task {
61 h := make(http.Header)
62 h.Set("Content-Type", "application/x-www-form-urlencoded")
63 return &tq.Task{
64 Path: path,
65 Header: h,
66 Payload: []byte(mkValues(params).Encode()),
67 Method: "POST",
68 }
69 }
70
71 // createPullTask is a generic pull queue task creation method. It is used to
72 // instantiate pull queue tasks.
73 func createPullTask(msg proto.Message) (*tq.Task, error) {
74 t := tq.Task{
75 Method: "PULL",
76 }
77
78 if msg != nil {
79 var err error
80 t.Payload, err = proto.Marshal(msg)
81 if err != nil {
82 return nil, err
83 }
84 }
85 return &t, nil
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698