config

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

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

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

Documentation

Overview

Package config holds and assists in the configuration of a writefreely instance.

Index

Constants

View Source
const (
	// FileName is the default configuration file name
	FileName = "config.ini"

	UserNormal UserType = "user"
	UserAdmin           = "admin"
)

Variables

This section is empty.

Functions

func DefaultHTTPClient

func DefaultHTTPClient() *http.Client

DefaultHTTPClient returns a sane default HTTP client.

func OrDefaultString

func OrDefaultString(input, defaultValue string) string

OrDefaultString returns input or a default value if input is empty.

func Save

func Save(uc *Config, fname string) error

Save writes the given Config to the given file.

Types

type AppCfg

type AppCfg struct {
	SiteName string `ini:"site_name"`
	SiteDesc string `ini:"site_description"`
	Host     string `ini:"host"`

	// Site appearance
	Theme      string `ini:"theme"`
	Editor     string `ini:"editor"`
	JSDisabled bool   `ini:"disable_js"`
	WebFonts   bool   `ini:"webfonts"`
	Landing    string `ini:"landing"`
	SimpleNav  bool   `ini:"simple_nav"`
	WFModesty  bool   `ini:"wf_modesty"`

	// Site functionality
	Chorus        bool `ini:"chorus"`
	Forest        bool `ini:"forest"` // The admin cares about the forest, not the trees. Hide unnecessary technical info.
	DisableDrafts bool `ini:"disable_drafts"`

	// Users
	SingleUser       bool `ini:"single_user"`
	OpenRegistration bool `ini:"open_registration"`
	OpenDeletion     bool `ini:"open_deletion"`
	MinUsernameLen   int  `ini:"min_username_len"`
	MaxBlogs         int  `ini:"max_blogs"`

	// Options for public instances
	// Federation
	Federation   bool `ini:"federation"`
	PublicStats  bool `ini:"public_stats"`
	Monetization bool `ini:"monetization"`
	NotesOnly    bool `ini:"notes_only"`

	// Access
	Private bool `ini:"private"`

	// Additional functions
	LocalTimeline bool   `ini:"local_timeline"`
	UserInvites   string `ini:"user_invites"`

	// Defaults
	DefaultVisibility string `ini:"default_visibility"`

	// Check for Updates
	UpdateChecks bool `ini:"update_checks"`

	// Disable password authentication if use only Oauth
	DisablePasswordAuth bool `ini:"disable_password_auth"`

	// Which Markdown renderer to use
	Renderer string `ini:"markdown_renderer"`

	// Options for the Goldmark renderer
	RendererOptions string `ini:"markdown_options"`
	// contains filtered or unexported fields
}

AppCfg holds values that affect how the application functions

func (AppCfg) CanCreateBlogs

func (ac AppCfg) CanCreateBlogs(currentlyUsed uint64) bool

func (AppCfg) FriendlyHost

func (ac AppCfg) FriendlyHost() string

FriendlyHost returns the app's Host sans any schema

func (*AppCfg) LandingPath

func (ac *AppCfg) LandingPath() string

func (AppCfg) MarkdownRenderer

func (ac AppCfg) MarkdownRenderer() string

func (AppCfg) RendererExtensions

func (ac AppCfg) RendererExtensions() []goldmark.Extender

func (AppCfg) SignupPath

func (ac AppCfg) SignupPath() string

type Config

type Config struct {
	Server       ServerCfg       `ini:"server"`
	Database     DatabaseCfg     `ini:"database"`
	App          AppCfg          `ini:"app"`
	SlackOauth   SlackOauthCfg   `ini:"oauth.slack"`
	WriteAsOauth WriteAsOauthCfg `ini:"oauth.writeas"`
	GitlabOauth  GitlabOauthCfg  `ini:"oauth.gitlab"`
	GiteaOauth   GiteaOauthCfg   `ini:"oauth.gitea"`
	GenericOauth GenericOauthCfg `ini:"oauth.generic"`
}

Config holds the complete configuration for running a writefreely instance

func Load

func Load(fname string) (*Config, error)

Load reads the given configuration file, then parses and returns it as a Config.

func New

func New() *Config

New creates a new Config with sane defaults

func (*Config) IsSecureStandalone

func (cfg *Config) IsSecureStandalone() bool

IsSecureStandalone returns whether or not the application is running as a standalone server with TLS enabled.

func (*Config) UseMySQL

func (cfg *Config) UseMySQL(fresh bool)

UseMySQL resets the Config's Database to use default values for a MySQL setup.

func (*Config) UseSQLite

func (cfg *Config) UseSQLite(fresh bool)

UseSQLite resets the Config's Database to use default values for a SQLite setup.

type DatabaseCfg

type DatabaseCfg struct {
	Type     string `ini:"type"`
	FileName string `ini:"filename"`
	User     string `ini:"username"`
	Password string `ini:"password"`
	Database string `ini:"database"`
	Host     string `ini:"host"`
	Port     int    `ini:"port"`
	TLS      bool   `ini:"tls"`
}

DatabaseCfg holds values that determine how the application connects to a datastore

type GenericOauthCfg

type GenericOauthCfg struct {
	ClientID         string `ini:"client_id"`
	ClientSecret     string `ini:"client_secret"`
	Host             string `ini:"host"`
	DisplayName      string `ini:"display_name"`
	CallbackProxy    string `ini:"callback_proxy"`
	CallbackProxyAPI string `ini:"callback_proxy_api"`
	TokenEndpoint    string `ini:"token_endpoint"`
	InspectEndpoint  string `ini:"inspect_endpoint"`
	AuthEndpoint     string `ini:"auth_endpoint"`
	Scope            string `ini:"scope"`
	AllowDisconnect  bool   `ini:"allow_disconnect"`
	MapUserID        string `ini:"map_user_id"`
	MapUsername      string `ini:"map_username"`
	MapDisplayName   string `ini:"map_display_name"`
	MapEmail         string `ini:"map_email"`
}

type GiteaOauthCfg

type GiteaOauthCfg struct {
	ClientID         string `ini:"client_id"`
	ClientSecret     string `ini:"client_secret"`
	Host             string `ini:"host"`
	DisplayName      string `ini:"display_name"`
	CallbackProxy    string `ini:"callback_proxy"`
	CallbackProxyAPI string `ini:"callback_proxy_api"`
}

type GitlabOauthCfg

type GitlabOauthCfg struct {
	ClientID         string `ini:"client_id"`
	ClientSecret     string `ini:"client_secret"`
	Host             string `ini:"host"`
	DisplayName      string `ini:"display_name"`
	CallbackProxy    string `ini:"callback_proxy"`
	CallbackProxyAPI string `ini:"callback_proxy_api"`
}

type ServerCfg

type ServerCfg struct {
	HiddenHost string `ini:"hidden_host"`
	WWWPort    int    `ini:"port"`
	Bind       string `ini:"bind"`

	TLSCertPath string `ini:"tls_cert_path"`
	TLSKeyPath  string `ini:"tls_key_path"`
	Autocert    bool   `ini:"autocert"`

	TemplatesParentDir string `ini:"templates_parent_dir"`
	StaticParentDir    string `ini:"static_parent_dir"`
	PagesParentDir     string `ini:"pages_parent_dir"`
	KeysParentDir      string `ini:"keys_parent_dir"`

	HashSeed string `ini:"hash_seed"`

	GopherPort int `ini:"gopher_port"`

	Dev bool `ini:"-"`
}

ServerCfg holds values that affect how the HTTP server runs

type SetupData

type SetupData struct {
	User   *UserCreation
	Config *Config
}

func Configure

func Configure(fname string, configSections string) (*SetupData, error)

type SlackOauthCfg

type SlackOauthCfg struct {
	ClientID         string `ini:"client_id"`
	ClientSecret     string `ini:"client_secret"`
	TeamID           string `ini:"team_id"`
	CallbackProxy    string `ini:"callback_proxy"`
	CallbackProxyAPI string `ini:"callback_proxy_api"`
}

type UserCreation

type UserCreation struct {
	Username   string
	HashedPass []byte
}

type UserType

type UserType string

type WriteAsOauthCfg

type WriteAsOauthCfg struct {
	ClientID         string `ini:"client_id"`
	ClientSecret     string `ini:"client_secret"`
	AuthLocation     string `ini:"auth_location"`
	TokenLocation    string `ini:"token_location"`
	InspectLocation  string `ini:"inspect_location"`
	CallbackProxy    string `ini:"callback_proxy"`
	CallbackProxyAPI string `ini:"callback_proxy_api"`
}

Jump to

Keyboard shortcuts

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