/* 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 . */ package cfg import ( "crypto/tls" "errors" "net/http" "os" "github.com/elastic/elastic-transport-go/v8/elastictransport" "github.com/elastic/go-elasticsearch/v9" ) const ( Version string = `v0.0.1` ) type Config struct { Uri, User, Pass string ES *elasticsearch.TypedClient Debug bool From, To int Index string Filter []string } func Init() (*Config, error) { cfg := Config{ Uri: os.Getenv("ES_URI"), User: os.Getenv("ES_USER"), Pass: os.Getenv("ES_PASS"), } switch { case cfg.Uri == "": return nil, errors.New("ES_URI unset") case cfg.User == "": return nil, errors.New("ES_USER unset") case cfg.Pass == "": return nil, errors.New("ES_PASS unset") } es, _ := elasticsearch.NewTyped( elasticsearch.WithAddresses(cfg.Uri), elasticsearch.WithBasicAuth(cfg.User, cfg.Pass), elasticsearch.WithTransportOptions( elastictransport.WithTransport( &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, }, ), ), ) cfg.ES = es return &cfg, nil }