// NewTokenBucketSet creates a `TokenBucketSet` from the specified `rates`.
514921
func NewTokenBucketSet(rates *RateSet, clock timetools.TimeProvider) *TokenBucketSet {
	tbs := new(TokenBucketSet)
	tbs.clock = clock
	// In the majority of cases we will have only one bucket.
	tbs.buckets = make(map[time.Duration]*tokenBucket, len(rates.m))
	for _, rate := range rates.m {
		newBucket := newTokenBucket(rate, clock)
		tbs.buckets[rate.period] = newBucket
		tbs.maxPeriod = maxDuration(tbs.maxPeriod, rate.period)
	}
	return tbs
}
973694
func (c *cachedGetter) Token() (string, error) {
	c.mutex.Lock()
	defer c.mutex.Unlock()

	var err error
	// no token or exceeds the TTL
	if c.token == "" || time.Since(c.born) > c.ttl {
		c.token, err = c.tokenGetter.Token()
		if err != nil {
			return "", fmt.Errorf("failed to get token: %s", err)
		}
		c.born = time.Now()
	}
	return c.token, nil
}
727883
func NewTTLRUCache(capacity int, ttl time.Duration) *TTLRUCache {
	rtn := &TTLRUCache{
		capacity:  capacity,
		mapping:   make(map[interface{}]*triple),
		order:     list.New(),
		timeorder: list.New(),
		ttl:       ttl,
	}
	rtn.triplePool.New = newTriple
	go rtn.timer()
	return rtn
}
718844
func NewTokenFromOAuth1Arg(Oauth1Token string, Oauth1TokenSecret string) *TokenFromOAuth1Arg {
	s := new(TokenFromOAuth1Arg)
	s.Oauth1Token = Oauth1Token
	s.Oauth1TokenSecret = Oauth1TokenSecret
	return s
}
972391
func (s *HTTPServer) parseToken(req *http.Request, token *string) {
	s.parseTokenInternal(req, token, true)
}
289564
func NewTokenProvider(opts ...TokenProviderOption) (*TokenProvider, error) {
	provider := new(TokenProvider)
	for _, opt := range opts {
		err := opt(provider)
		if err != nil {
			return nil, err
		}
	}
	return provider, nil
}
1048616
func NewTubeSet(c *Conn, name ...string) *TubeSet {
	ts := &TubeSet{c, make(map[string]bool)}
	for _, s := range name {
		ts.Name[s] = true
	}
	return ts
}
714721
func NewTokenRefresher(uaaClient UAAClient, cache TokenCache) *TokenRefresher {
	return &TokenRefresher{
		uaaClient: uaaClient,
		cache:     cache,
	}
}
488751
func NewTokenVerification(response *http.Response) (*TokenVerification, error) {
	tokenVerification := &TokenVerification{HTTPResponse: response}
	body, err := ioutil.ReadAll(response.Body)

	if err != nil {
		Logger.Println("Error reading from API:", err)
		return tokenVerification, err
	}

	err = json.Unmarshal(body, &tokenVerification)
	if err != nil {
		Logger.Println("Error parsing JSON:", err)
		return tokenVerification, err
	}

	return tokenVerification, nil
}
65140
func NewTokenizer(r io.Reader) *Tokenizer {
	return &Tokenizer{
		InStream: r,
		buf:      make([]byte, defaultBufSize),
	}
}
1077666
func parseContToken(token string) (pack int, offset int64, err error) {
	// Special case
	if token == "" {
		pack = 0
		offset = 0
		return
	}
	_, err = fmt.Sscan(token, &pack, &offset)

	return
}
778658
func joinTokens(tokens []tokenItem) string {
	var buf bytes.Buffer
	for i, tok := range tokens {
		if i > 0 {
			buf.WriteByte(' ')
		}
		buf.WriteString(tok.String())
	}
	return buf.String()
}
1181140
func NewToken(iss, scope string, key []byte) *Token {
	c := &ClaimSet{
		Iss:   iss,
		Scope: scope,
		Aud:   stdAud,
	}
	h := &Header{
		Algorithm: stdAlgorithm,
		Type:      stdType,
	}
	t := &Token{
		ClaimSet: c,
		Header:   h,
		Key:      key,
	}
	return t
}
835700
func newTokenInjector(meta *metadata.Client, acc string) func(*http.Request) error {
	if acc == "" {
		acc = "default"
	}
	acc = url.PathEscape(acc)
	return func(req *http.Request) error {
		aud := fmt.Sprintf("%s://%s", req.URL.Scheme, req.URL.Host)
		aud = url.QueryEscape(aud)
		// TODO(smut): Cache the token and reuse if not yet expired.
		// Currently the only user of this package only makes one
		// request per boot so caching isn't too important yet.
		tok, err := meta.Get(fmt.Sprintf(tokMetadata, acc, aud))
		if err != nil {
			return err
		}
		req.Header.Set(vmtoken.Header, tok)
		return nil
	}
}
170989
func NewTokenBuffer(l *xml.Lexer) *TokenBuffer {
	return &TokenBuffer{
		l:   l,
		buf: make([]Token, 0, 8),
	}
}
158646
func (g *globTokeniser) PeekToken() (token string, tokenType tc) {
	return g.peekToken, g.peekTokenType
}
809362
func NewTrackEngine(g *libkb.GlobalContext, arg *TrackEngineArg) *TrackEngine {
	return &TrackEngine{
		arg:          arg,
		Contextified: libkb.NewContextified(g),
	}
}