Skip to content

Commit 2033540

Browse files
committed
Fix linter
1 parent 0f14c82 commit 2033540

File tree

2 files changed

+47
-27
lines changed

2 files changed

+47
-27
lines changed

cmd/vcr-compressor/main.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package main
22

33
import (
44
"encoding/json"
5-
"fmt"
6-
"github.com/scaleway/scaleway-sdk-go/api/k8s/v1"
7-
"gopkg.in/dnaeon/go-vcr.v3/cassette"
85
"log"
96
"os"
7+
8+
"github.com/scaleway/scaleway-sdk-go/api/k8s/v1"
9+
"gopkg.in/dnaeon/go-vcr.v3/cassette"
1010
)
1111

1212
var transientStates = map[string]bool{
@@ -24,69 +24,82 @@ func main() {
2424
}
2525

2626
chemin := os.Args[1]
27+
2728
inputCassette, err := cassette.Load(chemin)
2829
if err != nil {
2930
log.Fatalf("Erreur de lecture du fichier : %v\n", err)
3031
}
3132

3233
outputCassette := cassette.New(chemin)
3334
transitioning := false
34-
for i := 0; i < len(inputCassette.Interactions); i++ {
35+
36+
for i := range len(inputCassette.Interactions) {
3537
interaction := inputCassette.Interactions[i]
3638
responseBody := interaction.Response.Body
3739
requestMethod := interaction.Request.Method
3840

3941
if requestMethod != "GET" {
4042
transitioning = false
43+
4144
log.Printf("Interaction %d is not a GET request. Recording it\n", i)
4245
outputCassette.AddInteraction(interaction)
46+
4347
continue
4448
}
4549

4650
if responseBody == "" {
4751
log.Printf("Interaction %d got an empty response body. Recording it\n", i)
4852
outputCassette.AddInteraction(interaction)
53+
4954
continue
5055
}
5156

5257
var m map[string]interface{}
58+
5359
err := json.Unmarshal([]byte(responseBody), &m)
5460
if err != nil {
55-
fmt.Printf("Interaction %d have an error with unmarshalling reponse body: %v. Recording it\n", i, err)
61+
log.Printf("Interaction %d have an error with unmarshalling response body: %v. Recording it\n", i, err)
5662
outputCassette.AddInteraction(interaction)
63+
5764
continue
5865
}
5966

6067
if m["status"] == nil {
6168
log.Printf("Interaction %d does not contain a status field. Recording it\n", i)
6269
outputCassette.AddInteraction(interaction)
70+
6371
continue
6472
}
6573

6674
if m["status"] != nil {
6775
// We test if the state is transient
6876
if _, ok := transientStates[m["status"].(string)]; ok {
6977
if transitioning {
70-
fmt.Printf("Interaction %d is in a transient state while we are already in transitient state. No need to record it: %s\n", i, m["status"])
78+
log.Printf("Interaction %d is in a transient state while we are already in transitient state. No need to record it: %s\n", i, m["status"])
79+
7180
continue
7281
} else {
7382
transitioning = true
74-
fmt.Printf("Interaction %d is in a transient state: %s, Recording it\n", i, m["status"])
83+
84+
log.Printf("Interaction %d is in a transient state: %s, Recording it\n", i, m["status"])
7585
outputCassette.AddInteraction(interaction)
7686
}
7787
} else {
7888
if transitioning {
79-
fmt.Printf("Interaction %d is not in a transient state anymore: %s, Recording it\n", i, m["status"])
89+
log.Printf("Interaction %d is not in a transient state anymore: %s, Recording it\n", i, m["status"])
8090
outputCassette.AddInteraction(interaction)
91+
8192
transitioning = false
8293
} else {
83-
fmt.Printf("Interaction %d is not in a transient state: %s, Recording it\n", i, m["status"])
94+
log.Printf("Interaction %d is not in a transient state: %s, Recording it\n", i, m["status"])
8495
outputCassette.AddInteraction(interaction)
8596
}
86-
8797
}
8898
}
8999
}
90100

91-
outputCassette.Save()
101+
err = outputCassette.Save()
102+
if err != nil {
103+
log.Fatalf("error while saving file: %v", err)
104+
}
92105
}

cmd/vcr-viewer/main.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package main
22

33
import (
44
"encoding/json"
5-
"fmt"
6-
"gopkg.in/dnaeon/go-vcr.v3/cassette"
75
"log"
86
"os"
7+
8+
"gopkg.in/dnaeon/go-vcr.v3/cassette"
99
)
1010

1111
func main() {
@@ -14,35 +14,42 @@ func main() {
1414
}
1515

1616
chemin := os.Args[1]
17+
1718
data, err := cassette.Load(chemin)
1819
if err != nil {
1920
log.Fatalf("Erreur de lecture du fichier : %v\n", err)
2021
}
2122

22-
for i := 0; i < len(data.Interactions); i++ {
23+
for i := range len(data.Interactions) {
2324
interaction := data.Interactions[i]
24-
fmt.Println("--------------")
25-
fmt.Printf("Interaction %d:\n", i+1)
26-
fmt.Printf(" Request:\n")
27-
fmt.Printf(" Method: %s\n", interaction.Request.Method)
28-
fmt.Printf(" URL: %s\n", interaction.Request.URL)
25+
26+
log.Println("--------------")
27+
log.Printf("Interaction %d:\n", i+1)
28+
log.Printf(" Request:\n")
29+
log.Printf(" Method: %s\n", interaction.Request.Method)
30+
log.Printf(" URL: %s\n", interaction.Request.URL)
31+
2932
if interaction.Request.Body != "" {
30-
fmt.Printf(" Body: %s\n", interaction.Request.Body)
33+
log.Printf(" Body: %s\n", interaction.Request.Body)
3134
}
32-
fmt.Printf(" Response:\n")
33-
fmt.Printf(" Status: %s\n", interaction.Response.Status)
34-
fmt.Printf(" Body: %s\n", interaction.Response.Body)
35+
36+
log.Printf(" Response:\n")
37+
log.Printf(" Status: %s\n", interaction.Response.Status)
38+
log.Printf(" Body: %s\n", interaction.Response.Body)
3539

3640
var m map[string]interface{}
41+
3742
err := json.Unmarshal([]byte(interaction.Response.Body), &m)
3843
if err != nil {
3944
continue
4045
}
46+
4147
if m["status"] != nil {
42-
fmt.Println("++++++++++++++++")
43-
fmt.Printf("status: %s\n", m["status"]) // Modifie le champ "status" pour qu'il soit "ok"
44-
fmt.Println("++++++++++++++++")
48+
log.Println("++++++++++++++++")
49+
log.Printf("status: %s\n", m["status"]) // Modifie le champ "status" pour qu'il soit "ok"
50+
log.Println("++++++++++++++++")
4551
}
46-
fmt.Println("--------------")
52+
53+
log.Println("--------------")
4754
}
4855
}

0 commit comments

Comments
 (0)