common

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PROTECTED_FILE_MODE is the expected file mode for protected files
	PROTECTED_FILE_MODE = 0o600

	// PROTECTED_FOLDER_MODE is the expected file mode for protected folders
	PROTECTED_FOLDER_MODE = 0o700

	// OPEN_FILE_MODE is the default file mode for open files
	OPEN_FILE_MODE = 0o644

	// OPEN_FOLDER_MODE is the default file mode for open folders
	OPEN_FOLDER_MODE = 0o755
)
View Source
const CHALLENGE_ID_LENGTH = 32

CHALLENGE_ID_LENGTH is the length of the challenge ID (in bytes)

View Source
const CHALLENGE_STATE_LENGTH = 32

CHALLENGE_STATE_LENGTH is the length of the challenge OAuth state (in bytes)

View Source
const VERIFICATION_CODE_LENGTH = 6

VERIFICATION_CODE_LENGTH is the length of the code (in decimal digits)

Variables

View Source
var About = fmt.Sprintf("%s (Build %s@%s at %s with %s)", Version, Commit, Branch, Timestamp.Format(time.RFC3339), runtime.Version())

About is the about string

View Source
var Branch = rawBranch

Branch is the branch the application was built from

View Source
var Commit = rawCommit

Commit is the commit the application was built from

View Source
var DEBUG = LogLevel(slog.LevelDebug.String())

LogLevel constants

View Source
var ERROR = LogLevel(slog.LevelError.String())
View Source
var INFO = LogLevel(slog.LevelInfo.String())
View Source
var Timestamp = lo.Must(time.Parse(time.RFC3339, rawTimestamp))

Timestamp is the time the application was built

View Source
var Version = lo.Must(version.NewSemver(rawVersion))

Version is the version of the application

View Source
var VersionConstraint = lo.Must(version.NewConstraint(fmt.Sprintf("~> %d.%d", Version.Segments()[0], Version.Segments()[1])))

VersionConstraint is the version constraint of the application

View Source
var WARN = LogLevel(slog.LevelWarn.String())

Functions

func DecodeCert

func DecodeCert(raw []byte) (*pem.Block, error)

DecodeCert decodes a certificate from a PEM-encoded byte array

func DecodeKey

func DecodeKey(raw []byte) (*pem.Block, error)

DecodeKey decodes a private key from a PEM-encoded byte array

func EncodeCert

func EncodeCert(raw []byte) ([]byte, error)

EncodeCert encodes a certificate into a PEM-encoded byte array

func EncodeKey

func EncodeKey(raw []byte) ([]byte, error)

EncodeKey encodes a private key into a PEM-encoded byte array

func EnsureProtectedFile

func EnsureProtectedFile(name string, relative string) error

EnsureProtectedFile ensures that the file at the specified path is protected

func InitLogger

func InitLogger(rawLevel LogLevel, rawOutput LogOutput, rawFile string, relative string) (func(), error)

InitLogger intializes a new slog logger, returning a cleanup function and an error (if any)

func MakeDirs

func MakeDirs(name string, relative string, folderPerm os.FileMode) error

MakeDirs makes the directories for the specified path

func ParseLogLevel

func ParseLogLevel(rawLevel LogLevel) (slog.Level, error)

ParseLogLevel parses a log level

func SafeCreate

func SafeCreate(name string, relative string, data []byte, filePerm os.FileMode, folderPerm os.FileMode, mode SafeOpenMode) error

SafeCreate safely creates a new file with the specified data

func SafeOpen

func SafeOpen(name string, relative string, filePerm os.FileMode, folderPerm os.FileMode, mode SafeOpenMode) (*os.File, error)

SafeOpen safely opens a new file handle

func SafeRead

func SafeRead(name string, relative string) ([]byte, error)

SafeRead reads a file safely

Types

type LogLevel

type LogLevel string

LogLevel is the log level

type LogOutput

type LogOutput string

LogOutput is the log output

const (
	FILE   LogOutput = "file"
	STDOUT LogOutput = "stdout"
	STDERR LogOutput = "stderr"
)

type SafeOpenMode

type SafeOpenMode int

SafeOpenMode is the mode to open a file

const (
	// SAFE_OPEN_MODE_EXCL is the mode to create a new file, requiring that the file does not already exist
	SAFE_OPEN_MODE_EXCL SafeOpenMode = iota

	// SAFE_OPEN_MODE_APPEND is the mode to open a file for appending, creating the file if it does not exist
	SAFE_OPEN_MODE_APPEND

	// SAFE_OPEN_MODE_TRUNCATE is the mode to open a file for writing, creating the file if it does not exist and truncating it if it does
	SAFE_OPEN_MODE_TRUNCATE
)

Jump to

Keyboard shortcuts

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