Sobes.tech

Golang

func Copy(src io.Reader, dst io.Writer) error { //... } import gocopy s := file.Open() err := gocopy.Copy(s, d) func Copy(src io.Reader, dst io.Writer) (statusCh, error) { //... go func() { statusCh }() } func Read() { select { case status := <-statusCh: } } type Stat struct { status string err error } func Copy(src io.Reader, dst io.Writer) chan Stat { //... statusCh := make(chan Stat{}) go func() { statusCh{ } } return statusCh } func Read() { select { case status := <-statusCh: } } import gocopy s := file.Open() err := gocopy.Copy(s, d) func Copy(src io.Reader, dst io.Writer) chan Stat { //... statusCh := make(chan Stat{}) buf := make([]byte, 1024) var total int64 go func() { for { n, err := src.Read(buf) if n > 0 { writen, err := dst.Write(buf[:n]) total += int64(writen) if err != nil { statusCh <- Stat{ status: "done with err", err: err, } return } } if err == io.EOF { statusCh <- Stat{ bCopy: total, status: "done", err: nil, } return } if err != nil { statusCh <- Stat{ status: "done with err", err: err, } return } } } return statusCh } func Read() { select { case status := <-statusCh: if status.err != nil { return } } } func Copy(src io.Reader, dst io.Writer) chan Stat { //... statusCh := make(chan Stat{}) buf := make([]byte, 1024) var total int64 go func() { for { select { case : n, err := src.Read(buf) if n > 0 { writen, err := dst.Write(buf[:n]) total += int64(writen) if err != nil { statusCh <- Stat{ status: "done with err", err: err, } return } } if err == io.EOF { statusCh <- Stat{ bCopy: total, status: "done", err: nil, } return } if err != nil { statusCh <- Stat{ status: "done with err", err: err, } return } default: statusCh <- Stat{ bCopy: total, status: "pending", err: nil, } } } } return statusCh } func Read() { select { case status := <-statusCh: if status.err != nil { return } } }

246

C'è una funzione `unpredictableFunc()`, che deve essere avvolta in modo che venga eseguita con un timeout (ad esempio, 1 secondo) e venga registrato il tempo di esecuzione. // C'è una funzione che funziona indefinitamente e restituisce un numero. // Il suo corpo non può essere modificato (supponiamo che all'interno ci sia una richiesta di rete). func unpredictableFunc() int64 { rnd := rand.Int63n(5000) time.Sleep(time.Duration(rnd) * time.Millisecond) return rnd } // È necessario modificare la funzione di wrapping, che funzionerà con un timeout impostato (ad esempio, 1 secondo). // Se la "funzione lunga" termina in questo tempo, ottimo, restituiamo il risultato. // Se no, restituiamo un errore. Il risultato di questa esecuzione in questo caso non ci interessa. // // Inoltre, bisogna misurare quanto tempo questa funzione è stata in esecuzione (basta stamparlo nel log). // La firma della funzione di wrapping può essere modificata. func predictableFunc() int64 { return unpredictableFunc() }

240

Cosa cerchi in un lavoro, cosa vuoi fare?

231

Come funziona SSL/TLS? Descrivi il processo di stabilimento della connessione.

201

In quale team hai lavorato in banca? Qual era il compito del team?

192

Come funziona internamente context.WithTimeout?

174

Cosa mostrerà il codice? package main import "fmt" func main() { nums := make([]int, 1, 2) fmt.Println(nums) // appendSlice(nums, 1024) fmt.Println(nums) // mutateSlice(nums, 1, 512) fmt.Println(nums) // } func appendSlice(sl []int, val int) { sl = append(sl, val) } func mutateSlice(sl []int, idx, val int) { sl[idx] = val }

170

Come verificare l'utilizzo della CPU e della memoria in Linux?

166

Cosa sono gli indici nei database? Quali sono i tipi di indici?

164

In cosa differiscono le goroutine dai thread del sistema operativo? A cosa servono le goroutine?

163

Quali sono i livelli di isolamento delle transazioni? Quali hai usato?

161

Parla di resp.Body.Close() — perché è necessario e perché hai impostato un buffer di 10?

160

**Condizione** Le richieste a più URL devono essere eseguite in parallelo. È necessario visualizzare gli stati HTTP e gestire gli errori.

156

Come trovare una query lenta in PostgreSQL e come ottimizzarla?

154

**Condizione** Le richieste a più URL devono essere eseguite in parallelo. Mostrare gli stati HTTP, gestire gli errori. ```go package main func main() { urls := []string{"[link]"} // Fare qualcosa } ```

153

Come distingui gli sviluppatori Junior, Middle e Senior? Per quali criteri ti consideri Senior?

149

Scrivi una query SQL che mostri **il nome del cliente**, la **città** e **la somma totale** di tutti i suoi ordini. La query finale deve includere solo quei clienti il cui totale speso supera **1000** unità. --- **Schema dei dati:** 1. **Tabella `customers`:** - `customer_id` (int) – identificativo unico del cliente. - `customer_name` (varchar) – nome del cliente. - `city` (varchar) – città di residenza. 2. **Tabella `orders`:** - `order_id` (int) – numero unico dell'ordine. - `customer_id` (int) – ID del cliente che ha effettuato l'acquisto. - `total_amount` (decimal) – importo di un ordine specifico.

145
/3