Skip to content

Commit 35f33b5

Browse files
authored
update test util
1 parent 9b72935 commit 35f33b5

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

util/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module util
2+
3+
go 1.21.5
4+
5+
require github.com/google/uuid v1.5.0

util/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
2+
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=

util/util.go renamed to util/main.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package utilties
1+
package main
22

33
import (
44
"crypto/hmac"
@@ -11,17 +11,31 @@ import (
1111
"github.com/google/uuid"
1212
)
1313

14+
func usageAndExit() {
15+
fmt.Printf("Usage: %s <mode> <secret> <endpoint>\n", os.Args[0])
16+
os.Exit(1)
17+
}
18+
1419
func main() {
20+
if len(os.Args) < 2 {
21+
usageAndExit()
22+
}
23+
1524
switch os.Args[1] {
1625
case "hmac":
1726
generateAuthHeader()
18-
27+
default:
28+
usageAndExit()
1929
}
2030
}
2131

2232
func generateAuthHeader() {
23-
endpoint := os.Args[2]
24-
secret := os.Args[3]
33+
if len(os.Args) < 4 {
34+
usageAndExit()
35+
}
36+
37+
secret := os.Args[2]
38+
endpoint := os.Args[3]
2539

2640
timestamp := time.Now().Unix()
2741
uuid, _ := uuid.NewRandom()
@@ -37,6 +51,5 @@ func generateAuthHeader() {
3751
fmt.Printf("%s\n", nonce)
3852
fmt.Printf("%s\n", auth)
3953
fmt.Println()
40-
4154
fmt.Printf("curl http://127.0.0.1:4000/%s -H 'Authorization: %s' -H 'X-Jarvis-Timestamp: %s'\n", endpoint, auth, nonce)
4255
}

util/util

2.05 MB
Binary file not shown.

0 commit comments

Comments
 (0)