config

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2021 License: GPL-3.0, GPL-3.0-or-later Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultPageTitle templates this title into the page so you can change title as required
	DefaultPageTitle = "8k.fyi"
	// DefaultAccentColour templates this colour into the HTML to accent the page with this colour
	DefaultAccentColour = "#FF8C00"
	// DefaultMaxBytes is the max bytes that the site will accept. This is enforced both in the frontend and the backend (because we don't trust the client)
	DefaultMaxBytes = 8192
	// DefaultMaxItems is the max number of items the site will accept. This multiplied by the MaxBytes gives a value for storage requirement.
	DefaultMaxItems = 1000
	// DefaultPathLength is used to set the length of autogenerated paths for the link address
	DefaultPathLength = 8

	// DefaultBindTLS sets whether the server should bind TLS by default
	DefaultBindTLS = false
	// DefaultBindAddress is the default address to bind the server to. Empty bind will bind all available addresses
	DefaultBindAddress = ""
	// DefaultBindPort is the dedault port to bind the server to.
	DefaultBindPort = 8192

	// DefaultPublicProtoTLS is used if you're terminating TLS at a reverse proxy (e.g. NGINX, Apache)
	// This proto is templated into the HTML for public use
	DefaultPublicProtoTLS = DefaultBindTLS
	// DefaultPublicAddress is used if you're NATing (e.g. Docker) and your public address is different from the bind address
	// This address is templated into the HTML for public use
	DefaultPublicAddress = ""
	// DefaultPublicPort is used if you're NATing (e.g. Docker) and your public port is different from the bind port
	// This port is templated into the HTML for public use
	DefaultPublicPort = 8192

	// DefaultTTL is the default expiry time for data in storage
	DefaultTTL = time.Minute * 60

	// DefaultTLSCertFilePath is the default path for the TLS certificate file
	DefaultTLSCertFilePath = "/tls/public.crt"
	// DefaultTLSKeyFilePath is the default path for the TLS key file
	DefaultTLSKeyFilePath = "/tls/private.key"

	// DefaultIndexFilePath is the default location for the html frontend
	DefaultIndexFilePath = ""
)

Variables

View Source
var (
	// Version of the server. Set at build time using -ldflags "-X github.com/2bytes/8k/internal/config.Version=<version number>"
	Version = "development"

	// ShowVersion displays the version and exits, when provided
	ShowVersion = flag.Bool("v", false, "show version")

	//DataTTL sets the time to keep data before deleting
	DataTTL = flag.Duration("ttl", DefaultTTL, "the time before an uploaded data item expires and is deleted")

	// PageTitle allows overriding the default page title in the UI
	PageTitle = flag.String("title", DefaultPageTitle, "set the title of the web page")
	// AccentColour allows overriding the beautiful orange accent colour
	AccentColour = flag.String("accent-colour", DefaultAccentColour, "set the accent colour for the web page")
	// MaxBytes allows overriding the carefully chosen 8192 byte limit for uploads
	MaxBytes = flag.Int("mb", DefaultMaxBytes, "override the max bytes count")
	//MaxItemsStored sets the maximum number of items to store before disallowing any further storage until some have been scrubber
	MaxItemsStored = flag.Int("mi", DefaultMaxItems, "set the maximum number of items to store before disallowing")
	// PathLength is used to set the length of the auto-generated path part of the URL
	PathLength = flag.Int("pl", DefaultPathLength, "override autogenerated path length")
	// BindTLS enables TLS directly in the server. Do not enable this if using a reverse proxy such as Nginx/Traefik
	BindTLS = flag.Bool("https", DefaultBindTLS, "enable TLS")
	// BindAddress overrides the default bind address
	BindAddress = flag.String("addr", DefaultBindAddress, "set the bind address")
	// BindPort overrides the default bind port of the server
	BindPort = flag.Int("port", DefaultBindPort, "set the bind port")

	// PublicProtoTLS sets whether to use 'https' for links in the UI
	PublicProtoTLS = flag.Bool("ui-https", false, "UI: use 'https' as the proto displayed in the UI text/links")
	// PublicAddress sets the address or hostname used in the UI
	PublicAddress = flag.String("ui-addr", DefaultPublicAddress, "UI: set the public address displayed in the UI text/links")
	// PublicPort sets the port used in the UI
	PublicPort = flag.Int(("ui-port"), DefaultPublicPort, "UI: set the public port displayed in the UI/text/links")

	// UIFileHTML is the path to the HTML file for the UI
	UIFileHTML = flag.String("html", DefaultIndexFilePath, "set the path to the index html template file for the frontend to override the embedded html")

	// TLSCertFile set the location of the TLS certificate file for binding TLS
	TLSCertFile = flag.String("tls-cert", DefaultTLSCertFilePath, "path to the TLS certificate")
	// TLSKeyFile sets the location of the TLS key file for binding TLS
	TLSKeyFile = flag.String("tls-key", DefaultTLSKeyFilePath, "path to the TLS key")
)

Functions

func FormatTime

func FormatTime(t time.Duration) string

FormatTime provides a human readable time string given a time.Duration

Types

type Config

type Config struct {
	Title          string
	AccentColour   string
	ProtoTLS       bool
	Address        string
	Port           int
	PathLength     int
	BindTLS        bool
	MaxBytes       int
	MaxItemsStored int
	// contains filtered or unexported fields
}

Config holds the server configuration

func Get

func Get() *Config

Get returns the configuration flags for the server

func (*Config) FormatBaseAddress

func (c *Config) FormatBaseAddress() string

FormatBaseAddress returns the public base address of the server given the server config it ignores the port if it's default for the given protocol

func (*Config) FormattedTime

func (c *Config) FormattedTime() string

FormattedTime returns a human readable formatted time for display

Jump to

Keyboard shortcuts

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