You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/en/guide/interview/golang/basic/1-basic.md
+89-56
Original file line number
Diff line number
Diff line change
@@ -220,6 +220,72 @@ s := []string{"red", "black"}
220
220
```
221
221
:::
222
222
223
+
## Map
224
+
225
+
### Can an uninitialized Map read a key?
226
+
227
+
::: details Answer
228
+
229
+
Yes, an uninitialized `map` that hasn't undergone `make` initialization will return the zero value of the current type for any `key` read.
230
+
231
+
```go
232
+
package main
233
+
234
+
import"fmt"
235
+
236
+
funcmain() {
237
+
varmmap[int]int
238
+
239
+
fmt.Println(m[1])
240
+
}
241
+
242
+
// Output:
243
+
// 0
244
+
```
245
+
:::
246
+
247
+
### What happens if you assign a value to an uninitialized Map?
248
+
249
+
::: details Answer
250
+
251
+
It will trigger a `panic` exception error.
252
+
253
+
```go
254
+
package main
255
+
256
+
funcmain() {
257
+
varmmap[int]int
258
+
259
+
m[1] = 1
260
+
}
261
+
262
+
// Output:
263
+
// panic: assignment to entry in nil map
264
+
```
265
+
266
+
:::
267
+
268
+
### What happens if you delete a key from an uninitialized Map?
269
+
270
+
::: details Answer
271
+
272
+
In earlier versions, performing a `delete` operation on an uninitialized `map` would throw a `panic` error. In current versions, performing a `delete` operation on an uninitialized `map` will not cause an error.
273
+
274
+
```go
275
+
package main
276
+
277
+
funcmain() {
278
+
varmmap[int]int
279
+
280
+
delete(m, 1)
281
+
}
282
+
283
+
// Output:
284
+
//
285
+
```
286
+
287
+
:::
288
+
223
289
224
290
## Others
225
291
### What is the difference between `rune` and `byte` in Go?
@@ -491,69 +557,36 @@ The advantage of using pointer transfer is that it directly transfers the addres
491
557
492
558
:::
493
559
560
+
### Golang Common String Concatenation Methods and Their Efficiency
494
561
495
-
## Map
496
-
497
-
### Can an uninitialized Map read a key?
498
-
499
-
::: details Answer
500
-
501
-
Yes, an uninitialized `map` that hasn't undergone `make` initialization will return the zero value of the current type for any `key` read.
502
-
503
-
```go
504
-
package main
505
-
506
-
import"fmt"
507
-
508
-
funcmain() {
509
-
varmmap[int]int
510
-
511
-
fmt.Println(m[1])
512
-
}
513
-
514
-
// Output:
515
-
// 0
516
-
```
517
-
:::
518
-
519
-
### What happens if you assign a value to an uninitialized Map?
### What happens if you delete a key from an uninitialized Map?
541
-
542
-
::: details Answer
543
-
544
-
In earlier versions, performing a `delete` operation on an uninitialized `map` would throw a `panic` error. In current versions, performing a `delete` operation on an uninitialized `map` will not cause an error.
583
+
### What Are Tags Used for in Golang?
545
584
546
-
```go
547
-
package main
585
+
::: details
548
586
549
-
funcmain() {
550
-
varmmap[int]int
551
-
552
-
delete(m, 1)
553
-
}
554
-
555
-
// Output:
556
-
//
557
-
```
587
+
In Go, struct fields can have various custom tags. When parsing a struct, these tags can be extracted for convenient operations. Common tags include:
558
588
559
-
:::
589
+
-`json`: Used to declare JSON serialization and deserialization operations, specifying fields and options.
590
+
-`db`: Primarily used for database field configuration, often in libraries like sqlx.
591
+
-`form`: Commonly used in web frameworks to declare form field bindings.
592
+
-`validate`: Frequently used for field validation rules by validators.
0 commit comments