utils

package
v0.0.0-...-d33063b Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsString

func ContainsString(slice []string, searchTerm string) bool

func GenerateConfidentialResponseExportSecretEnvVarName

func GenerateConfidentialResponseExportSecretEnvVarName(taskName string) string

GenerateConfidentialResponseExportSecretEnvVarName generates an environment variable name for a confidential export task's study global secret based on its name. Format: CONF_RESP_EXPORT_STUDY_GLOBAL_SECRET_FOR_{NORMALIZED_NAME}

func GenerateEnvVarName

func GenerateEnvVarName(input string) string

GenerateEnvVarName generates a standardized environment variable name from a given string. It converts the input to uppercase and replaces any non-alphanumeric characters with underscores. Leading and trailing underscores are removed.

func GenerateExternalServiceAPIKeyEnvVarName

func GenerateExternalServiceAPIKeyEnvVarName(serviceName string) string

GenerateExternalServiceAPIKeyEnvVarName generates an environment variable name for an external service's API key based on its name. Format: EXTERNAL_SERVICE_API_KEY_FOR_{NORMALIZED_NAME}

func GenerateSmtpServerPasswordEnvVarName

func GenerateSmtpServerPasswordEnvVarName(hostname, port string) string

GenerateSmtpServerPasswordEnvVarName generates an environment variable name for an SMTP server's password based on its hostname and port. Format: SMTP_SERVER_PASSWORD_FOR_{NORMALIZED_HOST}_{NORMALIZED_PORT}

func GenerateSmtpServerUsernameEnvVarName

func GenerateSmtpServerUsernameEnvVarName(hostname, port string) string

GenerateSmtpServerUsernameEnvVarName generates an environment variable name for an SMTP server's username based on its hostname and port. Format: SMTP_SERVER_USERNAME_FOR_{NORMALIZED_HOST}_{NORMALIZED_PORT}

func GenerateSurveyVersionID

func GenerateSurveyVersionID(oldVersions []*studyTypes.Survey) string

func GetFileExtensionFromContentType

func GetFileExtensionFromContentType(contentType string) string

getFileExtensionFromContentType returns the appropriate file extension (with leading dot) based on the detected content type. Returns empty string if content type is not recognized.

func InitLogger

func InitLogger(
	logLevel string,
	includeSrc bool,
	logToFile bool,
	logFilename string,
	logFileMaxSize int,
	logFileMaxAge int,
	logFileMaxBackups int,
	compressOldLogs bool,
	includeBuildInfo string,
)

func IsURLSafe

func IsURLSafe(value string) bool

check if a string value can be safely used as a part of an URL

func OverrideSmtpServerCredentialsFromEnv

func OverrideSmtpServerCredentialsFromEnv(servers []SmtpServerCredentialsOverride)

OverrideSmtpServerCredentialsFromEnv overrides SMTP server credentials from environment variables for any type that implements the SmtpServerCredentialsOverride interface

func ParseDurationString

func ParseDurationString(value string) (time.Duration, error)

func ValidateFileTypeFromContent

func ValidateFileTypeFromContent(fileHeader *multipart.FileHeader, allowedTypes []string) (string, error)

ValidateFileTypeFromContent extracts and validates file type based on actual file content. It reads the first 512 bytes of the file to detect the content type using http.DetectContentType. allowedTypes is a slice of allowed MIME types (e.g., []string{"image/jpeg", "image/png"}). Returns the validated content type and an error if validation fails.

Types

type BuildInfoMode

type BuildInfoMode int
const (
	BuildInfoNever BuildInfoMode = iota
	BuildInfoOnce
	BuildInfoAlways
)

type CustomHandler

type CustomHandler struct {
	slog.Handler
	// contains filtered or unexported fields
}

func (*CustomHandler) Handle

func (h *CustomHandler) Handle(ctx context.Context, r slog.Record) error

type LoggerConfig

type LoggerConfig struct {
	LogToFile        bool   `json:"log_to_file" yaml:"log_to_file"`
	Filename         string `json:"filename" yaml:"filename"`
	MaxSize          int    `json:"max_size" yaml:"max_size"`
	MaxAge           int    `json:"max_age" yaml:"max_age"`
	MaxBackups       int    `json:"max_backups" yaml:"max_backups"`
	LogLevel         string `json:"log_level" yaml:"log_level"`
	IncludeSrc       bool   `json:"include_src" yaml:"include_src"`
	CompressOldLogs  bool   `json:"compress_old_logs" yaml:"compress_old_logs"`
	IncludeBuildInfo string `json:"include_build_info" yaml:"include_build_info"` // never, always, once
}

type SmtpServerCredentialsOverride

type SmtpServerCredentialsOverride interface {
	GetHost() string
	GetPort() string
	SetUsername(username string)
	SetPassword(password string)
}

SmtpServerCredentialsOverride represents the interface needed for SMTP server credential overrides

Jump to

Keyboard shortcuts

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