|
@@ -6,6 +6,9 @@ import ( |
|
|
"sync" |
|
|
"sync" |
|
|
"regexp" |
|
|
"regexp" |
|
|
"html/template" |
|
|
"html/template" |
|
|
|
|
|
"database/sql" |
|
|
|
|
|
_ "github.com/go-sql-driver/mysql" |
|
|
|
|
|
"fmt" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type Page struct { |
|
|
type Page struct { |
|
@@ -14,6 +17,42 @@ type Page struct { |
|
|
Name string |
|
|
Name string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type LoanType struct { |
|
|
|
|
|
user int |
|
|
|
|
|
branch int |
|
|
|
|
|
name string |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type FeeTemplate struct { |
|
|
|
|
|
id sql.NullInt64 |
|
|
|
|
|
user sql.NullInt64 |
|
|
|
|
|
branch sql.NullInt64 |
|
|
|
|
|
amount sql.NullInt64 |
|
|
|
|
|
perc sql.NullInt64 |
|
|
|
|
|
ftype sql.NullString |
|
|
|
|
|
notes sql.NullString |
|
|
|
|
|
name sql.NullString |
|
|
|
|
|
category sql.NullString |
|
|
|
|
|
auto bool |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type Estimate struct { |
|
|
|
|
|
user int |
|
|
|
|
|
borrower int |
|
|
|
|
|
comparison int |
|
|
|
|
|
transaction int |
|
|
|
|
|
loanType LoanType |
|
|
|
|
|
loanAmount int |
|
|
|
|
|
price int |
|
|
|
|
|
property string |
|
|
|
|
|
pud bool |
|
|
|
|
|
term int |
|
|
|
|
|
interest int |
|
|
|
|
|
hoi int |
|
|
|
|
|
miName string |
|
|
|
|
|
miAmount int |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
|
regexen = make(map[string]*regexp.Regexp) |
|
|
regexen = make(map[string]*regexp.Regexp) |
|
|
relock sync.Mutex |
|
|
relock sync.Mutex |
|
@@ -52,18 +91,60 @@ func match(path, pattern string, args *[]string) bool { |
|
|
relock.Lock() |
|
|
relock.Lock() |
|
|
defer relock.Unlock() |
|
|
defer relock.Unlock() |
|
|
regex := regexen[pattern] |
|
|
regex := regexen[pattern] |
|
|
|
|
|
|
|
|
if regex == nil { |
|
|
if regex == nil { |
|
|
regex = regexp.MustCompile("^" + pattern + "$") |
|
|
regex = regexp.MustCompile("^" + pattern + "$") |
|
|
regexen[pattern] = regex |
|
|
regexen[pattern] = regex |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
matches := regex.FindStringSubmatch(path) |
|
|
matches := regex.FindStringSubmatch(path) |
|
|
if len(matches) <= 0 { |
|
|
if len(matches) <= 0 { |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
*args = matches[1:] |
|
|
*args = matches[1:] |
|
|
return true |
|
|
return true |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Fetch fees from the database |
|
|
|
|
|
func getFees(db *sql.DB, user int) ([]FeeTemplate, error) { |
|
|
|
|
|
var fees []FeeTemplate |
|
|
|
|
|
|
|
|
|
|
|
rows, err := db.Query("SELECT * FROM fee_template") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, fmt.Errorf("Fee error %v", err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
defer rows.Close() |
|
|
|
|
|
|
|
|
|
|
|
for rows.Next() { |
|
|
|
|
|
var fee FeeTemplate |
|
|
|
|
|
// var fee = FeeTemplate{ ftype: map[string]uint8{ |
|
|
|
|
|
// "Government": 0, "Title": 1, "Required": 2, "Lender": 3, "Other": 4, |
|
|
|
|
|
// }} |
|
|
|
|
|
|
|
|
|
|
|
if err := rows.Scan( |
|
|
|
|
|
&fee.id, |
|
|
|
|
|
&fee.user, |
|
|
|
|
|
&fee.branch, |
|
|
|
|
|
&fee.amount, |
|
|
|
|
|
&fee.perc, |
|
|
|
|
|
&fee.ftype, |
|
|
|
|
|
&fee.notes, |
|
|
|
|
|
&fee.name, |
|
|
|
|
|
&fee.category, |
|
|
|
|
|
&fee.auto) |
|
|
|
|
|
err != nil { |
|
|
|
|
|
return nil, fmt.Errorf("The fees %q: %v", user, err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fees = append(fees, fee) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fmt.Print("the fees: %v", fees) |
|
|
|
|
|
return fees, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func route(w http.ResponseWriter, r *http.Request) { |
|
|
func route(w http.ResponseWriter, r *http.Request) { |
|
|
var page Page |
|
|
var page Page |
|
|
var args []string |
|
|
var args []string |
|
@@ -88,6 +169,20 @@ func route(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
files := http.FileServer(http.Dir("")) |
|
|
files := http.FileServer(http.Dir("")) |
|
|
|
|
|
db, err := sql.Open("mysql", |
|
|
|
|
|
fmt.Sprintf( "%s:%s@tcp(127.0.0.1:3306)/skouter", |
|
|
|
|
|
config["DBUser"], |
|
|
|
|
|
config["DBPass"])) |
|
|
|
|
|
|
|
|
|
|
|
err = db.Ping() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
// do something here like abort |
|
|
|
|
|
print("Bad database configuration: %v", err) |
|
|
|
|
|
panic(err) |
|
|
|
|
|
// maybe os.Exit(1) instead |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fmt.Print(getFees(db, 0)) |
|
|
|
|
|
|
|
|
http.Handle("/assets/", files) |
|
|
http.Handle("/assets/", files) |
|
|
http.HandleFunc("/", route) |
|
|
http.HandleFunc("/", route) |
|
|