#i want to test this code. im confused about this repo. can anyone help me?

16 messages · Page 1 of 1 (latest)

placid ridge
#

i have written a go code alternative to this py file. ```package main

import (
"bytes"
"encoding/json"
"fmt"
"math/rand"
"net/http"
"time"

"github.com/google/uuid"

)

type LineItem struct {
ItemID string json:"item_id"
Quantity int json:"quantity"
Price int json:"price"
}

type Order struct {
CustomerID string json:"customer_id"
LineItems []LineItem json:"line_items"
}

func main() {
rand.New(rand.NewSource(time.Now().UnixNano()))

itemIDs := make([]string, 1000)
for i := 0; i < 1000; i++ {
    itemIDs[i] = uuid.New().String()
}

customers := make([]string, 100)
for i := 0; i < 100; i++ {
    customers[i] = uuid.New().String()
}

for i := 0; i < 120; i++ {
    customer := customers[rand.Intn(len(customers))]

    numLineItems := rand.Intn(10) + 1

    lineItems := make([]LineItem, numLineItems)
    for j := 0; j < numLineItems; j++ {
        itemID := itemIDs[rand.Intn(len(itemIDs))]
        lineItems[j] = LineItem{
            ItemID:   itemID,
            Quantity: rand.Intn(10) + 1,
            Price:    rand.Intn(10000) + 1,
        }
    }

    order := Order{
        CustomerID: customer,
        LineItems:  lineItems,
    }

    orderJSON, err := json.Marshal(order)
    if err != nil {
        fmt.Println("failed to marshal order:", err)
        return
    }

    resp, err := http.Post("http://localhost:3000/orders", "application/json", bytes.NewBuffer(orderJSON))
    if err != nil {
        fmt.Println("failed to send request:", err)
        return
    }
    defer resp.Body.Close()

    fmt.Println("posted order", i+1)
}

}

#

can you tell me what file name and folder name you give here

peak acorn
#

it looks like it's just generating 100 customers and 1000 products as test data

#

it's likely written in python for simplicitys sake, no need to compile as it's not part of the application

placid ridge
peak acorn
#

I don't think it's so much as a test as just putting some values into the database so you can actually see things in the app

placid ridge
peak acorn
#

personally, probably yeah

placid ridge
#

thanks bro!!

peak acorn
#

yeah it's literally only for use while developing the application - you need some data to show it's working

ionic steeple
#

just as example scripts

#

they don't have to work in the future necessarily