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

Unified Diff: go/src/infra/gae/libs/gae/mathrand.go

Issue 1230303003: Revert "Refactor current GAE abstraction library to be free of the SDK*" (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/src/infra/gae/libs/gae/helper/serialize_test.go ('k') | go/src/infra/gae/libs/gae/memcache.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/gae/libs/gae/mathrand.go
diff --git a/go/src/infra/gae/libs/gae/mathrand.go b/go/src/infra/gae/libs/gae/mathrand.go
deleted file mode 100644
index 99c8b2f2998745e037a8e896d83e9ed3ca5e15f9..0000000000000000000000000000000000000000
--- a/go/src/infra/gae/libs/gae/mathrand.go
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package gae
-
-import (
- "golang.org/x/net/context"
- "math/rand"
-
- "github.com/luci/luci-go/common/clock"
-)
-
-// MathRandFactory is the function signature for factory methods compatible with
-// SetMathRandFactory.
-type MathRandFactory func(context.Context) *rand.Rand
-
-// GetMathRand gets a *"math/rand".Rand from the context. If one hasn't been
-// set, this creates a new Rand object with a Source initialized from the
-// current time clock.Now(c).UnixNano().
-func GetMathRand(c context.Context) *rand.Rand {
- if f, ok := c.Value(mathRandKey).(MathRandFactory); ok && f != nil {
- return f(c)
- }
- return rand.New(rand.NewSource(clock.Now(c).UnixNano()))
-}
-
-// SetMathRandFactory sets the function to produce *"math/rand".Rand instances,
-// as returned by the GetMathRand method.
-func SetMathRandFactory(c context.Context, mrf MathRandFactory) context.Context {
- return context.WithValue(c, mathRandKey, mrf)
-}
-
-// SetMathRand sets the current *"math/rand".Rand object in the context. Useful
-// for testing with a quick mock. This is just a shorthand SetMathRandFactory
-// invocation to set a factory which always returns the same object.
-func SetMathRand(c context.Context, r *rand.Rand) context.Context {
- if r == nil {
- return SetMathRandFactory(c, nil)
- }
- return SetMathRandFactory(c, func(context.Context) *rand.Rand { return r })
-}
« no previous file with comments | « go/src/infra/gae/libs/gae/helper/serialize_test.go ('k') | go/src/infra/gae/libs/gae/memcache.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698