This commit is contained in:
17
main.go
17
main.go
@@ -16,6 +16,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
// For build numbers, from https://blog.kowalczyk.info/article/vEja/embedding-build-number-in-go-executable.html
|
||||
@@ -23,19 +24,27 @@ var sha1ver string // sha1 revision used to build the program
|
||||
var buildTime string // when the executable was built
|
||||
|
||||
func main() {
|
||||
|
||||
// Load data from environment file
|
||||
err := godotenv.Load(".env")
|
||||
if err != nil {
|
||||
panic("Error loading .env file")
|
||||
}
|
||||
|
||||
// Open connection to logfile
|
||||
// From https://ispycode.com/GO/Logging/Logging-to-multiple-destinations
|
||||
logFile := os.Getenv("LOG_FILE")
|
||||
if logFile == "" {
|
||||
logFile = "./ccsecrets.log"
|
||||
logFile = "./smt.log"
|
||||
}
|
||||
logfileWriter, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to write logfile", err)
|
||||
fmt.Printf("Unable to write logfile '%s' : '%s'\n", logFile, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
log.SetOutput(logfileWriter)
|
||||
log.Printf("CCSecrets starting execution. Built on %s from sha1 %s\n", buildTime, sha1ver)
|
||||
log.Printf("SMT starting execution. Built on %s from sha1 %s\n", buildTime, sha1ver)
|
||||
|
||||
// Initiate connection to sqlite and make sure our schema is up to date
|
||||
models.ConnectDatabase()
|
||||
@@ -64,7 +73,7 @@ func main() {
|
||||
|
||||
// TODO - think of a better default landing page
|
||||
router.GET("/", func(c *gin.Context) {
|
||||
c.String(http.StatusOK, fmt.Sprintf("Built on %s from sha1 %s\n", buildTime, sha1ver))
|
||||
c.String(http.StatusOK, fmt.Sprintf("SMT Built on %s from sha1 %s\n", buildTime, sha1ver))
|
||||
})
|
||||
|
||||
// Set some options for TLS
|
||||
|
@@ -10,7 +10,6 @@ import (
|
||||
"ccsecrets/utils"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/joho/godotenv"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
@@ -62,13 +61,6 @@ const createSchema string = `
|
||||
func ConnectDatabase() {
|
||||
var err error
|
||||
|
||||
// Load data from environment file
|
||||
err = godotenv.Load(".env")
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error loading .env file")
|
||||
}
|
||||
|
||||
// Try using sqlite as our database
|
||||
sqlPath := utils.GetFilePath(sqlFile)
|
||||
db, err = sqlx.Open("sqlite", sqlPath)
|
||||
|
Reference in New Issue
Block a user