package main

import (
	"log"

	"git.paulbsd.com/paulbsd/pki/src/config"
	"git.paulbsd.com/paulbsd/pki/src/database"
	"git.paulbsd.com/paulbsd/pki/src/pki"
	"git.paulbsd.com/paulbsd/pki/src/pkiws"
	_ "github.com/lib/pq"
)

//var version string

func main() {
	var PKICtx pki.User

	var cfg config.Config
	cfg.GetConfig()
	//cfg.Options.Version = version

	// Initialize database app context
	err := database.Init(&cfg)
	if err != nil {
		log.Fatalln(err)
	}
	defer cfg.Db.Close()

	// Initialize PKI app context
	err = PKICtx.Init(&cfg)
	if err != nil {
		log.Fatalln(err)
	}

	// Run the PKI web service
	err = pkiws.RunServer(&cfg)
	if err != nil {
		log.Fatalln(err)
	}
}
