Created
March 17, 2012 22:00
-
-
Save jordanorelli/2065698 to your computer and use it in GitHub Desktop.
pissing contest
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
package main | |
import ( | |
"fmt" | |
"github.com/ziutek/mymysql/mysql" | |
"io" | |
"net/http" | |
// "runtime" | |
_ "github.com/ziutek/mymysql/thrsafe" | |
) | |
var db mysql.Conn | |
func indexHandler(w http.ResponseWriter, r *http.Request) { | |
// fmt.Println(runtime.NumCPU(), "\t", runtime.NumGoroutine()) | |
rows, _, err := db.Query("select * from user") | |
if err != nil { | |
fmt.Println("Error sending query\n") | |
http.Error(w, err.Error(), http.StatusInternalServerError) | |
} | |
for _, row := range rows { | |
io.WriteString(w, row.Str(1) + "\n") | |
} | |
// io.WriteString(w, "hello, world!") | |
} | |
func main() { | |
db = mysql.New("unix", "", "/tmp/mysql.sock", "pissing", "pissing", "pissing") | |
err := db.Connect() | |
if err != nil { | |
fmt.Println("Error connecting to database.\n") | |
panic(err) | |
} | |
fmt.Println("Go serving on port 8080") | |
http.HandleFunc("/", indexHandler) | |
http.ListenAndServe(":8080", nil) | |
} |
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
import tornado.ioloop | |
import tornado.web | |
from tornado.database import Connection | |
db = Connection("localhost", "pissing", user="pissing", password="pissing") | |
class IndexHandler(tornado.web.RequestHandler): | |
def get(self): | |
for row in db.query("select * from user"): | |
self.write(row.username + "\n") | |
application = tornado.web.Application([ | |
(r'/', IndexHandler), | |
]) | |
if __name__ == "__main__": | |
application.listen(8888) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment