|
48 | 48 | version = "x.x.x-dev" //don't modify it, Jenkins will take care |
49 | 49 | commit = "xxxxxxxx" //don't modify it, Jenkins will take care |
50 | 50 | port string |
51 | | - portSSL string |
52 | 51 | requiredToolsAPILevel = "v1" |
53 | 52 | ) |
54 | 53 |
|
@@ -196,7 +195,7 @@ func loop() { |
196 | 195 | log.SetLevel(log.InfoLevel) |
197 | 196 | log.SetOutput(os.Stdout) |
198 | 197 |
|
199 | | - // the important forlders of the agent |
| 198 | + // the important folders of the agent |
200 | 199 | src, _ := os.Executable() |
201 | 200 | srcPath := paths.New(src) // The path of the agent's binary |
202 | 201 | srcDir := srcPath.Parent() // The directory of the agent's binary |
@@ -420,45 +419,33 @@ func loop() { |
420 | 419 | goa := v2.Server(agentDir.String()) |
421 | 420 | r.Any("/v2/*path", gin.WrapH(goa)) |
422 | 421 |
|
423 | | - go func() { |
424 | | - // check if certificates exist; if not, use plain http |
425 | | - if srcDir.Join("cert.pem").NotExist() { |
426 | | - log.Error("Could not find HTTPS certificate. Using plain HTTP only.") |
427 | | - return |
428 | | - } |
| 422 | + // check if certificates exist; if not, use plain http |
| 423 | + https := true |
| 424 | + if srcDir.Join("cert.pem").NotExist() { |
| 425 | + log.Error("Could not find HTTPS certificate. Using plain HTTP only.") |
| 426 | + https = false |
| 427 | + } |
| 428 | + go startServer(r, https, srcDir) |
| 429 | +} |
429 | 430 |
|
430 | | - start := 8990 |
431 | | - end := 9000 |
432 | | - i := start |
433 | | - for i < end { |
434 | | - i = i + 1 |
435 | | - portSSL = ":" + strconv.Itoa(i) |
436 | | - if err := r.RunTLS(*address+portSSL, srcDir.Join("cert.pem").String(), srcDir.Join("key.pem").String()); err != nil { |
437 | | - log.Printf("Error trying to bind to port: %v, so exiting...", err) |
438 | | - continue |
439 | | - } else { |
440 | | - log.Print("Starting server and websocket (SSL) on " + *address + "" + port) |
441 | | - break |
442 | | - } |
| 431 | +func startServer(r *gin.Engine, https bool, certDir *paths.Path) { |
| 432 | + start := 8990 |
| 433 | + end := 9000 |
| 434 | + i := start |
| 435 | + for i < end { |
| 436 | + i = i + 1 |
| 437 | + port = ":" + strconv.Itoa(i) |
| 438 | + var err error |
| 439 | + if https { |
| 440 | + err = r.RunTLS(*address+port, certDir.Join("cert.pem").String(), certDir.Join("key.pem").String()) |
| 441 | + } else { |
| 442 | + err = r.Run(*address + port) |
443 | 443 | } |
444 | | - }() |
445 | | - |
446 | | - go func() { |
447 | | - start := 8990 |
448 | | - end := 9000 |
449 | | - i := start |
450 | | - for i < end { |
451 | | - i = i + 1 |
452 | | - port = ":" + strconv.Itoa(i) |
453 | | - if err := r.Run(*address + port); err != nil { |
454 | | - log.Printf("Error trying to bind to port: %v, so exiting...", err) |
455 | | - continue |
456 | | - } else { |
457 | | - log.Print("Starting server and websocket on " + *address + "" + port) |
458 | | - break |
459 | | - } |
| 444 | + if err != nil { |
| 445 | + log.Printf("Error trying to bind to port: %v, so exiting...", err) |
| 446 | + continue |
460 | 447 | } |
461 | | - }() |
| 448 | + } |
462 | 449 | } |
463 | 450 |
|
464 | 451 | func parseIni(filename string) (args []string, err error) { |
|
0 commit comments