{"id":19202315,"url":"https://github.com/osamingo/goss","last_synced_at":"2025-02-23T05:42:33.714Z","repository":{"id":25424410,"uuid":"28853796","full_name":"osamingo/goss","owner":"osamingo","description":"Provides sorted-slice for golang","archived":false,"fork":false,"pushed_at":"2018-10-24T20:43:00.000Z","size":168,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-04T13:44:21.376Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/osamingo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-06T08:23:09.000Z","updated_at":"2018-04-28T09:29:05.000Z","dependencies_parsed_at":"2022-07-24T05:32:03.268Z","dependency_job_id":null,"html_url":"https://github.com/osamingo/goss","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osamingo%2Fgoss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osamingo%2Fgoss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osamingo%2Fgoss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osamingo%2Fgoss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/osamingo","download_url":"https://codeload.github.com/osamingo/goss/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240275899,"owners_count":19775614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T12:42:12.980Z","updated_at":"2025-02-23T05:42:33.487Z","avatar_url":"https://github.com/osamingo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"GoSS\n====\n\n[![Build Status](http://img.shields.io/travis/osamingo/goss.svg?style=flat)](https://travis-ci.org/osamingo/goss)\n[![Coverage](http://img.shields.io/codecov/c/github/osamingo/goss.svg?style=flat)](https://codecov.io/github/osamingo/goss)\n[![License](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://github.com/osamingo/goss/blob/master/LICENSE)\n\n## Description\n\nGoSS provides sorted-slice for golang.\n\n## Installation\n\n```\n$ go get github.com/osamingo/goss\n```\n\n## Quick start\n\n```go\npackage main\n\nimport (\n\t\"crypto/rand\"\n\t\"encoding/base64\"\n\t\"fmt\"\n\tmrand \"math/rand\"\n\t\"sync\"\n\n\t\"github.com/osamingo/goss\"\n)\n\ntype Result struct {\n\tID    string\n\tScore int\n}\n\nfunc (r *Result) Target() int64 {\n\treturn int64(r.Score)\n}\n\nfunc (r *Result) Priority() string {\n\treturn r.ID\n}\n\nfunc randStr() string {\n\trb := make([]byte, 32)\n\trand.Read(rb)\n\treturn base64.URLEncoding.EncodeToString(rb)\n}\n\nfunc main() {\n\n\trs := []*Result{}\n\tfmt.Println(\"# Before\")\n\tfor i := 0; i \u003c 10; i++ {\n\t\tr := \u0026Result{ID: randStr()}\n\t\tfmt.Printf(\"%2d: %v\\n\", i+1, r)\n\t\trs = append(rs, r)\n\t}\n\n\twg := new(sync.WaitGroup)\n\twg.Add(len(rs))\n\n\tfinChan := make(chan bool)\n\tretChan := make(chan *Result, len(rs))\n\n\tgo func() {\n\t\twg.Wait()\n\t\tfinChan \u003c- true\n\t}()\n\n\tfor _, r := range rs {\n\t\tgo func(res *Result) {\n\t\t\tdefer wg.Done()\n\t\t\tres.Score = mrand.Intn(1000)\n\t\t\tretChan \u003c- res\n\t\t}(r)\n\t}\n\n\ts := \u0026goss.SortedSlice{DESC: true}\n\nLOOP:\n\tfor {\n\t\tselect {\n\t\tcase \u003c-finChan:\n\t\t\tbreak LOOP\n\t\tcase r := \u003c-retChan:\n\t\t\ts.Add(r)\n\t\t}\n\t}\n\n\tfmt.Println(\"\\n# After\")\n\tfor i, r := range s.S {\n\t\tfmt.Printf(\"%2d: %v\\n\", i+1, r)\n\t}\n\n}\n```\n\n## Tips\n\n```go\ntype Result struct {\n\tID    string\n\tScore int\n\t\n\tTargetFunc   func() int64\n\tPriorityFunc func() string\n}\n\nfunc (r *Result) Target() int64 {\n\treturn r.TargetFunc()\n}\n\nfunc (r *Result) Priority() string {\n\treturn r.PriorityFunc()\n}\n```\n\n## License\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosamingo%2Fgoss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fosamingo%2Fgoss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosamingo%2Fgoss/lists"}