combluotion/app.go

82 lines
1.3 KiB
Go
Raw Normal View History

2024-09-12 16:40:31 -05:00
package lenore
import (
"errors"
"fmt"
"codeberg.org/danjones000/lenore/config"
2024-09-14 11:27:28 -05:00
"codeberg.org/danjones000/lenore/store"
2024-09-12 16:40:31 -05:00
vocab "github.com/go-ap/activitypub"
"github.com/go-ap/client"
boxap "github.com/go-ap/fedbox/activitypub"
)
type App struct {
conf config.Config
self vocab.Service
user vocab.Person
version string
2024-09-14 11:27:28 -05:00
storage store.Store
2024-09-12 16:40:31 -05:00
client client.C
}
2024-09-14 11:27:28 -05:00
func NewApp(ver string, conf config.Config, db store.Store) (*App, error) {
2024-09-12 16:40:31 -05:00
if conf.BaseURL == "" {
return nil, errors.New("Missing BaseURL")
}
app := App{
version: ver,
2024-09-13 17:45:06 -05:00
conf: conf,
2024-09-12 16:40:31 -05:00
}
selfIRI := boxap.DefaultServiceIRI(conf.BaseURL)
self, err := boxap.LoadActor(db, selfIRI)
if err != nil {
return nil, err
}
app.self = self
app.client = *client.New()
return &app, nil
}
func (l *App) Config() config.Config {
return l.conf
}
2024-09-13 17:45:06 -05:00
func (l *App) Environment() config.Env {
return l.conf.Environment()
}
2024-09-14 11:27:28 -05:00
func (l *App) Storage() store.Store {
2024-09-12 16:40:31 -05:00
return l.storage
}
func (l *App) Service() vocab.Service {
return l.self
}
func (l *App) ServiceIRI() vocab.IRI {
return l.self.ID
}
func (l *App) User() vocab.Actor {
return l.user
}
func (l *App) Version() string {
return l.version
}
2024-09-13 17:45:06 -05:00
func (l *App) Name() string {
if l.conf.Name == "" {
return "Lenore"
}
return l.conf.Name
}
2024-09-12 16:40:31 -05:00
func (l *App) String() string {
2024-09-13 17:45:06 -05:00
return fmt.Sprintf("%s (%s)", l.Name(), l.version)
2024-09-12 16:40:31 -05:00
}