-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
375 lines (318 loc) · 7.69 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
package main
import (
"context"
"encoding/json"
"fmt"
"net"
"time"
"log"
"os"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/chain/types"
"github.com/multiformats/go-multiaddr"
"github.com/woshidama323/LearningGolang/customMarshal"
"github.com/woshidama323/LearningGolang/filecoin"
"github.com/woshidama323/LearningGolang/htmltoimage"
"github.com/woshidama323/LearningGolang/learns3"
"github.com/woshidama323/LearningGolang/markdown"
// "github.com/woshidama323/LearningGolang/output"
"github.com/woshidama323/LearningGolang/ascii"
"github.com/woshidama323/LearningGolang/packagetest"
"github.com/woshidama323/LearningGolang/patterns/options"
"github.com/woshidama323/LearningGolang/reflectpractice"
"github.com/woshidama323/LearningGolang/rpcserver"
"github.com/woshidama323/LearningGolang/table"
"github.com/woshidama323/LearningGolang/timepractice"
cli "github.com/urfave/cli/v2"
"github.com/woshidama323/LearningGolang/grpcserver"
"github.com/woshidama323/LearningGolang/kafka"
"github.com/woshidama323/LearningGolang/systemmonitor"
"google.golang.org/grpc"
)
func main() {
app := &cli.App{
Name: "practicegolang",
Usage: "practice golang",
EnableBashCompletion: true,
Commands: []*cli.Command{
filecoinCmd,
optionsCmd,
RawMethodCmd,
RPCServerTestCmd,
MarkDownPocCmd,
Table2ImageCmd,
reflectCmd,
s3Cmd,
excelCmd,
timeCmd,
jsonCmd,
asciiCmd,
// loginCmd,
kafkaCmd,
grpcServerCmd,
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
var optionsCmd = &cli.Command{
Name: "optionspattern",
Usage: "optionspattern test",
Action: func(c *cli.Context) error {
helloperson := options.NewPerson("harry", options.Country("ChinaHello"))
fmt.Println("helloperson is:", helloperson)
return nil
},
}
var filecoinCmd = &cli.Command{
Name: "filecoin",
Usage: "filecoin test",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "urlstr",
Usage: "url for update the code",
},
&cli.StringFlag{
Name: "minerid",
Usage: "target miner for get addresses",
},
},
Action: func(c *cli.Context) error {
geturl := "ws://127.0.0.1:1234/rpc/v0" //
if c.IsSet("urlstr") {
geturl = c.String("urlstr")
}
minerID := "f0143858" //
if c.IsSet("minerid") {
minerID = c.String("minerid")
}
api, err := filecoin.NewMiner(geturl)
if err != nil {
fmt.Println("failed to new miner,err:", err)
return err
}
defer api.ChainProvider.Closer()
minerAddress, err := address.NewFromString(minerID)
if err != nil {
fmt.Println("failed to get miner addressL:", err)
return err
}
api.ChainProvider.Api.StateMinerInfo(context.Background(), minerAddress, types.EmptyTSK)
return nil
},
}
var RawMethodCmd = &cli.Command{
Name: "filecoinraw",
Usage: "filecoinraw test",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "urlstr",
Usage: "url for update the code",
},
&cli.StringFlag{
Name: "minerid",
Usage: "target miner for get addresses",
},
},
Action: func(c *cli.Context) error {
geturl := "http://192.168.1.102:1234:1234/rpc/v0" //
if c.IsSet("urlstr") {
geturl = c.String("urlstr")
}
minerID := "f0143858" //
if c.IsSet("minerid") {
minerID = c.String("minerid")
}
addrlist, err := filecoin.GetMinerInfo(geturl, minerID)
if err != nil {
fmt.Println("failed to get miner info,err:", err)
return err
}
for _, addr := range addrlist {
getaddr, err := filecoin.GetAddressInfo(geturl, addr)
if err != nil {
fmt.Println("failed to get the address info,err:", err)
continue
}
fmt.Println("get current addresslist :", getaddr)
}
return nil
},
}
var RPCServerTestCmd = &cli.Command{
Name: "runrpc",
Usage: "hello rpc server",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "xxx",
Usage: "xxx",
},
},
Action: func(c *cli.Context) error {
fn := &rpcserver.ImplementFullNode{
Test: "helo",
}
wfn, err := rpcserver.FlutterHandler(fn)
if err != nil {
return err
}
am, err := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/11111")
if err != nil {
return err
}
_, err = rpcserver.ServerRPC(wfn, "rpcserver", am)
if err != nil {
fmt.Println("failed to start rpc server:", err)
return err
}
// rpcStopper()
select {}
// return nil
},
}
var MarkDownPocCmd = &cli.Command{
Name: "markdown",
Usage: "command test for generating markdown file",
Action: func(c *cli.Context) error {
// mk := markdown.NewMarkDownTemplate()
mk, _ := markdown.NewMarkDownTemplate()
mk.MinerList = []string{
"f02301",
"f03223",
"f0143858",
"f0240185",
}
mk.BillInfo = markdown.TestBillInfo
mk.CostInfo = markdown.Costinfo
mk.MinerFeeInfo()
return nil
},
}
var Table2ImageCmd = &cli.Command{
Name: "table2image",
Usage: "generate table in image",
Action: func(c *cli.Context) error {
// ti := table2image.NewTableToImage()
// ti.CreateTableImage()
//0914
buf := table.Tabletest()
htmltoimage.TestHtmlToImage(buf.Bytes(), "harry.png")
// content := "![test](https://raw.githubusercontent.com/woshidama323/LearningGolang/de8f78453a9b1d2cd4f139b292093664b3b0bf1d/testme.png)"
// dingtalk.SendToDingTalkMarkDownMsg(content)
//尝试直接用html模板的方式进行
// bufOut := htmltoimage.TestTemplateForTable()
// htmltoimage.TestHtmlToImage(bufOut.Bytes(), "templatemethod.png")
return nil
},
}
var reflectCmd = &cli.Command{
Name: "reflecttest",
Usage: "know how reflect work",
Action: func(c *cli.Context) error {
reflectpractice.TestGetField()
return nil
},
}
var s3Cmd = &cli.Command{
Name: "s3list",
Usage: "know how reflect work",
Action: func(c *cli.Context) error {
learns3.TestS3ListBucket()
return nil
},
}
var excelCmd = &cli.Command{
Name: "exceltest",
Usage: "take exceltest code practice",
Action: func(c *cli.Context) error {
// output.TestWriteExcel()
// output.TestReadExcel()
// teststr := "F02301"
// strings.ToLower(teststr)
packagetest.TestPackagetest()
return nil
},
}
var timeCmd = &cli.Command{
Name: "timecmd",
Usage: "command for test time",
Action: func(c *cli.Context) error {
timepractice.TestTime()
return nil
},
}
var jsonCmd = &cli.Command{
Name: "jsoncustom",
Usage: "json custom",
Action: func(c *cli.Context) error {
why := customMarshal.TestJson{
Testitme: customMarshal.UnixTimestamp(time.Now()),
}
testbytes, err := json.Marshal(why)
if err != nil {
fmt.Printf("marshal failed err:%v", err)
return err
}
var j customMarshal.TestJson
err = json.Unmarshal(testbytes, &j)
if err != nil {
fmt.Printf("Unmarshal failed err:%v", err)
return err
}
return nil
},
}
var asciiCmd = &cli.Command{
Name: "asciitest",
Usage: "asciitest",
Action: func(c *cli.Context) error {
ascii.TestAscii()
return nil
},
}
// var loginCmd = &cli.Command{
// Name: "login",
// Usage: "login",
// Action: func(c *cli.Context) error {
// systemmonitor.TestSsh()
// return nil
// },
// }
var kafkaCmd = &cli.Command{
Name: "kafka",
Usage: "kafka cmd",
Action: func(c *cli.Context) error {
kafka.TestKafka()
return nil
},
}
var grpcServerCmd = &cli.Command{
Name: "grpc",
Usage: "grpc cmd",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "clienttest",
Usage: "client test",
Value: false,
},
},
Action: func(c *cli.Context) error {
if c.IsSet("clienttest") {
systemmonitor.TestServer()
return nil
}
fmt.Println("Welcome to streaming HW monitoring")
// Setup a tcp connection to port 7777
lis, err := net.Listen("tcp", ":7777")
if err != nil {
panic(err)
}
gRPCserver := grpc.NewServer()
s := &systemmonitor.Server{}
grpcserver.RegisterHardwareMonitorServer(gRPCserver, s)
gRPCserver.Serve(lis)
return nil
},
}