You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: loader.go
    path of file: ./repos/client/go/teams
    
    the code of the file until where you have to start completion: package teams

import (
	"errors"
	"fmt"
	"os"
	"sort"
	"sync"
	"time"

	"golang.org/x/net/context"

	"github.com/keybase/client/go/gregor"
	"github.com/keybase/client/go/libkb"
	"github.com/keybase/client/go/protocol/keybase1"
	hidden "github.com/keybase/client/go/teams/hidden"
	storage "github.com/keybase/client/go/teams/storage"
	pkgErrors "github.com/pkg/errors"
)

// Show detailed team profiling
var teamEnv struct {
	Profile             bool
	UserPreloadEnable   bool
	UserPreloadParallel bool
	UserPreloadWait     bool
	ProofSetParallel    bool
}

func init() {
	teamEnv.Profile = os.Getenv("KEYBASE_TEAM_PROF") == "1"
	teamEnv.UserPreloadEnable = os.Getenv("KEYBASE_TEAM_PE") == "1"
	teamEnv.UserPreloadParallel = os.Getenv("KEYBASE_TEAM_PP") == "1"
	teamEnv.UserPreloadWait = os.Getenv("KEYBASE_TEAM_PW") == "1"
	teamEnv.ProofSetParallel = os.Getenv("KEYBASE_TEAM_SP") == "0"
}

// How long until the tail of a team sigchain is considered non-fresh
const freshnessLimit = time.Duration(1) * time.Hour

// Load a Team from the TeamLoader.
// Can be called from inside the teams package.
func Load(ctx context.Context, g *libkb.GlobalContext, lArg keybase1.LoadTeamArg) (*Team, error) {
	teamData, hidden, err := g.GetTeamLoader().Load(ctx, lArg)
	if err != nil {
		return nil, err
	}
	team := NewTeam(ctx, g, teamData, hidden)

	if lArg.RefreshUIDMapper {
		// If we just loaded the group, then inform the UIDMapper of any UID->EldestSeqno
		// mappings, so that we're guaranteed they aren't stale.
		team.refreshUIDMapper(ctx, g)
	}

	// OK if it errors; just move on and return the team.
	_, _ = team.calculateAndCacheMemberCount(ctx)

	return team, nil
}

// Loader of keybase1.TeamData objects. Handles caching.
// Because there is one of this global object and it is attached to G,
// its Load interface must return a keybase1.TeamData not a teams.Team.
// To load a teams.Team use the package-level function Load.
// Threadsafe.
type TeamLoader struct {
	libkb.Contextified
	world         LoaderContext
	storage       *storage.Storage
	merkleStorage *storage.Merkle
	// Single-flight locks per team ID.
	// (Private and public loads of the same ID will block each other, should be fine)
	locktab *libkb.LockTable

	// Cache lookups of team name -> ID for a few seconds, to absorb bursts
    
func (l *TeamLoader) doOneLink(mctx libkb.MetaContext, arg load2ArgT, ret *keybase1.TeamData, hiddenPackage *hidden.LoaderPackage, link *ChainLinkUnpacked, i int, suppressLoggingStart int, suppressLoggingUpto int, lastSeqno keybase1.Seqno, parentChildOperations *[](*parentChildOperation), prev libkb.LinkID, fullVerifyCutoff keybase1.Seqno, readSubteamID keybase1.TeamID, proofSet *proofSetT, lkc *loadKeyCache, parentsCache *parentChainCache) (*keybase1.TeamData, libkb.LinkID, error) {

	var nilPrev libkb.LinkID

	ctx := mctx.Ctx()
	if suppressLoggingStart <= i && i < suppressLoggingUpto {
		if i == suppressLoggingStart {
			mctx.Debug("TeamLoader suppressing logs until %v", suppressLoggingUpto)
		}
		ctx = WithSuppressLogging(ctx, true)
		mctx = mctx.WithContext(ctx)
	}

	if !ShouldSuppressLogging(ctx) {
		mctx.Debug("TeamLoader processing link seqno:%v", link.Seqno())
	}

	if link.Seqno() > lastSeqno {
		// This link came from a point in the chain after when we checked the merkle leaf.
		// Processing it would require re-checking merkle.
		// It would be tricky to ignore it because off-chain data is asserted to be in sync with the chain.
		// So, return an error that the caller will retry.
		mctx.Debug("TeamLoader found green link seqno:%v", link.Seqno())
		return nil, nilPrev, NewGreenLinkError(link.Seqno())
	}

	if err := l.checkStubbed(ctx, arg, link); err != nil {
		return nil, nilPrev, err
	}

	if !link.Prev().Eq(prev) {
		return nil, nilPrev, NewPrevError("team replay failed: prev chain broken at link %d (%v != %v)",
			i, link.Prev(), prev)
	}

	if err := consumeRatchets(mctx, hiddenPackage, link); err != nil {
		return nil, nilPrev, err
	}

	if err := checkPTKGenerationNotOnHiddenChain(mctx, hiddenPackage, link); err != nil {
		return nil, nilPrev, err
	}

	var signer *SignerX
	var err error
	signer, err = l.verifyLink(ctx, arg.teamID, ret, arg.me, link, fullVerifyCutoff,
		readSubteamID, proofSet, lkc, *parentsCache)
	if err != nil {
		return nil, nilPrev, err
	}

	if l.isParentChildOperation(ctx, link) {
		pco, err := l.toParentChildOperation(ctx, link)
		if err != nil {
			return nil, nilPrev, err
		}
		*parentChildOperations = append(*parentChildOperations, pco)
	}

	ret, err = l.applyNewLink(ctx, ret, hiddenPackage.ChainData(), link, signer, arg.me)
	if err != nil {
		return nil, nilPrev, err
	}

	return ret, link.LinkID(), nil
}