rrgc

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Overview

Example
package main

import (
	"os"
	"time"

	"moul.io/rrgc/rrgc"
)

func main() {
	logGlobs := []string{
		"*/*.log",
		"*/*.log.gz",
	}
	windows := []rrgc.Window{
		{Every: 2 * time.Hour, MaxKeep: 5},
		{Every: time.Hour * 24, MaxKeep: 4},
		{Every: time.Hour * 24 * 7, MaxKeep: 3},
	}
	_, toDelete, _ := rrgc.GCListByPathGlobs(logGlobs, windows)
	for _, path := range toDelete {
		_ = os.Remove(path)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GCListByPathGlobs

func GCListByPathGlobs(inputs []string, windows []Window) ([]string, []string, error)

GCListByPathGlobs computes a list of paths that should be kept and deleted, based on a list of window rules.

Types

type Window

type Window struct {
	Every   time.Duration
	MaxKeep int
}

Window defines a file preservation rule.

func ParseWindow

func ParseWindow(input string) (Window, error)

ParseWindow parses a human-readable Window definition.

Syntax: "Duration,MaxKeep".

Examples: "1h,5" "1h2m3s,42".

Jump to

Keyboard shortcuts

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