Sobes.tech
Junior — Middle

How can you extract and process four separate requests from a batch operation?

sobes.tech AI

Answer from AI

In Go, if you have a batch operation that contains multiple requests, you can extract and process each request separately, for example, if these are SQL queries separated by semicolons.

Example of processing four separate queries from one line:

package main

import (
    "fmt"
    "strings"
)

func main() {
    batch := `SELECT * FROM users; INSERT INTO logs VALUES ('log1'); UPDATE users SET active=1; DELETE FROM sessions;`

    // Split the string by the ';' character
    queries := strings.Split(batch, ";")

    for i, q := range queries {
        q = strings.TrimSpace(q)
        if q == "" {
            continue
        }
        fmt.Printf("Query %d: %s\n", i+1, q)
        // Here you can process each query separately
    }
}

If the batch operation comes in the form of structured data (for example, an array of requests), then simply iterate over them and process each one individually.

How can you extract and process four separate… - sobes.tech