cfg

package
v0.0.0-...-59331fc Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Copyright © 2026 Thomas von Dein

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	DefaultMargin = 4
)
View Source
const (
	Version string = `v0.0.27`
)

Variables

View Source
var (
	// initialized during build, see Makefile:buildlocal
	APIVERSION, GOVERSION, BUILD, COMMIT, BRANCH string
)

Functions

func GetTermHeight

func GetTermHeight() int

func GetTermWidth

func GetTermWidth() int

Types

type Cluster

type Cluster struct {
	Name, Uri, User, Pass, Token string

	Default, DebugHTTP bool
	// contains filtered or unexported fields
}

used in general config struct

func (*Cluster) CheckAuth

func (cluster *Cluster) CheckAuth() error

add authentication to es client, if not yet done

func (*Cluster) ES

func (cluster *Cluster) ES() *elasticsearch.TypedClient

return the go-elasticsearch client object but before doing that, check if we need to tune auth

func (*Cluster) IsReachable

func (cluster *Cluster) IsReachable() (bool, error)

We do NOT use go-elasticsearch to check for cluster reachability, because at this stage, auth may not have been configured. So instead we just connect to the cluster using plan net/tcp

func (*Cluster) SetClient

func (cluster *Cluster) SetClient(client *elasticsearch.TypedClient)

type ClusterConfig

type ClusterConfig struct {
	Uri, User, Pass, Token string
	Default                bool
}

used just for writing back to the config file

type CompatibilityTransport

type CompatibilityTransport struct {
	Transport http.RoundTripper
}

func (*CompatibilityTransport) RoundTrip

func (t *CompatibilityTransport) RoundTrip(req *http.Request) (*http.Response, error)

type Config

type Config struct {
	ConfigFile     string // -c
	CurrentCluster string // -C
	Debug          bool   // -d
	Output         string // -o <mode>
	Clusters       map[string]*Cluster
	DefaultCluster *Cluster
	HaveJQ         bool   // determined at runtime by ourselfes
	ProfileFile    string // for internal use (golang profiling)
	AlignInts      bool   // -I

	Index            string // index: -i
	Failed, Partials bool   // index: flags
	Shards, Replicas int    // index create+allocation: -s -r
	Wait             bool   // index create: -w
	Policy           string // index create: -p
	Primary          bool   // index allocation: -p
	Searchable       bool   // index fields: -s
	Aggretable       bool   // index fields: -a

	Priority   int      // index template create: -p
	Settings   []string // index template create: -s
	Patterns   []string // index template create: -i
	Components []string // index template create: -c
	Meta       []string // index template create: -M
	Aliases    []string // index template create: -A
	Stream     bool     // index template create: -S
	AutoCreate bool     // index template create: -a
	Mode       string   // index template create: -a
	Retention  string   // index template create: -r
	Rollover   bool     // index template create: -R

	Missing           bool          // index copy: -m
	Sync              bool          // index copy: -S
	RequestsPerSecond float64       // index copy: -R
	Timeout           time.Duration // index copy: -T
	Refresh           bool          // index copy: -r
	SourceIndices     []string      // index copy: -s

	From, To, MaxItems int      // search: flags
	Filter             []string // search: -F
	Path               string   // search+doc sh: -p
	Subhelp            bool     // search+doc sh: -H
	Tail               bool     // search: -f [tail]
	Or                 bool     // search: -O
	Range              string   // search: -r
	TimestampFormat    string   // search: --timestamp-format
	Explain            bool     // search: -e
	Validate           bool     // search: --validate

	SortBy    string // sort: -k
	Ascending bool   // sort: -a

	All                            bool   // doc + node ls: -a
	Exclude                        string // cluster compare: -e (regexp)
	Verbose                        bool   // cluster status: -v
	Persistent, Transient, Default bool   // cluster settings set: -p -t -D

	Force bool // ccr follower renew: -f

	DebugHTTP       bool   // root: --debug-http
	DebugGoRoutines bool   // root: --debug-goroutines
	Separator       string // role diff: -s
	NotDeployed     bool   // role diff: -n
	Undefined       bool   // role diff: -u
	Diff            bool   // role diff: -D
	Hidden          bool   // ds ls: -H

	// rollover
	MaxAge                     string
	MaxDocs                    int64 // roll over, plus others
	MaxShardSize, MaxShardDocs int   // roll over
	DryRun                     bool  // rollover: -n

	Tag      string // api ls: -t
	HumanCat bool   // api repl: -H

	Ilm Ilm // ilm create

	FromNode, ToNode             string // cluster reroute move: -f + -t
	AllowPrimary, AcceptDataLoss bool   // cluster reroute cancel: -p,-a

	Pager string // api repl: -p || PAGER
}

func NewConfig

func NewConfig() *Config

func (*Config) Clone

func (conf *Config) Clone() Config

we are using reflect to clone a config obj w/o the ES stuff for shorter repr.Println() output (the ES structure is just too large)

func (*Config) Init

func (conf *Config) Init() error

func (*Config) LoadConfig

func (conf *Config) LoadConfig() error

func (*Config) LoadEnv

func (conf *Config) LoadEnv() error

func (*Config) PrintDebug

func (conf *Config) PrintDebug()

func (*Config) SetupES

func (conf *Config) SetupES() error

func (*Config) SwitchCluster

func (conf *Config) SwitchCluster(name string) error

set Default=true for the given cluster in the config (if exists)

type DebugTransport

type DebugTransport struct {
	Transport http.RoundTripper
}

used to print uri, path and body of a request made by the go-client

func (*DebugTransport) RoundTrip

func (t *DebugTransport) RoundTrip(req *http.Request) (*http.Response, error)

type Ilm

type Ilm struct {
	Description string

	HotMinAge                      string
	HotRolloverMaxAge              string
	HotRolloverMaxPrimaryShardSize string
	HotRolloverMaxDocs             int64
	HotReadonly                    bool

	WarmMinAge       string
	WarmForceMerge   int
	WarmShrinkShards int
	WarmPriority     int

	ColdMinAge                 string
	ColdSearchableSnapshotRepo string
	ColdForceMerge             int
	ColdPriority               int

	FrozenMinAge                 string
	FrozenSearchableSnapshotRepo string

	DeleteMinAge              string
	DeleteSearchableSnapshots bool

	MinAge, FromPhase, Within string // forecast
	Tree                      bool
}

func (*Ilm) HaveCold

func (cfg *Ilm) HaveCold() bool

func (*Ilm) HaveDelete

func (cfg *Ilm) HaveDelete() bool

func (*Ilm)