O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Learning Go From Hello World to Web Service.pptx

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Próximos SlideShares
Incompleteness for Startups
Incompleteness for Startups
Carregando em…3
×

Confira estes a seguir

1 de 66 Anúncio

Mais Conteúdo rRelacionado

Semelhante a Learning Go From Hello World to Web Service.pptx (20)

Anúncio

Mais recentes (20)

Learning Go From Hello World to Web Service.pptx

  1. 1. Learning Go From Hello World to Web Service Eric Potter
  2. 2. Learning Go From Hello World to Web Service Eric Potter
  3. 3. Background Before we go 4
  4. 4. Creators Rob Pike • Worked at Bell Labs and Google • co-creator of UTF-8 Ken Thompson • Designed and implemented the original Unix Robert Griesemer • Worked on Google's V8 JavaScript engine G e t G o i n g 5
  5. 5. Fast G e t G o i n g 6
  6. 6. G e t G o i n g 7
  7. 7. Tools All systems go 8
  8. 8. Installation P R E S E N T A T I O N T I T L E 9
  9. 9. Go CLI • go run • go build • go mod init • go test • go get • go fmt • etc G e t G o i n g 10
  10. 10. IDEs VS Code GoLand ($) G e t G o i n g 11
  11. 11. Hello World Demo G e t G o i n g 12
  12. 12. Hello World G e t G o i n g 13
  13. 13. Types Go your own way 14
  14. 14. Basic Types • bool • string • int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64 • rune // alias for int32 that represents a Unicode code point • float32, float64 • complex64, complex128 G e t G o i n g 15
  15. 15. Variable Declaration G e t G o i n g 16
  16. 16. Syntax Let it go 17
  17. 17. Terse ; ( ) G e t G o i n g 18
  18. 18. Notable Omissions ++i do {} while G e t G o i n g 19
  19. 19. Function Syntax C# public <returnType> <name> (<args>) Go func <name> (<args>) <returnType> G e t G o i n g 20
  20. 20. Fizz Buzz Demo G e t G o i n g 21
  21. 21. Fizz Buzz G e t G o i n g 22
  22. 22. Questions G e t G o i n g 23
  23. 23. Exercise 1 Euler 1 1) If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. 2) The Math.Sin values for 2 is positive and the value for 5 is negative. Print the sum of the positive sine values from the input between 0 and 10. If you get done, try Euler 2 (https://projecteuler.net/problem=2) G e t G o i n g 24
  24. 24. Euler 1 G e t G o i n g 25
  25. 25. G e t G o i n g 26
  26. 26. Arrays Go home 28
  27. 27. Declaring Arrays G e t G o i n g 29
  28. 28. Accessing Array Elements G e t G o i n g 30
  29. 29. G e t G o i n g 31
  30. 30. Iterate over an Array G e t G o i n g 32
  31. 31. The size is part of the type G e t G o i n g 33
  32. 32. Slices Go home 34
  33. 33. G e t G o i n g 35
  34. 34. Dynamic Sizing G e t G o i n g 36
  35. 35. Ranges G e t G o i n g 37
  36. 36. Classes Go home 38
  37. 37. Classes Go home 39 Packages & Structs
  38. 38. Defining a Struct G e t G o i n g 40
  39. 39. G e t G o i n g 41
  40. 40. G e t G o i n g 42
  41. 41. Associating Functions with Structs G e t G o i n g 43
  42. 42. Interfaces Go home 44
  43. 43. Defining an Interface G e t G o i n g 45
  44. 44. Questions G e t G o i n g 46
  45. 45. Exercise 2 Create a GIF Using the image/gif and image/color packages, create a gif of a checker board. Using the same libraries, create an animated gif of a sine wave. G e t G o i n g 47
  46. 46. Concurrency You go your way, I’ll go mine 48
  47. 47. Concurrent Functions Demo G e t G o i n g 49
  48. 48. G e t G o i n g 50
  49. 49. Channels Go change the channel 51
  50. 50. TextEntryWithTimeout Demo G e t G o i n g 52
  51. 51. TextEntryWithTimeout G e t G o i n g 53
  52. 52. WaitGroups Go wait in the corner 54
  53. 53. G e t G o i n g 55
  54. 54. Questions G e t G o i n g 56
  55. 55. Exercise 3 Create a GIF Concurrently Modify your code that creates a sine wave gif to create the file concurrently while the user enters the output file name. G e t G o i n g 57
  56. 56. G e t G o i n g 58
  57. 57. G e t G o i n g 59
  58. 58. Web Services Go on 60
  59. 59. net/http Package • The core functionality is in a standard library. • There are packages like gin that provide structure. G e t G o i n g 61
  60. 60. net/http G e t G o i n g 62
  61. 61. Data Access Go get it 63
  62. 62. database/sql • Go uses a driver and plugin model. • There are larger frameworks like Gorm G e t G o i n g 64
  63. 63. database/sql G e t G o i n g 65
  64. 64. Questions G e t G o i n g 66
  65. 65. Exercise 4 Web Services Create a webservice that returns the sine of a given number. Create a webservice that returns your sine wave GIF G e t G o i n g 67
  66. 66. Thank you Eric Potter • @pottereric • HumbleToolsmith.com G e t G o i n g 69

Notas do Editor

  • I’m not a go expert

    Open C:\Projects\exploration\GO\MIDOTNET\TextEntryWithTimeout
  • I’m not a go expert
    You are probably very good at your job. You write good code.
    But you may run into a situation where your services aren’t fast enough. You need a faster platform.
    That is where Go comes in. You can use go to build services that are fast and easy to maintain.
    This enables you to build software for your users that meets their needs and makes them successful.
  • Batteries included, fast
    Modernize systems programming
    Concurrency
    Garbage Collection
  • “The three of us got together and decided that we hated C++.” – Thompson

    First planned while waiting for C++ program to compile ('07)
    First stable released in '12
  • CLI go mod init, mod tidy, go fmt, go build, go run, go test
    VS Code, Go Land
  • Unit test runner, package manger, and formatter are built in
  • CLI and VS Code
  • No parens, no semi-colons
    Func, for, if
    (no do or while loops)
  • Generics only added recently
  • In go, if the function name is capitalized, it is visible outside the module
    The return type can be a tuple, or 2 values
  • VS CODE
  • If you get do
  • Slices are a powerful abstraction on top of arrays
    Go has pointers but doesn’t allow pointer arithmatic
  • The size is part of the type
  • Slices store data in an underlying array
  • The low end of the range is inclusive, the high end is exclusive
  • Interfaces are the only abstract data type
  • https://github.com/golang/go/blob/master/src/runtime/slice.go
  • Go has structural-typing
    The programmer doesn’t have to declare and a struct is a reader, it just needs to implement the io.Reader and io.ByteReader inerfaces
  • If you get do
  • Goroutine
    Managed by go runtime
    Channel
    Select
    Allow goroutine to read from channel(s)
  • Channel
    Select
    Allow goroutine to read from channel(s)
  • Go’s select lets you wait on multiple channel operations.
  • Channel
    Select
    Allow goroutine to read from channel(s)
  • If you get do
  • defer statements delay the execution of the function or method or an anonymous method until the nearby functions returns

    Defer is used to ensure that a function call is performed later in a program’s execution, usually for purposes of cleanup. defer is often used where e.g. ensure and finally would be used in other languages.
  • If you get do

×