Sobes.tech
Junior — Middle

Tell us how you worked with data in your last project

sobes.tech AI

Answer from AI

In my latest Go project, I worked with data received from REST APIs and a PostgreSQL database.

Main steps:

  • Received JSON data via HTTP requests using the net/http package.
  • Parsed JSON with encoding/json into Go structures.
  • Performed CRUD operations on the database using the database/sql library and the pq driver.
  • Used prepared statements and transactions for optimization.

Example code for fetching and processing data:

resp, err := http.Get("https://api.example.com/data")
if err != nil {
    log.Fatal(err)
}
defer resp.Body.Close()

var data []MyStruct
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
    log.Fatal(err)
}

// Working with data, e.g., inserting into the database
for _, item := range data {
    _, err := db.Exec("INSERT INTO table_name (field1, field2) VALUES ($1, $2)", item.Field1, item.Field2)
    if err != nil {
        log.Println("Insert error:", err)
    }
}

Thus, I ensured a correct data flow from external sources to internal storage and their processing.

Tell us how you worked with data in your last project… - sobes.tech