/
sa_node_const_go.goo
executable file
·538 lines (476 loc) · 15 KB
/
sa_node_const_go.goo
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
type Text struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Label string `json:"label"`
Size float64 `json:"size"`
Align_h int `json:"align_h"`
Align_v int `json:"align_v"`
Multi_line bool `json:"multi_line"`
Line_wrapping bool `json:"line_wrapping"`
Formating bool `json:"formating"`
Selection bool `json:"selection"`
Show_border bool `json:"show_border"`
}
type Editbox struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value string `json:"value"`
Ghost string `json:"ghost"`
Align_h int `json:"align_h"`
Align_v int `json:"align_v"`
Enable bool `json:"enable"`
Multi_line bool `json:"multi_line"`
Multi_line_enter_finish bool `json:"multi_line_enter_finish"`
Line_wrapping bool `json:"line_wrapping"`
Formating bool `json:"formating"`
Temp_to_value bool `json:"temp_to_value"`
Db_value bool `json:"db_value"`
}
type EditboxDB struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value string `json:"value"`
Ghost string `json:"ghost"`
Align_h int `json:"align_h"`
Align_v int `json:"align_v"`
Enable bool `json:"enable"`
Multi_line bool `json:"multi_line"`
Multi_line_enter_finish bool `json:"multi_line_enter_finish"`
Line_wrapping bool `json:"line_wrapping"`
Temp_to_value bool `json:"temp_to_value"`
Db_value bool `json:"db_value"`
}
func (db *EditboxDB) SetValue(db_path, table, column string, rowid int) {
db.Value = fmt.Sprintf("%s:%s:%s:%d", db_path, table, column, rowid)
}
type Button struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Background int `json:"background"`
Align int `json:"align"`
Label string `json:"label"`
Icon string `json:"icon"`
Icon_margin float64 `json:"icon_margin"`
Tooltip string `json:"tooltip"`
Enable bool `json:"enable"`
Triggered bool `json:"triggered"`
Confirmation string `json:"confirmation"`
Close_dialog bool `json:"close_dialog"`
}
type Checkbox struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value bool `json:"value"`
Label string `json:"label"`
Tooltip string `json:"tooltip"`
Enable bool `json:"enable"`
}
type CheckboxDB struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value string `json:"value"`
Label string `json:"label"`
Tooltip string `json:"tooltip"`
Enable bool `json:"enable"`
Db_value bool `json:"db_value"`
}
func (db *CheckboxDB) SetValue(db_path, table, column string, rowid int) {
db.Value = fmt.Sprintf("%s:%s:%s:%d", db_path, table, column, rowid)
}
type Switch struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value bool `json:"value"`
Label string `json:"label"`
Tooltip string `json:"tooltip"`
Enable bool `json:"enable"`
}
type SwitchDB struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value string `json:"value"`
Label string `json:"label"`
Tooltip string `json:"tooltip"`
Enable bool `json:"enable"`
Db_value bool `json:"db_value"`
}
func (db *SwitchDB) SetValue(db_path, table, column string, rowid int) {
db.Value = fmt.Sprintf("%s:%s:%s:%d", db_path, table, column, rowid)
}
type Slider struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value float64 `json:"value"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Step float64 `json:"step"`
Tooltip string `json:"tooltip"`
Enable bool `json:"enable"`
}
type SliderDB struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value string `json:"value"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Step float64 `json:"step"`
Tooltip string `json:"tooltip"`
Enable bool `json:"enable"`
Db_value bool `json:"db_value"`
}
func (db *SliderDB) SetValue(db_path, table, column string, rowid int) {
db.Value = fmt.Sprintf("%s:%s:%s:%d", db_path, table, column, rowid)
}
type Combo struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value string `json:"value"`
Options_names string `json:"options_names"` //separated by ';'
Options_values string `json:"options_values"` //separated by ';'
Tooltip string `json:"tooltip"`
Enable bool `json:"enable"`
}
type ComboDB struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value string `json:"value"`
Options_names string `json:"options_names"` //separated by ';'
Options_values string `json:"options_values"` //separated by ';'
Tooltip string `json:"tooltip"`
Enable bool `json:"enable"`
Db_value bool `json:"db_value"`
}
func (db *ComboDB) SetValue(db_path, table, column string, rowid int) {
db.Value = fmt.Sprintf("%s:%s:%s:%d", db_path, table, column, rowid)
}
type Date struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value int `json:"value"` //Unix time
Tooltip string `json:"tooltip"`
Enable bool `json:"enable"`
}
type DateDB struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value string `json:"value"`
Tooltip string `json:"tooltip"`
Enable bool `json:"enable"`
Db_value bool `json:"db_value"`
}
func (db *DateDB) SetValue(db_path, table, column string, rowid int) {
db.Value = fmt.Sprintf("%s:%s:%s:%d", db_path, table, column, rowid)
}
type Color struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Value_r int `json:"value_r"`
Value_g int `json:"value_g"`
Value_b int `json:"value_b"`
Value_a int `json:"value_a"`
Enable bool `json:"enable"`
}
type Disk_dir struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Path string `json:"path"`
Write bool `json:"write"`
Enable bool `json:"enable"`
}
type Disk_file struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Path string `json:"path"`
Write bool `json:"write"`
Enable bool `json:"enable"`
}
type Db_file struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Path string `json:"path"`
Write bool `json:"write"`
Enable bool `json:"enable"`
Init_sql string `json:"init_sql"`
Show_path bool `json:"show_path"`
Show_table_list bool `json:"show_table_list"`
Selected_table string `json:"selected_table"`
}
type Microphone struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Enable bool `json:"enable"`
Path string `json:"path"`
Triggered bool `json:"triggered"`
}
type MapLocator struct {
Lon float64 `json:"lon"`
Lat float64 `json:"lat"`
Label string `json:"label"`
}
type MapSegmentTrk struct {
Lon float64 `json:"lon"`
Lat float64 `json:"lat"`
Ele float64 `json:"ele"`
Time string `json:"time"`
}
type MapSegment struct {
Trkpts []MapSegmentTrk `json:"trkpts"`
Label string `json:"label"`
}
type Map struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Enable bool `json:"enable"`
Lon float64 `json:"lon"`
Lat float64 `json:"lat"`
Zoom float64 `json:"zoom"`
File string `json:"file"`
Url string `json:"url"`
copyright string `json:"copyright"`
copyright_url string `json:"copyright_url"`
Locators string `json:"locators"`
Segments string `json:"segments"`
Locators_cd_r int `json:"locators_cd_r"`
Locators_cd_g int `json:"locators_cd_g"`
Locators_cd_b int `json:"locators_cd_b"`
Locators_cd_a int `json:"locators_cd_a"`
Segments_cd_r int `json:"segments_cd_r"`
Segments_cd_g int `json:"segments_cd_g"`
Segments_cd_b int `json:"segments_cd_b"`
Segments_cd_a int `json:"segments_cd_a"`
}
type ChartItem struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Label string `json:"label"`
}
type Chart struct {
Grid_x int `json:"grid_x"`
Grid_y int `json:"grid_y"`
Grid_w int `json:"grid_w"`
Grid_h int `json:"grid_h"`
Show bool `json:"show"`
Enable bool `json:"enable"`
Values string `json:"values"`
//Values []*ChartItem `json:"values"`
Typee string `json:"typee"`
Cd_r int `json:"cd_r"`
Cd_g int `json:"cd_g"`
Cd_b int `json:"cd_b"`
Cd_a int `json:"cd_a"`
Left_margin float64 `json:"left_margin"`
Bottom_margin float64 `json:"bottom_margin"`
Point_rad float64 `json:"point_rad"`
Line_thick float64 `json:"line_thick"`
X_unit string `json:"x_unit"`
Y_unit string `json:"y_unit"`
Bound_x0 bool `json:"bound_x0"`
Bound_y0 bool `json:"bound_y0"`
Column_margin float64 `json:"column_margin"`
}
/*func (c *Chart)ClearItems() {
c.Values = nil
}
func (c *Chart)AddItem(x, y float64, label string) {
c.Values = append(c.Values, &ChartItem{X:x, Y:y, Label: label})
}*/
type Net struct {
Node string `json:"node"`
File_path string `json:"file_path"`
Url string `json:"url"`
}
func (net *Net) DownloadFile(filePath string, url string) error {
net.File_path = filePath
net.Url = url
js, err := json.Marshal(net)
if err != nil {
return fmt.Errorf("Marshal() failed: %w", err)
}
_, err = _send("net", js)
return err
}
type Whispercpp struct {
Node string `json:"node"`
File_path string `json:"file_path"`
Data []byte `json:"data"`
}
func (w *Whispercpp) TranscribeBlob(data []byte) (string, error) {
w.File_path = "blob"
w.Data = data
js, err := json.Marshal(w)
if err != nil {
return "", fmt.Errorf("Marshal() failed: %w", err)
}
resBody, err := _send("whispercpp", js)
return string(resBody), err
}
func (w *Whispercpp) TranscribeFile(filePath string) (string, error) {
w.File_path = filePath
//read file
var err error
w.Data, err = os.ReadFile(filePath)
if err != nil {
return "", err
}
js, err := json.Marshal(w)
if err != nil {
return "", fmt.Errorf("Marshal() failed: %w", err)
}
resBody, err := _send("whispercpp", js)
return string(resBody), err
}
type LlamaMessage struct {
Role string `json:"role"`
Content string `json:"content"`
}
type Llamacpp struct {
Node string `json:"node"`
Messages []LlamaMessage `json:"messages"`
}
func (ll *Llamacpp) GetAnswer(messages []LlamaMessage) (string, error) {
ll.Messages = messages
js, err := json.Marshal(ll)
if err != nil {
return "", fmt.Errorf("Marshal() failed: %w", err)
}
resBody, err := _send("llamacpp", js)
return string(resBody), err
}
type OpenaiMessage struct {
Role string `json:"role"`
Content string `json:"content"`
}
type Openai struct {
Node string `json:"node"`
Messages []OpenaiMessage `json:"messages"`
}
func (gf *Openai) GetAnswer(messages []OpenaiMessage) (string, error) {
gf.Messages = messages
js, err := json.Marshal(gf)
if err != nil {
return "", fmt.Errorf("Marshal() failed: %w", err)
}
resBody, err := _send("openai", js)
return string(resBody), err
}
func _send(url string, js []byte) ([]byte, error) {
body := bytes.NewReader([]byte(js))
req, err := http.NewRequest(http.MethodPost, G_SERVER_ADDR+url, body)
if err != nil {
return nil, fmt.Errorf("NewRequest() failed: %w", err)
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer "+G_JOB)
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("Do() failed: %w", err)
}
defer res.Body.Close()
resBody, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("ReadAll() failed: %w", err)
}
if res.StatusCode != 200 {
return nil, fmt.Errorf("statusCode != 200, response: %s", resBody)
}
return resBody, nil
}
var G_SERVER_ADDR = "http://127.0.0.1:8080/"
var G_JOB = ""
func main() {
if len(os.Args) < 3 {
fmt.Println("Missing <port> <job_id>")
return
}
G_PORT, err := strconv.Atoi(os.Args[1])
if err != nil {
fmt.Println("Port:", err)
return
}
G_JOB = os.Args[2]
if G_JOB == "" {
fmt.Println("Missing G_JOB")
return
}
G_SERVER_ADDR = fmt.Sprintf("http://127.0.0.1:%d/", G_PORT)
job, err := _send("getjob", []byte("{}"))
if err != nil {
fmt.Println("_send() failed:", err)
return
}
jobBack, err := _callIt(job)
if err != nil {
_, err = _send("returnerror", []byte(err.Error()))
if err != nil {
fmt.Println("_send() failed:", err)
return
}
}else{
_, err = _send("returnresult", jobBack)
if err != nil {
fmt.Println("_send() failed:", err)
return
}
}
}