本文整理汇总了Golang中gopkg/in/gilmour-libs/gilmour-e-go/v5.Gilmour.Signal方法的典型用法代码示例。如果您正苦于以下问题:Golang Gilmour.Signal方法的具体用法?Golang Gilmour.Signal怎么用?Golang Gilmour.Signal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gopkg/in/gilmour-libs/gilmour-e-go/v5.Gilmour
的用法示例。
在下文中一共展示了Gilmour.Signal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: stopWordsReply
func stopWordsReply(g *G.Gilmour, stopList *[]string) func(req *G.Request, resp *G.Message) {
return func(req *G.Request, resp *G.Message) {
line := fmt.Sprintf("Filtering out stop words")
g.Signal("example.log", G.NewMessage().SetData(line))
words := []string{}
if err := req.Data(&words); err != nil {
panic(words)
}
stopMap := map[string]bool{}
for _, w := range *stopList {
stopMap[w] = true
}
filtered := []string{}
for _, w := range words {
if _, ok := stopMap[w]; !ok {
filtered = append(filtered, w)
}
}
resp.SetData(filtered)
}
}
示例2: saveReply
func saveReply(g *G.Gilmour) func(req *G.Request, resp *G.Message) {
return func(req *G.Request, resp *G.Message) {
line := fmt.Sprintf("Save")
g.Signal("example.log", G.NewMessage().SetData(line))
resp.SetData("Hello from Save")
}
}
示例3: findReply
func findReply(g *G.Gilmour) func(req *G.Request, resp *G.Message) {
return func(req *G.Request, resp *G.Message) {
line := fmt.Sprintf("Find")
g.Signal("example.log", G.NewMessage().SetData(line))
input := getInput(req)
resp.SetData(input)
}
}
示例4: wordsReply
func wordsReply(g *G.Gilmour) func(req *G.Request, resp *G.Message) {
return func(req *G.Request, resp *G.Message) {
line := fmt.Sprintf("WordCount")
g.Signal("example.log", G.NewMessage().SetData(line))
input := getInput(req)
wordRe := regexp.MustCompile("\\w+")
words := wordRe.FindAllString(input, -1)
resp.SetData(words)
}
}
示例5: countReply
func countReply(g *G.Gilmour) func(req *G.Request, resp *G.Message) {
return func(req *G.Request, resp *G.Message) {
line := fmt.Sprintf("WordCount")
g.Signal("example.log", G.NewMessage().SetData(line))
input := []string{}
if err := req.Data(&input); err != nil {
panic(err)
}
word_counts := make(map[string]int)
for _, word := range input {
word_counts[word]++
}
resp.SetData(word_counts)
}
}
示例6: popularReply
func popularReply(g *G.Gilmour, wordLen int) func(req *G.Request, resp *G.Message) {
return func(req *G.Request, resp *G.Message) {
line := fmt.Sprintf("Popular %v", wordLen)
g.Signal("example.log", G.NewMessage().SetData(line))
input := map[string]int{}
if err := req.Data(&input); err != nil {
panic(err)
}
popular := map[int][]string{}
score := []int{}
for k, v := range input {
if len(k) != wordLen {
continue
}
popular[v] = append(popular[v], k)
}
for k := range popular {
score = append(score, k)
}
sort.Sort(sort.Reverse(sort.IntSlice(score)))
output := struct {
WordLength int
Score int
Words []string
}{WordLength: wordLen}
if len(score) > 0 {
output.Score = score[0]
output.Words = popular[score[0]]
}
resp.SetData(output)
}
}
示例7: fetchReply
//Fetch a remote file from the URL received in Request.
func fetchReply(g *G.Gilmour) func(req *G.Request, resp *G.Message) {
return func(req *G.Request, resp *G.Message) {
url := getInput(req)
line := fmt.Sprintf("Fetch %v", url)
g.Signal("example.log", G.NewMessage().SetData(line))
response, err := http.Get(url)
if err != nil {
panic(err)
}
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
panic(err)
}
//Send back the contents.
resp.SetData(string(contents))
}
}
示例8: glog
func glog(g *G.Gilmour, msg string) {
g.Signal("example.log", G.NewMessage().SetData(msg))
}