update moon api

master
Jordan Orelli 10 years ago
parent f14741d7fa
commit b1cf12269c

@ -24,12 +24,7 @@ func requestsHandler(w http.ResponseWriter, r *http.Request) {
}
func appServer() {
var addr string
if err := conf.Get("app_addr", &addr); err != nil {
bail(1, "error reading app_addr from config: %s", err)
}
m := http.NewServeMux()
m.HandleFunc("/requests", requestsHandler)
http.ListenAndServe(addr, m)
http.ListenAndServe(config.AppAddr, m)
}

@ -6,4 +6,4 @@ proxy_addr: ":8080"
# prox history.
app_addr: ":9000"
dbpath: "history.db"
dbpath: "fart_history.db"

@ -28,16 +28,10 @@ func freezeRequest(r *http.Request) error {
}
func openDB() error {
var dbpath string
var err error
err = conf.Get("dbpath", &dbpath)
if err != nil {
return err
}
log.Printf("opening sqlite file at %s", dbpath)
db, err = sql.Open("sqlite3", dbpath)
log.Printf("opening sqlite file at %s", config.DbPath)
db, err = sql.Open("sqlite3", config.DbPath)
if err != nil {
return err
}

@ -1,11 +1,9 @@
package main
import (
"flag"
"fmt"
"github.com/jordanorelli/moon/lib"
"io"
"log"
"net/http"
"net/http/httputil"
"os"
@ -16,9 +14,28 @@ import (
var (
client = new(http.Client)
conf *moon.Doc
)
var config struct {
ProxyAddr string `
name: proxy_addr
default: ":8080"
help: proxy address. Browsers send their http traffic to this port.
`
AppAddr string `
name: app_addr
default: ":9000"
help: app address. Users visit this address to view the proxy's history db
`
DbPath string `
name: dbpath
default: history.db
help: path to a sqlite file used for storing the user's history
`
}
func httpHandler(w http.ResponseWriter, r *http.Request) {
id := newRequestId()
fmt.Printf("%s >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n", id.String())
@ -82,27 +99,13 @@ func bail(status int, t string, args ...interface{}) {
}
func proxyListener() {
var addr string
if err := conf.Get("proxy_addr", &addr); err != nil {
bail(1, "error reading proxy_addr from config: %s", err)
}
m := http.NewServeMux()
m.HandleFunc("/", httpHandler)
http.ListenAndServe(addr, m)
http.ListenAndServe(config.ProxyAddr, m)
}
func main() {
var configPath string
flag.StringVar(&configPath, "config", "./prox_config.moon", "path to configuration file")
flag.Parse()
log.Printf("reading config from %s", configPath)
var err error
conf, err = moon.ReadFile(configPath)
if err != nil {
bail(1, "unable to read config: %s", err)
}
moon.Parse(&config)
if err := openDB(); err != nil {
bail(1, "unable to open db: %s", err)

Loading…
Cancel
Save