/** * Yats - yats * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * * @author Paolo Lulli * @copyright Paolo Lulli 2024 */ package main import ( "fmt" "os" "yats/config" flag "github.com/spf13/pflag" ) type YatsClient struct { config config.ClientConfiguration } func main() { var configPath string if len(os.Args) == 1 { fmt.Printf("For usage: %s --help\n", os.Args[0]) os.Exit(1) } configPath = os.Getenv("HOME") + "/.yats-client.json" cfg := config.GetClientConfig(configPath) var yatsClient = YatsClient{config: cfg} generatePki := flag.BoolP("csr", "c", false, "Create Certificate Signing Request") sourceOption := flag.StringP("source", "s", "", "Source Application") isShowPermsOption := flag.BoolP("show-permissions", "S", false, "Show User Permissions") fromOption := flag.Int64("from", 0, "From tstamp") toOption := flag.Int64("to", 0, "To tstamp") timestampOption := flag.Int64("timestamp", 0, "Metric/Event TimeStamp") writeEvent := flag.StringP("write-event", "E", "", "Write Event Name") writeMetric := flag.StringP("write-metric", "M", "", "Write Metric Name") metricValue := flag.StringP("metric-value", "v", "", "Metric Value") writePosition := flag.StringP("write-position", "P", "", "Write Position Name") listEvents := flag.BoolP("list-events", "e", false, "List Events") listMetrics := flag.StringP("list-metrics", "m", "", "List Metrics with Name") listPositions := flag.StringP("list-positions", "p", "", "List Positions with Name") longitudeOption := flag.Float64P("longitude", "o", 0, "Longitude") latitudeOption := flag.Float64P("latitude", "a", 0, "Latitude") flag.Parse() if *isShowPermsOption { listResponse, err := yatsClient.PermissionsList() if err == nil { fmt.Printf("%s", listResponse) } else { fmt.Println(err) } os.Exit(0) } if *generatePki { yatsClient.CreateCsr() os.Exit(0) } if "" != *writeEvent { saveEventResponse, err := yatsClient.EventSave(*writeEvent, *timestampOption) if err == nil { fmt.Printf("%s", saveEventResponse) } else { fmt.Println(err) } os.Exit(0) } if "" != *writeMetric { listResponse, err := yatsClient.MetricSave(*writeMetric, *metricValue, *timestampOption) if err == nil { fmt.Printf("%s", listResponse) } else { fmt.Println(err) } os.Exit(0) } if "" != *writePosition { savePositionResponse, err := yatsClient.PositionSave(*writePosition, *latitudeOption, *longitudeOption, *timestampOption) if err == nil { fmt.Printf("%s", savePositionResponse) } else { fmt.Println(err) } os.Exit(0) } if *listEvents { listEvents := yatsClient.EventList(*sourceOption, *fromOption, *toOption) fmt.Printf("%s", listEvents) os.Exit(0) } if "" != *listMetrics { listResponse, err := yatsClient.MetricList(*sourceOption, *listMetrics, *fromOption, *toOption) if err == nil { fmt.Printf("%s", listResponse) } else { fmt.Println(err) } os.Exit(0) } if "" != *listPositions { listResponse := yatsClient.PositionList(*sourceOption, *fromOption, *toOption) fmt.Printf("%s", listResponse) os.Exit(0) } }