app

package
v0.0.0-...-5cffe04 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2023 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Overview

Date: 24/06/2019 Created By ybenel

Date: 23/06/2019 Created By ybenel

Date: 2023/07/25 Unfinished Middleware for authentication.

Date: 23/06/2019 Created By ybenel

Date: 21/06/2019 || 2023/09/11 Created By ybenel

Index

Constants

This section is empty.

Variables

View Source
var (
	//DefaultLoggerPrintFunc is fmt.Printf without return values
	DefaultLoggerPrintFunc = func(format string, data ...interface{}) {
		fmt.Printf(format+"\n", data...)
	}
)

Functions

func ParseFlags

func ParseFlags(cfg *Config)

Types

type App

type App struct {
	Config     *Config
	Middleware *Middleware
	Library    *media.Library
	Watcher    *fsnotify.Watcher
	Templates  *template.Template
	Tor        *tor
	Listener   net.Listener
	Router     *mux.Router
	Sessions   *sessions.CookieStore
	Mdata      MData
	Logger     *mylog.Logger
	Debug      *DebugConfig
}

App represents main application.

func NewApp

func NewApp(cfg *Config) (*App, error)

NewApp returns a new instance of App from Config.

func (*App) Deniedhandler

func (a *App) Deniedhandler(w http.ResponseWriter, r *http.Request, error *ErrorHandler)

func (*App) FailedSession

func (a *App) FailedSession(w http.ResponseWriter, r *http.Request)

Failed Sessions

func (*App) GetLogger

func (app *App) GetLogger() *mylog.Logger

Get Logger.

func (*App) MediaAcess

func (a *App) MediaAcess(w http.ResponseWriter, r *http.Request, m *media.Video) (bool, error)

Restricted Acesss and authentication

func (*App) Run

func (a *App) Run() error

Run imports the library and starts server.

func (*App) Unfoundhandler

func (a *App) Unfoundhandler(w http.ResponseWriter, r *http.Request)

404 Page handler

type Config

type Config struct {
	Library []*PathConfig `json:"library"`
	Server  *ServerConfig `json:"server"`
	Feed    *FeedConfig   `json:"feed"`
	Tor     *TorConfig    `json:"tor,omitempty"`
}

Config settings for main App.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns Config initialized with default values.

func (*Config) ReadFile

func (c *Config) ReadFile(path string) error

ReadFile reads a JSON file into Config.

type DebugConfig

type DebugConfig struct {
	Config *errlog.Config
	Logger errlog.Logger
}

func (*DebugConfig) DefaultConfig

func (Conf *DebugConfig) DefaultConfig() *errlog.Config

func (*DebugConfig) NewDebug

func (c *DebugConfig) NewDebug() errlog.Logger

type ErrorHandler

type ErrorHandler struct {
	Error string
}

type FeedConfig

type FeedConfig struct {
	ExternalURL string `json:"external_url"`
	Title       string `json:"title"`
	Link        string `json:"link"`
	Description string `json:"description"`
	Author      struct {
		Name  string `json:"name"`
		Email string `json:"email"`
	} `json:"author"`
	Copyright string `json:"copyright"`
}

FeedConfig settings for App Feed.

type MData

type MData struct {
	Email string
}

func (*MData) Validate

func (data *MData) Validate() (string, error)

type Middleware

type Middleware struct {
	AppInstance *App
	DB          *sql.DB
}

func (*Middleware) AuthMiddleware

func (m *Middleware) AuthMiddleware(next http.Handler) http.Handler

Main Middleware

func (*Middleware) AuthenticateAndSetSession

func (m *Middleware) AuthenticateAndSetSession(username, password string, w http.ResponseWriter, r *http.Request) bool

Function to authenticate a user and set the session

func (*Middleware) InitializeDB

func (m *Middleware) InitializeDB() error

Initialize the SQLite database connection

func (*Middleware) SignUpAndSetSession

func (m *Middleware) SignUpAndSetSession(name, password, email string, w http.ResponseWriter, r *http.Request) (bool, error)

Sign up and set set a session

type PathConfig

type PathConfig struct {
	Path    string `json:"path"`
	Prefix  string `json:"prefix"`
	Private bool   `json:"private"`
}

PathConfig settings for media library path.

type ServerConfig

type ServerConfig struct {
	Host string `json:"host"`
	Port int    `json:"port"`
}

ServerConfig settings for App Server.

type TorConfig

type TorConfig struct {
	Enable     bool                 `json:"enable"`
	Controller *TorControllerConfig `json:"controller"`
}

TorConfig stores tor configuration.

type TorControllerConfig

type TorControllerConfig struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Password string `json:"password,omitempty"`
}

TorControllerConfig stores tor controller configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL