-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
809 lines (671 loc) · 19.5 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
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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
package main
import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
"os"
"os/signal"
"path/filepath"
"strconv"
"strings"
"syscall"
"time"
"github.com/gin-gonic/gin"
"github.com/gosnmp/gosnmp"
"github.com/kardianos/service"
"gopkg.in/natefinch/lumberjack.v2"
"gopkg.in/yaml.v2"
)
const (
programVersion = "v.1.0.3" // 공백이 트림되지 않게 처리
)
var (
logn = log.Println
logf = log.Printf
prn = fmt.Println
prf = fmt.Printf
serviceLogger service.Logger
listenPort string
logColorEnable = false
fileHashTargetPath string
fileHashTempPath string
fileHashInitailKeyword string
fileHashKeywords []string
fileHashTimeout int
logcontextpath string
ctxservicename string
)
type program struct{}
// Login is Binding from JSON
type Login struct {
User string `form:"user" json:"user" xml:"user" binding:"required"`
Password string `form:"password" json:"password" xml:"password" binding:"required"`
}
// FileHashConfig is ...
type FileHashConfig struct {
TargetPath string `yaml:"target-path"`
TempPath string `yaml:"temp-path"`
InitialKeyword string `yaml:"initial-keyword"`
Keywords []string `yaml:"keywords"`
ModuleName string `yaml:"module-name"`
FileHashTimeout int `yaml:"file-hash-timeout"`
}
// FileHashRequest is ...
type FileHashRequest struct {
FileSubPath string `json:"filesubpath" binding:"required"`
FileName string `json:"filename" binding:"required"`
FileHash string `json:"filehash" binding:"required"`
ApiKey string `json:"api-key" binding:"required"`
}
// FileHashResponse is ...
type FileHashResponse struct {
Result string `json:"result"`
ResultMessage string `json:"message"`
}
// SockRequest is ....
type SockRequest struct {
Host string `json:"host" binding:"required"`
Port int `json:"port" binding:"required"`
SendStr string `json:"sendstr" binding:"required"`
Type string `json:"type" binding:"required"`
ServiceName string `json:"servicename" binding:"required"`
}
type SockResponse struct {
Data string `json:"data"`
Size int `json:"size"`
Host string `json:"host"`
Port int `json:"port"`
Type string `json:"type"`
ServiceName string `json:"servicename"`
}
// APIRequest is Request ...
type APIRequest struct {
DeviceID string `json:"deviceid" binding:"required"`
DeviceIP string `json:"ip" binding:"required"`
OidGroupName string `json:"oid-group-name" binding:"required"`
UserName string `json:"user" binding:"required"`
AuthPass string `json:"authpass" binding:"required"`
PrivPass string `json:"privpass" binding:"required"`
Timeout int `json:"timeout" binding:"required"`
Oid string `json:"oid" binding:"required"`
IsYesterday bool `json:"is-yesterday"`
}
// Output is ...
type Output struct {
Success bool `json:"success"`
DeviceID string `json:"deviceid"`
DeviceIP string `json:"deviceip"`
OidGroupName string `json:"oid-group-name"`
IsYesterday bool `json:"is-yesterday"`
ElabsedTime string `json:"elapsedtime"`
Res []Responses `json:"response"`
}
// Responses is ...
type Responses struct {
Oid string `json:"oid"`
Value string `json:"value"`
}
func (r *Output) setResponses(res []Responses) {
r.Res = res
}
func (r *Output) getOutputJSON() string {
resJSON, _ := json.Marshal(r)
return string(resJSON)
}
func (sr *SockResponse) getSockResponse() []byte {
resJSON, _ := json.Marshal(sr)
return []byte(string(resJSON))
}
func (fhr *FileHashResponse) getFileHashResponse() []byte {
resJSON, _ := json.Marshal(fhr)
return []byte(string(resJSON))
}
// TCP SOCKET / SNMPv3 API 서버
// TODO: GIN SWAGGER 추가 : https://dejavuqa.tistory.com/330
func main() {
// from cmd flag
currpath := flag.String("currpath", "H:/shcsw", "program path define (WARNNING:Enter the absolute path when starting as a service.)")
port := flag.String("port", "8080", "http listen port")
logcolor := flag.Bool("color", false, "")
flag.Parse()
if !isFlagInputed("port") {
prn("")
prn("VERSION:", programVersion)
prn("PURPOSE: Light-Weight, Low-Latency API Server (TCP Client, SNMPv3, File hash check)")
prn("PUBLISHER: [email protected]")
prn("")
flag.Usage()
return
}
if !isFlagInputed("currpath") {
prn("")
prn("VERSION:", programVersion)
prn("PURPOSE: Light-Weight, Low-Latency API Server (TCP Client, SNMPv3, File hash check)")
prn("PUBLISHER: [email protected]")
prn("")
flag.Usage()
return
}
listenPort = *port
logColorEnable = *logcolor
prn("cmd args -> currpath:", *currpath, "port:", listenPort, "logColorEnable:", logColorEnable)
// Get Config From yaml
confFilename, _ := filepath.Abs("config.yml")
yamlFile, err := ioutil.ReadFile(confFilename)
var fileConfig FileHashConfig
err = yaml.Unmarshal(yamlFile, &fileConfig)
if err != nil {
panic(err)
}
prn("TargetPath:", fileConfig.TargetPath, "TempPath:", fileConfig.TempPath, ">>", len(fileConfig.Keywords))
fileHashTargetPath = fileConfig.TargetPath
fileHashTempPath = fileConfig.TempPath
fileHashInitailKeyword = fileConfig.InitialKeyword
fileHashKeywords = fileConfig.Keywords
fileHashTimeout = fileConfig.FileHashTimeout
logcontextpath = fileConfig.ModuleName
ctxservicename = fileConfig.ModuleName
prn("fileHashKeywords -------------------------------------")
for idx, keyword := range fileHashKeywords {
fmt.Println(idx, keyword)
}
// For Logging
createDirIfNotExist(*currpath + "/" + logcontextpath + "-logs")
l := &lumberjack.Logger{
Filename: *currpath + "/" + logcontextpath + "-logs/" + ctxservicename + ".log",
MaxSize: 10, // megabytes
MaxBackups: 3,
MaxAge: 28, //days
Compress: true, // disabled by default
}
log.SetOutput(l)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)
go func() {
for {
<-c
l.Rotate()
}
}()
// * For Service
svcConfig := &service.Config{
Name: ctxservicename,
DisplayName: ctxservicename,
Description: "Hansol Inticube IS-MON's API Service",
}
prg := &program{}
s, err := service.New(prg, svcConfig)
if err != nil {
log.Fatal(err)
}
serviceLogger, err = s.Logger(nil)
if err != nil {
log.Fatal(err)
}
err = s.Run()
if err != nil {
serviceLogger.Error(err)
}
}
// * For Service Start ----------------------------------------------------------------------------------------
func (p *program) Start(s service.Service) error {
// Start should not block. Do the actual work async.
go p.run()
return nil
}
func (p *program) Stop(s service.Service) error {
// Stop should not block. Return with a few seconds.
logn("Stop Service.... service name:", s.String())
prn("Stop Service.... service name:", s.String())
return nil
}
func (p *program) run() {
// #########################################################################################
// Disable Console Color, you don't need console color when writing the logs to file.
if !logColorEnable {
gin.DisableConsoleColor()
}
// Logging to a file.
// f, _ := os.Create("gin.log")
// gin.DefaultWriter = io.MultiWriter(f)
// gin.SetMode(gin.ReleaseMode)
router := gin.Default()
router.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
// https://gin-gonic.com/docs/examples/binding-and-validation/
// Example for binding JSON ({"user": "manu", "password": "123"})
// $ curl -v -X POST \
// http://localhost:8080/loginJSON \
// -H 'content-type: application/json' \
// -d '{ "user": "manu" }'
router.POST("/loginJSON", func(c *gin.Context) {
var json Login
if err := c.ShouldBindJSON(&json); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
if json.User != "manu" || json.Password != "123" {
c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized"})
return
}
c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})
})
// https://gin-gonic.com/docs/examples/goroutines-inside-a-middleware/
router.GET("/long_async", func(c *gin.Context) {
// create copy to be used inside the goroutine
cCp := c.Copy()
go func() {
// simulate a long task with time.Sleep(). 5 seconds
time.Sleep(5 * time.Second)
// note that you are using the copied context "cCp", IMPORTANT
log.Println("Done! in path " + cCp.Request.URL.Path)
// NOT WORKING...
// c.JSON(http.StatusOK, gin.H{"status": "long_async response"})
}()
})
router.GET("/long_sync", func(c *gin.Context) {
// simulate a long task with time.Sleep(). 5 seconds
time.Sleep(5 * time.Second)
// since we are NOT using a goroutine, we do not have to copy the context
log.Println("Done! in path " + c.Request.URL.Path)
c.JSON(http.StatusOK, gin.H{"status": "long_sync response"})
})
router.POST("/file-hash", func(c *gin.Context) {
var req FileHashRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"result": "fail",
"message": err.Error(),
})
return
}
timeoutSecDuration := strconv.Itoa(fileHashTimeout) + "s"
maxDuration, _ := time.ParseDuration(timeoutSecDuration)
ctx, _ := context.WithTimeout(context.Background(), maxDuration)
start := time.Now()
err := fileHashProcessWithCtxWrapper(ctx, req)
logf("duration:%v result:%s\n", time.Since(start), err)
if err != nil {
logn(err)
if err.Error() == "context deadline exceeded" {
c.JSON(http.StatusRequestTimeout, gin.H{
"result": "fail",
"message": err.Error(),
})
} else {
c.JSON(http.StatusInternalServerError, gin.H{
"result": "fail",
"message": err.Error(),
})
}
return
}
res := &FileHashResponse{}
res.Result = "success"
res.ResultMessage = "no message"
c.Data(http.StatusOK, gin.MIMEJSON, res.getFileHashResponse())
})
/*
type SockRequest struct {
SendStr string `json:"sendstr" binding:"required"`
Type string `json:"type" binding:"required"`
ServiceName string `json:"servicename" binding:"required"`
}
*/
router.POST("/api-sock", func(c *gin.Context) {
var req SockRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"error": err.Error(),
"success": false,
"sendstr": req.SendStr,
"type": req.Type,
"servicename": req.ServiceName,
"response": nil,
})
return
}
reqJSON, _ := json.Marshal(req)
logn("request trace :", string(reqJSON))
prn("Host : ", req.Host)
prn("Port : ", req.Port)
timeoutSecDuration := "3s"
maxDuration, _ := time.ParseDuration(timeoutSecDuration)
ctx, _ := context.WithTimeout(context.Background(), maxDuration)
start := time.Now()
result, err := sockWithCtxWrapper(ctx, req)
logf("duration:%v result:%s\n", time.Since(start), result)
if err != nil {
logn(err)
c.JSON(http.StatusRequestTimeout, gin.H{
"error": err.Error(),
"success": false,
"sendstr": req.SendStr,
"type": req.Type,
"servicename": req.ServiceName,
"response": nil,
})
return
}
sockRes := &SockResponse{}
sockRes.Data = result
sockRes.Host = req.Host
sockRes.Port = req.Port
sockRes.ServiceName = req.ServiceName
sockRes.Type = req.Type
sockRes.Size = len(result)
// c.JSON(http.StatusOK, sockRes.getSockResponse())
c.Data(http.StatusOK, gin.MIMEJSON, sockRes.getSockResponse())
})
router.POST("/api-snmp", func(c *gin.Context) {
var req APIRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"error": err.Error(),
"success": false,
"deviceid": req.DeviceID,
"deviceip": req.DeviceIP,
"oid-group-name": req.OidGroupName,
"is-yesterday": req.IsYesterday,
"response": nil,
})
return
}
reqJSON, _ := json.Marshal(req)
logn("request trace :", string(reqJSON))
timeoutSecDuration := strconv.Itoa(req.Timeout+1) + "s"
maxDuration, _ := time.ParseDuration(timeoutSecDuration)
ctx, _ := context.WithTimeout(context.Background(), maxDuration)
start := time.Now()
result, err := snmpWithCtxWrapper(ctx, req)
logf("duration:%v result:%s\n", time.Since(start), result)
if err != nil {
logn(err)
c.JSON(http.StatusRequestTimeout, gin.H{
"error": err.Error(),
"success": false,
"deviceid": req.DeviceID,
"deviceip": req.DeviceIP,
"oid-group-name": req.OidGroupName,
"is-yesterday": req.IsYesterday,
"response": nil,
})
return
}
c.JSON(http.StatusOK, result)
})
router.Run(":" + listenPort) // listen and serve on 0.0.0.0:8080
}
func fileHashProcessWithCtxWrapper(ctx context.Context, req FileHashRequest) error {
done := make(chan error)
go func() {
done <- fileHashProcess(req)
}()
select {
case <-ctx.Done():
return ctx.Err()
case result := <-done:
return result
}
}
// fileHashProcess(targetFilePath string, oHash string, tmpFilePrefix string)
func fileHashProcess(req FileHashRequest) error {
target := fileHashTargetPath + "/" + req.FileSubPath + "/" + req.FileName
oHash := req.FileHash
tmpFilePrefix := req.FileHash
input, err := ioutil.ReadFile(target)
if err != nil {
logn(err)
return err
}
lines := strings.Split(string(input), "\n")
// Manupulate target file (multi-part uploaded file http chunk string)
cnt := 0
for i, line := range lines {
if strings.Contains(line, fileHashInitailKeyword) {
// fmt.Println(line, ", ", len(lines), ", ", i)
lines = remove(lines, i)
cnt++
}
if i > 0 && cnt > 0 {
if (i - cnt) >= len(lines) {
break
}
for _, keyword := range fileHashKeywords {
if strings.Contains(lines[i-cnt], keyword) {
fmt.Println(lines[i-cnt])
lines = remove(lines, i-cnt)
}
}
}
}
tempFileName := tmpFilePrefix + "-" + strconv.FormatInt(time.Now().UnixNano(), 10)
output := strings.Join(lines, "\n")
err = ioutil.WriteFile(fileHashTempPath+"/"+tempFileName, []byte(output[2:len(output)-2]), 0644)
if err != nil {
logn(err)
return err
}
calculatedHash := fileHash(fileHashTempPath + "/" + tempFileName)
errRemove := os.Remove(fileHashTempPath + "/" + tempFileName)
if errRemove != nil {
logn(errRemove)
}
logn("[%s]\n", oHash)
logn("[%s]\n", calculatedHash)
if oHash == calculatedHash {
return nil
} else {
return errors.New("hash-inconsistent")
}
}
func remove(slice []string, s int) []string {
return append(slice[:s], slice[s+1:]...)
}
func fileHash(src string) string {
f, err := os.Open(src)
if err != nil {
log.Fatal(err)
}
defer f.Close()
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
log.Fatal(err)
}
return BytesToString(h.Sum(nil))
}
func BytesToString(data []byte) string {
// return string(data[:])
return hex.EncodeToString(data)
}
func sockWithCtxWrapper(ctx context.Context, req SockRequest) (string, error) {
done := make(chan string)
go func() {
done <- sockRun(req)
}()
select {
case <-ctx.Done():
return "Fail", ctx.Err()
case result := <-done:
return result, nil
}
}
func sockRun(req SockRequest) string {
strSend := req.SendStr // "Halo"
servAddr := req.Host + ":" + strconv.Itoa(req.Port) // "localhost:9000"
tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr)
if err != nil {
logn("ResolveTCPAddr failed:", err.Error())
// os.Exit(1)
}
conn, err := net.DialTCP("tcp", nil, tcpAddr)
if err != nil {
logn("Dial failed:", err.Error())
return "failed"
}
// if conn != nil {
defer conn.Close()
// }
_, err = conn.Write([]byte(strSend))
if err != nil {
logn("Write to server failed:", err.Error())
// os.Exit(1)
}
logn("write to server = ", strSend)
reply := make([]byte, 1024*30)
_, err = conn.Read(reply)
if err != nil {
logn("Write to server failed:", err.Error())
// os.Exit(1)
}
reply = bytes.Trim(reply, "\x00")
logn("reply from server=", string(reply))
// conn.Close()
return string(reply) // strings.Trim(string(reply), " ")
}
func snmpWithCtxWrapper(ctx context.Context, req APIRequest) (string, error) {
done := make(chan string)
go func() {
done <- snmpWalkRun(req)
}()
select {
case <-ctx.Done():
return "Fail", ctx.Err()
case result := <-done:
return result, nil
}
}
func snmpWalkRun(req APIRequest) string {
_host := req.DeviceIP
_oids := req.Oid
_timeout := req.Timeout
_user := req.UserName
_authprotocol := "SHA"
_authpass := req.AuthPass
_privcypass := req.PrivPass
_privacyprotocol := "AES"
_version := "v3"
timeoutSecDuration := strconv.Itoa(_timeout) + "s"
duration, _ := time.ParseDuration(timeoutSecDuration)
target := _host
oidstr := _oids
splitedOid := strings.Split(oidstr, "|")
startTime := time.Now()
gosnmp.Default.Target = target
gosnmp.Default.Timeout = duration // time.Duration(*timeout * time.Second) // Timeout better suited to walking
gosnmp.Default.Retries = 1
if _version == "v3" {
var authProtocol gosnmp.SnmpV3AuthProtocol
switch _authprotocol {
case "SHA":
authProtocol = gosnmp.SHA
default:
authProtocol = gosnmp.MD5
}
var privacyProtocol gosnmp.SnmpV3PrivProtocol
switch _privacyprotocol {
case "DES":
privacyProtocol = gosnmp.DES
case "AES":
privacyProtocol = gosnmp.AES
case "AES192":
privacyProtocol = gosnmp.AES192
case "AES256":
privacyProtocol = gosnmp.AES256
default:
privacyProtocol = gosnmp.AES
}
gosnmp.Default.Version = gosnmp.Version3
gosnmp.Default.SecurityModel = gosnmp.UserSecurityModel
gosnmp.Default.MsgFlags = gosnmp.AuthPriv
gosnmp.Default.SecurityParameters = &gosnmp.UsmSecurityParameters{
UserName: _user,
AuthenticationProtocol: authProtocol,
AuthenticationPassphrase: _authpass,
PrivacyProtocol: privacyProtocol,
PrivacyPassphrase: _privcypass,
}
} else if _version == "v2c" {
gosnmp.Default.Version = gosnmp.Version2c
gosnmp.Default.Community = _user
} else if _version == "v1" {
gosnmp.Default.Version = gosnmp.Version1
gosnmp.Default.Community = _user
} else {
log.Println("Only v3, v2c available")
return "" // TODO
}
err := gosnmp.Default.Connect()
if err != nil {
logf("Connect err: %v\n", err)
return "" // TODO
}
defer gosnmp.Default.Conn.Close()
oid := splitedOid[0]
output := &Output{}
output.DeviceID = req.DeviceID
output.DeviceIP = req.DeviceIP
output.OidGroupName = req.OidGroupName
output.IsYesterday = req.IsYesterday
var res []Responses
asyncRes := func(pdu gosnmp.SnmpPDU) error {
// fmt.Printf("%s = ", pdu.Name)
var value string
switch pdu.Type {
case gosnmp.OctetString:
b := pdu.Value.([]byte)
// fmt.Printf("STRING: %s\n", string(b))
value = string(b)
default:
// fmt.Printf("TYPE %d: %d\n", pdu.Type, gosnmp.ToBigInt(pdu.Value))
value = strconv.Itoa(int(gosnmp.ToBigInt(pdu.Value).Int64()))
}
res = append(res, Responses{
Oid: pdu.Name,
Value: value,
})
return nil
}
errorB := gosnmp.Default.BulkWalk(oid, asyncRes)
if errorB != nil {
logf("Walk Error: %v\n", errorB)
output.Success = false
} else {
output.Success = true
}
unitElapsedTime := time.Since(startTime)
output.ElabsedTime = unitElapsedTime.String()
output.setResponses(res)
return output.getOutputJSON()
}
func createDirIfNotExist(dir string) {
if _, err := os.Stat(dir); os.IsNotExist(err) {
err = os.MkdirAll(dir, 0755)
if err != nil {
logn(err.Error())
panic(err)
}
}
}
func isFlagInputed(name string) bool {
found := false
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
}
})
return found
}