C
C
chumric2018-08-29 10:11:55
go
chumric, 2018-08-29 10:11:55

How to parse many files with TailFile?

To track log files I use TailFile (github.com/hpcloud/tail)
For one file it looks like this

t, err := tail.TailFile(v, tail.Config{Follow: true, ReOpen: true, MustExist: true})

I need to keep track of several logs that I get a list of from
YML I'm new to Go and I'm trying PHP
var t = map[int]string
for k, value := range config.Settings.Logs {
   t[k], err := tail.TailFile(value, tail.Config{Follow: true, ReOpen: true, MustExist: true})
}

On what, it is reasonable to receive an error
./main.go:37:6: type map[int]string is not an expression
./main.go:40:4: non-name t[k] on left side of :=

Which array to declare and how to put results from TailFile into it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2018-08-29
@chumric

var t = map[int]string
You are not trying to declare an array, but a hashmap. Correct like this: But you would also like the option with a slice:

var t []string
for k, value := range config.Settings.Logs {
   elem, err := tail.TailFile(value, tail.Config{Follow: true, ReOpen: true, MustExist: true})
   ...... тут надо ошибку проверить .....
   t = append(t, elem)
}

However, I'm not sure that you really have a string type returned from TailFile, but this is beyond the scope of this question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question