70 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			70 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
|  | package lenore | ||
|  | 
 | ||
|  | import ( | ||
|  | 	"errors" | ||
|  | 	"fmt" | ||
|  | 
 | ||
|  | 	"codeberg.org/danjones000/lenore/config" | ||
|  | 	vocab "github.com/go-ap/activitypub" | ||
|  | 	"github.com/go-ap/client" | ||
|  | 	boxap "github.com/go-ap/fedbox/activitypub" | ||
|  | 	proc "github.com/go-ap/processing" | ||
|  | ) | ||
|  | 
 | ||
|  | type App struct { | ||
|  | 	conf    config.Config | ||
|  | 	self    vocab.Service | ||
|  | 	user    vocab.Person | ||
|  | 	version string | ||
|  | 	storage proc.Store | ||
|  | 	client  client.C | ||
|  | } | ||
|  | 
 | ||
|  | func NewApp(ver string, conf config.Config, db proc.Store) (*App, error) { | ||
|  | 	if conf.BaseURL == "" { | ||
|  | 		return nil, errors.New("Missing BaseURL") | ||
|  | 	} | ||
|  | 	app := App{ | ||
|  | 		version: ver, | ||
|  | 	} | ||
|  | 
 | ||
|  | 	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 | ||
|  | } | ||
|  | 
 | ||
|  | func (l *App) Storage() proc.Store { | ||
|  | 	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 | ||
|  | } | ||
|  | 
 | ||
|  | func (l *App) String() string { | ||
|  | 	return fmt.Sprintf("Lenore (%s)", l.version) | ||
|  | } |