本文整理匯總了Golang中github.com/fatih/set.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getStats
func (server *Server) getStats(writer http.ResponseWriter, request *http.Request) *statsResponse {
sourceSet := set.New(set.ThreadSafe)
metricSet := set.New(set.ThreadSafe)
for _, origin := range server.Catalog.GetOrigins() {
for _, source := range origin.GetSources() {
sourceSet.Add(source.Name)
for _, metric := range source.GetMetrics() {
metricSet.Add(metric.Name)
}
}
}
sourceGroupsCount := 0
metricGroupsCount := 0
for _, group := range server.Library.Groups {
if group.Type == library.LibraryItemSourceGroup {
sourceGroupsCount++
} else {
metricGroupsCount++
}
}
return &statsResponse{
Origins: len(server.Catalog.GetOrigins()),
Sources: sourceSet.Size(),
Metrics: metricSet.Size(),
Graphs: len(server.Library.Graphs),
Collections: len(server.Library.Collections),
SourceGroups: sourceGroupsCount,
MetricGroups: metricGroupsCount,
}
}
示例2: serveMetricList
func (server *Server) serveMetricList(writer http.ResponseWriter, request *http.Request) {
var offset, limit int
if response, status := server.parseListRequest(writer, request, &offset, &limit); status != http.StatusOK {
server.serveResponse(writer, response, status)
return
}
originName := request.FormValue("origin")
sourceName := request.FormValue("source")
sourceSet := set.New(set.ThreadSafe)
if strings.HasPrefix(sourceName, library.LibraryGroupPrefix) {
for _, entryName := range server.Library.ExpandSourceGroup(
strings.TrimPrefix(sourceName, library.LibraryGroupPrefix),
) {
sourceSet.Add(entryName)
}
} else if sourceName != "" {
sourceSet.Add(sourceName)
}
metricSet := set.New(set.ThreadSafe)
for _, origin := range server.Catalog.GetOrigins() {
if originName != "" && origin.Name != originName {
continue
}
for _, source := range origin.GetSources() {
if sourceName != "" && sourceSet.IsEmpty() || !sourceSet.IsEmpty() && !sourceSet.Has(source.Name) {
continue
}
for _, metric := range source.GetMetrics() {
if request.FormValue("filter") != "" && !utils.FilterMatch(request.FormValue("filter"), metric.Name) {
continue
}
metricSet.Add(metric.Name)
}
}
}
response := &listResponse{
list: StringListResponse(set.StringSlice(metricSet)),
offset: offset,
limit: limit,
}
server.applyResponseLimit(writer, request, response)
server.serveResponse(writer, response.list, http.StatusOK)
}
示例3: toSet
// toSet converts a slice of strings into a set
func toSet(s []string) set.Interface {
if s == nil {
return set.New(set.NonThreadSafe)
}
is := make([]interface{}, len(s))
for i, s := range s {
is[i] = s
}
set := set.New(set.NonThreadSafe)
set.Add(is...)
return set
}
示例4: LoadConf
func LoadConf() {
var err error
conf, err = yaml.ReadFile("botconf.yaml")
if err != nil {
log.Panic(err)
}
Categories = List2SliceInConf("catagoris")
CategoriesSet = set.New(set.NonThreadSafe)
Groups = []Group{}
for _, v := range Categories {
CategoriesSet.Add(v)
for _, i := range List2SliceInConf(v) {
reg := regexp.MustCompile("^(.+) (http(s)?://(.*))$")
strs := reg.FindAllStringSubmatch(i, -1)
if !reg.MatchString(i) {
Groups = append(Groups,
Group{GroupName: i,
GroupURL: ""})
}
if len(strs) > 0 {
Groups = append(Groups,
Group{GroupName: strs[0][1],
GroupURL: strs[0][2]})
}
}
}
}
示例5: serveOriginList
func (server *Server) serveOriginList(writer http.ResponseWriter, request *http.Request) {
var offset, limit int
if response, status := server.parseListRequest(writer, request, &offset, &limit); status != http.StatusOK {
server.serveResponse(writer, response, status)
return
}
originSet := set.New(set.ThreadSafe)
for _, origin := range server.Catalog.GetOrigins() {
if request.FormValue("filter") == "" || utils.FilterMatch(request.FormValue("filter"), origin.Name) {
originSet.Add(origin.Name)
}
}
response := &listResponse{
list: StringListResponse(set.StringSlice(originSet)),
offset: offset,
limit: limit,
}
server.applyResponseLimit(writer, request, response)
server.serveResponse(writer, response.list, http.StatusOK)
}
示例6: serveSource
func (server *Server) serveSource(writer http.ResponseWriter, request *http.Request) {
name := routeTrimPrefix(request.URL.Path, urlCatalogPath+"sources")
if name == "" {
server.serveSourceList(writer, request)
return
} else if response, status := server.parseShowRequest(writer, request); status != http.StatusOK {
server.serveResponse(writer, response, status)
return
}
originSet := set.New(set.ThreadSafe)
for _, origin := range server.Catalog.GetOrigins() {
if origin.SourceExists(name) {
originSet.Add(origin.Name)
}
}
if originSet.Size() == 0 {
server.serveResponse(writer, serverResponse{mesgResourceNotFound}, http.StatusNotFound)
return
}
origins := set.StringSlice(originSet)
sort.Strings(origins)
response := SourceResponse{
Name: name,
Origins: origins,
}
server.serveResponse(writer, response, http.StatusOK)
}
示例7: init
func init() {
rc = redis.NewClient(&redis.Options{
Addr: "localhost:6379",
})
// Init categories
categories = []string{
"Linux", "Programming", "Software",
"影音", "科幻", "ACG", "IT", "社區",
"閑聊", "資源", "同城", "Others",
}
categoriesSet = set.New(set.NonThreadSafe)
for _, v := range categories {
categoriesSet.Add(v)
}
LoadConf()
botapi, _ := conf.Get("botapi")
vimTipsCache, _ := conf.GetInt("vimTipsCache")
hitokotoCache, _ := conf.GetInt("hitokotoCache")
vimtips = new(Tips).GetChan(int(vimTipsCache))
hitokoto = new(Hitokoto).GetChan(int(hitokotoCache))
sticker = RandSticker(rc)
var err error
bot, err = tgbotapi.NewBotAPI(botapi)
if err != nil {
log.Panic(err)
}
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
bot.UpdatesChan(u)
}
示例8: serveMetric
func (server *Server) serveMetric(writer http.ResponseWriter, request *http.Request) {
metricName := routeTrimPrefix(request.URL.Path, urlCatalogPath+"metrics")
if metricName == "" {
server.serveMetricList(writer, request)
return
} else if response, status := server.parseShowRequest(writer, request); status != http.StatusOK {
server.serveResponse(writer, response, status)
return
}
originSet := set.New(set.ThreadSafe)
sourceSet := set.New(set.ThreadSafe)
for _, origin := range server.Catalog.GetOrigins() {
for _, source := range origin.GetSources() {
if source.MetricExists(metricName) {
originSet.Add(origin.Name)
sourceSet.Add(source.Name)
}
}
}
if originSet.Size() == 0 {
server.serveResponse(writer, serverResponse{mesgResourceNotFound}, http.StatusNotFound)
return
}
origins := set.StringSlice(originSet)
sort.Strings(origins)
sources := set.StringSlice(sourceSet)
sort.Strings(sources)
response := MetricResponse{
Name: metricName,
Origins: origins,
Sources: sources,
}
server.serveResponse(writer, response, http.StatusOK)
}
示例9: handleAPIHosts
func (s *Server) handleAPIHosts(c *gin.Context) {
hs := set.New(set.ThreadSafe)
// Get hosts list
hosts, _ := s.poller.GetHosts()
for _, h := range hosts {
hs.Add(h.Name)
}
// Get unique set of hosts names
result := set.StringSlice(hs)
sort.Strings(result)
c.Header("Cache-Control", "private, max-age=0")
c.JSON(http.StatusOK, result)
}
示例10: GetQuestions
func GetQuestions() []Question {
var result []Question
questions := List2SliceInConf("questions")
for _, v := range questions {
qs := strings.Split(v, "|")
question := qs[0]
answers := strings.Split(qs[1], ";")
s := set.New(set.ThreadSafe)
for _, v := range answers {
s.Add(v)
}
result = append(result, Question{question, s})
}
return result
}
示例11: GetQuestions
func GetQuestions(config *yaml.File, text string) []Question {
var result []Question
questions := YamlList2Slice(config, text)
for _, v := range questions {
qs := strings.Split(v, "|")
question := qs[0]
answers := strings.Split(qs[1], ";")
s := set.New(set.ThreadSafe)
for _, v := range answers {
s.Add(v)
}
result = append(result, Question{question, s})
}
return result
}
示例12: GetNotes
func (g *GitHub) GetNotes(owner string, repo string, milestoneID string) (*Note, error) {
opt := github.IssueListByRepoOptions{Milestone: milestoneID, State: "all"}
note := &Note{}
issues, _, err := g.ListByRepo(owner, repo, &opt)
if err != nil {
return note, err
}
note.Mentioned = set.New(set.NonThreadSafe)
//var buf bytes.Buffer
for _, issue := range issues {
summary := fmt.Sprintf("- %v [%s #%d / %s](%s)\n", issue.Labels, repo, *issue.Number, *issue.Title, *issue.HTMLURL)
note.IssueSummary += summary
note.RepoVersion = fmt.Sprintf("- [%s:%s]()\n", repo, *issue.Milestone.Title)
// TODO: check Mentions
m := getMensionedPersons(issue.Body)
if m != "" {
ids := strings.Split(m, " ")
// fmt.Println("******** m : ", m)
// fmt.Println("******** ids : ", ids)
for i := range ids {
id := strings.TrimRight(ids[i], ",")
note.Mentioned.Add(id)
// fmt.Println("******** id : ", id)
}
}
// TODO 하루 전 날로 나올까? (지금은 +1 해줬다)
//note.MilestoneDate = fmt.Sprintf("- %s:%s 10:00\n", repo, issue.Milestone.DueOn.Format("2006-01-02"))
note.MilestoneDate = fmt.Sprintf("- %s:%s 10:00\n", repo, issue.Milestone.DueOn.AddDate(0, 0, 1).Format("2006-01-02"))
//note.DeployDate = issue.Milestone.DueOn.Format("2006-01-02")
note.DeployDate = issue.Milestone.DueOn.AddDate(0, 0, 1).Format("2006-01-02")
//fmt.Println("DeployDate ", note.DeployDate)
}
//fmt.Println("after mention:", buf.String())
return note, nil
}
示例13: main
// TODO: classify by Labels
func main() {
gitHubURL := baseGitHubURL
url := os.Getenv("GITHUB_URL")
if url != "" {
gitHubURL = url
}
clientID := os.Getenv("CLIENT_ID")
clientSecret := os.Getenv("CLIENT_SECRET")
owner := os.Getenv("OWNER")
milestoneID := os.Getenv("MILESTONE_ID")
repos := os.Getenv("REPOS")
// check arguments..
if gitHubURL == "" || owner == "" || milestoneID == "" || repos == "" {
fmt.Println(getUsage())
os.Exit(0)
}
var note Note
hub := GitHub{
apiURL: gitHubURL,
user: clientID,
password: clientSecret,
}
// TODO: magic string
note.Title = "통합검색 배포 안내드립니다."
note.Mentioned = set.New(set.NonThreadSafe)
for _, repo := range strings.Split(repos, ":") {
n, err := hub.GetNotes(owner, repo, milestoneID)
if err != nil {
log.Fatalln("error: %v", err)
}
note.Merge(n)
}
note.MentionedPersons = fmt.Sprintf("- %v", strings.Trim(note.Mentioned.String(), "[]"))
t := template.Must(template.New("note").Parse(noteTemplate))
err := t.Execute(os.Stdout, note)
if err != nil {
log.Fatalln("template error:", err)
}
}
示例14: LoadConf
func LoadConf() {
var err error
conf, err = yaml.ReadFile("botconf.yaml")
if err != nil {
log.Panic(err)
}
Categories = List2SliceInConf("catagoris")
CategoriesSet = set.New(set.NonThreadSafe)
Groups = []string{}
for _, v := range Categories {
CategoriesSet.Add(v)
for _, i := range List2SliceInConf(v) {
if i != "\\n" {
Groups = append(Groups, i)
}
}
}
}
示例15: handleAPIGroups
func (s *Server) handleAPIGroups(c *gin.Context) {
gs := set.New(set.ThreadSafe)
// Get unique sets of groups names
hosts, _ := s.poller.GetHosts()
for _, h := range hosts {
for _, g := range h.Groups {
gs.Add(g)
}
for _, s := range h.Services {
for _, g := range s.Groups {
gs.Add(g)
}
}
}
result := set.StringSlice(gs)
natsort.Sort(result)
c.Header("Cache-Control", "private, max-age=0")
c.JSON(http.StatusOK, result)
}