51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
|
|
"git.wicak.co/arif/budgl/controllers"
|
|
"git.wicak.co/arif/budgl/models"
|
|
)
|
|
|
|
type Configuration struct {
|
|
HTTPHost string
|
|
HTTPPort string
|
|
SqlDatabase string
|
|
SqlUser string
|
|
SqlPassword string
|
|
SqlHost string
|
|
SqlPort string
|
|
}
|
|
|
|
func main() {
|
|
var err error
|
|
conf, err := ioutil.ReadFile("config/config.json")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
var Config Configuration
|
|
err = json.Unmarshal(conf, &Config)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
dbconn := fmt.Sprintf("dbname=%s user=%s password=%s host=%s port=%s sslmode=disable", Config.SqlDatabase, Config.SqlUser, Config.SqlPassword, Config.SqlHost, Config.SqlPort)
|
|
err = models.InitDB(dbconn)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fs := http.FileServer(http.Dir("static"))
|
|
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
|
http.HandleFunc("/", controllers.Index)
|
|
http.HandleFunc("/expenses", controllers.Expenses)
|
|
|
|
srvinfo := fmt.Sprintf("%s:%s", Config.HTTPHost, Config.HTTPPort)
|
|
http.ListenAndServe(srvinfo, nil)
|
|
}
|
|
|