-
Notifications
You must be signed in to change notification settings - Fork 23
/
example_test.go
66 lines (50 loc) · 1.16 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package crontab_test
import (
"fmt"
"log"
"github.com/mileusna/crontab"
)
func ExampleCrontab() {
ctab := crontab.New() // create cron table
// MustAddJob panics on wrong syntax or problem with func and args for easier initialization
ctab.MustAddJob("0 12 * * *", myFunc3)
ctab.MustAddJob("* * * * *", myFunc2, "on every minute", 123) // fn with args
ctab.MustAddJob("*/2 * * * *", myFunc2, "every two min", 18)
// or use AddJob if you want to test the error
err := ctab.AddJob("* * * * *", myFunc)
if err != nil {
log.Println(err)
return
}
// all your other app code as usual, or put sleep timer for example
// time.Sleep(5 * time.Minute)
}
func myFunc() {
fmt.Println("Helo, world")
}
func myFunc3() {
fmt.Println("Noon!")
}
func myFunc2(s string, n int) {
fmt.Printf("We have params here, string `%s` and nymber %d\n", s, n)
}
type MyTypeInterface struct {
ID int
Name string
}
func (m MyTypeInterface) Bar() string {
return "OK"
}
type MyTypeNoInterface struct {
ID int
Name string
}
func myFuncStruct(m MyTypeInterface) {
fmt.Println("Custom type as param")
}
func myFuncInterface(i Foo) {
i.Bar()
}
type Foo interface {
Bar() string
}