100% found this document useful (4 votes)
27 views

Download full Go Crazy: A Fun Projects-based Approach to Golang Programming 1st Edition Nicolas Modrzyk ebook all chapters

Modrzyk

Uploaded by

aumbimeribe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
27 views

Download full Go Crazy: A Fun Projects-based Approach to Golang Programming 1st Edition Nicolas Modrzyk ebook all chapters

Modrzyk

Uploaded by

aumbimeribe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

Download Full Version ebookmass - Visit ebookmass.

com

Go Crazy: A Fun Projects-based Approach to Golang


Programming 1st Edition Nicolas Modrzyk

https://ebookmass.com/product/go-crazy-a-fun-projects-based-
approach-to-golang-programming-1st-edition-nicolas-modrzyk/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmass.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Software Development with Go: Cloud-Native Programming


using Golang with Linux and Docker 1st Edition Nanik
Tolaram
https://ebookmass.com/product/software-development-with-go-cloud-
native-programming-using-golang-with-linux-and-docker-1st-edition-
nanik-tolaram/
ebookmass.com

Practical MATLAB Deep Learning: A Projects-Based Approach,


2nd Edition Michael Paluszek

https://ebookmass.com/product/practical-matlab-deep-learning-a-
projects-based-approach-2nd-edition-michael-paluszek/

ebookmass.com

Kubernetes Programming with Go: Programming Kubernetes


Clients and Operators Using Go and the Kubernetes API 1st
Edition Philippe Martin
https://ebookmass.com/product/kubernetes-programming-with-go-
programming-kubernetes-clients-and-operators-using-go-and-the-
kubernetes-api-1st-edition-philippe-martin/
ebookmass.com

A Dish for All Seasons Kathryn Pauline

https://ebookmass.com/product/a-dish-for-all-seasons-kathryn-pauline/

ebookmass.com
Coding Clean, Reliable, and Safe REST APIs with ASP.NET
Core 8: Develop Robust Minimal APIs with .NET 8 Anthony
Giretti
https://ebookmass.com/product/coding-clean-reliable-and-safe-rest-
apis-with-asp-net-core-8-develop-robust-minimal-apis-with-
net-8-anthony-giretti/
ebookmass.com

The World According to Kant: Appearances and Things in


Themselves in Critical Idealism Anja Jauernig

https://ebookmass.com/product/the-world-according-to-kant-appearances-
and-things-in-themselves-in-critical-idealism-anja-jauernig/

ebookmass.com

Book of Viking Sagas - 4th Edition 2022 Collective

https://ebookmass.com/product/book-of-viking-sagas-4th-
edition-2022-collective/

ebookmass.com

Flash (Soulless Kings MC Book 9) Andi Rhodes

https://ebookmass.com/product/flash-soulless-kings-mc-book-9-andi-
rhodes/

ebookmass.com

Forgotten People, Forgotten Diseases, 3rd Edition Peter J.


Hotez

https://ebookmass.com/product/forgotten-people-forgotten-diseases-3rd-
edition-peter-j-hotez/

ebookmass.com
Subsea Valves and Actuators for the Oil and Gas Industry
Karan Sotoodeh

https://ebookmass.com/product/subsea-valves-and-actuators-for-the-oil-
and-gas-industry-karan-sotoodeh/

ebookmass.com
Go Crazy
A Fun Projects-based Approach
to Golang Programming

Nicolas Modrzyk
Contributed by David Li, Jun Akiyama and
Tony Broyez
Go Crazy: A Fun Projects-based Approach to Golang Programming
Nicolas Modrzyk
tokyo-to suginami-ku, Japan

ISBN-13 (pbk): 978-1-4842-9665-3 ISBN-13 (electronic): 978-1-4842-9666-0


https://doi.org/10.1007/978-1-4842-9666-0

Copyright © 2023 by Nicolas Modrzyk


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Melissa Duffy
Development Editor: Jim Markham
Coordinating Editor: Gryffin Winkler
Copy Editor: Kezia Endsley
Cover image designed by Scott Webb on unsplash (https://unsplash.com/)
Distributed to the book trade worldwide by Springer Science+Business Media LLC, 1 New York Plaza, Suite
4600, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.
com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner)
is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware
corporation.
For information on translations, please e-mail [email protected]; for reprint,
paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub. For more detailed information, please visit https://www.apress.com/gp/services/
source-code.
Paper in this product is recyclable.
I dedicate this book to planet Earth.
Table of Contents
About the Author����������������������������������������������������������������������������������������������������� xi

About the Technical Reviewer������������������������������������������������������������������������������� xiii


Acknowledgments���������������������������������������������������������������������������������������������������xv

Introduction�����������������������������������������������������������������������������������������������������������xvii

Chapter 1: Go to the Basics�������������������������������������������������������������������������������������� 1


First Steps������������������������������������������������������������������������������������������������������������������������������������� 2
Run and Debug Your First Go Program������������������������������������������������������������������������������������ 2
A Short Note on Debugging with GoLand�������������������������������������������������������������������������������� 8
Before Talking to OpenAI: Reviewing Concepts��������������������������������������������������������������������������� 10
Read from Input��������������������������������������������������������������������������������������������������������������������� 12
Reading from a File��������������������������������������������������������������������������������������������������������������� 13
Custom Data: Go Structs�������������������������������������������������������������������������������������������������������� 14
Writing and Reading Structs from Files��������������������������������������������������������������������������������� 17
Reading a Struct from a File�������������������������������������������������������������������������������������������������� 19
Slicing Program Arguments��������������������������������������������������������������������������������������������������� 20
Using a Custom Library to Load the API Key������������������������������������������������������������������������� 21
Asynchronous Code: Go Routines������������������������������������������������������������������������������������������ 25
Asynchronous Code: Go Routines and Channels������������������������������������������������������������������� 25
Using Go Contexts����������������������������������������������������������������������������������������������������������������� 30
Putting Things Together Into a ChatGPT Client���������������������������������������������������������������������������� 34
Getting an API Key����������������������������������������������������������������������������������������������������������������� 34
First Request������������������������������������������������������������������������������������������������������������������������� 36
Customize the ChatGPT Request������������������������������������������������������������������������������������������� 38

v
Table of Contents

Create a Loop Prompt������������������������������������������������������������������������������������������������������������ 41


Streaming the Response������������������������������������������������������������������������������������������������������� 42
Query and Use a Custom Model�������������������������������������������������������������������������������������������� 43
Summary������������������������������������������������������������������������������������������������������������������������������������ 45

Chapter 2: Write a Tested HTTP Image Generator API�������������������������������������������� 47


Pour Me Some Gin!��������������������������������������������������������������������������������������������������������������������� 48
Working with Queues������������������������������������������������������������������������������������������������������������������ 56
Image Generators������������������������������������������������������������������������������������������������������������������������ 67
Image Generator in a Gin������������������������������������������������������������������������������������������������������������ 71
Quick Gin Tonic and Templates��������������������������������������������������������������������������������������������������� 76
Use a Synchronized Map������������������������������������������������������������������������������������������������������������� 80
Testing the API���������������������������������������������������������������������������������������������������������������������������� 84
Simple Go and Gin Testing����������������������������������������������������������������������������������������������������� 84
Testing the Image Generator������������������������������������������������������������������������������������������������� 90
Summary������������������������������������������������������������������������������������������������������������������������������������ 92

Chapter 3: Writing the Basics for a 2D Game in Go������������������������������������������������ 93


Some Tile Set History������������������������������������������������������������������������������������������������������������������ 93
Library Setup: Raylib������������������������������������������������������������������������������������������������������������� 94
Game Setup��������������������������������������������������������������������������������������������������������������������������� 95
Quick Game Generation with ChatGPT���������������������������������������������������������������������������������� 97
The Moyashi Game�������������������������������������������������������������������������������������������������������������������� 103
The Basic Game Loop���������������������������������������������������������������������������������������������������������� 105
Loading Textures����������������������������������������������������������������������������������������������������������������� 107
Adding a Player Texture������������������������������������������������������������������������������������������������������� 110
Using Key Inputs������������������������������������������������������������������������������������������������������������������ 113
Doing the Game Music�������������������������������������������������������������������������������������������������������� 115
Game Camera���������������������������������������������������������������������������������������������������������������������� 118
Animate Sprites������������������������������������������������������������������������������������������������������������������� 121
Animation for an Idle Moyashi��������������������������������������������������������������������������������������������� 126
Loading the World Map�������������������������������������������������������������������������������������������������������� 127

vi
Table of Contents

Loading the Full World Map������������������������������������������������������������������������������������������������� 131


Full Map and Full Screen����������������������������������������������������������������������������������������������������� 137
Summary���������������������������������������������������������������������������������������������������������������������������������� 138

Chapter 4: Trend Follower for Blockchain Trading����������������������������������������������� 139


Go Crazy or Go Home���������������������������������������������������������������������������������������������������������������� 139
Why Trade in the Financial Markets?����������������������������������������������������������������������������������� 141
Why Automate Trading?������������������������������������������������������������������������������������������������������� 144
The Secret Sauce���������������������������������������������������������������������������������������������������������������� 147
The Recipe��������������������������������������������������������������������������������������������������������������������������� 150
Utensils in the Kitchen��������������������������������������������������������������������������������������������������������� 155
Cooking�������������������������������������������������������������������������������������������������������������������������������� 160
Performance Evaluation������������������������������������������������������������������������������������������������������ 175
A Taste Before Serving the Meal����������������������������������������������������������������������������������������� 187
Dinner Is Served������������������������������������������������������������������������������������������������������������������ 193
Dessert!������������������������������������������������������������������������������������������������������������������������������� 197
Appendix������������������������������������������������������������������������������������������������������������������������������ 204

Chapter 5: Writing a Kubernetes Operator to Run EVM-Compatible


Blockchains����������������������������������������������������������������������������������������� 213
Setting Up Kubernetes on Your Machine����������������������������������������������������������������������������������� 214
Resources Overview����������������������������������������������������������������������������������������������������������������� 216
Let’s Run a Pod������������������������������������������������������������������������������������������������������������������������� 218
Demystifying Kubernetes Operators����������������������������������������������������������������������������������������� 219
Custom Resource Definition������������������������������������������������������������������������������������������������ 220
Controller����������������������������������������������������������������������������������������������������������������������������� 222
Bootstrapping the Project with Operator-SDK��������������������������������������������������������������������������� 222
Creating an API�������������������������������������������������������������������������������������������������������������������������� 223
Generating the Manifests���������������������������������������������������������������������������������������������������������� 225
Configuring the Makefile����������������������������������������������������������������������������������������������������������� 225
Implementing the Operator Reconciliation Logic���������������������������������������������������������������������� 227
Using the Kubernetes Go SDK��������������������������������������������������������������������������������������������������� 237

vii
Table of Contents

Interacting with the JSON-RPC API������������������������������������������������������������������������������������������� 246


Using Port-Forward������������������������������������������������������������������������������������������������������������� 247
Parameterizing Resources and Ports���������������������������������������������������������������������������������������� 248
Implementing the Update Logic������������������������������������������������������������������������������������������������ 250
Implementing Health Checks���������������������������������������������������������������������������������������������������� 258
Creating a Minimal Go HTTP Server������������������������������������������������������������������������������������ 259
Performing a net_peerCount Health Check������������������������������������������������������������������������� 262
Configuring the Readiness Probe���������������������������������������������������������������������������������������� 266
Summary���������������������������������������������������������������������������������������������������������������������������������� 268

Chapter 6: Go Beyond : Connecting to C for a Performance Boost����������������������� 271


C is for Change�������������������������������������������������������������������������������������������������������������������������� 272
Calling C������������������������������������������������������������������������������������������������������������������������������ 272
Calling C Code Located in a C File��������������������������������������������������������������������������������������� 273
C Code Calling Go Code������������������������������������������������������������������������������������������������������� 274
Passing Parameters������������������������������������������������������������������������������������������������������������ 275
Using a Header File������������������������������������������������������������������������������������������������������������� 277
Using a C Struct from Go����������������������������������������������������������������������������������������������������� 278
Matisse, ImageMagick, and Sepia�������������������������������������������������������������������������������������������� 284
ImageMagick on OSX���������������������������������������������������������������������������������������������������������� 285
ImageMagick on Linux�������������������������������������������������������������������������������������������������������� 288
ImageMagick on Raspberry Pi��������������������������������������������������������������������������������������������� 288
GPU Coding on OSX������������������������������������������������������������������������������������������������������������������� 289
Basics: Adding Values from Two Arrays������������������������������������������������������������������������������� 290
Back to the Plot������������������������������������������������������������������������������������������������������������������� 294
Generic GPU Processing Go Code���������������������������������������������������������������������������������������� 297
Opens ETHUSD Hourlies Quotes: Moving Average��������������������������������������������������������������� 299
Slightly Better Moving Average on the GPU������������������������������������������������������������������������� 300
Normalized Set�������������������������������������������������������������������������������������������������������������������� 302
Pearson Coefficient Moving Factor�������������������������������������������������������������������������������������� 304
Sepia Gopher����������������������������������������������������������������������������������������������������������������������� 307

viii
Table of Contents

Extreme Calling OpenCV/C++ from Go������������������������������������������������������������������������������������� 309


Summary���������������������������������������������������������������������������������������������������������������������������������� 315

Chapter 7: Alef from Plan 9���������������������������������������������������������������������������������� 317


Plan 9 from Bell Labs���������������������������������������������������������������������������������������������������������������� 319
The Network Is the Computer��������������������������������������������������������������������������������������������������� 321
The Alef Language�������������������������������������������������������������������������������������������������������������������� 323
Hello Tuple!�������������������������������������������������������������������������������������������������������������������������� 324
Channels and Processes����������������������������������������������������������������������������������������������������� 324
Proc and Task���������������������������������������������������������������������������������������������������������������������� 326
Have Fun with Plan 9���������������������������������������������������������������������������������������������������������������� 330

Index��������������������������������������������������������������������������������������������������������������������� 359

ix
About the Author
Nicolas Modrzyk acts as the CTO of Karabiner Software, a
successful consulting company located in the never-asleep
Tokyo, with its mix of ancestral culture and eco-friendly,
future-oriented dynamic.
He is an active contributor to the open-source
community in various domains, including imaging, ML, AI,
and cloud computing. As an engineer and a leader, Nico
has been involved in designing large-scale applications,
managing mammoth-sized clusters of servers, sometimes
using handwritten software, and enabling world-class
leaders by pushing international boundaries.
Nico ardently focuses on making life simple. (And we all
know how difficult that is!)
He loves pushing people to challenge themselves and go beyond their comfort zones.
To learn other cultures and explore different world views, he has been living around
the planet in various countries, including France, Ireland, Japan, China, Korea, India,
and the United States. You can talk to Nico in French, English, and Japanese, and you can
get along with him in Spanish and Chinese.
Nico is the author of a few programming books, available on Amazon. He recently
picked up the saxophone to honor his grandfather and his uncle, in the hope to match
their skill with a brass instrument.
He will be ready for a jazzy jam session whenever you are.

xi
About the Technical Reviewer
David Li is the executive director of Shenzhen Open
Innovation Lab, which facilitates the collaboration between
global smart hardware entrepreneurs and the Shenzhen
Open Innovation ecosystem. Before SZOIL, he co-founded
XinCheJian, the first hackerspace in China to promote
the hacker/maker culture and open-­source hardware. He
co-founded Hacked Matter, a research hub on the maker
movement and open innovation. He also co-founded Maker
Collier, an AI company focusing on motion and sports
recognition and analysis.

xiii
Acknowledgments
All the involved authors—Jun, Tony, David—as well as the technical reviewers, Mathieu
and David, of this book have gone the extra mile to match the deadlines and bring the
writing and code samples to a top-class level.
My two strong daughters, Mei and Manon—you always keep me focused and in line
with my goals.
Psy Mom, French Chef Dad, Little Bro, Artful Sis—I thank you for your love every day,
your support, and all the ideas we share together.
My partner at Karabiner, Chris Mitchell—we’ve been working together for ten years,
and I think we both made tremendous efforts to make the planet a better place. Also,
the whole Karabiner people, at work now or busy making babies, we make a pretty
impressive world team.
Abe-san—who did not participate directly in the making of this book, but we wrote
our first computer book together, and without a first one, and without his trust, I would
not be here to even talk about it.
Kanaru-san—without your Iranian lifestyle and your life changing vision, I would
probably be a monk.
Marshall—without your world encompassing vision, I could have been focusing on
the bigger picture.
Ogier—without your summertime raclette and life-long friendship, I would probably
have been 5 kilos skinnier.
Jumpei—without your strong focus on music, I could not have played in all those
beautiful Tokyo live stages. And welcome Rei-chan!
Gryffin and Melissa—I could not have survived this without your hard work
and trust.
And of course, Marcel le chat—my open-source project on imaging would not be the
same without your feline cuteness.

xv
Introduction
On a sunny drive on the busy roads of Tokyo, over the rainbow bridge and facing the
ocean, my daughter Mei and I are having one of these philosophical talks.
Among the slur of questions she had ready for me, like “what is work for?,” she was
telling me about her need to have someone monitor her and give her deadlines. While
at the time of this writing, she’s barely 20 and hasn’t started a full-blown professional
career yet, she is right in the sense that the need to have deadlines and a purpose is at the
core of many adults’ professional lives.
At the very root of a school system, you are being told what to complete, and by what
date. You do not have input regarding the what or the when. A regular office worker is
told to finish their tasks by the fifth of next month, for example, and some authors are
told to finish three chapters by the end of the month.
That de facto need of what to do and by when happens very early in your career.
I am in favor of looking at things from a different angle. You should set your own
deadlines, and you should be in control of those deadlines. You have a goal, you set
milestones to achieve that goal, and you work on walking that path to that goal.
You want to live your own life and reach your own goals, not someone else’s.
Although I am critical about many of his actions, Elon Musk does not have someone
telling him when to land a rocket on Mars. He has his own schedule. He owns his
schedule. He owns his life.
This is a book on how to own your life again. More precisely, how Go, the
programming language, can help you get your time back, manage it along your dreams,
and own your life again.
I discovered the Go programming language a few years back. At that time, to be
honest, I was more of a Clojure-loving propaganda evangelist. Anything I developed or
touched had to be in Clojure. A deployment script, a web app, a dynamically generated
API around some custom datasets, image and video processing, or applying the latest
Computer Vision algorithm in real time—it did not matter. It greatly helped my career. I
would go even further and say, my life.

xvii
Introduction

How can a programming language help make your life better, you might ask? A
programming language is at first a language, and as such its first goal is to communicate.
We tend to think that a programming language’s only goal is to deal with a computer, but
we deal with computers because we want to communicate something to other people.
Take a simple email, for example. You use a computer to write an email because it
takes less time to reach its recipient, but the goal of an email is still to convey a message
to another person.
Now let’s say you have a lot to communicate, or you want to communicate something
to many people, but with that simple personal touch that makes all the difference
between your email being ignored and it being read and acted upon.
You don’t have much time. In life in general, but also to realize a task. You can use a
computer to help you with that task and save time.
Nowadays one of the best programming languages to put in your toolbox is GoLang.
It includes all the important concepts of Clojure, and that I love in a programming
language, but it’s also in the top ten of the TIOBE index, meaning you can find a few
more programmers to help you do your job.
Don’t get me wrong, there are other great languages, but there are many things that
GoLang gets absolutely right:

–– It is simple

–– It is concise

–– The code is short

–– Concurrency is not an afterthought

–– It can be compiled and run on a large variety of operating systems


and architectures

–– It’s easy to reuse bits of code from one project to the other

–– Errors are simple to handle

–– It is cloud-ready

–– It is very fast (this is probably my favorite)

xviii
Introduction

Go, as a programming language, has a clear and strong purpose: Implement


architecture based on microservices in the most convenient way possible.

This programming book will take you on the path to Ikigai, finding joy in life through
purpose.

xix
CHAPTER 1

Go to the Basics

The goal of this first chapter is to write a ChatGPT client in Go. You’ve probably heard
about ChatGPT. It is an AI-trained chatbot that generates text according to questions
you ask it.
To get to this point, you will run basic Go programs and get used to the language.
Then you will put things together into a ChatGPT client.
But you first need to set up your code editor.

1
© Nicolas Modrzyk 2023
N. Modrzyk, Go Crazy, https://doi.org/10.1007/978-1-4842-9666-0_1
Chapter 1 Go to the Basics

First Steps
As with any new skill, you need a basic setup where you feel comfortable practicing
and trying new things. While Go, the language, makes writing code easier, GoLand, the
editor, makes writing Go easier.
To kick-start this chapter, you learn how to use GoLand as your editor for writing Go.

Run and Debug Your First Go Program


Running your first Go program using JetBrains GoLand should take approximately ten
minutes or less.
In the context of this book, the goal is to go deep into the language as quickly as
possible and become proficient in Go in a matter of hours. Within that context, it’s best
if you use JetBrains’s Go editor called GoLand. Of course, you can use any editor you
choose, but you will find it easier to follow along if you use GoLand.
You can download GoLand for individual use from the following URL:
www.jetbrains.com/go/download/
You will have 30 days of use for free, which should be enough to finish reading and
applying the lessons in this book—and to get you excited for more coding.
GoLand handles all the core Go language installers, paths, and dependencies
for you.
Once you start the editor, click New Project. You’ll see the screen in Figure 1-1.

2
Chapter 1 Go to the Basics

Figure 1-1. Creating a new project in GoLand

Once you have created a new project, a blank project window will be available.
The left side of the window shows your project file, and the right side shows your
code editor (which, at this stage, is empty). See Figure 1-2.

3
Chapter 1 Go to the Basics

Figure 1-2. New Project window

You can right-click in the Project Files tab and create a new Go file, as shown in
Figure 1-3.

4
Chapter 1 Go to the Basics

Figure 1-3. Creating a new Go file

Give your new file a name (see Figure 1-4).

Figure 1-4. The new Go file

5
Chapter 1 Go to the Basics

A potential layout for your project looks like Figure 1-5.

Figure 1-5. Simple project layout

A few things to note about this GoLand window layout:

1. The green arrow allows you to simply click and run your code. You
also get an arrow when you have test cases. You will learn about
that in a few pages.

2. Try copying and pasting this line into the main() function:

fmt.Printf("Go version: %s\n", runtime.Version())

3. GoLand will auto-complete the code and do the necessary


namespace imports for you (see Figure 1-6).

4. The list of functions in the current file is shown in the


Structure tab.

5. You can click most of your code and navigate to the corresponding
section in the Go packages, whether it’s part of the core language
or an external library.

6
Chapter 1 Go to the Basics

Figure 1-6. Displaying the current Go version in a simple Go program

Your first code snippet will do just that—display the Go version of your current
installation. See Listing 1-1.

Listing 1-1. Displaying the Go Version

package main

import (
   "fmt"
   "runtime"
)

func main() {
   fmt.Printf("Go version: %s\n", runtime.Version())
}

A few explanations in this first code listing:

1. To be executable, the package name should be main.


2. You cannot have two package definitions in the same folder (even
in different files).

7
Chapter 1 Go to the Basics

3. fmt is the namespace that imports formatting functions, such as


Printf (print to screen) and Sprintf (format without printing).

4. runtime is the namespace containing functions that retrieve


information about the Go runtime, such as version, CPU, memory,
and tracing.

5. The one and only function is called main, and that is the entry
function. It is called first when running the program.

6. Once the main function exits, the program exits too.

A Short Note on Debugging with GoLand


Debugging is the process of finding and fixing errors or bugs in software or computer
systems. The goal of debugging is to identify the root cause of an issue and then apply a
solution to fix it. Debugging can be done manually, using tools like print statements and
logging, or with the help of specialized software development tools, like debuggers and
integrated development environments.
GoLand makes debugging a program a breeze. Let’s say you want to see the value of
the version while the program is running, before printing it.
In GoLand, you can click in the gutter right next the line number (as in Figure 1-7).
If you then start the execution in debug mode by clicking the debugging button, the
execution will stop at the requested place (the breakpoint).

8
Chapter 1 Go to the Basics

Figure 1-7. Execution stops at the breakpoint in debugging mode

You can also ask the execution to not suspend when reaching a specific breakpoint
(see Figure 1-8) and just log the variables that are accessible to the debugger.

9
Chapter 1 Go to the Basics

Figure 1-8. Breakpoint settings while debugging

While writing code, I recommend using GoLand debugging mode most, if not all, the
time. That way, you avoid unnecessary logging statements in the program and can focus
on the business logic that really matters, not the logging mess.
You now know the basics to run/debug a program, so next you review basic Go
concepts that you will use to write a ChatGPT client.

Before Talking to OpenAI: Reviewing Concepts


To get a good grasp on using Go in a useful situation, you are going to write a program
straight from this first chapter. The goal: write a Go program that will ask simple
questions to ChatGPT and display its AI-looking answers.
Since this is the first chapter, I quickly review the underlying simple Go concepts
needed to write the Go code that will talk to ChatGPT.
Get the setup ready again (see Figures 1-9 and 1-10) so you can start coding.

10
Chapter 1 Go to the Basics

Figure 1-9. New project again

11
Chapter 1 Go to the Basics

Figure 1-10. New file in the new project

Read from Input


You need to read user input from a prompt for the ChatGPT program, so here is a sample
of what is to come. Listing 1-2 uses the bufio package to create a NewReader object.

Listing 1-2. Reading from Standard Input


package main

import (
   "bufio"
   "fmt"
   "log"
   "os"
)

func main() {
   for true {
      fmt.Print("What is your name ? > ")
      reader := bufio.NewReader(os.Stdin)

12
Chapter 1 Go to the Basics

      line, err := reader.ReadString('\n')


      if err != nil {
         log.Fatal(err)
      }
      fmt.Printf("hello %s\n", line)
   }
}

The for loop uses true as the condition of the loop continuity check. I put it there to
make it obvious what the condition is, but it can be removed altogether.

Reading from a File


Note that this is almost like reading from a file. In Listing 1-3, you open a file named
hello.txt in read mode and output all its contents, line by line.

Listing 1-3. Reading from a File

package main

import (
   "bufio"
   "fmt"
   "os"
)

func main() {
   file, _ := os.OpenFile("hello.txt", os.O_RDONLY, 0666)
   defer file.Close()
   reader := bufio.NewReader(file)
   for {
      line, err := reader.ReadString('\n')
      fmt.Printf("> %s", line)
      if err != nil {
         return
      }
   }
}

13
Chapter 1 Go to the Basics

Custom Data: Go Structs


GoLang (the Go programming language) uses data structures, conveniently named
structs, to handle custom data objects. Basically, where you would use generic maps in
other languages, Go helps you enforce type checks when handling custom data. This
includes reading data from HTTP forms, database persistence, files, or even sockets.
Listing 1-4 defines a Message struct, with one string field named Hello, and simply
prints the struct object itself as a string using fmt.Printf.

Listing 1-4. Defining and Printing Custom Data with Structs

package main

import (
   "fmt"
)

type Message struct {


   Hello string
}

func main() {
   h := Message{Hello: "world"}
   fmt.Printf("%s\n", h)
}

Running this program produces this simple output:

; {  world}

The output could be slightly more useful if you could print out the fields as well as
the actual data. There are two ways to do this.
One way is to use +v in the formatting part of the fmt.Printf formatting and print
call. All the fields in the struct will then be printed, as shown in Listing 1-5.

14
Chapter 1 Go to the Basics

Listing 1-5. Printing a Struct with %+v

package main

import (
   "fmt"
)

type Message struct {


   Hello string
}

func main() {
   h := Message{Hello: "world"}
   fmt.Printf("%+v\n", h)
}

This code prints:

{Hello:world}

Another way, and one that is often used to send and receive custom-defined structs
via HTTP, is to marshal the object to the universal JSON format.
This is a very custom way to print or parse data. Golang makes it very easy to achieve
this, using the encoding/json package included in the core libraries.
The use of this core library is shown in Listing 1-6.

Listing 1-6. Marshalling a Struct to JSON Using Encoding/JSON


package main

import (
   "encoding/json"
   "fmt"
)

type Message struct {


   Hello string
}

15
Chapter 1 Go to the Basics

func main() {
   h := Message{Hello: "world"}
   AsString, _ := json.Marshal(h)
   fmt.Printf("%s\n", AsString)
}

This code will print a more detailed version of the custom data:

{"Hello":"world"}

Note the quotes around “Message” and “world”, which were not present when using
simple standard formatting to string.

Important Note If a field name in your custom struct does not start with a
capital letter, the field will not be marshalled and thus not printed. This happens
both when using the standard toString marshalling and the other marshalling
techniques. Starting a field with a lowercase character indicates that the field is
not to be exported.

Consider a struct like this:

type Message struct {


   Hello   string
   ignored string
}

While the struct contains the ignored field, that field will not be exported when using
JSON marshaling because it starts with a lowercase letter.
In Golang, you can also specify metadata on fields of structs using what is called a
tag line.
This tag line is used for different things. One common use is to format the output
of the fields in JSON. That tag line can also be used to format data for persistence to
database, for example.
You write a tag line by adding a specific directive after the field’s type, using
backquotes, as shown in Listing 1-7.

16
Chapter 1 Go to the Basics

Listing 1-7. Struct with Marshalling and a Tag Line

package main

import (
   "encoding/json"
   "fmt"
)

type Hello struct {


   Message string `json:"hellooo"`
}

func main() {
   h := Hello{Message: "world"}
   b, _ := json.Marshal(h)
   fmt.Printf("%s\n", string(b))
}

This time the output of the code is as follows:

{"hellooo":"world"}

Writing and Reading Structs from Files


You have seen how to marshal a struct to JSON, and the next listing shows you how to
expand on this and write the contents of a struct and an embedded struct to a file.
Note that the code would be quite similar when marshalling via HTTP or sockets, as
shown in Listing 1-8.

Listing 1-8. Marshalling a Struct to File via JSON

package main

import (
   "encoding/json"
   "io/ioutil"
)

17
Chapter 1 Go to the Basics

type Salary struct {


   Basic float64
}

type Employee struct {


   FirstName, LastName, Email string
   Age                        int
   MonthlySalary              []Salary
}

func main() {
   data := Employee{
      FirstName:     "Nicolas",
      LastName:      "Modrzyk",
      Email:         "hellonico at gmail.com",
      Age:           43,
      MonthlySalary: []Salary{{Basic: 15000.00}, {Basic: 16000.00},
{Basic: 17000.00}},
   }

   file, _ := json.MarshalIndent(data, "", " ")


   _ = ioutil.WriteFile("my_salary.json", file, 0644)
}

The resulting output file is shown in Listing 1-9.

Listing 1-9. File Containing a Struct as JSON

{
"FirstName": "Nicolas",
"LastName": "Modrzyk",
"Email": "hellonico at gmail.com",
"Age": 43,
"MonthlySalary": [
  {
   "Basic": 15000
  },

18
Chapter 1 Go to the Basics

  {
   "Basic": 16000
  },
  {
   "Basic": 17000
  }
]
}

Reading a Struct from a File


Now that the struct has been exported to a file, let’s see how the opposite operation—
reading the same struct from the file—works. To achieve that and to make it easier to
read batches of data from the file, you use the io/ioutil package again, as shown in
Listing 1-10.

Listing 1-10. Reading a Struct from a File Containing JSON

package main

import (
   "encoding/json"
   "fmt"
   "io/ioutil"
   "os"
)

type Salary struct {


   Basic float64
}

type Employee struct {


   FirstName, LastName, Email string
   Age                        int
   MonthlySalary              []Salary
}

19
Chapter 1 Go to the Basics

func main() {
   jsonFile, _ := os.Open("my_salary.json")
   byteValue, _ := ioutil.ReadAll(jsonFile)
   var employee Employee
   _ = json.Unmarshal(byteValue, &employee)
   fmt.Printf("%+v", employee)
}

Running this code will produce the following output:

{FirstName:Nicolas LastName:Modrzyk Email:hellonico at gmail.com Age:43


MonthlySalary:[{Basic:15000} {Basic:16000} {Basic:17000}]}

Remember that you can pretty-print the content by reverting to JSON, as shown in
Listing 1-11.

Listing 1-11. JSON Again

func main() {
   jsonFile, _ := os.Open("my_salary.json")
   byteValue, _ := ioutil.ReadAll(jsonFile)
   var employee Employee
   _ = json.Unmarshal(byteValue, &employee)
   //fmt.Printf("%+v", employee)
   json, _ := json.MarshalIndent(employee, "", " ")
   fmt.Println(string(json))
}

Slicing Program Arguments


You will also use that piece of code in the ChatGPT code. Listing 1-12 shows how to
retrieve questions from the arguments passed to the program.
The first element called os.Args is the program name, and the rest of the program
arguments. Listing 1-12 shows how you “slice” the arguments into a string array named
questions.

20
Chapter 1 Go to the Basics

Listing 1-12. Parsing of a Program Argument

package main

import (
   "fmt"
   "os"
)

func main() {
   programName, questions := os.Args[0], os.Args[1:]
   fmt.Printf("Starting:%s", programName)

   if len(questions) == 0 {
fmt.Printf("Usage:%s <question1> <question2> ...", programName)
   } else {
      for i, question := range questions {
         fmt.Printf("Question [%d] > %s\n", i, question)
      }
   }
}

For more advanced parsing, you use flag (https://pkg.go.dev/flag), but I won’t
review this now.

Using a Custom Library to Load the API Key


To connect and use ChatGPT from the code, as with other services nowadays, the user
needs to provide an API key. The API key is private and if used by somebody else can
lead to leakage, so the key itself is usually left outside the program and loaded from a
separate file at runtime.
While you can do that by loading that key using custom structs, in this case, you use
a non-standard library so the API key to access ChatGPT will later be loaded from a text
file using the dotenv library, a port of the Ruby library of the same name.
To find a library for Go, you usually head to https://pkg.go.dev/, which has a nice
web interface to search for Go packages, as shown in Figure 1-11.

21
Chapter 1 Go to the Basics

Figure 1-11. The place to go when looking for libraries: the pkg.go.dev website

Then enter dotenv, the library you need for this example (see Figure 1-12).

Figure 1-12. Looking for the dotenv library

22
Chapter 1 Go to the Basics

The code that uses the godotenv library, the first one in the list, is shown in
Listing 1-13.

Listing 1-13. Loading Environment Variables Using the godotenv Library

package main

import (
   "fmt"
   "github.com/joho/godotenv"
   "os"
)

func main() {
   godotenv.Load()

   s3Bucket := os.Getenv("S3_BUCKET")
   secretKey := os.Getenv("SECRET_KEY")

   fmt.Printf("S3: %s and secret: %s", s3Bucket, secretKey)


}

godotenv.Load() loads environment variables from different places. This example


uses an .env file, with a potential .env file like this:

S3_BUCKET: s3prod
SECRET_KEY: secretprod

When you write, copy, or open Listing 1-13 in GoLand, the library will not be found
because it has not been downloaded yet (see Figure 1-13).

23
Chapter 1 Go to the Basics

Figure 1-13. Looking for the dotenv library (again)

In the editor, the import statement at the top of the file will be highlighted in red, and
you can right-click or press Option+Enter to get GoLand to retrieve the library for you.
The go.mod file will then be filled in with the necessary information, as shown in
Listing 1-14.

Listing 1-14. Contents of the go.mod File

module listing-14

go 1.18

require github.com/joho/godotenv v1.5.1

Note that you can of course add the library manually in the go.mod file.
Once the library is correctly downloaded and added to the project, running Listing 1-13
will give the following output:

S3: s3prod and secret: secretprod

This code is loading fake keys to access S3 buckets, but some very similar code will
be used for loading the API key for ChatGPT.

24
Chapter 1 Go to the Basics

Asynchronous Code: Go Routines


While the programs you’ll write usually do only one thing very nicely, they may need to
achieve this one thing by running small “pieces of work” in the background. This is done
by writing asynchronous code. One of the easiest ways to run asynchronous code in Go
is to use Go routines.
Go routines are lightweight threads, processing units, that run concurrently with the
main function.
In Listing 1-15, you start the execution of the printNumbers function in the
background, using the go keyword. In parallel, you execute the same printNumbers
function on the main thread. This starts the function’s execution in a concurrent context.

Listing 1-15. Go Routines

package main

import (
    "fmt"
    "time"
)

func printNumbers() {
    for i := 0; i < 10; i++ {
       time.Sleep(100 * time.Millisecond)
       fmt.Printf("%d", i)
    }
}

func main() {
    go printNumbers()
    printNumbers()
}

Asynchronous Code: Go Routines and Channels


Go routines usually communicate via another powerful concept: Go channels. Channels
allow different Go routines to communicate easily and efficiently.
Listing 1-16 shows how to send data into the channel and how to read from it.

25
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of Worth his
while
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.

Title: Worth his while

Author: Amy Ella Blanchard

Illustrator: Ida Waugh

Release date: February 20, 2024 [eBook #72998]

Language: English

Original publication: United States: George W. Jacobs & Co, 1901

Credits: Carol Brown, Aaron Adrignola and the Online Distributed


Proofreading Team at https://www.pgdp.net (This file was
produced from images generously made available by The
Internet Archive)

*** START OF THE PROJECT GUTENBERG EBOOK WORTH HIS


WHILE ***
He Sat Swinging His Bare Feet Over the Water
WORTH HIS WHILE

BY
Amy E. Blanchard
Author of “Kittyboy’s Christmas,” “Taking a Stand,” “A
Dear Little Girl,” “Thy Friend Dorothy,” Etc.

Philadelphia
George W. Jacobs & Co.
103-105 So. Fifteenth St.
Copyright, 1901, by

GEORGE W. JACOBS & CO.


CONTENTS
I. ON THE WAY TO BIG CREEK 7

II. BENNY FINDS A FRIEND 23

III. AMONG THE PICKERS 38

IV. A HIDDEN ENEMY 52

V. BENNY AND A RING 65

VI. BEN’S BEAUTIFUL SURPRISE 80

VII. HIS FATHER’S PLAN 94


LIST OF ILLUSTRATIONS
“HE SAT SWINGING HIS BARE FEET OVER THE
WATER,” Frontispiece

“IT WAS NOT VERY PLEASANT WORK,” 39

“SUCH A GLAD MOTHER,” 102


CHAPTER I

ON THE WAY TO BIG CREEK

Oh, how hot it was! Down in the narrow streets, where straight rows
of little brick houses were crowded together there was not the
faintest breeze, and even on the wharf where Benny Jordan sat
swinging his bare feet over the water, it was scarcely cooler. Usually
there were little waves splashing up against the green logs of the
pier, but to-day only the faintest little ripples swished lazily against
the piles and the boats lying farther out did not flap a sail.

“It’s no good staying here,” said Benny to himself, as he got up


and stretched his arms over his head. “It’s just about as hot as it is
at home. I wonder what there is for supper. My, but I’d like some ice
cream! I haven’t had any for so long, and I reckon I never will have
any again.” And at this very sobering thought Benny began to patter
along over the sidewalk, almost forgetting that this was the hottest
day of the season, entirely too hot for May, and that the big
excursion steamer, which he had been waiting to see, would soon be
in sight.

“’Tain’t any use to wait,” he said to himself, as if apologizing. “I’d


only see the crowd, and what’s a crowd, anyhow?”

So he marched on up the street, passing the fruit stands and ill-


smelling warehouses, until he turned into one of the small streets
leading out of the thoroughfare, and presently he arrived at a small
two-story brick house, one of a long row. So much alike were these
buildings that it is a wonder Benny knew how to tell his own home
without counting the doorways.
“Where’s mother?” was his question as he reached the door.

His sister Kitty, sitting on the doorstep, looked up, “She’s upstairs,
of course, sewing as hard as she can, and it’s so hot.”

Benny went pounding up the stairs to the room where his mother
sat sewing. “Say, mother, it’s too hot to sew,” he exclaimed.
“But it isn’t too hot to eat, is it?” she said, looking up with a smile.
“You know if I didn’t sew we wouldn’t have anything to eat.”
“That’s so,” replied Benny, slowly.

“Where have you been?” asked his mother, stopping to push back
the damp hair from her face.
“I’ve been down on the wharf; it’s generally cool there, but it’s
hot everywhere to-day. I like to go there, though; I like to see the
people come up from the country with big bundles of flowers, and I
like to watch the men unload the boats. They brought such a lot of
strawberries to-day.”

“This weather ripens them fast. It is very early to have such


heat.”

“I wish we lived in the country,” said Benny. “Isn’t it cheaper to


live there?”

“Ye-es, if you have some one to work your garden and take care
of your stock. But how could I make a living for you and Kitty?”
“We could help,” Benny replied.
“Not much, I’m afraid. A little boy ten years old and a little girl
seven would scarcely be able to do much toward making a living.”

“But shouldn’t you like to live there?” persisted Benny.

“I should, indeed,” returned his mother, with a sigh. “I was


brought up on a farm, you know, and so was your father.”
Benny had heard of that farm many, many times. He knew all
about the spring and the orchard, the barn and the garden.
“Grandfather sold it, didn’t he?” was his remark, made regretfully.

“Yes, long ago. Come, we must have some supper. You and sister
can set the table.”
“What is there for supper?”

“Nothing but bread and molasses, I’m afraid.”

“I wish we could have some ice cream and strawberries.”

“Now you are making an extravagant wish. We can’t have that,


but, perhaps, we might have some bread and milk. You can go and
get a quart of milk and we’ll have a treat.”
Benny’s face brightened. Bread and cold milk on a hot day was a
much more appetizing prospect than bread and molasses, and the
little boy promptly ran down to tell his sister.
“Hurry up, Kit, and set the table; we’re going to have bread and
milk. Where’s a tin bucket?”
Pale little Kitty put down her paper dolls with alacrity, and before
long the little family were seated at the table. Slowly and reluctantly
the children disposed of the last drop of milk in their bowls.
“If we lived in the country, we could have this every night,” Benny
said.
“What has set you harping so on the country?” asked Mrs.
Jordan.

“Why, I don’t know. I reckon it’s hearing the men talk down at the
wharf. One of ’em said this morning: ‘There’s no money for farmers
nowadays. A man can’t make anything in the country.’ ‘He can
always make a living,’ said the other, ‘and a pretty good one, too.
How’d you like your wife and babies to be in the city this weather?
Why, sir, there’s lots of folks would give anything to see their
children tumble ’round on the grass under such trees as you’ve got
and have all the good milk they wanted to drink. I think we country
people are pretty well off, myself. We don’t make a fortune, but
we’ve got a good living right handy.’”

Benny unconsciously imitated the man, and his mother laughed.


“You surely took in that conversation, Benny. I’d like well enough
to live under the green trees again. It’s what your father always
planned to do some day when he had made enough to buy a little
place.”

Benny looked sober. He always felt as if he wanted to carry out


his father’s plans, and this looked like a very hard one.
“You make it worth while, and we’ll go,” said his mother, smiling.
“Now I must go back to my buttonholes and you children can clear
away the dishes.”
“Don’t you wish you could find a way to get to the country?” said
big-eyed little Kitty, as she carefully put away the last bowl.
Benny turned his round, good-natured, freckled little face toward
her. “I’m a goin’ to,” he said, determinedly. “Mother said she go if I’d
make it worth while, and I’m a goin’ to.”
“Oh, Benny, are you?” said Kitty. She had the utmost confidence
in this elder brother, who, although only three years older, seemed
so much larger and stronger than herself, and was a person always
to be depended upon to undertake any difficult task. “How are you
going to?” she continued.

“I’m a goin’ to,” reiterated Benny, with the same emphasis. And
the fact of his saying this and nothing more gave greater weight to
his words. So all that evening Kitty dreamed beautiful dreams of a
little home near green meadows and under leafy trees.

Benny’s determination had not left him the next day. It was a
holiday and Benny pattered off down to the wharf as early as
possible. Somehow then it seemed as if that land of delight known
as the country were more accessible by reason of the arrival of the
crafts which plied between the lower counties and the city. It
appeared so easy to step aboard a little steamer and be borne along
over the bay to the green shores melting away in the distance.
Those shores from which were brought, on the little sailing vessels,
mountains of green peas, crates of luscious strawberries, baskets of
downy peaches. It represented to Benny a veritable Canaan, that
country from which the little vessels came, and many a time he had
sat on the pier looking off into the distance and dreaming of the
fullness and plenty which he imagined existed there.
He was standing at the gangway of a small steamer which lay
moored to her dock, when his attention was arrested by two men
who halted near him.

“Hello, Jim!” said one. “What’s bringing you to town? Thought this
was a busy time with you.”
“So it is, or ought to be, but my pickers disappointed me. Here
my strawberries and peas are ready and waiting and not a soul to
pick ’em. It certainly is aggravating.”

“It certainly is,” returned his friend. “What you going to do about
it?”

“I’ve come up to see if I can get a new gang. I shall have to take
what I can get. People make a very poor mouth, but I notice when
anyone wants farm hands of any kind it isn’t always so easy to get
hold of ’em. Good pay and good food, with good, fresh air thrown in,
and yet they shy off. Well, I can’t tarry; good-by.”
“Well, good luck to you,” returned his friend. And then, turning
around he saw by his side an eager-faced little lad.

“Well, sonny?” said the man.


“If you please, sir, what did that man want?”

“Pickers, to pick his strawberries and peas for him. Do you know
anyone who wants a job in that line?”

“Could I do it?” and Benny’s blue eyes were very wistful.


“You? Why I don’t know. How old are you?”

“Ten.”
“I’m afraid you’d soon give out. It’s no fun to stay among the
vines all day in the hot sun, and I’ll venture to say you wouldn’t pick
as many for your box as you would for your mouth. How about
that?”

Benny shook his head decidedly, “No, sir.”


“You wouldn’t? Well, I reckon Mr. Bentley will be back here for the
afternoon boat. You might ask him then,” and the man walked away.

Benny lost no time in speeding home. He burst in upon his


mother with the breathless question, “Mother, may I go down on the
“Emma Jones” and be a picker?”

Mrs. Jordan turned from her machine with a look of amazement.


“Why, Benny, what do you mean?”

“Why, there’s a man, a Mr. Bentley, who is hunting up people to


pick strawberries and peas for him, and maybe I could go. Maybe it
would be finding the way, you know, for father’s plan.”

His mother smiled sadly.

“Dear little lad, I’m afraid Mr. Bentley will not want little boys like
you, and besides how can I let my boy go away from me without my
knowing anything about where he is going or the people he is to be
thrown with.”

“I would be good; indeed I would, mother. I’d work awfully hard,


and I wouldn’t go with bad boys.”

“Well, my darling, I’m afraid it would not be best for me to say


yes.”
“But if Mr. Bentley should want me,” pleaded Benny, “I would be
right in the country, mother, and I wouldn’t get into mischief.”

His mother smiled at this absolute faith in the safety of the place.
Then she was very thoughtful. “If I could see Mr. Bentley himself,
and find out more about it,” she said finally.

“Can’t I go and try it for a week? Only a week?” begged Benny.

“You may do this—you may ask Mr. Bentley if he will take you,
and if he consents, you must tell him that your mother will see Mr.
Higgins, who used to live in that neighborhood, and that she will
probably send you down to-morrow. I know where the “Emma
Jones” lands, and Mr. Higgins will know all about it. I will see him
this evening.”
Benny went off highly pleased with this concession.

Long before two o’clock he was waiting eagerly by the gangway


of the “Emma Jones” for Mr. Bentley to appear.
Passengers began to straggle along; here a man with a huge
basket, there a woman, followed by two or three hot, tired children,
next two or three negroes, ragged and happy, shuffled lazily on
board. Presently the captain came up. “Who are you waiting for,
sonny?”
“Mr. Bentley.”

“Jim Bentley? I reckon he’s on the upper deck. I saw Welch up


there, and they generally hunt up one another. You go up there and
look for him. You might get in the way here.” Benny found his way
on deck and began looking along the row of passengers for Mr.
Bentley, but not seeing him, he sat down and began to watch the
big excursion steamer which lay in the next dock. She was dressed
with flags, and the music of the band on her deck made her seem a
very gay sort of an affair to Benny.

He was so busy watching the crowds of people gathering aboard


this big steamer, that he did not notice the warning sound of a bell,
nor the slow movement of paddles, till presently he perceived the
dock gliding from sight and found that the “Emma Jones” was
actually on her way to Big Creek.
CHAPTER II

BENNY FINDS A FRIEND

For a moment Benny was bewildered. He could not tell what he


ought to do. He had not been on a steamboat since he was quite a
little fellow, and that it was possible to send him ashore was out of
the question. “What will mother think?” was his first thought. “How
shall I get back?” was his second. He stood looking around him,
each moment increasing the distance between the steamboat and
the shore.

“Hallo!” cried a voice at his side, “what are you doing here?” And
looking up, Benny saw the man whom he had talked to that morning
on the dock.
“I don’t know what I am doing,” he returned, in a distressed
voice. “I’m getting carried off.”
“Kidnapped, eh? Who’s the fellow that’s run you aboard?”

Benny smiled a little, and told the man his story, ending with,
“And I haven’t any money to pay my way.”

“And you’re afraid the captain will throw you overboard to get rid
of you. Is that it?”

Benny looked a little disturbed. He didn’t know just what the


captain might do.
“Well, it won’t break me to pay fifteen cents for you,” the man
said, good-naturedly. “Jim Bentley ain’t aboard. He hunted up a lot
of pickers and is taking ’em down on his bug-eye; wanted to be sure
of ’em this time.”
Benny was a little puzzled as to what a bug-eye might be till he
remembered that the small sailing vessels which came up from the
truck farms were so called by those familiar with the craft in the bay.
“Yes,” continued the man, “Jim’s not goin’ to let ’em get away this
time. There’s no boat back this evening, so you can’t get back home
to-night.”

“Oh, what will mother say? She’ll be so worried,” exclaimed


Benny, looking ready to cry.

“Sho! that’s too bad. How’ll we fix it? You might find a chance to
get back real late. There are lots of boats that get loaded up and
start off through the night so as to get the loads in for the hucksters
by sun-up or earlier; but it seems to me as long as you’ll be really
down there you might as well try pickin’. I’d give you a job myself,
but I don’t have any crop. I keep a store at the Cross Roads. Let me
see. How’ll we fix it?” And the man rubbed his stubby beard
thoughtfully.

Presently he slapped Benny on the shoulder, as a bright idea


came to him. “I know!” he exclaimed; “we’ll drive ’round by
Sanders’s. He’s got a telephone, and I’ll ask him to telephone up to
Dick Bond’s, at the railroad station, then Dick can telegraph to your
mother that you’re all right, and that she’ll hear from you later.
How’ll that do?”
Benny’s face beamed. “Fine,” he responded, gratefully, although
he was but half aware of the trouble and expense to which the kind
man was placing himself on the little boy’s account.

“All right. It’s a go. My name is Welch. I’ll take you home with me.
We’ll find a corner for you somewhere, and to-morrow you can go to
see Jim Bentley. Like as not Jim’ll be over himself in the morning. So
just make yourself easy.”

It was evident that Benny’s honest little face had taken the man’s
fancy, and for the rest of the trip the boy was treated as a guest by
Mr. Welch.

The small steamboat was pushing its way along steadily by this
time, and Benny gave himself up to the enjoyment of the occasion.
Far off a broad expanse of blue water, dotted with white sails,
touched the horizon; on each side could be seen banks of vivid
green; an old half-ruined fort loomed up before them. Benny could
see through the open gateway flowers blooming in the inclosure; a
big dog lay sleeping upon a strong parapet. So peaceful and quiet
did the fort look that one could scarcely imagine that there had been
a time when threatening cannon pointed from those walls and that
armed men stood behind the strong embrasure.

Just beyond the fort the “Emma Jones” turned into a broad creek,
along the shores of which were little landings where sailboats and
rowboats were moored. The tall trees were reflected in the placid
waters, and Benny caught sight of pink flowers dotting the green of
the woods. It seemed a perfect paradise to him. Oh, how Kitty would
like to see it! His mother had told him of just such places, but he
had not half realized how beautiful they could be.
Every now and then the boat stopped to let off passengers and
freight till at the head of the creek the last landing was made, and
Benny followed his good friend ashore.

A motley collection of vehicles awaited the arrival of the steamer.


Here was a spring wagon drawn by a mule; there a substantial
looking Dayton; soberly standing under a tree were two oxen
harnessed to a small cart painted bright blue. An old colored woman
in a purple sunbonnet drove the oxen.
Into a big wagon Mr. Welch packed various barrels and bundles,
and Benny soon found himself placed between an old colored man
and Mr. Welch, while the horses trotted briskly along the white-
shelled road.

“We’re going round by Sanders’s,” said Mr. Welch to the driver;


and this arrangement having been complied with, all fears as to his
mother’s anxiety disappeared as Benny was told by Mr. Welch that
he had made matters all right. “I told Bill to turn on his ’phone, and I
waited, so he’d get the message straight. I shouldn’t wonder if it
was going over the wire this minute. I told him to say, ‘Ben in safe
hands. Made trip by mistake. Nobody’s fault.’ That’ll let her know you
aren’t to blame, and it’ll ease her mind. I know how mothers feel.
Had one myself.”
The little country store, before which they finally drew up, was a
long white building; a pretty lawn was on one side and a garden in
the rear. Outbuildings, a stable and henhouse, woodhouse and corn
crib, showed that it was a true country home. There was a little
church across the way, a blacksmith shop not far off, and between
the two half a dozen houses were scattered. These constituted the
village of Jennings’s Cross Roads.
Benny clambered down from the wagon and lent a willing hand to
the unloading of it, depositing the parcels on the porch in front of
the store, not pausing till the last bundle was safe.
“Hot work,” said Mr. Welch. “You’ve earned your supper, Ben;
come, let’s see what mother has for us.”

A rosy-faced woman stood on a side step as Benny and Mr. Welch


made their way to the pump in the back yard.

“Got back, Thad?” she said, pleasantly.


“Yes, and brought company,” was the reply. “That’s my wife, Ben.”
“Got room for a city visitor, Sue?”
Mrs. Welch looked curiously at Benny. “Why, yes, I reckon so,” she
answered, and then she joined them at the pump, where Mr. Welch
began vigorously to wash his face and hands, telling his wife
meanwhile of Benny’s adventures.
“That’s just like you, Thad,” she remarked, as he concluded. But a
pleased smile showed that she approved of just such proceedings
herself. “Come, supper’s ready,” she said, and led the way to the
dining-room.

Benny never forgot that supper. Hot biscuits and broiled ham;
fried potatoes and radishes; a great bowl of huge strawberries
served with thick, yellow cream; home-made sponge cake, and milk
in unlimited supply.
Mr. Welch kept piling up his plate, with due appreciation of a boy’s
appetite, till Benny felt that this was a land of plenty indeed, his only
regret being that he could not share this feast with his mother and
Kitty. Never in all his life had he eaten such a meal.

A little girl about Benny’s age sat opposite him; another, four or
five years older, and a boy nearly grown made up the additional
members of the family.
“Now, Jennie,” said Mrs. Welch to her younger daughter, as they
rose from the table, “take Ben with you to feed the chickens; I’ll
venture to say he won’t find a nicer lot anywhere.”

Jennie smiled an invitation over her shoulder, and Benny followed


her into the poultry yard, where he saw chickens of all sizes, cunning
yellow ducklings, and a flock of little turkeys. Then she took him to
the barn and displayed to his delighted eyes some little collie
puppies.
“How I should like to have one, that dear little fellow with a white
spot on his forehead, for instance,” thought Benny; and Jennie, as if
reading his thoughts, said:

“Now, if you only had a place where you could keep a dog, Joe
would give you one of these, I know.”
It seemed as if the whole family were interested in the welfare of
this little candidate for the office of strawberry picker, for Benny’s
childish confidences were given honestly and freely.

He went to sleep that night in a small attic room; a tall locust tree
hanging white blooms about the little dormer window, and the
sound of a whippoorwill’s cry being his last conscious recollection
before he went to sleep. He was awakened by stirring sounds out of
doors and in, and by the time he was ready for a descent to the
lower floor found that the family were up and all at work.

Breakfast was not less bountiful than supper, and after came a
second visit to the puppies, during which time he was called in the
store to confront Mr. Bentley.
It was evident that the way to a conference had been well paved
by Mr. Welch, for Mr. Bentley’s greeting was, “Well, boy, you want to
join my pickers, I hear.”

“Yes, sir,” replied Benny.

“How will you manage about your meals? They do their own
cooking, you know.”

Benny didn’t know, and his heart sank, but Mr. Welch’s kind voice
came in with the question, “’Twouldn’t put you out much to let him
eat with your regular farm hands, would it?”

“No-o,” returned Mr. Bentley, “I don’t reckon it would.” And then


turning to Benny he said, “Well, my boy, you’ll find a pretty rough
set—Bohemians, and Italians, and Poles, and I don’t know what all—
but if you’ve a mind to try it, I’ll take you along and give you a
chance; that’s what you want, I suppose.”

“It isn’t so hot to-day, must have been a storm somewhere, last
night, Thad.”

“Yes,” returned Mr. Welch, “must have been; I saw thunder heads
off toward the northwest; they must have got it down Broad Neck
way.”
“Well I’ve no time to lose,” said Mr. Bentley; “come along, boy, I’ll
give you a lift over our way;” and Benny, with a strong regret at
leaving this kind family at the Cross Roads, climbed up beside Mr.
Bentley in his road cart, and after a ride of a mile saw a white house
at the end of a long lane.
“That’s my place,” said Mr. Bentley. “I’ll let you off at the
strawberry field, and when you hear the dinner horn come up to the
house. That man sitting under the tree yonder is keeping tally. Every
dozen boxes you pick you take ’em up there and he’ll give you a little
wooden check, so that we both can keep count of what you pick.
Each check means so much, and you can earn as much or as little as
you’ve the will to do. There’s a board over yonder to carry your
boxes on. Now, we’ll see what you can do.”

And Benny was left in the big strawberry field amid a motley crew
of foreigners, strong misgivings at heart, and a little feeling of
homesickness coming over him as he faced the reality of a day’s
work in the hot sun, with no one to speak to him but strangers. He
picked up courage, however, wondering, as he started to work, how
much he could earn, and when his mother would get the queer,
blotchy little letter he had written to her the night before.
CHAPTER III

AMONG THE PICKERS

Benny was not a saint by any means. He was just as full of faults as
many other boys, but he had a warm, generous heart, and had been
carefully brought up, so, even if he was not always as thoughtful as
he might be, and sometimes forgot to be promptly obedient, he was
at least truthful, honest, and pure in heart, a fact which made the
boys in his neighborhood call him “old Particular,” or “old Partick” for
short. He was used to pretty rough company sometimes, but he had
never been thrown with quite such a crowd as that which
surrounded him in the strawberry patch. Coarse, boorish men,
vixenish, loud-voiced women, who jostled and elbowed him at times,
the younger ones teasing and badgering him in queer broken
English.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like