package main import "surdeus.su/core/amo" import "surdeus.su/core/ss/urlenc" import "surdeus.su/core/cli/mtool" import "encoding/json" import "strconv" import "log" import "fmt" //import "os" var getLead = mtool.T("get-leads").Func(func(flags *mtool.Flags){ var ( secretPath string ) flags.StringVar( &secretPath, "secret", "", "path to JSON file with AMO CRM secrets", "AMO_SECRET", ) idStrs := flags.Parse() ids := make([]int, len(idStrs)) for i, idStr := range idStrs { var err error ids[i], err = strconv.Atoi(idStr) if err != nil { log.Printf("Error: Atoi(%q): %s\n", err) return } } c, err := amo.NewClient(secretPath) if err != nil { log.Fatalf("NewAmoClient(...): %s\n", err) } leads, err := c.GetLeads( urlenc.Array[int]{ "id", ids, }, ) if err != nil { log.Fatalf("GetLeadsByIDs(...): %s\n", err) } bts, err := json.MarshalIndent(leads, "", " ") if err != nil { log.Fatalf("json.Marshal(...): %s\n", err) } fmt.Printf("%s\n", bts) })