Skip to content

Commit 6ef05d4

Browse files
committed
Created basic CLI app logic statements
Created basic CLI app logic statements such as asking user about sending/saving request, creating body etc.
1 parent 611e922 commit 6ef05d4

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

main.go

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,63 @@
11
package main
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
)
46

57
func main() {
8+
9+
var url string
10+
var method string
11+
var option string
12+
var body string
13+
var header string
14+
615
fmt.Println("Starting HTTP request creator")
716
fmt.Println("HTTP request URL: ")
17+
fmt.Scan(&url)
818
fmt.Println("What HTTP method do you want to use: ")
19+
fmt.Scan(&method)
920

1021
//* HTTP REQUEST BODY
1122
fmt.Println("Do you want to add body to the request? [y/n]")
23+
fmt.Scan(&option)
1224

13-
//! if body TRUE
14-
fmt.Printf("Do you want to: \n1. Type json body,\n2. Import body from json file.\n")
15-
//!--- if option 1
16-
fmt.Println("Body: ")
17-
//!--- if option 2
18-
fmt.Println("Path to json file: ")
19-
//! if body FALSE
25+
if ynToBool(option) {
26+
fmt.Printf("Do you want to: \n1. Type json body,\n2. Import body from json file.\n")
27+
if option == "1" {
28+
fmt.Println("Body: ")
29+
fmt.Scan(&body)
30+
}
31+
if option == "2" {
32+
fmt.Println("Path to json file: ")
33+
}
34+
}
2035

2136
//* HTTP REQUEST HEADER
2237
fmt.Println("Header: ")
38+
fmt.Scan(&header)
2339

2440
//* HTTP REQUEST SENDING
2541
fmt.Println("Do you want to send request? [y/n]")
26-
//! if send TRUE
27-
fmt.Println("Sending request")
28-
//! if send FALSE
29-
fmt.Println("Do you want to save request to file? [y/n]")
30-
//!--- if save FALSE
31-
fmt.Println("Closing CLI app")
32-
//!--- if save TRUE
33-
fmt.Println("Path to directory where do you want to save request: ")
34-
//! CREATING FILE IN PATH, SAVING REQUEST
42+
fmt.Scan(&option)
43+
if ynToBool(option) {
44+
fmt.Println("Sending request")
45+
} else {
46+
fmt.Println("Do you want to save request to file? [y/n]")
47+
fmt.Scan(&option)
48+
if ynToBool(option) {
49+
fmt.Println("Closing CLI app")
50+
} else if ynToBool(option) {
51+
fmt.Println("Path to directory where do you want to save request: ")
52+
//! CREATING FILE IN PATH, SAVING REQUEST
53+
}
54+
}
55+
}
56+
57+
func ynToBool(option string) bool {
58+
if option == "y" {
59+
return true
60+
} else {
61+
return false
62+
}
3563
}

0 commit comments

Comments
 (0)