protomolecule/main.go

84 lines
1.7 KiB
Go

package main
import (
//"flag"
"os"
"protomolecule/src/dust"
"protomolecule/src/eros"
"protomolecule/src/scanStuff"
"time"
//projVars "protomolecule/src/vars"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
//"tinygo.org/x/bluetooth"
)
var ScanMgr *scanStuff.Meta
func init() {
// initialize database engine
eros.Awaken()
ScanMgr = &scanStuff.Meta{
Count: 0,
Scans: make(map[int]*scanStuff.Scan),
}
// TODO: make this a commandline argument
// assure the log directory exists
var logDir string = "./.logs/"
err := os.MkdirAll(logDir, 0755)
if err != nil {
panic(err.Error())
}
// define log file itself using the current date and time
Now := time.Now()
date := Now.Format(time.RFC3339)
logFileName := date + ".log"
lf, err := os.OpenFile(logDir+logFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
panic(err.Error())
}
// define pretty printer
consoleWriter := zerolog.ConsoleWriter{Out: os.Stderr}
// initialize simultaneous pretty printing and json logging
multi := zerolog.MultiLevelWriter(consoleWriter, lf)
log.Logger = zerolog.New(multi).With().Timestamp().Logger()
// suppress debug messages unless -d is called
zerolog.SetGlobalLevel(zerolog.InfoLevel)
for _, arg := range os.Args {
if arg == "-d" {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
}
log.Debug().Msg("Logging initialized")
}
func main() {
var scanID int
var scan *scanStuff.Scan
//values := flag.Args()
scanID = ScanMgr.NewScan()
scan = ScanMgr.Scans[scanID]
dust.Must("Scan", scan.Start())
/*
connectToStuff := func(addr bluetooth.Addresser, device *bluetooth.Device) {
d, _ := adapter.Connect(addr, bluetooth.ConnectionParams{}, err ==
*device == d)
color.Red("Trying a connection", addr)
}
*/
}