|
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 |
| 51 | + https = true |
52 | 52 | requiredToolsAPILevel = "v1" |
53 | 53 | ) |
54 | 54 |
|
@@ -144,6 +144,9 @@ func main() { |
144 | 144 | Hibernate: *hibernate, |
145 | 145 | Version: version + "-" + commit, |
146 | 146 | DebugURL: func() string { |
| 147 | + if https { |
| 148 | + return "https://" + *address + port |
| 149 | + } |
147 | 150 | return "http://" + *address + port |
148 | 151 | }, |
149 | 152 | AdditionalConfig: *additionalConfig, |
@@ -196,7 +199,7 @@ func loop() { |
196 | 199 | log.SetLevel(log.InfoLevel) |
197 | 200 | log.SetOutput(os.Stdout) |
198 | 201 |
|
199 | | - // the important forlders of the agent |
| 202 | + // the important folders of the agent |
200 | 203 | src, _ := os.Executable() |
201 | 204 | srcPath := paths.New(src) // The path of the agent's binary |
202 | 205 | srcDir := srcPath.Parent() // The directory of the agent's binary |
@@ -420,45 +423,32 @@ func loop() { |
420 | 423 | goa := v2.Server(agentDir.String()) |
421 | 424 | r.Any("/v2/*path", gin.WrapH(goa)) |
422 | 425 |
|
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 | | - } |
| 426 | + // check if certificates exist; if not, use plain http |
| 427 | + if srcDir.Join("cert.pem").NotExist() { |
| 428 | + log.Error("Could not find HTTPS certificate. Using plain HTTP only.") |
| 429 | + https = false |
| 430 | + } |
| 431 | + go startServer(r, https, srcDir) |
| 432 | +} |
429 | 433 |
|
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 | | - } |
| 434 | +func startServer(r *gin.Engine, https bool, certDir *paths.Path) { |
| 435 | + start := 8990 |
| 436 | + end := 9000 |
| 437 | + i := start |
| 438 | + for i < end { |
| 439 | + i = i + 1 |
| 440 | + port = ":" + strconv.Itoa(i) |
| 441 | + var err error |
| 442 | + if https { |
| 443 | + err = r.RunTLS(*address+port, certDir.Join("cert.pem").String(), certDir.Join("key.pem").String()) |
| 444 | + } else { |
| 445 | + err = r.Run(*address + port) |
443 | 446 | } |
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 | | - } |
| 447 | + if err != nil { |
| 448 | + log.Printf("Error trying to bind to port: %v, so exiting...", err) |
| 449 | + continue |
460 | 450 | } |
461 | | - }() |
| 451 | + } |
462 | 452 | } |
463 | 453 |
|
464 | 454 | func parseIni(filename string) (args []string, err error) { |
|
0 commit comments