working toward storing state in db
This commit is contained in:
@@ -1,27 +1,33 @@
|
||||
package process
|
||||
|
||||
import "os"
|
||||
import "time"
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
import "github.com/jinzhu/gorm"
|
||||
import _ "github.com/jinzhu/gorm/dialects/sqlite" // required for orm
|
||||
"git.eeqj.de/sneak/feta/database"
|
||||
"git.eeqj.de/sneak/feta/ingester"
|
||||
"git.eeqj.de/sneak/feta/instance"
|
||||
"git.eeqj.de/sneak/feta/locator"
|
||||
"git.eeqj.de/sneak/feta/manager"
|
||||
"git.eeqj.de/sneak/feta/storage"
|
||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||
"github.com/k0kubun/pp"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
import "github.com/rs/zerolog"
|
||||
import "github.com/rs/zerolog/log"
|
||||
import "github.com/mattn/go-isatty"
|
||||
|
||||
import "git.eeqj.de/sneak/feta/ingester"
|
||||
import "git.eeqj.de/sneak/feta/storage"
|
||||
import "git.eeqj.de/sneak/feta/locator"
|
||||
import "git.eeqj.de/sneak/feta/manager"
|
||||
import "git.eeqj.de/sneak/feta/instance"
|
||||
// required for orm
|
||||
|
||||
// CLIEntry is the main entrypoint for the feta process from the cli
|
||||
func CLIEntry(version string, buildarch string) int {
|
||||
f := new(Feta)
|
||||
f.version = version
|
||||
f.buildarch = buildarch
|
||||
f.configure()
|
||||
f.setupLogging()
|
||||
f.setupDatabase()
|
||||
return f.runForever()
|
||||
}
|
||||
|
||||
@@ -33,10 +39,41 @@ type Feta struct {
|
||||
manager *manager.InstanceManager
|
||||
ingester *ingester.TootIngester
|
||||
api *Server
|
||||
db *gorm.DB
|
||||
dbm *database.Manager
|
||||
startup time.Time
|
||||
}
|
||||
|
||||
func (f *Feta) configure() {
|
||||
viper.SetConfigName("feta")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath("/etc/feta") // path to look for the config file in
|
||||
viper.AddConfigPath("$HOME/.config/feta") // call multiple times to add many search paths
|
||||
|
||||
viper.SetEnvPrefix("FETA")
|
||||
viper.AutomaticEnv()
|
||||
|
||||
viper.SetDefault("Debug", false)
|
||||
viper.SetDefault("HostDiscoveryParallelism", 5)
|
||||
viper.SetDefault("FSStorageLocation", os.ExpandEnv("$HOME/Library/ApplicationSupport/feta/tootarchive.d"))
|
||||
viper.SetDefault("DBStorageLocation", os.ExpandEnv("$HOME/Library/ApplicationSupport/feta/feta.state.db"))
|
||||
viper.SetDefault("LogReportInterval", time.Second*10)
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
// Config file not found; ignore error if desired
|
||||
} else {
|
||||
// Config file was found but another error was produced
|
||||
log.Panic().
|
||||
Err(err).
|
||||
Msg("cannot read config file")
|
||||
}
|
||||
}
|
||||
|
||||
if viper.GetBool("debug") {
|
||||
pp.Print(viper.AllSettings())
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Feta) identify() {
|
||||
log.Info().
|
||||
Str("version", f.version).
|
||||
@@ -44,6 +81,10 @@ func (f *Feta) identify() {
|
||||
Msg("starting")
|
||||
}
|
||||
|
||||
func (f *Feta) setupDatabase() {
|
||||
f.dbm = database.New()
|
||||
}
|
||||
|
||||
func (f *Feta) setupLogging() {
|
||||
|
||||
log.Logger = log.With().Caller().Logger()
|
||||
@@ -66,7 +107,7 @@ func (f *Feta) setupLogging() {
|
||||
}
|
||||
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
if viper.GetBool("debug") {
|
||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||
}
|
||||
|
||||
@@ -82,6 +123,7 @@ func (f *Feta) setupDatabase() {
|
||||
var err error
|
||||
f.db, err = gorm.Open("sqlite3", "feta.sqlite")
|
||||
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package process
|
||||
|
||||
import "time"
|
||||
import "net/http"
|
||||
import "encoding/json"
|
||||
import "runtime"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type hash map[string]interface{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user