Replaced tab with space, fixed #40

pull/39/head
マリウス 2 years ago
parent c89a201b78
commit 078b3164ab
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F

10
cache/cache.go vendored

@ -1,22 +1,22 @@
package cache
import (
"encoding/json"
"encoding/json"
"github.com/mrusme/superhighway84/models"
"github.com/tidwall/buntdb"
"github.com/mrusme/superhighway84/models"
"github.com/tidwall/buntdb"
)
type Cache struct {
db *buntdb.DB
dbPath string
dbPath string
}
func NewCache(dbPath string) (*Cache, error) {
var err error
cache := new(Cache)
cache.dbPath = dbPath
cache.dbPath = dbPath
cache.db, err = buntdb.Open(cache.dbPath)
if err != nil {
return nil, err

@ -3,7 +3,7 @@
package common
import(
"github.com/mrusme/go-poolsuite"
"github.com/mrusme/go-poolsuite"
)
type Player struct {

@ -1,17 +1,17 @@
package config
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/BurntSushi/toml"
"github.com/gdamore/tcell/v2"
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/BurntSushi/toml"
"github.com/gdamore/tcell/v2"
)
type ConfigProfile struct {
@ -37,7 +37,7 @@ type Config struct {
ConnectionString string
CachePath string // Deprecated, should be removed soon
DatabaseCachePath string
DatabaseCachePath string
ProgramCachePath string
Logfile string
@ -153,10 +153,10 @@ func (cfg *Config) Persist() (error) {
func (cfg *Config) WasSetup() (bool) {
if cfg.DatabaseCachePath == "" ||
cfg.ProgramCachePath == "" ||
cfg.ProgramCachePath == "" ||
cfg.ConnectionString == "" ||
cfg.Logfile == "" ||
cfg.Profile.From == "" {
cfg.Profile.From == "" {
return false
}
@ -167,9 +167,9 @@ func (cfg *Config) Setup() (error) {
fmt.Printf("\nSUPERHIGHWAY84\n\nInitial Setup\n-------------\n\n")
defaultConnectionString := "/orbitdb/bafyreifdpagppa7ve45odxuvudz5snbzcybwyfer777huckl4li4zbc5k4/superhighway84"
if cfg.ConnectionString != "" {
defaultConnectionString = cfg.ConnectionString
}
if cfg.ConnectionString != "" {
defaultConnectionString = cfg.ConnectionString
}
fmt.Printf("Database connection string [%s]: ", defaultConnectionString)
fmt.Scanln(&cfg.ConnectionString)
if strings.TrimSpace(cfg.ConnectionString) == "" {
@ -182,10 +182,10 @@ func (cfg *Config) Setup() (error) {
}
defaultDatabaseCachePath := filepath.Join(cacheDir, "superhighway84", "database")
// Migration step from old CachePath to new DatabaseCachePath
if cfg.CachePath != "" {
defaultDatabaseCachePath = cfg.CachePath
}
// Migration step from old CachePath to new DatabaseCachePath
if cfg.CachePath != "" {
defaultDatabaseCachePath = cfg.CachePath
}
fmt.Printf("Database cache path [%s]: ", defaultDatabaseCachePath)
fmt.Scanln(&cfg.DatabaseCachePath)
if strings.TrimSpace(cfg.DatabaseCachePath) == "" {
@ -194,12 +194,12 @@ func (cfg *Config) Setup() (error) {
os.MkdirAll(filepath.Dir(cfg.DatabaseCachePath), 0755)
defaultProgramCachePath := filepath.Join(cacheDir, "superhighway84", "program")
// Migration step from old CachePath to new DatabaseCachePath
if cfg.CachePath != "" {
// If the previous CachePath was used, the folder already contains the
// OrbitDB, hence we need to find a different place
defaultProgramCachePath = filepath.Join(cacheDir, "superhighway84.program")
}
// Migration step from old CachePath to new DatabaseCachePath
if cfg.CachePath != "" {
// If the previous CachePath was used, the folder already contains the
// OrbitDB, hence we need to find a different place
defaultProgramCachePath = filepath.Join(cacheDir, "superhighway84.program")
}
fmt.Printf("Program cache path [%s]: ", defaultProgramCachePath)
fmt.Scanln(&cfg.ProgramCachePath)
if strings.TrimSpace(cfg.ProgramCachePath) == "" {
@ -208,9 +208,9 @@ func (cfg *Config) Setup() (error) {
os.MkdirAll(filepath.Dir(cfg.ProgramCachePath), 0755)
defaultLogfile := filepath.Join(cacheDir, "superhighway84.log")
if cfg.Logfile != "" {
defaultLogfile = cfg.Logfile
}
if cfg.Logfile != "" {
defaultLogfile = cfg.Logfile
}
fmt.Printf("Logfile path [%s]: ", defaultLogfile)
fmt.Scanln(&cfg.Logfile)
if strings.TrimSpace(cfg.Logfile) == "" {
@ -221,19 +221,19 @@ func (cfg *Config) Setup() (error) {
fmt.Printf("\nProfile information\n-------------------\n\n")
defaultProfileFrom := fmt.Sprintf("%s@localhost", os.Getenv("USER"))
if cfg.Profile.From != "" {
defaultProfileFrom = cfg.Profile.From
}
if cfg.Profile.From != "" {
defaultProfileFrom = cfg.Profile.From
}
fmt.Printf("From [%s]: ", defaultProfileFrom)
fmt.Scanln(&cfg.Profile.From)
if strings.TrimSpace(cfg.Profile.From) == "" {
cfg.Profile.From = defaultProfileFrom
}
defaultProfileOrganization := ""
if cfg.Profile.Organization != "" {
defaultProfileOrganization = cfg.Profile.Organization
}
defaultProfileOrganization := ""
if cfg.Profile.Organization != "" {
defaultProfileOrganization = cfg.Profile.Organization
}
fmt.Printf("Organization [%s]: ", defaultProfileOrganization)
fmt.Scanln(&cfg.Profile.Organization)

@ -1,26 +1,26 @@
package database
import (
"context"
"sort"
"sync"
orbitdb "berty.tech/go-orbit-db"
"berty.tech/go-orbit-db/accesscontroller"
"berty.tech/go-orbit-db/events"
"berty.tech/go-orbit-db/iface"
"berty.tech/go-orbit-db/stores"
"berty.tech/go-orbit-db/stores/documentstore"
config "github.com/ipfs/go-ipfs-config"
"github.com/ipfs/go-ipfs/core"
icore "github.com/ipfs/interface-go-ipfs-core"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/mitchellh/mapstructure"
"go.uber.org/zap"
"github.com/mrusme/superhighway84/cache"
"github.com/mrusme/superhighway84/models"
"context"
"sort"
"sync"
orbitdb "berty.tech/go-orbit-db"
"berty.tech/go-orbit-db/accesscontroller"
"berty.tech/go-orbit-db/events"
"berty.tech/go-orbit-db/iface"
"berty.tech/go-orbit-db/stores"
"berty.tech/go-orbit-db/stores/documentstore"
config "github.com/ipfs/go-ipfs-config"
"github.com/ipfs/go-ipfs/core"
icore "github.com/ipfs/interface-go-ipfs-core"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/mitchellh/mapstructure"
"go.uber.org/zap"
"github.com/mrusme/superhighway84/cache"
"github.com/mrusme/superhighway84/models"
)
type Database struct {
@ -97,27 +97,27 @@ func(db *Database) GetOwnPubKey() crypto.PubKey {
}
func(db *Database) connectToPeers() error {
var wg sync.WaitGroup
var wg sync.WaitGroup
peerInfos, err := config.DefaultBootstrapPeers()
if err != nil {
return err
}
wg.Add(len(peerInfos))
for _, peerInfo := range peerInfos {
go func(peerInfo *peer.AddrInfo) {
defer wg.Done()
err := db.IPFSCoreAPI.Swarm().Connect(db.ctx, *peerInfo)
if err != nil {
wg.Add(len(peerInfos))
for _, peerInfo := range peerInfos {
go func(peerInfo *peer.AddrInfo) {
defer wg.Done()
err := db.IPFSCoreAPI.Swarm().Connect(db.ctx, *peerInfo)
if err != nil {
db.Logger.Debug("failed to connect", zap.String("peerID", peerInfo.ID.String()), zap.Error(err))
} else {
} else {
db.Logger.Debug("connected!", zap.String("peerID", peerInfo.ID.String()))
}
}(&peerInfo)
}
wg.Wait()
return nil
}(&peerInfo)
}
wg.Wait()
return nil
}
func NewDatabase(
@ -142,8 +142,8 @@ func NewDatabase(
}
if err := setupPlugins(defaultPath); err != nil {
return nil, err
}
return nil, err
}
db.IPFSNode, db.IPFSCoreAPI, err = createNode(ctx, defaultPath)
if err != nil {
@ -168,14 +168,14 @@ func (db *Database) Connect(onReady func(address string)) (error) {
// }
// }
// go func() {
err = db.connectToPeers()
if err != nil {
// go func() {
err = db.connectToPeers()
if err != nil {
db.Logger.Debug("failed to connect: %s", zap.Error(err))
} else {
db.Logger.Debug("connected to peer!")
}
// }()
// }()
// log.Println(db.Store.ReplicationStatus().GetBuffered())
// log.Println(db.Store.ReplicationStatus().GetQueued())

@ -1,57 +1,57 @@
package database
import (
"context"
"fmt"
"os"
"path/filepath"
files "github.com/ipfs/go-ipfs-files"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreapi"
"github.com/ipfs/go-ipfs/core/node/libp2p"
"github.com/ipfs/go-ipfs/plugin/loader"
"github.com/ipfs/go-ipfs/repo/fsrepo"
icore "github.com/ipfs/interface-go-ipfs-core"
"github.com/mitchellh/mapstructure"
"context"
"fmt"
"os"
"path/filepath"
files "github.com/ipfs/go-ipfs-files"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreapi"
"github.com/ipfs/go-ipfs/core/node/libp2p"
"github.com/ipfs/go-ipfs/plugin/loader"
"github.com/ipfs/go-ipfs/repo/fsrepo"
icore "github.com/ipfs/interface-go-ipfs-core"
"github.com/mitchellh/mapstructure"
)
func setupPlugins(path string) error {
plugins, err := loader.NewPluginLoader(filepath.Join(path, "plugins"))
if err != nil {
return fmt.Errorf("error loading plugins: %s", err)
}
plugins, err := loader.NewPluginLoader(filepath.Join(path, "plugins"))
if err != nil {
return fmt.Errorf("error loading plugins: %s", err)
}
if err := plugins.Initialize(); err != nil {
return fmt.Errorf("error initializing plugins: %s", err)
}
if err := plugins.Initialize(); err != nil {
return fmt.Errorf("error initializing plugins: %s", err)
}
if err := plugins.Inject(); err != nil {
return fmt.Errorf("error initializing plugins: %s", err)
}
if err := plugins.Inject(); err != nil {
return fmt.Errorf("error initializing plugins: %s", err)
}
return nil
return nil
}
func createNode(ctx context.Context, repoPath string) (*core.IpfsNode, icore.CoreAPI, error) {
repo, err := fsrepo.Open(repoPath)
if err != nil {
return nil, nil, err
}
nodeOptions := &core.BuildCfg{
Online: true,
Routing: libp2p.DHTClientOption, // DHTOption
Repo: repo,
repo, err := fsrepo.Open(repoPath)
if err != nil {
return nil, nil, err
}
nodeOptions := &core.BuildCfg{
Online: true,
Routing: libp2p.DHTClientOption, // DHTOption
Repo: repo,
ExtraOpts: map[string]bool{
"pubsub": true,
},
}
}
node, err := core.NewNode(ctx, nodeOptions)
if err != nil {
return nil, nil, err
}
node, err := core.NewNode(ctx, nodeOptions)
if err != nil {
return nil, nil, err
}
coreAPI, err := coreapi.NewCoreAPI(node)
if err != nil {
@ -62,17 +62,17 @@ func createNode(ctx context.Context, repoPath string) (*core.IpfsNode, icore.Cor
}
func getUnixfsNode(path string) (files.Node, error) {
st, err := os.Stat(path)
if err != nil {
return nil, err
}
st, err := os.Stat(path)
if err != nil {
return nil, err
}
f, err := files.NewSerialFile(path, false, st)
if err != nil {
return nil, err
}
f, err := files.NewSerialFile(path, false, st)
if err != nil {
return nil, err
}
return f, nil
return f, nil
}
func structToMap(v interface{}) (map[string]interface{}, error) {

@ -1,10 +1,10 @@
package models
import (
"time"
"time"
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
)
type Article struct {

@ -1,24 +1,24 @@
package main
import (
"context"
"embed"
"encoding/json"
"net/http"
"net/url"
"os"
"runtime"
"strings"
"time"
"log"
"github.com/mrusme/superhighway84/cache"
"github.com/mrusme/superhighway84/config"
"github.com/mrusme/superhighway84/database"
"github.com/mrusme/superhighway84/models"
"github.com/mrusme/superhighway84/tui"
"go.uber.org/zap"
"context"
"embed"
"encoding/json"
"net/http"
"net/url"
"os"
"runtime"
"strings"
"time"
"log"
"github.com/mrusme/superhighway84/cache"
"github.com/mrusme/superhighway84/config"
"github.com/mrusme/superhighway84/database"
"github.com/mrusme/superhighway84/models"
"github.com/mrusme/superhighway84/tui"
"go.uber.org/zap"
)
//go:embed superhighway84.jpeg

@ -1,16 +1,16 @@
package tui
import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
"time"
"github.com/mrusme/superhighway84/models"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
"time"
"github.com/mrusme/superhighway84/models"
)
func MillisecondsToDate(ms int64) (string) {

@ -1,15 +1,15 @@
package tui
import (
"fmt"
"regexp"
"sort"
"strings"
"time"
"github.com/gdamore/tcell/v2"
"github.com/mrusme/superhighway84/models"
"github.com/rivo/tview"
"fmt"
"regexp"
"sort"
"strings"
"time"
"github.com/gdamore/tcell/v2"
"github.com/mrusme/superhighway84/models"
"github.com/rivo/tview"
)
var HEADER_LOGO =

@ -1,13 +1,13 @@
package tui
import (
"bytes"
"fmt"
"image/color"
"bytes"
"fmt"
"image/color"
"github.com/eliukblau/pixterm/pkg/ansimage"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"github.com/eliukblau/pixterm/pkg/ansimage"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
@ -22,9 +22,9 @@ func(t *TUI) NewSplashscreen(logo *[]byte) (*Splashscreen) {
splashscreen.T = t
canvas := tview.NewTextView().
SetDynamicColors(true).
SetRegions(true).
SetWrap(true)
SetDynamicColors(true).
SetRegions(true).
SetWrap(true)
canvas.SetBorder(false)
canvas.Clear()
@ -54,7 +54,7 @@ func(splashscreen *Splashscreen) Refresh() {
return
}
// splashscreen.Canvas.Clear()
fmt.Fprint(splashscreen.Canvas, tview.TranslateANSI(logoImage.RenderExt(false, false)))
fmt.Fprint(splashscreen.Canvas, tview.TranslateANSI(logoImage.RenderExt(false, false)))
}
func (splashscreen *Splashscreen) HandleInput(event *tcell.EventKey) (*tcell.EventKey) {

@ -1,19 +1,19 @@
package tui
import (
"embed"
"log"
"strconv"
"time"
"unicode"
"github.com/gdamore/tcell/v2"
"github.com/mrusme/superhighway84/cache"
"github.com/mrusme/superhighway84/common"
"github.com/mrusme/superhighway84/config"
"github.com/mrusme/superhighway84/models"
"github.com/rivo/tview"
"go.uber.org/zap"
"embed"
"log"
"strconv"
"time"
"unicode"
"github.com/gdamore/tcell/v2"
"github.com/mrusme/superhighway84/cache"
"github.com/mrusme/superhighway84/common"
"github.com/mrusme/superhighway84/config"
"github.com/mrusme/superhighway84/models"
"github.com/rivo/tview"
"go.uber.org/zap"
)
type TUI struct {
@ -121,17 +121,17 @@ func (t *TUI) getInputEvent(event *tcell.EventKey) (string) {
}
func (t *TUI) initInput() {
t.App.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
t.App.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
action := t.getInputEvent(event)
switch action {
case "refresh":
switch action {
case "refresh":
t.RefreshMainscreen()
t.SetInfo(true)
t.App.Sync()
return nil
case "quit":
t.App.Stop()
return nil
case "quit":
t.App.Stop()
return nil
case "play":
t.Player.Play()
@ -151,8 +151,8 @@ func (t *TUI) initInput() {
} else {
return t.Views[t.ActiveView].HandleInput(event)
}
}
})
}
})
}
func (t *TUI) Launch() {

Loading…
Cancel
Save