utils

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TenderCodeRegex = regexp.MustCompile(`\d{4}-[A-Z0-9]+-[A-Z0-9]+`)

TenderCodeRegex matches tender codes such as "2023-JQ01-W1295".

Functions

func ResolveURL added in v1.4.10

func ResolveURL(base, ref string) string

ResolveURL turns a link reference into an absolute URL: absolute references are returned unchanged, relative ones are joined to base. An empty base leaves a relative reference unresolved (""), so the caller can drop it.

func SimplifyHTML added in v1.4.1

func SimplifyHTML(content, baseURL string) (string, bool)

SimplifyHTML rewrites notice HTML into the markup Telegram's HTML parse mode renders: b/i/u/s/code/pre/blockquote/a/span.tg-spoiler plus literal newlines.

It rewrites instead of stripping because Telegram renders the message as HTML: block elements have to become line breaks, unsupported elements must be unwrapped (their text kept), and text must be escaped so a stray "<" cannot make the message unparseable.

Relative links are resolved against baseURL; when it is empty they degrade to their text.

The second result reports whether the notice contains a table too complex to flatten (see complexTableColumns/complexTableRows): such a table is replaced by a placeholder line and the caller is expected to attach the original page as a PDF instead.

Call it once per notice: the result encodes line breaks as literal newlines (Telegram has no <br>), so running it again would fold them into spaces.

See https://core.telegram.org/bots/api#html-style

func ToString

func ToString(v any) string

ToString renders v as indented JSON. It returns an empty string when v cannot be encoded.

Types

type Config

type Config struct {
	// Enable console logging
	ConsoleLoggingEnabled bool

	// EncodeLogsAsJson makes the log framework log JSON
	EncodeLogsAsJson bool
	// FileLoggingEnabled makes the framework log to a file
	// the fields below can be skipped if this value is false!
	FileLoggingEnabled bool
	// Directory to log to when file logging is enabled
	Directory string
	// Filename is the name of the logfile which will be placed inside the directory
	Filename string
	// MaxSize the max size in MB of the logfile before it's rolled
	MaxSize int
	// MaxBackups the max number of rolled files to keep
	MaxBackups int
	// MaxAge the max age in days to keep a logfile
	MaxAge   int
	LogLevel zerolog.Level
}

Config for logging

type Logger

type Logger struct {
	*zerolog.Logger
}

func Configure

func Configure(config Config) *Logger

Jump to

Keyboard shortcuts

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