2018-10-19 15:31:41 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2019-01-11 15:13:42 -02:00
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
|
|
|
|
"strconv"
|
|
|
|
|
|
2018-10-19 15:31:41 -04:00
|
|
|
"github.com/openaccounting/oa-server/core/api"
|
|
|
|
|
"github.com/openaccounting/oa-server/core/auth"
|
|
|
|
|
"github.com/openaccounting/oa-server/core/model"
|
|
|
|
|
"github.com/openaccounting/oa-server/core/model/db"
|
|
|
|
|
"github.com/openaccounting/oa-server/core/model/types"
|
|
|
|
|
"github.com/openaccounting/oa-server/core/util"
|
|
|
|
|
//"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
//filename is the path to the json config file
|
|
|
|
|
var config types.Config
|
|
|
|
|
file, err := os.Open("./config.json")
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
decoder := json.NewDecoder(file)
|
|
|
|
|
err = decoder.Decode(&config)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-11 15:13:42 -02:00
|
|
|
connectionString := config.User + ":" + config.Password + "@" + config.DatabaseAddress + "/" + config.Database
|
2018-10-19 15:31:41 -04:00
|
|
|
|
|
|
|
|
db, err := db.NewDB(connectionString)
|
|
|
|
|
|
|
|
|
|
bc := &util.StandardBcrypt{}
|
|
|
|
|
|
|
|
|
|
model.NewModel(db, bc, config)
|
|
|
|
|
auth.NewAuthService(db, bc)
|
|
|
|
|
|
2018-11-08 11:35:11 -05:00
|
|
|
app, err := api.Init(config.ApiPrefix)
|
2018-10-19 15:31:41 -04:00
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Fatal(http.ListenAndServeTLS(":"+strconv.Itoa(config.Port), config.CertFile, config.KeyFile, app.MakeHandler()))
|
|
|
|
|
}
|