mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-10-31 16:00:05 -04:00
Aaron Lindsay
58c7c17727
Still needs some fixups: * UI is incomplete * Investment transactions are unbalanced initially * OFX imports don't detect if one of the description fields for a transaction is empty (to fall back on another) * I'm sure plenty of other issues I haven't discovered yet
83 lines
2.4 KiB
Go
83 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"github.com/gorilla/context"
|
|
"log"
|
|
"net"
|
|
"net/http"
|
|
"net/http/fcgi"
|
|
"os"
|
|
"path"
|
|
"strconv"
|
|
)
|
|
|
|
var serveFcgi bool
|
|
var baseDir string
|
|
var tmpDir string
|
|
var port int
|
|
var smtpServer string
|
|
var smtpPort int
|
|
var smtpUsername string
|
|
var smtpPassword string
|
|
var reminderEmail string
|
|
|
|
func init() {
|
|
flag.StringVar(&baseDir, "base", "./", "Base directory for server")
|
|
flag.StringVar(&tmpDir, "tmp", "/tmp", "Directory to create temporary files in")
|
|
flag.IntVar(&port, "port", 80, "Port to serve API/files on")
|
|
flag.StringVar(&smtpServer, "smtp.server", "smtp.example.com", "SMTP server to send reminder emails from.")
|
|
flag.IntVar(&smtpPort, "smtp.port", 587, "SMTP server port to connect to")
|
|
flag.StringVar(&smtpUsername, "smtp.username", "moneygo", "SMTP username")
|
|
flag.StringVar(&smtpPassword, "smtp.password", "password", "SMTP password")
|
|
flag.StringVar(&reminderEmail, "email", "moneygo@example.com", "Email address to send reminder emails as.")
|
|
flag.BoolVar(&serveFcgi, "fcgi", false, "Serve via fcgi rather than http.")
|
|
flag.Parse()
|
|
|
|
static_path := path.Join(baseDir, "static")
|
|
|
|
// Ensure base directory is valid
|
|
dir_err_str := "The base directory doesn't look like it contains the " +
|
|
"'static' directory. Check to make sure you're passing the right " +
|
|
"value to the -base argument."
|
|
static_dir, err := os.Stat(static_path)
|
|
if err != nil {
|
|
log.Print(err)
|
|
log.Fatal(dir_err_str)
|
|
}
|
|
if !static_dir.IsDir() {
|
|
log.Fatal(dir_err_str)
|
|
}
|
|
}
|
|
|
|
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
|
http.ServeFile(w, r, path.Join(baseDir, "static/index.html"))
|
|
}
|
|
|
|
func staticHandler(w http.ResponseWriter, r *http.Request) {
|
|
http.ServeFile(w, r, path.Join(baseDir, r.URL.Path))
|
|
}
|
|
|
|
func main() {
|
|
servemux := http.NewServeMux()
|
|
servemux.HandleFunc("/", rootHandler)
|
|
servemux.HandleFunc("/static/", staticHandler)
|
|
servemux.HandleFunc("/session/", SessionHandler)
|
|
servemux.HandleFunc("/user/", UserHandler)
|
|
servemux.HandleFunc("/security/", SecurityHandler)
|
|
servemux.HandleFunc("/account/", AccountHandler)
|
|
servemux.HandleFunc("/transaction/", TransactionHandler)
|
|
|
|
listener, err := net.Listen("tcp", ":"+strconv.Itoa(port))
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
log.Printf("Serving on port %d out of directory: %s", port, baseDir)
|
|
if serveFcgi {
|
|
fcgi.Serve(listener, context.ClearHandler(servemux))
|
|
} else {
|
|
http.Serve(listener, context.ClearHandler(servemux))
|
|
}
|
|
}
|