-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathfuncs.go
More file actions
80 lines (64 loc) · 1.31 KB
/
funcs.go
File metadata and controls
80 lines (64 loc) · 1.31 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2015 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package funcs
import (
"fmt"
"github.com/rudderlabs/gopy/_examples/cpkg"
)
type FunStruct struct {
FieldI int
FieldS string
}
func (fs *FunStruct) CallBack(i int, fun func(fs *FunStruct, i int, s string)) {
fun(fs, i, fs.FieldS)
}
type RecvFunc func(fs *FunStruct, i int, v interface{})
func (fs *FunStruct) CallBackIf(i int, fun RecvFunc) {
fun(fs, i, fs.FieldS)
}
func (fs *FunStruct) CallBackRval(i int, fun func(fs *FunStruct, i int, v interface{}) bool) {
rv := fun(fs, i, fs.FieldS)
fmt.Printf("got return value: %v\n", rv)
}
func (fs *FunStruct) OtherMeth(i int, s string) {
fs.FieldI = i
fs.FieldS = s
fmt.Printf("i=%d s=%s\n", i, s)
}
func (fs *FunStruct) ObjArg(ofs *FunStruct) {
if ofs == nil {
fmt.Printf("got nil\n")
} else {
fmt.Printf("ofs FieldI: %d FieldS: %s\n", ofs.FieldI, ofs.FieldS)
}
}
var (
F1 func()
F2 Func
F3 S1
F4 S2
F5 []func()
F6 []Func
F7 [2]func()
F8 [3]Func
)
type Func func()
type S1 struct {
F1 Func
F2 []Func
F3 [4]Func
}
type S2 struct {
F1 func()
F2 []func()
F3 [5]func()
}
func init() {
F1 = func() {
cpkg.Printf("calling F1\n")
}
F2 = Func(func() {
cpkg.Printf("calling F2\n")
})
}