client:=client.NewAutoClient(keypair,"",&client.AutoClientOptions{MaxPaymentAmount:"10.0",})deferclient.Close()// Just call the endpoint - payment handled automaticallyresp,err:=client.Get(ctx,"https://api.example.com/premium")iferr!=nil{log.Fatal(err)}data,_:=io.ReadAll(resp.Body)resp.Body.Close()log.Println(string(data))
typePaymentTrackerstruct{totalSpentfloat64maxSpendfloat64payments[]string}func(pt*PaymentTracker)trackPayment(auth*core.PaymentAuthorization){amount,_:=strconv.ParseFloat(auth.ActualAmount,64)pt.totalSpent+=amountpt.payments=append(pt.payments,auth.TransactionHash)log.Printf("Total spent: %.2f / %.2f",pt.totalSpent,pt.maxSpend)}// Usagetracker:=&PaymentTracker{totalSpent:0,maxSpend:10.0,}client:=client.NewAutoClient(keypair,"",&client.AutoClientOptions{MaxPaymentAmount:"5.0",// Prevent individual payments over $5})// Track payments by monitoring response// Note: Auto client doesn't expose auth, so you'd need explicit mode for tracking
// Use payment limitsclient:=client.NewAutoClient(keypair,"",&client.AutoClientOptions{MaxPaymentAmount:"10.0",// Prevent overspending})// Use context timeoutctx,cancel:=context.WithTimeout(context.Background(),30*time.Second)defercancel()// Close client when donedeferclient.Close()// Validate URLs in explicit mode// Client validates URLs automatically
// Don't use without payment limitclient:=client.NewAutoClient(keypair,"",nil)// Don't allow local in productionclient:=client.NewAutoClient(keypair,"",&client.AutoClientOptions{AllowLocal:true,// Only for dev!})// Don't forget to closeclient:=client.NewAutoClient(keypair,"",nil)// Missing: defer client.Close()// Don't hardcode URLsclient.Get(ctx,"http://192.168.1.1/api")// SSRF risk
// Good: Reuse client for multiple requestsclient:=client.NewAutoClient(keypair,"",nil)deferclient.Close()for_,url:=rangeurls{resp,_:=client.Get(ctx,url)// Use response}
// Different timeouts for different needsshortTimeout:=10*time.SecondlongTimeout:=60*time.Secondfor_,url:=rangeurls{ctx,cancel:=context.WithTimeout(context.Background(),shortTimeout)resp,_:=client.Get(ctx,url)cancel()}
// Process multiple endpoints efficientlyresults:=make(chanstring)for_,url:=rangeurls{gofunc(ustring){resp,_:=client.Get(ctx,u)data,_:=io.ReadAll(resp.Body)results<-string(data)resp.Body.Close()}(url)}forrangeurls{log.Println(<-results)}