47 lines
985 B
Go
47 lines
985 B
Go
package sriracha
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
fmt.Fprintf(w, "<h1>Testing</h1>")
|
|
|
|
reader := bytes.NewReader([]byte("Test"))
|
|
a, err := attach(reader, 4, "image/png")
|
|
log.Println(a, "-", err)
|
|
|
|
p := &Post{
|
|
ID: 1,
|
|
Thread: 0,
|
|
Email: "test@mail.com",
|
|
Name: "Anonymous",
|
|
Subject: "Sub",
|
|
Message: "Msg",
|
|
}
|
|
err = post(p)
|
|
log.Println("post err", err)
|
|
|
|
err = p.render(w)
|
|
if err != nil {
|
|
log.Fatal("render post err", err)
|
|
}
|
|
}
|
|
|
|
func Run(driver string, dataSource string) error {
|
|
log.Println("Connecting to database...")
|
|
err := connectDB(driver, dataSource)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.Println("Connected to database successfully")
|
|
|
|
listenAddress := ":8080" // TODO
|
|
log.Printf("Listening on %s...", listenAddress)
|
|
http.HandleFunc("/imgboard", handleRequest)
|
|
return http.ListenAndServe(listenAddress, nil)
|
|
}
|