Index

Symbols

  • := operator, 62, 179, 204
  • != operator, 82, 83
  • & operator, 50, 51, 52
  • & (AND) operator, 90
  • && (AND) operator, 86–88, 104–105
  • + (addition) operator, 70
  • += (addition) operator, 78, 79
  • < operator, 82
  • <= operator, 82
  • = operator, 78
  • == operator, 82, 254–255
  • > operator, 82
  • >= operator, 82
  • _ (blank identifier), 184, 387–388
  • ` (back-tick single quotes), 445
  • {} (curly brackets), 106, 108, 177, 240, 289, 487
  • * (dereferencing operator), 225, 227
  • // (double slashes), 23, 26
  • -- (decrement) operator, 70, 71
  • / (division) operator, 70
  • /= (division) operator, 78
  • / (forward slash), 455
  • ++ (increment) operator, 70, 71
  • << (left shift) operator, 90
  • * (multiplication) operator, 70
  • *= (multiplication) operator, 78
  • % (modulus) operator, 70
  • %= (modulus) operator, 78
  • ! (NOT) operator, 86–88
  • | (OR) operator, 90
  • || (OR) operator, 86–88, 104–105
  • >> (right shift) operator, 90
  • [] (square brackets), 196
  • − (subtraction) operator, 70
  • −= (subtraction) operator, 78
  • _ (underscore), 387
  • ^ (XOR) operator, 90

A

  • Abbott, Edward (author)
    • Flatland, 454
  • Abs function, 88
  • acceptance testing, 528
  • access rights, 651–654
  • accessing
    • Google location data, 616
    • Yahoo! Finance, 624–627
  • Account struct, 563–564
  • Add function, 176–177, 439
  • addCondiment method, 347
  • AddDate function, 439–440
  • adding
    • assignment operations for, 78–80
    • conditional statements, 154–156
    • custom errors, 515–516
    • data, 566
    • days, 439–440
    • delays, 411–412
    • duration to date/time, 436–438
    • exception handling, 515–516
    • hours, 438–439
    • methods to structs, 250–252
    • minutes, 438–439
    • months, 439–440
    • in PEMDAS, 76
    • records, 578–584
    • routers, 571–574
    • seconds, 438–439
    • years, 439–440
  • After function, 433–434
  • anonymous function, 188–189
  • api.go file, 635–637, 639–644
  • APIs, 635–644. See also REST API; smart data
  • append function, 278
  • appending to slices, 278
  • architecture-independent integer types, 58–60
  • arguments
    • command-line, 479–480
    • defined, 176
    • working with, 314–319
  • arithmetic operations, 70–75
  • arrays
    • about, 195–196
    • assigning values to elements in, 196–198
    • basic rules of, 198–200
    • changing values in, 229–230
    • comparing, 210–212
    • creating multidimensional, 207–209
    • declaring, 196–204
    • duplicating, 209–210, 214
    • exercises, 212–214
    • inferring size of, 204–205
    • initializing, 203–204
    • of pointers, 227–230
    • slicing, 265–268
    • using for loops to define, 205–206
    • using range with, 206–207
    • variables compared with elements from, 201
  • assigning
    • numeric data types, 65–66
    • values
      • to array elements, 196–198
      • to Boolean variables, 84
    • variables, 65
  • assignment operations
    • about, 78
    • addition, 78–80
    • division, 80–81
    • modulus, 80–81
    • multiplication, 80–81
    • subtraction, 78–80
  • Atom, 4

B

  • Before function, 433–434
  • Beginning Regular Expressions (Watt), 498
  • Behave, 556
  • behavior-driven development (BDD), 555–558
  • binary operator, 70
  • bitwise operations, 90–91
  • block comments, 27–28
  • block of code, 25
  • Booleans
    • about, 81–82
    • assigning values to variables, 84
    • Boolean operations, 86–88
    • simplifying expressions, 255
    • working with, 81–82
  • break statement, 136–137
  • buffered reader, 461–462
  • buffered writer, 468–470
  • Building a Burger Shop application
    • about, 343
    • creating helper functions, 359–364
    • creating structs, 345–359
    • full listing for, 367–375
    • planning code, 344–345
    • requirements for, 344
    • tying code together, 364–367
  • BuildYahooRequest function, 630–631
  • burger struct, 346–349
  • byte type, 59

C

  • calculating
    • current value of deposit, 96
    • date differences, 435–436
    • simple interest, 96
    • tax rate in income tax calculator, 152–163
    • taxable income in income tax calculator, 150–152
  • cap function, 266–267
  • case, 30–31
  • Ceil function, 88
  • changing
    • access rights, 653–654
    • directories, 475–477
    • values
      • in arrays, 229–230
      • from functions, 231–232
    • variables using pointers, 225–226
  • channels
    • adding delays, 411–412
    • closing, 413–415
    • concurrency and, 409–411
    • creating using make, 409
    • iterating through, 415–417
    • with multiple goroutines, 412–413
    • working with, 408–412
  • chat package, creating, 600–601
  • chat service, creating, 597–599
  • Chdir function, 476–477
  • checking
    • interface type, 332–334
    • for keys, 296–298
    • sorted values, 423–424
  • circleStuff function, 183, 187, 191
  • client_finance.go file, 623–624, 633–635
  • client_geolocation.go file, 619–621
  • clients, 601–603
  • close statement, 459
  • closeAccount function, 247
  • closing channels, 413–415
  • closures, 188–190
  • Cloudhadoop, 63
  • code
    • block of, 25
    • compared to standards, 167
    • formatting, 14–15
    • interfaces and reusability of, 328–329
    • planning for Building a Burger Shop application, 344–345
    • tagging, 37
  • code listings
    • accessing
      • pointer's stored value, 222–223
      • variable's address in memory, 50–51
    • Account struct, 563–564
    • add function, 176–177, 189
    • addCondiment method, 347
    • adding
      • conversions, 151–152
      • days, 440
      • delays, 411–412
      • duration to date/time, 436–438
      • first tier of tax calculator, 153–154
      • hours, 438–439
      • minutes, 438–439
      • months, 440
      • prompts in income tax calculator, 149–150
      • second tier of tax calculator, 155–156
      • second tier using else if statement, 156–157
      • seconds, 438–439
      • taxable income formula, 150–151
      • 22% tier, 157–158
      • 24% tier, 158–159
      • two values, 54–55
      • unmarshaling to read_json_file function, 492
      • weeks, 438–439
      • years, 440
    • api.go file, 635–637, 639–644
    • appending to slices, 278
    • architecture-independent integers, 59–60
    • assigning
      • different data types, 202–203
      • extra index values, 200
      • multiple types in declarations, 48
      • values out of range, 60–61
      • values to array indexes, 201–202
      • values to Boolean variables, 84
    • basic for loop, 126–128
    • blank identifiers, 387–388
    • Building a Burger Shop application, 367–375
    • BuildYahooRequest function, 630–631
    • burger struct, 346, 348–349
    • capturing syntax errors, 380–381
    • changing
      • active directories, 476–477
      • for low incomes, 166–167
      • read_json_file, 495–496
      • values in arrays, 229–230
      • variable's value via pointers, 225–226
    • checking
      • case, 230–231
      • interface type, 332–334
      • for keys, 297–298
      • for nil, 224
    • client_finance.go file, 623–624, 633–635
    • client_geolocation.go file, 619–621
    • closing channels, 414–415
    • code reusability, 328–329
    • code to test combo, 356
    • combo struct, 355
    • comparing
      • arrays, 210–212
      • pointers, 226–227
      • structs, 254–255
      • time, 433–434
    • computePrice method, 346–347, 351, 353–354, 355–356, 358
    • contains function, 360–361
    • converting
      • data types for operations, 74–75
      • input text to lowercase, 500–501
      • strings to ints, 56
      • strings to uppercase, 232
    • copying slices, 279–280
    • counting
      • to 10 linearly, 124–125
      • reviews, 506–509
      • words in reviews, 505–506
    • count_words, 518–524
    • createAccount function, 578–579
    • creating
      • arrays of pointers, 227–228
      • channels using make, 409
      • chat package, 600–601
      • chat service, 598
      • clients, 601–603
      • custom error methods, 384–385
      • detailed custom error messages, 388–390
      • directories, 471–472
      • dynamically typed variables using := operator, 45
      • empty maps, 291
      • files, 467–468
      • gRPC servers, 596–597
      • interfaces, 326–328
      • maps using make, 293
      • nil pointers, 223–224
      • pointers to functions, 247–248
      • random numbers, 91–92
      • series of directories, 473–474
      • servers, 595–596
      • slice variables, 272–273
      • slices with make function, 272
      • statements, 35
      • statically typed variables, 45
      • structs, 238–239, 245–246
      • temporary files/directories, 477–479
      • test data, 566, 567
      • variables to store strings, 41
    • custom error handling, 382–383
    • Dataset struct, 510
    • declaring
      • arrays, 197, 203–204
      • high-range value variables, 159–160
      • multiple variables in one statement, 43
      • multiple variables on one line, 44
      • pointers in one statement, 218–219
      • two variables, 216–217
    • defining
      • arrays with for loops, 205–206
      • channels, 408–409
      • maps, 289–290
      • methods on custom types, 307–308
      • slices, 267–268
    • deleteAccount function, 584–585
    • deleting
      • directories, 472–473
      • map elements, 300–301
    • display method, 347–348, 351–352, 354, 356, 358–359
    • displaying individual attributes in read_json_file function, 492–493
    • Dollar.go file, 536, 539–540, 542–545, 549–550, 553–555
    • Dollar_test.go file, 535–541, 543–544, 548–549, 551–553
    • drink struct, 350
    • dropping initialization and post-argument expressions, 128–129
    • duplicating
      • arrays, 209–210
      • keys, 290–291
    • dynamic typing, 219
    • dynamically typing age variable, 46
    • embedded functions, 189–190
    • embedded if statements, 109
    • embedded interfaces, 337–339
    • empty function, 517
    • empty interfaces, 332
    • empty slices, 275
    • end-of-line comments, 27
    • equivalent of while loop, 129–130
    • Errorf function, 385–387
    • example of final tokens, 23–24
    • exercises, 19–20
    • expanding read_json_file, 489–490
    • failing to add values to array elements, 199
    • final main function for burger shop, 365–367
    • finance.go file, 623, 632–633
    • finance.proto file, 621–622
    • fixing problems, 34–35
    • FormatAmount function, 539–540
    • function vs. method, 306–307
    • geolocation directory, 614–615
    • geolocation.go file, 614–618
    • geolocation.proto file, 613
    • getGeoLocationData function, 637–638
    • getName method, 346, 350, 353, 355, 357
    • getQuote function, 638–639
    • GetQuoteData function, 632–633
    • getSize method, 350–351
    • getting
      • current date and time, 429–430
      • parts of dates/times, 431–432
    • global variable scope, 49–50
    • gRPC server, 612
    • handleRequests function, 565–566, 571–572, 575, 579–582, 585
    • Hello, World! program, 10, 15, 24–25
    • homePage function, 564
    • implementation-specific integer types, 62
    • improving structs, 509–510
    • indenting single-line comments, 26–27
    • inferring array size, 205
    • infinite loops, 131–132
    • initializing
      • arrays, 203–204
      • maps, 289–290
      • multiple variables on one line, 44
      • pointers, 217–219
    • inputting two variables, 51–53
    • internal representation of interfaces, 330–331
    • invalid variable declarations, 47
    • iterating
      • slices, 270–271
      • through maps, 298–299
    • listing contents of directories, 474–475
    • local variable scope, 48–49
    • looping
      • through slices with range, 277
      • through strings, 132–133
    • main function, 348, 354, 496–497, 503–504, 511–515
    • main.go file, 613–614, 622–623
    • map length, 294
    • method and value receiver, 309–310
    • misusing case, 30–31
    • mixing
      • data types in operations, 72–73
      • data types of declarations, 46–47
    • multi-line comments, 27–28
    • multiple interfaces, 334–337
    • naming methods, 313–314
    • nested if statements, 108
    • order struct, 357
    • orderBurger function, 361
    • orderCombo function, 364
    • orderDrink function, 363–364
    • orderSide function, 362
    • outputting
      • text, 35–36
      • zero, 95–96
    • parsing time, 441–442
    • passing
      • pointers to value arguments, 316
      • structs created with new, 246–247
      • values to pointer arguments, 318–319
    • pausing execution, 404
    • pointers of various types, 220–221
    • powers of 2, 130–131
    • presenting case values on separate lines, 115
    • printing
      • individual array elements, 198
      • sections of slices, 276
      • without repeating, 36
    • prompting for income in income tax calculator, 149
    • reading
      • bytes from files, 457–459
      • files, 454–456
      • lines, 463–465
      • values from channels, 415–416
    • read_json_file function, 488–489, 510–511, 515–516
    • reassigning values, 310–311
    • recursion, 187
    • removing elements from slices, 282–283
    • replacing slice elements, 274
    • resizing slices, 269–270
    • retrieving
      • values from maps, 295, 296
      • values from structs, 240
    • returnAccount function, 574–575
    • returnAllAccounts function, 565
    • returning named types, 183
    • reversing sort order, 427–428
    • sending values to pointers, 317–318
    • showing PEMDAS in action, 77–78
    • side struct, 352–353
    • simple goroutine, 403–404
    • single-line comments, 26–27
    • skipping return values, 184–185
    • slicing arrays, 265–266
    • sorting
      • integers, 422–423
      • by length, 425–426
      • strings, 423
    • splitting strings, 501–502
    • Square.go program, 531
    • Square_test.go program, 532–533
    • storing floats in integers, 58
    • structs for modeling JSON, 490–491
    • SubtractFormatAmount function, 540–545, 549–550
    • subtracting dates, 435–436
    • supporting arrays for user choices, 360
    • tax calculations with remaining tiers added, 162–163
    • tax program with updated tax calculation, 164–165
    • testing
      • drink functionality, 352
      • programs to call modules, 648–649
    • TestSubtractFormatAmount3 function, 548–549
    • tokenize function, 502–503, 512–514, 517–518, 520–524
    • tokenizing
      • datasets, 504
      • reviews, 506–509
    • two-dimensional arrays, 208–209
    • type and value, 252–253
    • type casting in relational operations, 85–86
    • type mismatch in relational operations, 84–85
    • updating
      • server code, 599–600
      • tax calculations with variables, 161–162
    • using
      • addition and subtraction assignment operators, 79–80
      • arithmetic operators, 70–71
      • bitwise operators, 90–91
      • Boolean operators, 87–88
      • Boolean type variables, 81–82
      • break statement, 136–137
      • buffered readers, 462
      • buffers, 468–470
      • cap function, 266–267
      • channels with two goroutines, 412–413
      • command-line arguments, 479–480
      • Compile, 446–448
      • concatenation on strings, 53
      • concurrent channels, 409–411
      • conditions in switch statements to determine grades, 115–116
      • continue statement to print odd numbers, 137–138
      • defer statement, 459–460
      • fallthrough, 112–113
      • float types, 63
      • functions as values, 188
      • functions in structs, 250–252
      • functions with different return types, 182–183
      • functions with multiple return values, 181–182
      • functions with no return value, 179–180
      • goto statement, 138–139
      • identifiers, 28–30
      • if statements, 102–103
      • if-else statements, 106
      • Intn to limit integer values, 92–93
      • invalid variable names, 41–42
      • key-value pairs, 244
      • len function, 266–267
      • literal declarations for months, 301–302
      • math package, 88–90
      • methods with value receivers, 314–315
      • multiple conditions, 104–105
      • multiple custom error messages, 390–393
      • multiple expressions in a case, 114–115
      • multiple functions, 178–179
      • multiple goroutines, 405–406
      • multiplication, division, and modulus assignment operators, 80–81
      • nested structs, 249–250
      • new keyword, 281–282
      • nonlocal receiver, 308–309
      • panic function, 456–457
      • pointer receivers, 311–312
      • pointers to different types, 221–222
      • range function, 134, 206–207, 416–417
      • regexp package, 445–446, 499–500
      • relational operators, 83
      • seed when generating random numbers, 93–94
      • Seek function, 460–461
      • short assignment operator (:=), 241–242
      • struct literals to initialize structs, 241
      • switch statements, 110–111
      • two timers, 406–408
      • Unix time, 443
      • variables calculating maximum tier taxes, 160
    • utilities.go file, 646–647
    • utilities_test.go file, 647
    • variadic functions to sum integers, 185–186
    • verifying values are sorted, 424
    • working with other standards, 444
    • writing files, 467–468
    • writing to empty maps, 292
    • writing to files, 465–467
  • coercion, 75
  • combo struct, 354–356
  • command prompt, opening, 8
  • command-line arguments, 479–480
  • comments
    • about, 25
    • block, 27–28
    • multi-line, 27–28
    • single-line, 26–27
  • comparing
    • arrays, 210–212
    • pointers, 226–227
    • structs, 254–255
    • times, 432–434
  • Compile, 446–448
  • compiling Hello, World! program, 11–13
  • complex numbers, 63
  • computePrice method, 346–347, 351, 353–354, 355–356, 358
  • concatenation, using on strings, 53
  • concurrency
    • about, 395
    • channels and, 409–411
    • channels with goroutines, 412–413
    • closing channels, 413–415
    • exercises, 418–419
    • goroutines, 402–404
    • iterating through channels, 415–417
    • multiple goroutines, 404–408
    • mutual exclusion, 398–400
    • parallelism, 400–402
    • problems with, 397–398
    • role of operating system, 396–397
    • using, 395–400
    • working with channels, 408–412
  • condition expression, 125
  • conditional statements
    • about, 99–100
    • adding, 154–156
    • creating nested if statements, 107–109
    • exercises, 117–121
    • using
      • if statements, 100–103
      • if-else statements, 105–107
      • switch statements, 109–116
    • working with multiple conditions, 104–105
  • contains function, 360–361
  • continue statement, 137–138
  • control statements, 135–139
  • converting
    • input text to lowercase, 500–501
    • strings
      • to numbers, 53–56
      • to uppercase, 232
    • variables, 65
  • copy function, 278–280
  • copying
  • counting
    • reviews, 506–509
    • words in reviews, 504–506
  • count_words function, 505–506, 518–524
  • Create function, 467–468
  • createAccount function, 578–579
  • creating
    • API, 635–644
    • burger struct, 346–349
    • channels using make, 409
    • chat package, 600–601
    • chat service, 597–599
    • clients, 601–603
    • combo struct, 354–356
    • datasets, 562–571
    • directories, 471–472
    • directory trees, 473–474
    • drink struct, 350–352
    • files, 467–468
    • functions, 191
    • go.mod file, 647–648
    • gRPC servers, 596–597
    • Hello, World! program, 10
    • helper functions, 359–364
    • inputs for income tax calculator program, 148–150
    • interfaces, 325–328
    • maps, 292–293, 303
    • multidimensional arrays, 207–209
    • nested conditionals, 156–163
    • nested if statements, 107–109
    • order struct, 357–359
    • pointers, 215–222
    • programs, 646–647
    • project directory, 645–646
    • servers, 595–596
    • side struct, 352–354
    • slice variables with var, 272–273
    • slices using new keyword, 280–282
    • statements, 35
    • structs, 345–359
    • test programs, 647
    • testing programs, 531
    • tokenize function, 502–504
    • variables, 41, 45, 65
  • criteria statements, 103
  • CRUD actions, 562, 574
  • Cucumber, 556
  • current value of deposit, calculating, 96
  • CurrentAccount function, 247
  • custom error handling, 382–383
  • custom sort functions, 425–427

D

  • data
    • adding, 566
    • examining, 486–488
    • reading review data, 488–497
  • Dataset struct, 510
  • datasets
    • creating, 562–571
    • datasets, 563–564
    • tokenizing, 504
  • dates. See time and date operations
  • Day() function, 430
  • days, adding, 439–440
  • deadlocks, 400
  • declaring
    • arrays, 196–204
    • pointers, 218–219
    • structs, 238–242
    • variables, 42–44
  • default values, 199
  • defer statement, 459–460
  • defining
    • datasets, 563–564
    • maps, 287–291
    • methods, 307–309
    • time, 431–432
    • user stories, 558
  • delays, adding, 411–412
  • DELETE request, 562, 574
  • deleteAccount function, 584–585
  • deleting
    • directories, 472–473
    • elements of maps, 299–301
    • items from slices, 282–283
    • records, 584–588
  • designing
    • APIs for smart data, 608–611
    • improvements for, 509–520
    • income tax calculator program, 148
  • digital representation, for permissions, 654
  • directories
    • about, 470
    • changing, 475–477
    • creating, 471–472
    • creating directory trees, 473–474
    • deleting, 472–473
    • listing contents of, 474–475
    • temporary, 477–479
  • display method, 347–348, 351–352, 354, 356, 358–359
  • displaying access rights, 652–653
  • DisplayUpper function, 180
  • distributed processing, 396
  • division
    • assignment operations for, 80–81
    • in PEMDAS, 76
  • Dollar.go file, 536, 539–540, 542–545, 549–550, 553–555
  • Dollar_test.go file, 537–544, 548–549, 551–553
  • downloading installation files, 4–5
  • drink struct, 350–352
  • duration, adding to date/time, 436–438
  • dynamic interface type, 330–331
  • dynamic type declarations, 44–48
  • dynamic typing, 219

E

  • editor, online, 16–18
  • else if statement, 156–157
  • else keyword, 107
  • embedded functions, 189–190
  • embedded interfaces, 337–339
  • empty function, 517
  • empty interfaces, 332
  • empty maps, 291–292
  • empty slices, 274–275
  • encoding/json package, 562
  • Equal function, 433–434
  • error handling
    • about, 379
    • blank identifiers, 387–388
    • custom, 382–383
    • error messages with structs, 388–390
    • error methods, 383–385
    • error types, 380–382
    • Errorf function, 385–387
    • exercises, 393–394
    • in Go programs, 379–380
    • multiple custom error messages, 390–393
  • error types, 380–382
  • Errorf function, 385–387
  • examining data, 486–488
  • exception handling, adding, 515–516
  • EXE file, 13
  • executable specifications, 558
  • Execute access, 651
  • executing
    • more than one case with fallthrough, 111–114
    • request handler, 566–568
  • exercises
    • arrays, 212–214
    • code listing, 19–20
    • concurrency, 418–419
    • conditional statements, 117–121
    • creating statements, 35
    • error handling, 393–394
    • file I/O and OS operations, 481–483
    • functions, 191–193
    • Go, 18–20, 33–37
    • gRPC, 604–605
    • interfaces, 339–341
    • loops, 140–144
    • maps, 302–304
    • methods, 320–324
    • modules, 649–650
    • operations, 95–98
    • outputting text, 35–36
    • pointers, 233–236
    • printing without repeating, 36
    • for problem-solving, 34–35
    • REST API, 588–589
    • slices, 283–286
    • sorting, 448–452
    • structs, 256–261
    • tagging code, 37
    • time and date operations, 448–452
    • variables, 64–67
  • Exp function, 88
  • explicit type conversion, 75
  • exponents, in PEMDAS, 75

F

  • fallthrough, executing more than one case with, 111–114
  • Fibonacci function, 192
  • Fields function, 501–502
  • file I/O and OS operations
    • about, 453
    • command-line arguments, 479–480
    • directories, 470–479
    • exercises, 481–483
    • reading files, 454–465
    • writing to files, 465–470
  • files
    • creating, 467–468
    • permissions for, 651–654
    • reading
      • from specific starting points, 460–461
      • subsets of, 457–459
    • temporary, 477–479
    • writing to, 465–470
  • Finance Server Shell, 621–635
  • finance.go file, 623, 632–633
  • finance.proto file, 621–622
  • FindString function, 447
  • Flatland (Abbott), 454
  • Float32() function, 74, 92, 183, 221
  • Float64() function, 92, 152
  • floats
    • about, 73–74
    • sorting, 448
    • types of, 62–63
  • Floor function, 88
  • flowcharts, 101
  • for loops
    • about, 125–128, 490
    • infinite, 131–132
    • instead of while, 129–131
    • optional items in, 128–129
    • using to define arrays, 205–206
  • Format function, 444
  • FormatAmount function, 539–540
  • formatting
    • code, 14–15
    • standard times, 443–444
  • func keyword, 177
  • functions
    • about, 175
    • changing values from, 231–232
    • closures, 188–190
    • creating, 191
    • defining, 175–185
    • exercises, 191–193
    • with integers, 320–321
    • with multiple return values, 180–185
    • with no return values, 179–180
    • recursion, 186–187
    • using multiple, 177–179
    • using pointers with, 230–232
    • as values, 187–188
    • variadic, 185–186

G

  • Geeks for Geeks, How to Write Regular Expressions, 446
  • geolocation, 608
  • geolocation directory, 614–615
  • Geolocation server, 612–621
  • geolocation.go file, 614–615, 617–618
  • geolocation.proto file, 613
  • GET request, 562, 568–569, 574, 575
  • getGeoLocationData function, 637–638
  • getName method, 346, 350, 353, 355, 357
  • getQuote function, 638–639
  • GetQuoteData function, 632–633
  • getSize method, 350–351
  • Git, 592–593
  • Go
    • about, 3
    • basics of, 21–37
    • comments, 25–28
    • errors in programs, 379–380
    • exercises, 18–20, 33–37
    • identifiers, 28–32
    • installing, 4–8
    • keywords, 32–33
    • online editor, 16–18
    • statements, 22–23
    • tokens, 22
    • versions of, 16
  • go build command, 12, 14
  • go fmt command, 15, 16
  • Go fmt package, 16
  • Go formatting tool, 16
  • Go Playground, 16–18, 190
  • GoLang package regexp, 446
  • go.mod file, 647–648
  • Google location data, 616
  • Google Maps API, 616, 617–618
  • Google's Language Guide, 598
  • Gorilla Mux, 571–574
  • goroutine function, 403
  • goroutines
    • channels with multiple, 412–413
    • multiple, 405–408
    • passing to, 418
    • using, 402–404
  • gotest command, 13
  • goto statement, 138–139
  • gRPC
    • about, 591
    • creating
      • chat package, 600–601
      • chat service, 597–599
      • clients, 601–603
      • gRPC servers, 596–597
      • servers, 595–596
    • exercises, 604–605
    • Git, 592–593
    • implementing servers, 611–635
    • Protobuf, 593–594
    • Protoc, 594
    • running servers and clients, 603
    • setting up, 592–595
    • updating server code to include chat service, 599–600
    • user directory, 595
    • working with, 592

H

  • handleRequests function, 565–566, 571–572, 575, 579–582, 585
  • handlers, 562
  • Hello, World! program
    • code listing, 15, 24–25
    • compiling, 11–13
    • creating, 10
    • running, 11–13
    • troubleshooting, 14
  • helper functions, creating, 359–364
  • homePage function, 564
  • Hour() function, 430
  • hours, adding, 438–439

I

  • identifiers
    • about, 28–30
    • case, 30–31
    • defined, 22
    • naming conventions, 31–32
  • if statements
    • nested, 107–109
    • using, 100–103
  • if-else statements, 105–107
  • implementation-specific integer types, 61–62
  • implementing
    • getGeoLocationData function, 637–638
    • getQuote function, 638–639
    • gRPC servers, 611–635
    • parallelism, 400–401
  • implicit type conversion, 75
  • import statement, 55, 89
  • improving
    • structs, 509–515
    • tokenizing, 516–518
    • word counting, 518–520
  • income tax calculator
    • about, 145–146
    • addressing UI, 168–171
    • calculating
      • tax rate, 152–163
      • taxable income, 150–152
    • creating inputs, 148–150
    • designing program, 148
    • gathering requirements, 146–148
    • getting started, 146
    • updating application, 164–168
  • infinite loops, 131–132
  • initialization expression, 125
  • initializing
    • arrays, 203–204
    • pointers, 217–219
    • structs, 238–242
    • variables, 42–44
  • input reviews, tokenizing, 503–504
  • input strings, tokenizing, 497–502
  • input text, converting to lowercase, 500–501
  • inputs, creating for income tax calculator, 148–150
  • installing
    • Go, 4–8
    • testing installation, 8–10
  • Int() function, 61, 92
  • integers
    • functions with, 320–321
    • methods with, 321
    • sorting, 422–423
  • integration testing, 528
  • interfaces
    • about, 325
    • checking type of, 332–334
    • code reusability and, 328–329
    • creating, 325–328
    • embedded, 337–339
    • empty, 332
    • exercises, 339–341
    • multiple, 334–337
    • static vs. dynamic types, 330–331
  • Ints function, 422
  • isupper function, 231
  • iterating
    • slices, 270–271
    • through channels, 415–417
    • through maps, 298–299

K

  • keys, duplicating, 290–291
  • key-value pairs
    • using with structs, 242–244
    • for Yahoo! Finance API, 627
  • keywords, 22, 32–33

L

  • Len function, 266–267, 425–426
  • length, of maps, 294
  • Less function, 425–426, 427
  • limiting values, 92–93
  • lines, 462
  • Linux
    • changing access rights in, 653–654
    • displaying access rights in, 652–653
  • listing directory contents, 474–475
  • literal declarations, in maps, 301–302
  • literals, 22
  • Local() function, 431
  • Location() function, 431
  • log package, 563
  • loops
    • for, 125–132
    • about, 123–124
    • control statements, 135–139
    • exercises, 140–144
    • looping statements, 124–125
    • range function, 134–135
    • through strings, 132–133
  • lowercase, converting input text to, 500–501

M

  • main() function, 11, 176, 181, 187, 239, 334, 336, 339, 348, 354, 407–408, 428, 494, 496–497, 503–504, 508, 511–515, 536, 566–568
  • main package, 22
  • main.go file, 613–614, 622–623
  • make function
    • about, 271–272
    • creating channels using, 409
    • creating maps using, 292–293
  • maps
    • about, 287
    • checking for keys, 296–298
    • creating, 292–293, 303
    • defining, 287–291
    • deleting elements of, 299–301
    • duplicating keys, 290–291
    • empty, 291–292
    • exercises, 302–304
    • iterating through, 298–299
    • length of, 294
    • literal declarations in, 301–302
    • maintaining type, 289–290
    • retrieving elements of, 294–296
  • MatchString function, 447
  • math functions, 88–90
  • memory address, 50–51
  • methods
    • about, 305
    • adding to structs, 250–252
    • defining, 307–309
    • error, 383–385
    • exercises, 320–324
    • with integers, 321
    • naming, 312–314
    • using pointers with, 309–312
    • working with, 305–307
    • working with arguments, 314–319
    • working with pointer receivers, 317–319
    • working with value receivers, 314–316
  • Minute() function, 430
  • minutes, adding, 438–439
  • mismatched types, using in relational operations, 84–86
  • mixing number types, 72–73
  • Mkdir function, 471–472
  • MkdirAll function, 473–474
  • modules
    • about, 645
    • creating
      • go.mod file, 647–648
      • programs, 646–647
      • project directory, 645–646
      • test program, 647
    • exercises, 649–650
    • getting started with, 645
    • naming functions of, 649
    • testing, 648
    • using, 648–649
  • modulus assignment operations, 80–81
  • Month() function, 430
  • months, adding, 439–440
  • MSI installer, 8
  • multidimensional arrays, 207–209
  • multi-line comments, 27–28
  • multiple conditions, working with, 104–105
  • multiple interfaces, 334–337
  • multiplication
    • assignment operations for, 80–81
    • in PEMDAS, 76
  • multiprocessing, 396
  • multiprogramming, 396
  • MustCompile function, 499
  • mutual exclusion, 398–400

N

  • naming
    • methods, 312–314
    • module functions, 649
    • variables, 41–42
  • naming conventions, 31–32
  • Nanosecond() function, 430
  • negative taxable income, 166–167
  • nested conditionals, 156–163
  • nested if statements, 107–109
  • nested structs, 248–250
  • net/http package, 563
  • new() function, 246
  • new keyword
    • creating slices using, 280–282
    • using, 245–247
  • NewChatServiceClient function, 602–603
  • NewReader function, 461–462
  • NewScanner function, 465, 489
  • nil pointers, 223–224
  • Now() function, 94
  • numbers
    • converting strings to, 53–56
    • mixing types, 72–73
    • type casting, 73–75
  • numeric data types
    • about, 57–58
    • architecture-independent integer types, 58–60
    • assigning, 65–66
    • float types, 62–63
    • implementation-specific integer types, 61–62
    • out-of-range values, 60–61

O

  • online editor, 16–18
  • Open function, 464–465
  • opening command prompt, 8
  • operating system (OS), role of, 396–397
  • operations
    • about, 69
    • arithmetic, 70–75
    • assignment, 78–81
    • bitwise, 90–91
    • Booleans, 81–82, 86–88
    • exercises, 95–98
    • math functions, 88–90
    • PEMDAS, 75–78
    • random numbers, 91–94
    • relational, 82–86
  • operators, 22
  • order struct, 357–359
  • orderBurger function, 359, 361
  • orderCombo function, 359, 364
  • orderDrink function, 359, 363–364
  • orderSide function, 359, 362
  • out-of-range values, 60–61
  • outputting
    • text, 35–36
    • zero, 95–96

P

  • package token, 22
  • panic function, 456–457
  • parallelism
    • about, 400
    • implementing, 400–401
    • preventing problems with, 401–402
  • parentheses, in PEMDAS, 75
  • Parse function, 441–442
  • parsing time, 441–442
  • passGenerator function, 190
  • passing to goroutines, 418
  • Peek function, 462
  • PEMDAS, 75–78
  • pointer receivers, 317–319
  • pointers
    • about, 215
    • accessing stored value of, 222–223
    • changing
      • values from functions, 231–232
      • values in arrays, 229–230
    • comparing, 226–227
    • creating, 215–222
    • declaring, 218–219
    • dynamic typing, 219
    • exercises, 233–236
    • initializing, 217–219
    • nil, 223–224
    • structs and, 247–248
    • types of, 219–222
    • using
      • to change variables, 225–226
      • with functions, 230–232
      • with methods, 309–312
    • working with arrays of, 227–230
  • post expression, 125
  • POST request, 562, 574, 578
  • Postman app, 562, 568–569
  • Pow function, 88
  • prefix operators, 71
  • Print statement, 52–53
  • printing, without repeating, 36
  • Println() function, 11, 30, 31, 53, 71, 79, 83, 89, 134–135, 176, 275, 331, 332, 403, 408, 444, 490
  • problem-solving, exercises for, 34–35
  • Project Gutenberg, 454, 481
  • Protobuf, 593–594
  • Protoc, 594
  • punctuation
    • defined, 22
    • identifying, 498–500
    • replacing with a space, 498–500
  • PUT request, 562, 574

Q

  • querying Yahoo! Finance API, 627–630

R

  • random number generator, 93–94
  • random numbers, 91–94
  • range function
    • about, 134–135
    • using with arrays, 206–207
    • using with slices, 277
  • Read access, 651
  • ReadDir function, 474–475
  • ReadFile function, 455
  • reading
    • files
      • line by line, 462–465
      • from specific starting points, 460–461
    • review data, 488–497
    • subsets of files, 457–459
  • read_json_file function, 488–489, 492–493, 495–496, 503–504, 510–511, 515–516
  • records
    • adding, 578–584
    • deleting, 584–588
    • retrieving, 574–578
  • rectStuff function, 181
  • recursion, 186–187, 192
  • reflect package, 382
  • regexp package, 445–446, 498–500
  • RegisterChatServiceServer function, 600
  • Regular Expression Library, 446
  • regular expressions (regex/regexp), 445–448
  • relational operations, 82–86, 98
  • Remove function, 477–479
  • RemoveAll function, 472–473, 477–479
  • repeating, printing without, 36
  • RepeatString function, 646–647
  • ReplaceAllString function, 498
  • replacing
    • punctuation with a space, 498–500
    • slice elements, 273–274
  • Representational State Transfer (REST). See REST API
  • request handler, executing, 566–568
  • requests
    • defined, 562
    • managing and routing incoming, 565–566
  • requirements
    • for Building a Burger Shop application, 344
    • for REST API, 561–562
  • resizing slices, 268–270
  • REST API
    • about, 561
    • adding
      • data, 566
      • records, 578–584
      • router, 571–574
    • creating
      • datasets, 562–571
      • simple API, 562–571
    • defining datasets, 563–564
    • deleting records, 584–588
    • executing request handler, 566–568
    • exercises, 588–589
    • homePage function, 564
    • managing incoming requests, 565–566
    • overview and requirements for, 561–562
    • retrieving records, 574–578
    • return handler, 565
    • routing incoming requests, 565–566
    • running program, 568–571
  • retrieving
    • elements of maps, 294–296
    • records, 574–578
    • values from structs, 239–240
  • return handler, 565
  • return statement, 180–181
  • returnAccount function, 574–575
  • returnAllAccounts function, 565
  • returning reviews, 495–497
  • Reverse function, 428–429
  • reversing sort order, 427–429
  • reviews
    • counting, 506–509
    • tokenizing, 506–509
  • Round function, 88
  • routers
    • adding, 571–574
    • defined, 562
  • routing incoming requests, 565–566
  • rune type, 59
  • running
    • clients, 603
    • Hello, World! program, 11–13
    • REST API program, 568–571
    • servers, 603
    • tests, 533–534

S

  • SayHello method, 601
  • Scan function, 53–54
  • Scanln function, 54
  • scanning, for values, 51–53
  • scope, of variables, 48–50
  • searching strings, 450
  • Second() function, 430
  • seconds, adding, 438–439
  • Seek function, 460–461
  • select function, 33
  • semicolon, 23–25
  • servers
    • creating, 595–596
    • gRPC, 596–597
    • running, 603
    • updating code for, 599–600
  • short assignment operator (:=), 241–242
  • shortcuts, 267–268
  • side struct, 352–354
  • simple interest, calculating, 96
  • simplifying Boolean expressions, 255
  • single-line comments, 26–27
  • size, of arrays, 204–205
  • skip operator, 184
  • Sleep function, 403–404, 406
  • slices
    • about, 263
    • appending to, 278
    • of arrays, 265–268
    • copying, 278–280
    • creating
      • using new keyword, 280–282
      • variables with var, 272–273
    • empty, 274–275
    • exercises, 283–286
    • how they work, 264
    • iterating through, 270–271
    • make function, 271–272
    • removing items from, 282–283
    • replacing elements in, 273–274
    • resizing, 268–270
    • selections of, 275–276
    • using
      • cap function, 266–267
      • len function, 266–267
      • range with, 277
      • shortcuts, 267–268
    • working with elements of, 273–277
  • smart data
    • about, 607
    • creating API, 635–644
    • designing API, 608–611
    • implementing gRPC server, 611–635
    • project overview, 608
  • Sort function, 426
  • sorting
    • about, 421–422
    • checking sorted values, 423–424
    • custom functions for, 425–427
    • exercises, 448–452
    • floats, 448
    • integers, 422–423
    • regular expressions, 445–448
    • reversing sort order, 427–429
    • strings, 423
  • SpecFlow, 556
  • specification workshops, 558
  • spheres, 191
  • Split function, 465, 489, 498
  • splitting strings into words, 501–502
  • Sqrt function, 88
  • Square.go program, 531
  • Square_test.go program, 532–533
  • standard times, formatting, 443–444
  • standards
    • compared to code, 167
    • for income tax calculator, 148
  • starting installation, 5–8
  • statements. See also conditional statements
    • about, 22–23
    • creating, 35
    • criteria, 103
    • group of, 25
    • looping, 124–125
    • mixing type declarations in single, 47–48
  • static interface type, 330–331
  • static type declarations, 44–48
  • stopping servers, 597
  • storing. See variables
  • strconv package, 55
  • strings
    • converting
      • to numbers, 53–56
      • to uppercase, 232
    • looping through, 132–133
    • searching, 450
    • sorting, 423
    • splitting into words, 501–502
  • Strings function, 423
  • StringsAreSorted function, 423–424
  • struct keyword, 253
  • struct literal, 240
  • structs
    • about, 237–238
    • adding methods to, 250–252
    • comparing, 254–255
    • creating, 345–359
    • declaring, 238–242
    • error messages with, 388–390
    • exercises, 256–261
    • improving, 509–515
    • initializing, 238–242
    • nested, 248–250
    • pointers and, 247–248
    • retrieving values from, 239–240
    • types, 252–253
    • using key-value pairs with, 242–244
    • using new keyword, 245–247
    • values, 252–253
  • Sub function, 435–436, 437
  • SubtractFormatAmount function, 540–545, 549–550
  • subtraction
    • assignment operations for, 78–80
    • in PEMDAS, 76
  • sumN function, 186
  • Swap function, 425–426
  • switch statements
    • executing more than one case with fallthrough, 111–114
    • using
      • about, 109–111
      • conditions in, 115–116
      • multiple expressions in one case, 114–115
  • syntax errors, 24, 380–381
  • system testing, 528

T

  • tagging code, 37
  • TempDir function, 479
  • TempFile function, 479
  • temporary files/directories, 477–479
  • test programs, creating, 647
  • test-driven development (TDD)
    • about, 527–528
    • tutorial for, 534–555
    • workflow of, 529–530
  • testing
    • about, 527
    • behavior-driven development (BDD), 555–558
    • exercises, 559–560
    • installation, 8–10
    • levels of, 528–529
    • modules, 648
    • package for, 531–534
    • test-driven development (TDD), 527–528, 529–530
    • Testing Pyramid, 529
    • tutorial on test-driven development, 534–555
    • updates, 575–578
  • Testing Pyramid, 529
  • TestSubtractFormatAmount3 function, 548–549
  • text, outputting, 35–36
  • three-dimensional arrays, 209
  • time and date operations
    • about, 421, 429–431
    • comparing times, 432–434
    • date-time calculator, 450–452
    • defining time, 431–432
    • exercises, 448–452
    • formatting standard times, 443–444
    • parsing time, 441–442
    • time math, 434–440
    • Unix time, 443
  • time package, 429. See also time and date operations
  • time zones, 432, 439
  • tokenize function, 502–504, 506–509, 512–514, 517–518, 520–524
  • tokenizing
    • datasets, 504
    • improving, 516–518
    • input reviews, 503–504
    • input strings, 497–502
    • reviews, 506–509
  • tokens, 22
  • ToLower function, 501
  • troubleshooting
    • Hello, World! program, 14
    • variable problems, 64
  • Trunc function, 88
  • truncating, 96
  • two-dimensional arrays, 213–214
  • type casting numbers, 73–75
  • type keyword, 239
  • TypeOf function, 252–253, 382

U

  • uint, 61
  • unary operator, 70
  • unit testing, 528
  • Unix function, 443
  • Unix time, 443
  • UnixNano() function, 94, 443
  • Unmarshal function, 491
  • updating
    • api.go file, 639–644
    • income tax calculator application, 164–168
    • server code, 599–600
    • testing updates, 575–578
  • user directory, 595
  • user input, obtaining, 50–53
  • user interface (UI)
    • addressing, 168–171
    • for income tax calculator, 147
  • user stories, 558
  • UTF-8, 190
  • utilities.go file, 646–647
  • utilities_test.go file, 647

V

  • value receivers, 314–316
  • ValueOf function, 252–253
  • values
    • assigning
      • to array elements, 196–198
      • to Boolean variables, 84
    • changing
      • in arrays, 229–230
      • from functions, 231–232
    • checking sorted, 423–424
    • functions
      • as, 187–188
      • with multiple return, 180–185
      • with no return, 179–180
    • for income tax calculator, 147
    • limiting, 92–93
    • retrieving from structs, 239–240
    • scanning for, 51–53
    • structs, 252–253
  • var function, creating slice variables with, 272–273
  • variables
    • about, 39–41
    • architecture-independent integer types, 58–60
    • assigning, 65
    • compared with array elements, 201
    • converting
      • about, 65
      • strings to numbers, 53–56
    • creating, 41, 45, 65
    • declaring, 42–44
    • dynamic type declarations, 44–48
    • exercises, 64–67
    • float types, 62–63
    • implementation-specific integer types, 61–62
    • initializing, 42–44
    • memory address, 50–51
    • mixing types of declarations, 46–48
    • naming, 41–42
    • numeric data types, 57–63
    • obtaining user input, 50–53
    • out-of-range values, 60–61
    • scanning for values, 51–53
    • scope of, 48–50
    • static type declarations, 44–48
    • using pointers to change, 225–226
  • variadic functions, 185–186
  • versions, 16
  • Visual Studio Code, 4

W

  • Watt, Andrew (author)
    • Beginning Regular Expressions, 498
  • websites
    • Atom, 4
    • Behave, 556
    • Cloudhadoop, 63
    • Cucumber, 556
    • Fibonacci function, 192
    • Geeks for Geeks, How to Write Regular Expressions, 446
    • Git, 593
    • Go Playground, 16, 190
    • GoLang package regexp, 446
    • Google's Language Guide, 598
    • Project Gutenberg, 481
    • Protoc, 594
    • Regular Expression Library, 446
    • SpecFlow, 556
    • Testing Pyramid, 529
    • Unix time, 443
    • Visual Studio Code, 4
    • Yahoo! Finance, 624
  • Weekday() function, 430
  • while loop, 129–131
  • withdraw function, 319, 390
  • word analysis
    • about, 485
    • counting words in reviews, 504–506
    • creating tokenize function, 502–504
    • design improvements, 509–520
    • examining data, 486–488
    • final code listing, 520–524
    • improvements in, 520
    • reading review data, 488–497
    • tokenizing and counting reviews, 506–509
    • tokenizing input strings, 497–502
  • Write access, 651
  • WriteFile function, 465–467
  • WriteString function, 470
  • writing
    • to files, 465–470
    • tests, 531–533

Y

  • Yahoo! Finance, 624–627
  • Year() function, 430
  • YearDay() function, 431
  • years, adding, 439–440

Z

  • zero, outputting, 95–96
  • Zip file, 9
  • Zone() function, 431
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset