pkg

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 38 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 added in v1.0.22

func AppendGeneralInfo(lines *[]LineResult)

func BindRequest

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

func CleanString added in v1.0.7

func CleanString(input string) string

CleanString removes non-printable characters from a string

func Cleanup added in v1.1.0

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 added in v1.0.7

func ContainerStdoutToTmp(containerID string) *os.File

func F64NumberToK added in v1.0.4

func F64NumberToK(num *float64) string

func FilePathInGlobalFilePaths added in v1.0.4

func FilePathInGlobalFilePaths(filePath string) bool

func FileStats added in v1.0.4

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 added in v1.0.7

func GetTmpFileNameForContainer() string

func GetTmpFileNameForSTDIN added in v1.0.7

func GetTmpFileNameForSTDIN() string

func HTTPErrorHandler

func HTTPErrorHandler(err error, c echo.Context)

HTTPErrorHandler handles HTTP errors for entire application

func HandleCltrC added in v1.0.4

func HandleCltrC(f func())

func HandleStdinPipe added in v1.1.0

func HandleStdinPipe()

func IsGzip

func IsGzip(buffer []byte) bool

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

func IsInputFromPipe added in v1.0.3

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 added in v1.0.7

func ListDockerContainers() ([]types.Container, error)

func NewEcho

func NewEcho(opts ...EchoOption) error

func NewOrReusableClient added in v1.0.20

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

func NewSession added in v1.0.20

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

func OpenBrowser added in v1.0.3

func OpenBrowser(url string)

func PipeLinesToTmp added in v1.0.4

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 added in v1.0.21

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 added in v1.1.0

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

func WatchFilePaths added in v1.1.0

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

Types

type API added in v1.0.5

type API struct {
}

func NewAPI added in v1.0.5

func NewAPI() *API

func (*API) FindSSHConfig added in v1.0.5

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 added in v1.1.0

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 added in v1.0.7

type DockerPathConfig struct {
	ContainerID string
	FilePath    string
}

func StringToDockerPathConfig added in v1.0.7

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 added in v1.0.4

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 added in v1.0.7

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

func GetFileInfos added in v1.0.4

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

func UniqueFileInfos added in v1.1.0

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 added in v1.0.5

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

SSHConfig holds the SSH connection parameters

type SSHPathConfig added in v1.0.5

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

func StringToSSHPathConfig added in v1.0.5

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 added in v1.0.7

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

type SliceFlags added in v1.1.0

type SliceFlags []string

func (*SliceFlags) Set added in v1.1.0

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 added in v1.1.0

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