Created
November 1, 2019 08:19
-
-
Save roz3x/d6bd586bf5b70219110590bbe5e701ca to your computer and use it in GitHub Desktop.
This file contains 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
package main | |
import ( | |
"fmt" | |
_"sync" | |
"log" | |
"net/http" | |
"io" | |
"os/exec" | |
"os" | |
) | |
var ( | |
channel = make(chan string) | |
) | |
func Handler(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "thanks for entering the data into db ") | |
query := string([]byte(r.URL.Path)[1:]) | |
channel <- query | |
} | |
func dbside() { | |
password := "" | |
fmt.Printf("enter password:") | |
fmt.Scan(&password) | |
cmd := exec.Command("sh","-c","mysql -u root -p"+password+" --database=temp_app 2>/dev/null") | |
cmd.Stdout = os.Stdout | |
cmd.Stderr = os.Stderr | |
query , err := cmd.StdinPipe() | |
if err != nil { | |
fmt.Printf("cant continue") | |
panic(err) | |
} | |
err = cmd.Start() | |
if err != nil { | |
fmt.Printf("cant continue") | |
panic(err) | |
} | |
for { | |
q := <- channel | |
io.WriteString(query,`INSERT INTO users VALUES("`+q+`");`) | |
} | |
} | |
func main() { | |
go dbside() | |
http.HandleFunc("/", Handler) | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment