In the main function gocron.go files, which have the following one, you can learn from this code and the slice type integrated use
cliApp.Flags = append (cliApp.Flags, [] cli.Flag {} ...)
First, define a type require the use of type struct {} in the name of the language go, you can also give this type definition member method
type Taoshihan struct { } func (t Taoshihan) Say() string { return "my name is taoshihan" }
Here I define Taoshihan type, as he increased the Say method
Examples of this type requires {name}, the following is an example of a target Taoshihan
mytao: = Taoshihan {}
A slice can be seen as an array of variable length, a slice may be defined to declare follows
type var name [] stored
var myslice [] Taoshihan
I is stored in this slice of this type Taoshihan
Add slices to append data required function, the following two data I added to the slices
myslice = append (myslice, mytao, Taoshihan {})
and the three points in the original code ..., broken sections represents , each element sections are added to it, in my case represented as such
myslice = the append (myslice, [] {} ... Taoshihan)
[] {} Taoshihan fact represents another slice is empty
Loop through loop sections required for range, each of which represents the t is added to the list each object
for _, t := range myslice { fmt.Println(t.Say()) }
The full story:
package main import ( "fmt" ) type Taoshihan struct { } func (t Taoshihan) Say() string { return "taoshihan" } func main() { var myslice []Taoshihan mytao := Taoshihan{} myslice = append(myslice, Taoshihan{}, mytao) //这里遍历输出两次 for _, t := range myslice { fmt.Println(t.Say()) } }