-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (53 loc) · 1.92 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
// Copyright 2019 Alberto Bregliano. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"regexp"
"crypto/tls"
"io/ioutil"
"log"
"net/http"
"os"
)
const (
endpointTgu = "https://10.38.34.138:8443/DiagnosticTool/api.php?method=DiagnosticTool&sincrono=N&format=json&tgu="
endpointEsito = "https://10.38.34.138:8443/DiagnosticTool/api.php?method=DiagnosticTool&sincrono=Y&format=json&cod_esito="
)
var re = regexp.MustCompile(`(?m)^\d+$`)
func main() {
var endpoint string
parametro := os.Args[1]
if !re.MatchString(parametro) {
endpoint = endpointEsito
}
if re.MatchString(parametro) {
endpoint = endpointTgu
}
// Costringe il client ad accettare anche certificati https non validi
// o scaduti.
transCfg := &http.Transport{
// Ignora certificati SSL scaduti.
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: transCfg}
url := endpoint + parametro
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Printf("ERROR Impossibile creare richiesta: %s\n", err.Error())
}
username := os.Getenv("DiagnosticToolUsername")
password := os.Getenv("DiagnosticToolPassoword")
req.SetBasicAuth(username, password)
resp, err := client.Do(req)
if err != nil {
log.Printf("ERROR Impossibile inviare richiesta http: %s\n", err.Error())
}
//defer resp.Body.Close()
responsBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Printf("ERROR Impossibile leggere body reqest: %s\n", err.Error())
}
fmt.Println(string(responsBody))
}