Created
October 20, 2019 17:22
-
-
Save zackproser/18c6b36fd77982f735cac1c534380cc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func handleAdminSMSRequest(sender, body string, w http.ResponseWriter) { | |
| // Attempt to parse a target number from the body of the message | |
| valid, formatted := validateNumber(body) | |
| if valid { | |
| // If the number is already being attacked, stop it | |
| if isUnderAttack(formatted) { | |
| success, attack := stopAttack(formatted) | |
| if success { | |
| fmt.Fprintf(w, "Successfully terminated attack on: %v, with %v total messages sent since %v", attack.Target, attack.MsgCount, attack.StartTime) | |
| } | |
| } else { | |
| // Otherwise start a new attack | |
| atkResponse := createAttack(formatted) | |
| if atkResponse != nil { | |
| fmt.Fprintf(w, "Successfully intitiated attack on: %v, at %v", atkResponse.Target, atkResponse.StartTime) | |
| } else { | |
| fmt.Fprintf(w, "Error initializing attack on %v", body) | |
| } | |
| } | |
| } else if strings.Contains(strings.ToLower(body), "status") { | |
| status := getServiceStatus() | |
| fmt.Fprintf(w, AppName+" Status - Count of currently running attacks: %v, on current targets: %v", status.AttackCount, status.Targets) | |
| } else { | |
| fmt.Fprintf(w, "Invalid attack target: %v - please supply a valid phone number", body) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment