/** * 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} sourceOption := flag.StringP("source", "s", "", "Source Application") isMetricOption := flag.BoolP("metric", "m", false, "Metric Mode") isPositionOption := flag.BoolP("position", "p", false, "Position Mode") isShowPermsOption := flag.BoolP("show-permissions", "S", false, "Show User Permissions") writeModeOption := flag.BoolP("write", "w", false, "Write Mode") fromOption := flag.Int64("from", 0, "From tstamp") toOption := flag.Int64("to", 0, "To tstamp") metricNameOption := flag.StringP("metricName", "n", "", "Metric Name") metricValueOption := flag.StringP("value", "v", "", "Metric Value") timestampOption := flag.Int64("timestamp", 0, "Metric/Event TimeStamp") eventNameOption := flag.StringP("eventName", "e", "", "Event Name") positionNameOption := flag.StringP("positionName", "x", "", "Position 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 !*writeModeOption { if *isMetricOption { //fmt.Printf("metricNameOption: %s", *metricNameOption) listResponse, err := yatsClient.MetricList(*sourceOption, *metricNameOption, *fromOption, *toOption) if err == nil { fmt.Printf("%s", listResponse) } else { fmt.Println(err) } } else if *isPositionOption { listResponse := yatsClient.PositionList(*sourceOption, *fromOption, *toOption) fmt.Printf("%s", listResponse) } else { listEvents := yatsClient.EventList(*sourceOption, *fromOption, *toOption) fmt.Printf("%s", listEvents) } } else { // Write Mode if *isMetricOption { fmt.Printf("metricNameOption: %s", *metricNameOption) listResponse, err := yatsClient.MetricSave(*metricNameOption, *metricValueOption, *timestampOption) if err == nil { fmt.Printf("%s", listResponse) } else { fmt.Println(err) } } else if *isPositionOption { savePositionResponse, err := yatsClient.PositionSave(*positionNameOption, *latitudeOption, *longitudeOption, *timestampOption) if err == nil { fmt.Printf("%s", savePositionResponse) } else { fmt.Println(err) } } else { saveEventResponse, err := yatsClient.EventSave(*eventNameOption, *timestampOption) if err == nil { fmt.Printf("%s", saveEventResponse) } else { fmt.Println(err) } } } }