config

package
v0.0.0-...-1709d23 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "development"

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DB contains database connection config.
	DB DB `json:"db"`
	// SocketFile contains path to socket.
	SocketFile string `json:"socket_file"`
	// Server contains API server config.
	Server *Server `json:"server"`
	// Security contains security config.
	Security *Security `json:"security"`
	// LogLevel contains level of logging.
	//
	// You can use following values:
	//  * debug
	//  * info (default)
	//  * warn
	//  * error
	//  * off
	LogLevel LogLevel `json:"log_level,omitempty"`
}

Config stores configuration for GoQuiz.

func LoadFromFile

func LoadFromFile(file string) (Config, error)

LoadFromFile loads configuration from json file.

type DB

type DB struct {
	// Options contains options for database driver.
	//
	// For SQLiteDriver field should contains SQLiteOptions.
	// For PostgresDriver field should contains PostgresOptions.
	Options any
}

DB stores configuration for database connection.

func (*DB) Create

func (c *DB) Create() (*gosql.DB, error)

Create creates database connection using current configuration.

func (DB) MarshalJSON

func (c DB) MarshalJSON() ([]byte, error)

func (*DB) UnmarshalJSON

func (c *DB) UnmarshalJSON(bytes []byte) error

UnmarshalJSON parses JSON to create appropriate connection configuration.

type DBDriver

type DBDriver string

DBDriver represents database driver name.

const (
	// SQLiteDriver represents SQLite driver.
	SQLiteDriver DBDriver = "sqlite"
	// PostgresDriver represents Postgres driver.
	PostgresDriver DBDriver = "postgres"
)

type LogLevel

type LogLevel = config.LogLevel

type PostgresOptions

type PostgresOptions struct {
	// Hosts contains hosts addresses.
	Hosts []string `json:"hosts"`
	// Port contains port address.
	Port int `json:"port"`
	// User contains username of user.
	User string `json:"user"`
	// Password contains password of user.
	Password string `json:"password"`
	// Name contains name of database.
	Name string `json:"name"`
	// SSLMode contains sslmode configuration.
	SSLMode string `json:"sslmode"`
}

PostgresOptions stores Postgres connection options.

type SQLiteOptions

type SQLiteOptions struct {
	// Path contains path to SQLite database file.
	Path string `json:"path"`
}

SQLiteOptions stores SQLite connection options.

type Security

type Security struct {
	// PasswordSalt contains salt for password hashing.
	PasswordSalt string `json:"password_salt"`
}

Security contains security config.

type Server

type Server struct {
	// Host contains server host.
	Host string `json:"host"`
	// Port contains server port.
	Port int `json:"port"`
	// Static contains path to static files.
	Static string `json:"static"`
}

Server contains server config.

func (Server) Address

func (s Server) Address() string

Address returns string representation of server address.

Jump to

Keyboard shortcuts

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