config

package
v3.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2016 License: AGPL-3.0, AGPL-3.0-or-later Imports: 8 Imported by: 0

Documentation

Overview

Package config stores and exports the configuration for server-side use and the public availability JSON struct, which includes a small subset of the server configuration.

Index

Constants

This section is empty.

Variables

View Source
var (

	// AllBoardConfigs stores board-specific configurations for the /all/
	// metaboard. Constant.
	AllBoardConfigs = BoardConfContainer{
		BoardConfigs: BoardConfigs{
			ID: "all",
			BoardPublic: BoardPublic{
				PostParseConfigs: PostParseConfigs{
					HashCommands: true,
				},
				CodeTags: true,
				Spoiler:  "default.jpg",
				Title:    "Aggregator metaboard",
				Banners:  []string{},
			},
		},
		Hash: "0",
	}

	// Defaults contains the default server configuration values
	Defaults = Configs{
		ThreadExpiry:  14,
		BoardExpiry:   7,
		JPEGQuality:   80,
		MaxSize:       5,
		MaxHeight:     6000,
		MaxWidth:      6000,
		SessionExpiry: 30,
		Salt:          "LALALALALALALALALALALALALALALALALALALALA",
		FeedbackEmail: "admin@email.com",
		RootURL:       "http://localhost",
		FAQ:           defaultFAQ,
		Public: Public{
			DefaultCSS:  "moe",
			DefaultLang: "en_GB",
			Links:       map[string]string{"4chan": "http://www.4chan.org/"},
		},
	}

	// EightballDefaults contains the default eightball answer set
	EightballDefaults = []string{
		"Yes",
		"No",
		"Maybe",
		"It can't be helped",
		"Hell yeah, motherfucker!",
		"Anta baka?",
	}
)

Functions

func Clear

func Clear()

Clear resets package state. Only use in tests.

func ClearBoards

func ClearBoards()

ClearBoards clears any existing board configuration entries. Only use in tests.

func GetBoards

func GetBoards() []string

GetBoards returns an array of currently existing boards

func GetClient

func GetClient() ([]byte, string)

GetClient returns public availability configuration JSON and a truncated configuration MD5 hash

func IsBoard

func IsBoard(b string) bool

IsBoard returns whether the passed string is a currently existing board

func RemoveBoard

func RemoveBoard(b string)

RemoveBoard removes a board from the exiting board list and deletes its configurations. To be called, when a board is deleted.

func Set

func Set(c Configs) error

Set sets the internal configuration struct

func SetBoardConfigs

func SetBoardConfigs(conf BoardConfigs) (bool, error)

SetBoardConfigs sets configurations for a specific board as well as pregenerates their public JSON and hash. Returns if any changes were made to the configs in result.

func SetClient

func SetClient(json []byte, cHash string)

SetClient sets the client configuration JSON and hash. To be used only in tests.

Types

type BoardConfContainer

type BoardConfContainer struct {
	BoardConfigs
	JSON []byte
	Hash string
}

BoardConfContainer contains configurations for an individual board as well as pregenerated public JSON and it's hash

func GetAllBoardConfigs

func GetAllBoardConfigs() []BoardConfContainer

GetAllBoardConfigs returns board-specific configurations for all boards. Do not modify the retrieved structs.

func GetBoardConfigs

func GetBoardConfigs(b string) BoardConfContainer

GetBoardConfigs returns board-specific configurations for a board combined with pregenerated public JSON of these configurations and their hash. Do not modify the retrieved struct.

func (*BoardConfContainer) MarshalJSON added in v3.1.0

func (mj *BoardConfContainer) MarshalJSON() ([]byte, error)

func (*BoardConfContainer) MarshalJSONBuf added in v3.1.0

func (mj *BoardConfContainer) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type BoardConfigs

type BoardConfigs struct {
	BoardPublic
	ID        string              `json:"id" gorethink:"id"`
	Eightball []string            `json:"eightball" gorethink:"eightball"`
	Staff     map[string][]string `json:"staff" gorethink:"staff"`
}

BoardConfigs stores board-specific configuration

func (*BoardConfigs) MarshalJSON added in v3.1.0

func (mj *BoardConfigs) MarshalJSON() ([]byte, error)

func (*BoardConfigs) MarshalJSONBuf added in v3.1.0

func (mj *BoardConfigs) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type BoardPublic

type BoardPublic struct {
	PostParseConfigs
	CodeTags bool     `json:"codeTags" gorethink:"codeTags"`
	Spoiler  string   `json:"spoiler" gorethink:"spoiler"`
	Title    string   `json:"title" gorethink:"title"`
	Notice   string   `json:"notice" gorethink:"notice"`
	Rules    string   `json:"rules" gorethink:"rules"`
	Banners  []string `json:"banners" gorethink:"banners"`
}

BoardPublic contains publically accessible board-specific configurations

func (*BoardPublic) MarshalJSON added in v3.1.0

func (mj *BoardPublic) MarshalJSON() ([]byte, error)

func (*BoardPublic) MarshalJSONBuf added in v3.1.0

func (mj *BoardPublic) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type BoardTitle

type BoardTitle struct {
	ID    string `json:"id"`
	Title string `json:"title"`
}

BoardTitle contains a board's ID and title

func (*BoardTitle) MarshalJSON added in v3.1.0

func (mj *BoardTitle) MarshalJSON() ([]byte, error)

func (*BoardTitle) MarshalJSONBuf added in v3.1.0

func (mj *BoardTitle) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type BoardTitles

type BoardTitles []BoardTitle

BoardTitles implements sort.Interface

func GetBoardTitles

func GetBoardTitles() BoardTitles

GetBoardTitles returns a slice of all existing boards and their titles

func (BoardTitles) Len

func (b BoardTitles) Len() int

func (BoardTitles) Less

func (b BoardTitles) Less(i, j int) bool

func (BoardTitles) Swap

func (b BoardTitles) Swap(i, j int)

type Configs

type Configs struct {
	Public
	PruneThreads      bool `json:"pruneThreads" gorethink:"pruneThreads"`
	PruneBoards       bool `json:"pruneBoards" gorethink:"pruneBoards"`
	Pyu               bool `json:"pyu" gorethink:"pyu"`
	JPEGQuality       uint8
	MaxWidth          uint16 `json:"maxWidth" gorethink:"maxWidth"`
	MaxHeight         uint16 `json:"maxHeight" gorethink:"maxHeight"`
	ThreadExpiry      uint   `json:"threadExpiry" gorethink:"threadExpiry"`
	BoardExpiry       uint   `json:"boardExpiry" gorethink:"boardExpiry"`
	MaxSize           uint   `json:"maxSize" gorethink:"maxSize"`
	SessionExpiry     uint   `json:"sessionExpiry" gorethink:"sessionExpiry"`
	RootURL           string `json:"rootURL" gorethink:"rootURL"`
	Salt              string `json:"salt" gorethink:"salt"`
	FeedbackEmail     string `json:"feedbackEmail" gorethink:"feedbackEmail"`
	CaptchaPrivateKey string `json:"captchaPrivateKey" gorethink:"captchaPrivateKey"`
	FAQ               string
}

Configs stores the global server configuration

func Get

func Get() *Configs

Get returns a pointer to the current server configuration struct. Callers should not modify this struct.

func (*Configs) MarshalJSON added in v3.1.0

func (mj *Configs) MarshalJSON() ([]byte, error)

func (*Configs) MarshalJSONBuf added in v3.1.0

func (mj *Configs) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type DatabaseBoardConfigs

type DatabaseBoardConfigs struct {
	BoardConfigs
	Created time.Time `gorethink:"created"`
}

DatabaseBoardConfigs contains extra fields not exposed on database reads

func (*DatabaseBoardConfigs) MarshalJSON added in v3.1.0

func (mj *DatabaseBoardConfigs) MarshalJSON() ([]byte, error)

func (*DatabaseBoardConfigs) MarshalJSONBuf added in v3.1.0

func (mj *DatabaseBoardConfigs) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type PostParseConfigs

type PostParseConfigs struct {
	ReadOnly     bool `json:"readOnly" gorethink:"readOnly"`
	TextOnly     bool `json:"textOnly" gorethink:"textOnly"`
	ForcedAnon   bool `json:"forcedAnon" gorethink:"forcedAnon"`
	HashCommands bool `json:"hashCommands" gorethink:"hashCommands"`
}

PostParseConfigs contains board-specific flags for post text parsing

func (*PostParseConfigs) MarshalJSON added in v3.1.0

func (mj *PostParseConfigs) MarshalJSON() ([]byte, error)

func (*PostParseConfigs) MarshalJSONBuf added in v3.1.0

func (mj *PostParseConfigs) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type Public

type Public struct {
	Captcha          bool              `json:"captcha" gorethink:"captcha"`
	Mature           bool              `json:"mature" gorethink:"mature"`
	DefaultLang      string            `json:"defaultLang" gorethink:"defaultLang"`
	DefaultCSS       string            `json:"defaultCSS" gorethink:"defaultCSS"`
	CaptchaPublicKey string            `json:"captchaPublicKey" gorethink:"captchaPublicKey"`
	Links            map[string]string `json:"links" gorethink:"links"`
}

Public contains configurations exposeable through public availability APIs

func (*Public) MarshalJSON added in v3.1.0

func (mj *Public) MarshalJSON() ([]byte, error)

func (*Public) MarshalJSONBuf added in v3.1.0

func (mj *Public) MarshalJSONBuf(buf fflib.EncodingBuffer) error

Jump to

Keyboard shortcuts

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