pkg

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeFile         = "file"
	TypeStdin        = "stdin"
	TypeSSH          = "ssh"
	TypeDocker       = "docker"
	TmpStdinPath     = "/tmp/GOL-STDIN-"
	TmpContainerPath = "/tmp/GOL-CONTAINER-"

	ErrorMsgSessionAlreadyStarted = "ssh: session already started"
)

Variables

View Source
var GlobalFilePaths []FileInfo
View Source
var GlobalPathSSHConfig []SSHPathConfig
View Source
var GlobalPipeTmpFilePath string
View Source
var GlobalSSHClients = make(map[string]*ssh.Client)

Functions

func AppendGeneralInfo

func AppendGeneralInfo(lines *[]LineResult)

func BindRequest

func BindRequest[T any](c echo.Context, request T) error

func CleanString

func CleanString(input string) string

CleanString removes non-printable characters from a string

func Cleanup

func Cleanup()

func ConsistentFormat

func ConsistentFormat(logLines []string) (bool, int)

ConsistentFormat checks if all log lines have log levels at the same position

func ContainerStdoutToTmp

func ContainerStdoutToTmp(containerID string) *os.File

func F64NumberToK

func F64NumberToK(num *float64) string

func FilePathInGlobalFilePaths

func FilePathInGlobalFilePaths(filePath string) bool

func FileStats

func FileStats(filePath string, isRemote bool, sshConfig *SSHConfig) (int, int64, error)

FileStats returns the number of lines and size of the file at the given path.

func FilesByPattern

func FilesByPattern(pattern string, isRemote bool, sshConfig *SSHConfig) ([]string, error)

func GetHomedir

func GetHomedir() string

func GetTmpFileNameForContainer

func GetTmpFileNameForContainer() string

func GetTmpFileNameForSTDIN

func GetTmpFileNameForSTDIN() string

func HTTPErrorHandler

func HTTPErrorHandler(err error, c echo.Context)

HTTPErrorHandler handles HTTP errors for entire application

func HandleCltrC

func HandleCltrC(f func())

func HandleStdinPipe

func HandleStdinPipe()

func IsGzip

func IsGzip(buffer []byte) bool

IsGzip checks if the given buffer starts with the gzip magic number

func IsInputFromPipe

func IsInputFromPipe() bool

IsInputFromPipe checks if there is input from a pipe

func IsReadableFile

func IsReadableFile(filename string, isRemote bool, sshConfig *SSHConfig, checkUTF8 bool) (bool, error)

IsReadableFile checks if the file is readable and optionally checks for valid UTF-8 encoded content

func JudgeLogLevel

func JudgeLogLevel(line string, keywordPosition int) string

JudgeLogLevel returns the log level based on the content of the log line if the format is consistent

func ListDockerContainers

func ListDockerContainers() ([]container.Summary, error)

func NewEcho

func NewEcho(opts ...EchoOption) error

func NewOrReusableClient

func NewOrReusableClient(config *SSHConfig) (*ssh.Client, error)

func NewSession

func NewSession(config *SSHConfig) (*ssh.Session, error)

func OpenBrowser

func OpenBrowser(url string)

func PipeLinesToTmp

func PipeLinesToTmp(tmpFile *os.File) error

func ResponseHTML

func ResponseHTML(c echo.Context, b []byte, cacheMS string) error

func ResponsePlain

func ResponsePlain(c echo.Context, b []byte, cacheMS string) error

func SetHeadersResponseHTML

func SetHeadersResponseHTML(header http.Header, cacheMS string)

func SetHeadersResponseJSON

func SetHeadersResponseJSON(header http.Header)

func SetHeadersResponsePNG

func SetHeadersResponsePNG(header http.Header)

func SetHeadersResponsePlainText

func SetHeadersResponsePlainText(header http.Header, cacheMS string)

func SetHeadersResponseSvg

func SetHeadersResponseSvg(header http.Header)

func SetupCors

func SetupCors(e *echo.Echo, options *EchoOptions)

func SetupLoggingStdout

func SetupLoggingStdout(logLevel slog.Leveler)

func SetupMiddlewares

func SetupMiddlewares(e *echo.Echo)

func SetupRoutes

func SetupRoutes(e *echo.Echo, options *EchoOptions)

func StringInSlice

func StringInSlice(s string, ss []string) bool

func UpdateGlobalFilePaths

func UpdateGlobalFilePaths(filePaths SliceFlags, sshPaths SliceFlags, dockerPaths SliceFlags, limit int)

func WatchFilePaths

func WatchFilePaths(seconds int64, filePaths SliceFlags, sshPaths SliceFlags, dockerPaths SliceFlags, limit int)

Types

type API

type API struct {
}

func NewAPI

func NewAPI() *API

func (*API) FindSSHConfig

func (a *API) FindSSHConfig(host string) *SSHPathConfig

type APIHandler

type APIHandler struct {
	API *API
}

func NewAPIHandler

func NewAPIHandler() *APIHandler

func (*APIHandler) Get

func (h *APIHandler) Get(c echo.Context) error

type APIRequest

type APIRequest struct {
	Query    string `json:"query" query:"query"`
	Ignore   string `json:"ignore" query:"ignore"`
	FilePath string `json:"file_path" query:"file_path"`
	Host     string `json:"host" query:"host"`
	Type     string `json:"type" query:"type"`
	Page     int    `json:"page" query:"page" default:"1" validate:"required,gte=1" message:"page >=1 is required"`
	PerPage  int    `json:"per_page" query:"per_page" default:"15" validate:"required" message:"per_page is required"`
	Reverse  bool   `json:"reverse" query:"reverse" default:"false"`
}

type APIResponse

type APIResponse struct {
	Result    ScanResult `json:"result"`
	FilePaths []FileInfo `json:"file_paths"`
}

type AssetsHandler

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

func NewAssetsHandler

func NewAssetsHandler(publicDir *embed.FS, distDir string, filename string) *AssetsHandler

func (*AssetsHandler) Get

func (h *AssetsHandler) Get(c echo.Context) error

func (*AssetsHandler) GetICO

func (h *AssetsHandler) GetICO(c echo.Context) error

func (*AssetsHandler) GetPlain

func (h *AssetsHandler) GetPlain(c echo.Context) error

type DockerPathConfig

type DockerPathConfig struct {
	ContainerID string
	FilePath    string
}

func StringToDockerPathConfig

func StringToDockerPathConfig(s string) (*DockerPathConfig, error)

s is an input of the form "container_id /path/to/file"

type EchoOption

type EchoOption func(*EchoOptions) error

type EchoOptions

type EchoOptions struct {
	Host      string
	Port      int64
	Cors      int64
	BaseURL   string
	Access    bool
	PublicDir *embed.FS
}

type FileInfo

type FileInfo struct {
	FilePath   string `json:"file_path"`
	LinesCount int    `json:"lines_count"`
	FileSize   int64  `json:"file_size"`
	Name       string `json:"name"`
	Type       string `json:"type"`
	Host       string `json:"host"`
}

func GetContainerFileInfos

func GetContainerFileInfos(pattern string, limit int, containerID string) []FileInfo

func GetFileInfos

func GetFileInfos(pattern string, limit int, isRemote bool, sshConfig *SSHConfig) []FileInfo

func UniqueFileInfos

func UniqueFileInfos(fileInfos []FileInfo) []FileInfo

type HTTPErrorResponse

type HTTPErrorResponse struct {
	Error interface{} `json:"error"`
}

HTTPErrorResponse is the response for HTTP errors

type LineResult

type LineResult struct {
	LineNumber int    `json:"line_number"`
	Content    string `json:"content"`
	Level      string `json:"level"`
	Date       string `json:"date"`
	Agent      struct {
		Device string `json:"device"`
	} `json:"agent"`
}

type SSHConfig

type SSHConfig struct {
	Host           string
	Port           string
	User           string
	Password       string
	PrivateKeyPath string
}

SSHConfig holds the SSH connection parameters

type SSHPathConfig

type SSHPathConfig struct {
	Host           string
	Port           string
	User           string
	Password       string
	PrivateKeyPath string
	FilePath       string
}

func StringToSSHPathConfig

func StringToSSHPathConfig(s string) (*SSHPathConfig, error)

s is an input of the form "user@host[:port] [password=/path/to/password] [private_key=/path/to/key] /path/to/file"

type ScanResult

type ScanResult struct {
	FilePath     string       `json:"file_path"`
	Host         string       `json:"host"`
	Type         string       `json:"type"`
	MatchPattern string       `json:"match_pattern"`
	Total        int          `json:"total"`
	Lines        []LineResult `json:"lines"`
}

func ContainerLogsFromFile

func ContainerLogsFromFile(containerID string, query string, ignorePattern string, filePath string, page, pageSize int, reverse bool) (*ScanResult, error)

type SliceFlags

type SliceFlags []string

func (*SliceFlags) Set

func (i *SliceFlags) Set(value string) error

provide a Set() method on the type so we can use it with flag.Var

func (*SliceFlags) String

func (i *SliceFlags) String() string

provide a String() method on the type so we can use it with flag.Var

type ValidationErrs

type ValidationErrs map[string][]string

func ValidateRequest

func ValidateRequest[T any](request T) (ValidationErrs, error)

type Watcher

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

func NewWatcher

func NewWatcher(
	filePath string,
	matchPattern string,
	ignorePattern string,
	isRemote bool,
	sshHost string,
	sshPort string,
	sshUser string,
	sshPassword string,
	sshPrivateKeyPath string,
) (*Watcher, error)

func (*Watcher) Scan

func (w *Watcher) Scan(page, pageSize int, reverse bool) (*ScanResult, error)

Jump to

Keyboard shortcuts

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