Проблема с работой горутин

Меня эта проблема мучает уже достаточно много времени и я все вникнуть никак не могу из-за чего такое происходит, подскажите мне, пожалуйста.

Я запускаю функцию, в которой горутина собирает данные из источника и собирает их в список, который впоследствии летит в канал, ожидающий этот список. После всех этих процедур функция возвращает канал.

Само получение данных

package main

import (
    "github.com/PuerkitoBio/goquery"
    "net/http"
)

type (
    TextField struct {
        Selector string
    }
    GraphicField struct {
        Selector  string
        Attribute string
    }
    Item struct {
        InclusiveSelector string
        TextFields        []TextField
        GraphicFields     []GraphicField
    }
    Source struct {
        Address       string
        ContentObject Item
    }
)

func (s Source) DocumentProvidedSourceInformation() (*goquery.Document, error) {
    r, err := http.Get(s.Address)

    if err != nil {
        return nil, err
    }

    document, err := goquery.NewDocumentFromReader(r.Body)

    if err != nil {
        return nil, err
    }

    defer r.Body.Close()

    return document, nil
}

func (s Source) TheftLastItem(html *goquery.Document) <-chan []string {
    var exhaustChannel chan []string

    go func() {
        var exhaustData []string

        html.Find(s.ContentObject.InclusiveSelector).First().Each(
            func(index int, item *goquery.Selection) {
                for _, textField := range s.ContentObject.TextFields {
                    exhaustData = append(exhaustData, item.Find(textField.Selector).Text())
                }
                for _, graphicField := range s.ContentObject.GraphicFields {
                    graphicItem, presence := item.Find(graphicField.Selector).Attr(graphicField.Attribute)

                    if presence {
                        exhaustData = append(exhaustData, graphicItem)
                    }
                }
                exhaustChannel <- exhaustData
            },
        )
    }()
    return exhaustChannel
}

Запуск кода

package main

import "fmt"


func main() {
   textFields := []TextField{
       {
           Selector: ".caption",
       },
       {
           Selector: ".game-specs",
       },
       {
           Selector: ".score",
       },
   }

   graphicFields := []GraphicField{
       {
           Selector: ".image",
           Attribute: "style",
       },
   }

   game := Item{
       InclusiveSelector: ".simple-list .item",
       TextFields: textFields,
       GraphicFields: graphicFields,
   }

   stopGame := Source{
       Address: "https://stopgame.ru/games",
       ContentObject: game,
   }

   document, err := stopGame.DocumentProvidedSourceInformation()

   if err != nil {
       fmt.Println(err)
   }

   for {
       data := stopGame.TheftLastItem(document)
       fmt.Println(<-data) // на этом моменте останавливается осуществление кода
   }
}

Методом проб(fmt.Println) я выяснил, что сама функция работает корректно, а вот когда я получаю данные во время запуска и выкидываю их, чтобы вывести у меня прекращается работа. Я сразу запустил бесконечный цикл потому что эта реализация меня в будущем и интересует. Но если одноразово попробовать запустить результат тот же.


Ответы (1 шт):

Автор решения: Ainar-G
var exhaustChannel chan []string

А инициализировать канал кто будет?

var exhaustChannel = make(chan []string)
→ Ссылка