utils

package
v0.0.0-...-a234957 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFileToArchive

func AddFileToArchive(tarWriter *tar.Writer, filePath, nameInArchive string) error

addFileToArchive streams a file into the tar archive

func CreateDirectory

func CreateDirectory(dirPath string, perm os.FileMode) error

CreateDirectory creates a directory with the specified permissions if it doesn't exist

func Decrypt

func Decrypt(encryptedText string) (string, error)

func DockerLoginECR

func DockerLoginECR(ctx context.Context, region, registryID string) error

DockerLoginECR logs in to an AWS ECR repository using the AWS SDK

func Encrypt

func Encrypt(plaintext string) (string, error)

func ErrorResponse

func ErrorResponse(ctx *web.Controller, status int, message string, err error)

func ExistsInArray

func ExistsInArray[T comparable](arr []T, value T) bool

func ExtractJSON

func ExtractJSON(output string) (map[string]interface{}, error)

ExtractJSON extracts and returns the last valid JSON block from output

func ExtractJobIDFromWorkflowID

func ExtractJobIDFromWorkflowID(workflowID, projectID string) (int, bool)

ExtractJobIDFromWorkflowID extracts the JobID from Temporal workflow IDs created by this system.

Expected workflow ID shapes: - sync-<projectID>-<jobID> - sync-<projectID>-<jobID>-<suffix>

projectID itself can contain '-', so we match the exact prefix and then parse the leading integer.

func GetAndValidateLogBaseDir

func GetAndValidateLogBaseDir(filePath string) (string, error)

GetAndValidateLogBaseDir returns the base directory path for log files based on the SHA256 hash of the filePath (workflow ID) and validates it exists

func GetAndValidateSyncDir

func GetAndValidateSyncDir(baseDir string) (string, string, error)

GetAndValidateSyncDir returns the logs directory and sync_* folder name under it

func GetCachedImages

func GetCachedImages(ctx context.Context) ([]string, error)

GetCachedImages retrieves locally cached Docker images

func GetDriverImageTags

func GetDriverImageTags(ctx context.Context, imageName string, cachedTags bool) ([]string, string, error)

GetDriverImageTags returns image tags from ECR or Docker Hub with fallback to cached images

func GetLogArchiveFilename

func GetLogArchiveFilename(jobID int, filePath string) (string, error)

GetLogArchiveFilename generates the filename for the log archive download

func GetWorkerEnvVars

func GetWorkerEnvVars() map[string]string

GetWorkerEnvVars returns the environment variables from the worker container.

func HandleError

func HandleError(w http.ResponseWriter, statusCode int, err error)

send error as direct text/string

func HandleErrorAsMessage

func HandleErrorAsMessage(w http.ResponseWriter, statusCode int, err error)

send error as json response

func HandleErrorJS

func HandleErrorJS(w http.ResponseWriter, r *http.Request, err error)

Handle errors and pass it to /error page

func HandleJSONOK

func HandleJSONOK(w http.ResponseWriter, content interface{})

func HandleResponseMessage

func HandleResponseMessage(w http.ResponseWriter, statusCode int, content interface{}, message string)

send a message as response

func ParseECRDetails

func ParseECRDetails(fullImageName string) (accountID, region, repoName string, err error)

ParseECRDetails extracts account ID, region, and repository name from ECR URI Example:

Input:  "123456789012.dkr.ecr.us-west-2.amazonaws.com/olakego/source-mysql:latest"
Output: accountID = "123456789012"
        region    = "us-west-2"
        repoName  = "olakego/source-mysql:latest"

func ReadLinesBackward

func ReadLinesBackward(f *os.File, startOffset int64, limit int, fileSize int64) ([]string, int64, bool, error)

ReadLinesBackward reads up to `limit` complete VALID log lines from file backwards starting at startOffset. Filters out empty lines, invalid JSON, and debug-level logs DURING reading. startOffset is treated as exclusive - we read lines that END BEFORE startOffset. Returns: valid lines (oldest->newest), newOffset (byte position before first returned line), hasMore, error.

func ReadLinesForward

func ReadLinesForward(f *os.File, startOffset int64, limit int, fileSize int64) ([]string, int64, bool, error)

ReadLinesForward reads up to `limit` complete VALID log lines from file forwards starting at startOffset. Filters out empty lines, invalid JSON, and debug-level logs DURING reading. startOffset is treated as inclusive - we start reading from exactly that position. Returns: valid lines (oldest->newest), newOffset (byte position after last returned line), hasMore, error.

func ReadLogs

func ReadLogs(mainLogDir string, cursor int64, limit int, direction string) (*dto.TaskLogsResponse, error)

ReadLogs reads logs from the given mainLogDir and returns structured log entries. Direction can be "older" or "newer". If cursor < 0, it tails from the end of the file. Returns a TaskLogsResponse-like struct: oldest->newest logs plus cursors and hasMore flags.

func RespondJSON

func RespondJSON(ctx *web.Controller, status int, success bool, message string, data interface{})

func RetryWithBackoff

func RetryWithBackoff(fn func() error, maxRetries int, initialDelay time.Duration) error

RetryWithBackoff retries a function with exponential backoff

func SuccessResponse

func SuccessResponse(ctx *web.Controller, message string, data interface{})

func Ternary

func Ternary(cond bool, a, b any) any

func ToCron

func ToCron(frequency string) string

ToCron converts a frequency string to a cron expression

func ToMapOfInterface

func ToMapOfInterface(structure any) map[string]interface{}

func ULID

func ULID() string

func WriteFile

func WriteFile(filePath string, data []byte, perm os.FileMode) error

WriteFile writes data to a file, creating the directory if necessary

Types

type DockerHubTag

type DockerHubTag struct {
	Name string `json:"name"`
}

DockerHubTag represents a single tag from Docker Hub API response

type DockerHubTagsResponse

type DockerHubTagsResponse struct {
	Results []DockerHubTag `json:"results"`
}

DockerHubTagsResponse represents the response structure from Docker Hub tags API

type LineWithPos

type LineWithPos struct {
	// contains filtered or unexported fields
}

type LogEntry

type LogEntry struct {
	Level   string          `json:"level"`
	Time    time.Time       `json:"time"`
	Message json.RawMessage `json:"message"` // store raw JSON
}

LogEntry represents a log entry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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