本文整理汇总了Golang中go/skia/org/infra/go/util.In函数的典型用法代码示例。如果您正苦于以下问题:Golang In函数的具体用法?Golang In怎么用?Golang In使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了In函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewDocSetForIssue
// NewDocSetForIssue creates a new DocSet patched to the latest patch level of
// the given issue.
//
// The returned DocSet is not periodically refreshed.
func NewDocSetForIssue(workDir, repo string, issue int64) (*DocSet, error) {
// Only do pull and patch if directory doesn't exist.
issueInfo, err := rc.Issue(issue)
if err != nil {
return nil, fmt.Errorf("Failed to load issue info: %s", err)
}
patchset := issueInfo.Patchsets[len(issueInfo.Patchsets)-1]
addr, err := mail.ParseAddress(issueInfo.OwnerEmail)
if err != nil {
return nil, fmt.Errorf("CL contains invalid author email: %s", err)
}
domain := strings.Split(addr.Address, "@")[1]
if !util.In(domain, config.WHITELIST) {
return nil, fmt.Errorf("User is not authorized to test docset CLs.")
}
var d *DocSet
repoDir := filepath.Join(workDir, "patches", fmt.Sprintf("%d-%d", issue, patchset))
if _, err := os.Stat(repoDir); os.IsNotExist(err) {
d, err = newDocSet(repoDir, repo, issue, patchset, false)
if err != nil {
if err := os.RemoveAll(repoDir); err != nil {
glog.Errorf("Failed to remove %q: %s", repoDir, err)
}
return nil, fmt.Errorf("Failed to create new doc set: %s", err)
}
} else {
d = &DocSet{
repoDir: repoDir,
}
d.BuildNavigation()
}
return d, nil
}
示例2: addResultToTile
// addResultToTile adds the Digests from the DMResults to the tile at the given offset.
func addResultToTile(res *DMResults, tile *tiling.Tile, offset int, counter metrics.Counter) {
res.ForEach(func(traceID, digest string, params map[string]string) {
if ext, ok := params["ext"]; !ok || ext != "png" {
return // Skip non-PNG results they are be converted to PNG by a separate process.
}
var trace *types.GoldenTrace
var ok bool
needsUpdate := false
if tr, ok := tile.Traces[traceID]; !ok {
trace = types.NewGoldenTrace()
tile.Traces[traceID] = trace
needsUpdate = true
} else {
trace = tr.(*types.GoldenTrace)
if !util.MapsEqual(params, tile.Traces[traceID].Params()) {
needsUpdate = true
}
}
trace.Params_ = params
if needsUpdate {
// Update the Tile's ParamSet with any new keys or values we see.
for k, v := range params {
if _, ok = tile.ParamSet[k]; !ok {
tile.ParamSet[k] = []string{v}
} else if !util.In(v, tile.ParamSet[k]) {
tile.ParamSet[k] = append(tile.ParamSet[k], v)
}
}
}
trace.Values[offset] = digest
counter.Inc(1)
})
}
示例3: Merge
// Merge adds in new info from the passed in ClusterSummary.
func (c *ClusterSummary) Merge(from *ClusterSummary) {
for _, k := range from.Keys {
if !util.In(k, c.Keys) {
c.Keys = append(c.Keys, k)
}
}
}
示例4: Get
// Get returns the ShortCommit info for the given branch, target, and buildID.
func (i *info) Get(branch, target, buildID string) (*gitinfo.ShortCommit, error) {
// Get the list of targets and confirm that this target is in it, otherwise add it to the list of targets.
branchtargets := i.branchtargets()
branchtarget := fmt.Sprintf("%s:%s", branch, target)
if !util.In(branchtarget, branchtargets) {
// If we aren't currently scanning results for this (branch, target) pair
// then add it to the list.
branchtargets = append(branchtargets, branchtarget)
err := i.db.Put([]byte(TARGETS_KEY), []byte(strings.Join(branchtargets, " ")), nil)
if err != nil {
glog.Errorf("Failed to add new target %s: %s", branchtarget, err)
}
// Always try to fetch the information from the Android Build API directly if
// we don't have it yet.
return i.single_get(branch, target, buildID)
} else {
key, err := toKey(branch, target, buildID)
if err != nil {
return nil, fmt.Errorf("Can't Get with an invalid build ID %q: %s", buildID, err)
}
// Scan backwards through the build info until we find a buildID that is equal to or
// comes before the buildID we are looking for.
iter := i.db.NewIterator(lutil.BytesPrefix([]byte(toPrefix(branch, target))), nil)
defer iter.Release()
if found := iter.Seek([]byte(key)); found {
value := &gitinfo.ShortCommit{}
if err := json.Unmarshal(iter.Value(), value); err != nil {
return nil, fmt.Errorf("Unable to deserialize value: %s", err)
}
return value, nil
} else {
return i.single_get(branch, target, buildID)
}
}
}
示例5: CombineClusters
// CombineClusters combines freshly found clusters with existing clusters.
//
// Algorithm:
// Run clustering and pick out the "Interesting" clusters.
// Compare all the Interesting clusters to all the existing relevant clusters,
// where "relevant" clusters are ones whose Hash/timestamp of the step
// exists in the current tile.
// Start with an empty "list".
// For each cluster:
// For each relevant existing cluster:
// Take the top 20 keys from the existing cluster and count how many appear
// in the cluster.
// If there are no matches then this is a new cluster, add it to the "list".
// If there are matches, possibly to multiple existing clusters, find the
// existing cluster with the most matches.
// Take the cluster (old/new) with the most members, or the best fit if
// they have the same number of matches.
// Return all the updated clusters.
func CombineClusters(freshSummaries, oldSummaries []*types.ClusterSummary) []*types.ClusterSummary {
ret := []*types.ClusterSummary{}
stillFresh := []*types.ClusterSummary{}
// If two cluster summaries have the same hash and same Regression direction
// then they are the same, merge them together.
for _, fresh := range freshSummaries {
for _, old := range oldSummaries {
if fresh.Hash == old.Hash && math.Signbit(fresh.StepFit.Regression) == math.Signbit(old.StepFit.Regression) {
old.Merge(fresh)
ret = append(ret, old)
break
}
}
stillFresh = append(stillFresh, fresh)
}
// Even if a summary has a different hash it might still be the same event if
// there is an overlap in the traces each summary contains.
for _, fresh := range stillFresh {
var bestMatch *types.ClusterSummary = nil
bestMatchHits := 0
for _, old := range oldSummaries {
hits := 0
for _, key := range util.AtMost(old.Keys, 20) {
if util.In(key, fresh.Keys) {
hits += 1
}
}
if hits > bestMatchHits {
bestMatchHits = hits
bestMatch = old
}
}
if bestMatch != nil {
keysLengthEqual := len(fresh.Keys) == len(bestMatch.Keys)
regressionInSameDirection := math.Signbit(fresh.StepFit.Regression) == math.Signbit(bestMatch.StepFit.Regression)
freshHasBetterFit := math.Abs(fresh.StepFit.Regression) > math.Abs(bestMatch.StepFit.Regression)
freshHasMoreKeys := len(fresh.Keys) > len(bestMatch.Keys)
if freshHasMoreKeys || (keysLengthEqual && regressionInSameDirection && freshHasBetterFit) {
fresh.Status = bestMatch.Status
fresh.Message = bestMatch.Message
fresh.ID = bestMatch.ID
fresh.Bugs = bestMatch.Bugs
ret = append(ret, fresh)
// Find the bestMatch in oldSummaries and replace it with fresh.
for i, oldBest := range oldSummaries {
if oldBest == bestMatch {
oldSummaries[i] = fresh
break
}
}
}
} else {
ret = append(ret, fresh)
}
}
return ret
}
示例6: Matches
// Matches returns true if the given Trace matches the given query.
func Matches(tr Trace, query url.Values) bool {
for k, values := range query {
if _, ok := tr.Params()[k]; !ok || !util.In(tr.Params()[k], values) {
return false
}
}
return true
}
示例7: makeRollResult
// makeRollResult determines what the result of a roll should be, given that
// it is going to be closed.
func (r *AutoRoller) makeRollResult(roll *autoroll.AutoRollIssue) string {
if util.In(roll.Result, autoroll.DRY_RUN_RESULTS) {
if roll.Result == autoroll.ROLL_RESULT_DRY_RUN_IN_PROGRESS {
return autoroll.ROLL_RESULT_DRY_RUN_FAILURE
} else {
return roll.Result
}
}
return autoroll.ROLL_RESULT_FAILURE
}
示例8: scoreBuild
// scoreBuild returns the current score for the given commit/builder pair. The
// details on how scoring works are described in the doc for NewBuildQueue.
func scoreBuild(commit *vcsinfo.LongCommit, build *buildbot.Build, now time.Time, timeLambda float64) float64 {
s := -1.0
if build != nil {
if build.GotRevision == commit.Hash {
s = 1.0
} else if util.In(commit.Hash, build.Commits) {
s = 1.0 / float64(len(build.Commits))
}
}
return s * timeFactor(now, commit.Timestamp, timeLambda)
}
示例9: GetParamSet
// Finds the paramSet for the given slice of traces.
func GetParamSet(traces map[string]Trace, paramSet map[string][]string) {
for _, trace := range traces {
for k, v := range trace.Params() {
if _, ok := paramSet[k]; !ok {
paramSet[k] = []string{v}
} else if !util.In(v, paramSet[k]) {
paramSet[k] = append(paramSet[k], v)
}
}
}
}
示例10: differences
// differences returns all strings that appear in server but not local.
func differences(server, local []string) ([]string, []string) {
newPackages := []string{}
installedPackages := []string{}
for _, s := range server {
if util.In(s, local) {
installedPackages = append(installedPackages, s)
} else {
newPackages = append(newPackages, s)
}
}
return newPackages, installedPackages
}
示例11: setStatus
// setStatus sets the current reporting status of the bot.
func (r *AutoRoller) setStatus(s string, lastError error) error {
r.mtx.Lock()
defer r.mtx.Unlock()
if !util.In(string(s), VALID_STATUSES) {
return fmt.Errorf("Invalid status: %s", s)
}
if s == STATUS_ERROR {
if lastError == nil {
return fmt.Errorf("Cannot set error status without an error!")
}
} else if lastError != nil {
return fmt.Errorf("Cannot be in any status other than error when an error occurred.")
}
r.status = s
r.lastError = lastError
return nil
}
示例12: polyListTestsHandler
// polyListTestsHandler returns a JSON list with high level information about
// each test.
//
// Takes two query parameters:
// include - True if ignored digests should be included. (true, false)
// query - A query to restrict the responses to, encoded as a URL encoded paramset.
// head - True if only digest that appear at head should be included.
//
// The return format looks like:
//
// [
// {
// "name": "01-original",
// "diameter": 123242,
// "untriaged": 2,
// "num": 2
// },
// ...
// ]
//
func polyListTestsHandler(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
util.ReportError(w, r, err, "Failed to parse form data.")
return
}
// If the query only includes source_type parameters, and include==false, then we can just
// filter the response from summaries.Get(). If the query is broader than that, or
// include==true, then we need to call summaries.CalcSummaries().
if err := r.ParseForm(); err != nil {
util.ReportError(w, r, err, "Invalid request.")
return
}
q, err := url.ParseQuery(r.FormValue("query"))
if err != nil {
util.ReportError(w, r, err, "Invalid query in request.")
return
}
_, hasSourceType := q["source_type"]
sumSlice := []*summary.Summary{}
if r.FormValue("include") == "false" && r.FormValue("head") == "true" && len(q) == 1 && hasSourceType {
sumMap := summaries.Get()
corpus := q["source_type"]
for _, s := range sumMap {
if util.In(s.Corpus, corpus) {
sumSlice = append(sumSlice, s)
}
}
} else {
glog.Infof("%q %q %q", r.FormValue("query"), r.FormValue("include"), r.FormValue("head"))
sumMap, err := summaries.CalcSummaries(nil, r.FormValue("query"), r.FormValue("include") == "true", r.FormValue("head") == "true")
if err != nil {
util.ReportError(w, r, err, "Failed to calculate summaries.")
return
}
for _, s := range sumMap {
sumSlice = append(sumSlice, s)
}
}
sort.Sort(SummarySlice(sumSlice))
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
if err := enc.Encode(sumSlice); err != nil {
glog.Errorf("Failed to write or encode result: %s", err)
}
}
示例13: Validate
// Validate returns an error iff there is some problem with the issue.
func (i *AutoRollIssue) Validate() error {
if i.Closed {
if i.Result == ROLL_RESULT_IN_PROGRESS {
return fmt.Errorf("AutoRollIssue cannot have a Result of %q if it is Closed.", ROLL_RESULT_IN_PROGRESS)
}
if i.CommitQueue {
return errors.New("AutoRollIssue cannot be marked CommitQueue if it is Closed.")
}
} else {
if i.Committed {
return errors.New("AutoRollIssue cannot be Committed without being Closed.")
}
if !util.In(i.Result, OPEN_ROLL_VALID_RESULTS) {
return fmt.Errorf("AutoRollIssue which is not Closed must have as a Result one of: %v", OPEN_ROLL_VALID_RESULTS)
}
}
return nil
}
示例14: changeHandler
// changeHandler changes the status of a service.
//
// Takes the following query parameters:
//
// name - The name of the service.
// action - The action to perform. One of ["start", "stop", "restart"].
//
// The response is of the form:
//
// {
// "result": "started"
// }
//
func changeHandler(w http.ResponseWriter, r *http.Request) {
var err error
if err := r.ParseForm(); err != nil {
util.ReportError(w, r, err, "Failed to parse form.")
return
}
action := r.Form.Get("action")
if !util.In(action, ACTIONS) {
util.ReportError(w, r, fmt.Errorf("Not a valid action: %s", action), "Invalid action.")
return
}
name := r.Form.Get("name")
if name == "" {
util.ReportError(w, r, fmt.Errorf("Not a valid service name: %s", name), "Invalid service name.")
return
}
if *local {
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(ChangeResult{"started"}); err != nil {
glog.Errorf("Failed to write or encode output: %s", err)
}
return
}
ch := make(chan string)
switch action {
case "start":
_, err = dbc.StartUnit(name, "replace", ch)
case "stop":
_, err = dbc.StopUnit(name, "replace", ch)
case "restart":
_, err = dbc.RestartUnit(name, "replace", ch)
}
if err != nil {
util.ReportError(w, r, err, "Action failed.")
return
}
res := ChangeResult{}
res.Result = <-ch
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(res); err != nil {
glog.Errorf("Failed to write or encode output: %s", err)
}
}
示例15: Add
// Add inserts a new ModeChange.
func (mh *ModeHistory) Add(m, user, message string) error {
if !util.In(m, VALID_MODES) {
return fmt.Errorf("Invalid mode: %s", m)
}
modeChange := &ModeChange{
Message: message,
Mode: m,
Time: time.Now(),
User: user,
}
mh.mtx.Lock()
defer mh.mtx.Unlock()
if err := mh.db.SetMode(modeChange); err != nil {
return err
}
return mh.refreshHistory()
}