path to refreshing states from email that doesnt work over vpn

master
Bel LaPointe 2022-01-09 23:42:53 -05:00
parent 485293466e
commit 366b35d76b
3 changed files with 40 additions and 6 deletions

View File

@ -10,8 +10,8 @@
},
"Emailer": {
"From": "breellocaldev@gmail.com",
"POP3": "pop.gmail.com:995",
"noIMAP": "imap.gmail.com:993",
"Password": "gojfkkfrkmtxzyro",
"Limit": 1
"Limit": 10
}
}

View File

@ -28,12 +28,16 @@ type Config struct {
var live Config
func Refresh() error {
configPath, ok := os.LookupEnv("CONFIG")
func configPath() string {
p, ok := os.LookupEnv("CONFIG")
if !ok {
configPath = "./config.json"
p = "./config.json"
}
b, err := ioutil.ReadFile(configPath)
return p
}
func Refresh() error {
b, err := ioutil.ReadFile(configPath())
if err != nil {
return err
}
@ -52,6 +56,15 @@ func Get() *Config {
return &live
}
func Set(other Config) {
b, err := json.Marshal(other)
if err != nil {
return
}
ioutil.WriteFile(configPath(), b, os.ModePerm)
Refresh()
}
func (c *Config) DB() storage.DB {
if c.db == nil {
c.lock.Lock()

21
main.go
View File

@ -1,6 +1,7 @@
package main
import (
"errors"
"local/storage"
"local/truckstop/broker"
"local/truckstop/config"
@ -9,11 +10,31 @@ import (
)
func main() {
go func() {
email()
c := time.NewTicker(time.Minute)
for range c.C {
if err := email(); err != nil {
log.Print(err)
}
}
}()
if err := _main(); err != nil {
panic(err)
}
}
func email() error {
ch, err := config.Get().Emailer.ReadIMAP()
if err != nil {
return err
}
for email := range ch {
log.Printf("%+v", email)
}
return errors.New("not impl")
}
func _main() error {
for {
if err := config.Refresh(); err != nil {