Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "strings"
- )
- type Message struct {
- UserID int
- Text string
- DateTimeStamp string
- responseGoFunction string
- }
- func find_words(messages []Message, search_word1, search_word2 string) []Message {
- var result []Message
- for _, message := range messages {
- if strings.Contains(message.Text, search_word1) || strings.Contains(message.Text, search_word2) {
- result = append(result, message)
- }
- }
- return result
- }
- func main() {
- // IMAGINE you loaded this array at startup or in a repl from a csv file or what ever
- // Format: UserID;Text;DateTimeStampResponseGopFunction, bla bla bla
- messages := []Message{
- {UserID: 1, Text: "Hello world", responseGoFunction: "funA"},
- {UserID: 2, Text: "This is a test", responseGoFunction: "funA"},
- {UserID: 3, Text: "Golang is awesome", responseGoFunction: "funB"},
- {UserID: 4, Text: "Hello, how are you?", responseGoFunction: "funC"},
- }
- search_word1 := "Hello"
- search_word2 := "awesome"
- result := find_words(messages, search_word1, search_word2)
- for _, message := range result {
- // HERE YOU WOULD "ACT" on the responseGoFunction
- fmt.Printf("UserID: %d, Text: %s ResponseGoFunction: %s\n", message.UserID, message.Text, message.responseGoFunction)
- if message.responseGoFunction == "funB" {
- responseText := "Answer: Go away troll!"
- fmt.Printf(responseText)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement