Table of Contents....5
About the Author....10
About the Technical Reviewer....11
Acknowledgments....12
Introduction....13
Chapter 1: Go to the Basics....16
First Steps....17
Run and Debug Your First Go Program....17
A Short Note on Debugging with GoLand....23
Before Talking to OpenAI: Reviewing Concepts....25
Read from Input....27
Reading from a File....28
Custom Data: Go Structs....29
Writing and Reading Structs from Files....32
Reading a Struct from a File....34
Slicing Program Arguments....35
Using a Custom Library to Load the API Key....36
Asynchronous Code: Go Routines....40
Asynchronous Code: Go Routines and Channels....40
Using Go Contexts....45
Putting Things Together Into a ChatGPT Client....49
Getting an API Key....49
First Request....51
Customize the ChatGPT Request....53
Create a Loop Prompt....56
Streaming the Response....57
Query and Use a Custom Model....58
Summary....60
Chapter 2: Write a Tested HTTP Image Generator API....62
Pour Me Some Gin!....63
Working with Queues....71
Image Generators....82
Image Generator in a Gin....86
Quick Gin Tonic and Templates....91
Use a Synchronized Map....95
Testing the API....99
Simple Go and Gin Testing....99
Testing the Image Generator....105
Summary....107
Chapter 3: Writing the Basics for a 2D Game in Go....108
Some Tile Set History....108
Library Setup: Raylib....109
Game Setup....110
Quick Game Generation with ChatGPT....112
Display the Date in Real Time....112
Hangman Game....115
The Moyashi Game....118
The Basic Game Loop....120
Loading Textures....122
Adding a Player Texture....125
Using Key Inputs....128
Doing the Game Music....130
Game Camera....133
Animate Sprites....136
Animation for an Idle Moyashi....141
Loading the World Map....142
Loading the Full World Map....146
Full Map and Full Screen....152
Summary....153
Chapter 4: Trend Follower for Blockchain Trading....154
Go Crazy or Go Home....154
Why Trade in the Financial Markets?....156
The Origins of Money....156
The Financial Economy vs. the Real Economy....157
Market Efficiency....158
Why Automate Trading?....159
The Secret Sauce....162
Charts....163
Data....163
News and Content....163
Strategy....164
Backtesting....164
Real-Time Trading....164
The Recipe....165
Clear Objectives and a Structured Approach....165
Macroeconomic Tendencies....166
Timeframe....167
Risk Management....167
Testing and Debugging....167
Performance Evaluation....168
Scalability and Maintainability....168
Compliance and Regulation....168
Security....169
Building Confidence....169
Refining Trading Strategies....170
Utensils in the Kitchen....170
Modern Trading Tool....170
Brokers....174
Cloud Infrastructure....174
Cooking....175
Backtesting....175
Data....176
Indicators....178
Levels....178
Simple Moving Averages....181
Exponential Moving Averages....182
Relative Strength Index....182
Additional Notes....183
Enhancing Discipline and Consistency....184
Why So Many Features?....184
Sample Code....185
Exchange Connectivity (Listing 4-1)....185
Building Indicators (Listing 4-2)....186
The Strategy....187
Run the Bot....189
Performance Evaluation....190
Stats....190
PnL....190
PnL in Backtesting....190
PnL in Real-Time Testing....191
Hit Rate....191
Hit Rate in Trading Strategy Evaluation....192
The Potential Drawbacks of an Excessively High Hit Rate....192
Sharpe Ratio....193
Risk-Adjusted Performance....193
Benchmarking and Comparison....193
Portfolio Diversification....193
Potential Pitfalls....194
MAR Ratio....195
Emphasis on Drawdown Risk....195
Risk-Adjusted Performance....195
Comparison of Strategies....196
Suitability for Trend-Following Strategies....196
Potential Pitfalls....196
Success or Failure and Why....198
Benchmark Comparison....198
Timeframe....198
Risk Management and Continuous Improvement....199
Potential Pitfalls....199
Example of Backtesting Multiple Strategies....199
A Taste Before Serving the Meal....202
Ensuring System Stability....203
Hidden Difficulties....203
Forensic Analysis....203
Potential Pitfalls....205
Dinner Is Served....208
Skin in the Game....209
Fear vs. Greed....209
Which Products to Trade....210
Machine Learning....211
Dessert!....212
The Exponential Age Is Here....212
The Proverbial “Cherry on Top”....213
Appendix....219
Finance Jargon....219
Glossary....219
One-liner....222
Extra Indicators of Interest....223
Tom Demark’s Indicators....223
Extra Statistics....223
Side Notes on Geth....225
Ethereum’s GoLang Implementation: Geth....225
GoLang’s Advantages for Blockchain Development....225
References....226
Chapter 5: Writing a Kubernetes Operator to Run EVM-Compatible Blockchains....228
Setting Up Kubernetes on Your Machine....229
Resources Overview....231
Let’s Run a Pod....233
Demystifying Kubernetes Operators....234
Custom Resource Definition....235
Controller....237
Bootstrapping the Project with Operator-SDK....237
Creating an API....238
Generating the Manifests....240
Configuring the Makefile....240
Implementing the Operator Reconciliation Logic....242
Using the Kubernetes Go SDK....252
Interacting with the JSON-RPC API....261
Using Port-Forward....262
Parameterizing Resources and Ports....263
Implementing the Update Logic....265
Implementing Health Checks....273
Creating a Minimal Go HTTP Server....274
Performing a net_peerCount Health Check....277
Configuring the Readiness Probe....281
Summary....283
Chapter 6: Go Beyond: Connecting to C for a Performance Boost....285
C is for Change....286
Calling C....286
Calling C Code Located in a C File....287
C Code Calling Go Code....288
Passing Parameters....289
Using a Header File....291
Using a C Struct from Go....292
Matisse, ImageMagick, and Sepia....298
ImageMagick on OSX....299
ImageMagick on Linux....302
ImageMagick on Raspberry Pi....302
GPU Coding on OSX....303
Basics: Adding Values from Two Arrays....304
Back to the Plot....308
Generic GPU Processing Go Code....311
Opens ETHUSD Hourlies Quotes: Moving Average....313
Slightly Better Moving Average on the GPU....314
Normalized Set....316
Pearson Coefficient Moving Factor....318
Sepia Gopher....321
Extreme Calling OpenCV/C++ from Go....323
Summary....329
Chapter 7: Alef from Plan 9....330
Plan 9 from Bell Labs....332
The Network Is the Computer....334
The Alef Language....336
Hello Tuple!....337
Channels and Processes....337
Proc and Task....339
Have Fun with Plan 9....343
Index....372
Go beyond the basics of Go and build complete applications using open-source libraries or the Go programming language by Google. This book will take you deep into the memory lane of the Go language with crunchy details straight from outer space.
The applications in this book include the framework for a 2D Go-based game, an image random generator Rest API, financial time series handling for trading, a Kubernetes operator, a Blockchain coding and more. You'll also get refreshers on Go constructs and useful code tricks to build performant projects, and develop an HTTP based cloud ready image generator.
Each chapter will be organized in the following format: what the particular application looks like; requirements and user stories of our example program; an introduction to the Go libraries or frameworks used; and the actual implementation of the example program, including common pitfalls and their solutions.
Go Crazy will open your eyes to a new world of practical applications for Go. After reading the book, you will be able to apply your Golang knowledge to build your own crazy projects. Free source code will be available on this book's Apress GitHub page.
Go programmers both experienced and novice.