| OLD | NEW |
| 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 coordinator | 5 package coordinator |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "net/http" | 8 "net/http" |
| 9 "sync" | 9 "sync" |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 GSClient(context.Context) (gs.Client, error) | 52 GSClient(context.Context) (gs.Client, error) |
| 53 | 53 |
| 54 // ArchivalPublisher returns an ArchivalPublisher instance. | 54 // ArchivalPublisher returns an ArchivalPublisher instance. |
| 55 ArchivalPublisher(context.Context) (ArchivalPublisher, error) | 55 ArchivalPublisher(context.Context) (ArchivalPublisher, error) |
| 56 } | 56 } |
| 57 | 57 |
| 58 // WithProdServices is a middleware Handler that installs a production Services | 58 // WithProdServices is a middleware Handler that installs a production Services |
| 59 // instance into its Context. | 59 // instance into its Context. |
| 60 func WithProdServices(h middleware.Handler) middleware.Handler { | 60 func WithProdServices(h middleware.Handler) middleware.Handler { |
| 61 return func(c context.Context, rw http.ResponseWriter, r *http.Request,
params httprouter.Params) { | 61 return func(c context.Context, rw http.ResponseWriter, r *http.Request,
params httprouter.Params) { |
| 62 » » c = WithServices(c, &prodServices{}) | 62 » » c = UseProdServices(c) |
| 63 h(c, rw, r, params) | 63 h(c, rw, r, params) |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 // UseProdServices installs production Services instance into the supplied |
| 68 // Context. |
| 69 func UseProdServices(c context.Context) context.Context { |
| 70 return WithServices(c, &prodServices{}) |
| 71 } |
| 72 |
| 67 // Request is a Service context for a given request. | 73 // Request is a Service context for a given request. |
| 68 type prodServices struct { | 74 type prodServices struct { |
| 69 sync.Mutex | 75 sync.Mutex |
| 70 | 76 |
| 71 // gcfg is the cached global configuration. | 77 // gcfg is the cached global configuration. |
| 72 gcfg *config.GlobalConfig | 78 gcfg *config.GlobalConfig |
| 73 // cfg is the cached configuration. | 79 // cfg is the cached configuration. |
| 74 cfg *svcconfig.Config | 80 cfg *svcconfig.Config |
| 75 } | 81 } |
| 76 | 82 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 psClient, err := gcps.NewClient(c, project, cloud.WithBaseHTTP(client)) | 219 psClient, err := gcps.NewClient(c, project, cloud.WithBaseHTTP(client)) |
| 214 if err != nil { | 220 if err != nil { |
| 215 log.WithError(err).Errorf(c, "Failed to create Pub/Sub client.") | 221 log.WithError(err).Errorf(c, "Failed to create Pub/Sub client.") |
| 216 return nil, errors.New("failed to create Pub/Sub client") | 222 return nil, errors.New("failed to create Pub/Sub client") |
| 217 } | 223 } |
| 218 | 224 |
| 219 return &pubsubArchivalPublisher{ | 225 return &pubsubArchivalPublisher{ |
| 220 topic: psClient.Topic(topic), | 226 topic: psClient.Topic(topic), |
| 221 }, nil | 227 }, nil |
| 222 } | 228 } |
| OLD | NEW |