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

Side by Side Diff: appengine/logdog/coordinator/service.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Update tests Created 4 years, 6 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 LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package coordinator 5 package coordinator
6 6
7 import ( 7 import (
8 "net/http"
9 "sync" 8 "sync"
10 "sync/atomic" 9 "sync/atomic"
11 10
12 "github.com/julienschmidt/httprouter"
13 gaeauthClient "github.com/luci/luci-go/appengine/gaeauth/client" 11 gaeauthClient "github.com/luci/luci-go/appengine/gaeauth/client"
14 "github.com/luci/luci-go/appengine/logdog/coordinator/config" 12 "github.com/luci/luci-go/appengine/logdog/coordinator/config"
15 luciConfig "github.com/luci/luci-go/common/config" 13 luciConfig "github.com/luci/luci-go/common/config"
16 "github.com/luci/luci-go/common/errors" 14 "github.com/luci/luci-go/common/errors"
17 "github.com/luci/luci-go/common/gcloud/gs" 15 "github.com/luci/luci-go/common/gcloud/gs"
18 "github.com/luci/luci-go/common/gcloud/pubsub" 16 "github.com/luci/luci-go/common/gcloud/pubsub"
19 log "github.com/luci/luci-go/common/logging" 17 log "github.com/luci/luci-go/common/logging"
20 "github.com/luci/luci-go/common/proto/logdog/svcconfig" 18 "github.com/luci/luci-go/common/proto/logdog/svcconfig"
21 "github.com/luci/luci-go/server/logdog/storage" 19 "github.com/luci/luci-go/server/logdog/storage"
22 "github.com/luci/luci-go/server/logdog/storage/bigtable" 20 "github.com/luci/luci-go/server/logdog/storage/bigtable"
23 » "github.com/luci/luci-go/server/middleware" 21 » "github.com/luci/luci-go/server/router"
24 "golang.org/x/net/context" 22 "golang.org/x/net/context"
25 "google.golang.org/cloud" 23 "google.golang.org/cloud"
26 gcps "google.golang.org/cloud/pubsub" 24 gcps "google.golang.org/cloud/pubsub"
27 "google.golang.org/grpc/metadata" 25 "google.golang.org/grpc/metadata"
28 ) 26 )
29 27
30 // Services is a set of support services used by Coordinator. 28 // Services is a set of support services used by Coordinator.
31 // 29 //
32 // Each Services instance is valid for a singel request, but can be re-used 30 // Each Services instance is valid for a singel request, but can be re-used
33 // throughout that request. This is advised, as the Services instance may 31 // throughout that request. This is advised, as the Services instance may
(...skipping 24 matching lines...) Expand all
58 56
59 // GSClient instantiates a Google Storage client. 57 // GSClient instantiates a Google Storage client.
60 GSClient(context.Context) (gs.Client, error) 58 GSClient(context.Context) (gs.Client, error)
61 59
62 // ArchivalPublisher returns an ArchivalPublisher instance. 60 // ArchivalPublisher returns an ArchivalPublisher instance.
63 ArchivalPublisher(context.Context) (ArchivalPublisher, error) 61 ArchivalPublisher(context.Context) (ArchivalPublisher, error)
64 } 62 }
65 63
66 // WithProdServices is a middleware Handler that installs a production Services 64 // WithProdServices is a middleware Handler that installs a production Services
67 // instance into its Context. 65 // instance into its Context.
68 func WithProdServices(h middleware.Handler) middleware.Handler { 66 func WithProdServices() router.Handler {
69 » return func(c context.Context, rw http.ResponseWriter, r *http.Request, params httprouter.Params) { 67 » return func(c *router.Context) {
70 » » c = UseProdServices(c) 68 » » c.Context = UseProdServices(c.Context)
71 » » h(c, rw, r, params)
72 } 69 }
73 } 70 }
74 71
75 // UseProdServices installs production Services instance into the supplied 72 // UseProdServices installs production Services instance into the supplied
76 // Context. 73 // Context.
77 func UseProdServices(c context.Context) context.Context { 74 func UseProdServices(c context.Context) context.Context {
78 return WithServices(c, &prodServicesInst{}) 75 return WithServices(c, &prodServicesInst{})
79 } 76 }
80 77
81 // prodServicesInst is a Service exposing production faciliites. A unique 78 // prodServicesInst is a Service exposing production faciliites. A unique
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 // value as a sentinel that the archival index has wrapped. 277 // value as a sentinel that the archival index has wrapped.
281 // 278 //
282 // This is reasonable, as it is very unlikely that a single request will issue 279 // This is reasonable, as it is very unlikely that a single request will issue
283 // more than MaxInt32 archival tasks. 280 // more than MaxInt32 archival tasks.
284 v := atomic.AddInt32(&s.archivalIndex, 1) - 1 281 v := atomic.AddInt32(&s.archivalIndex, 1) - 1
285 if v < 0 { 282 if v < 0 {
286 panic("archival index has wrapped") 283 panic("archival index has wrapped")
287 } 284 }
288 return uint64(v) 285 return uint64(v)
289 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698