Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
github.com/packtpublishing/hands-on-dependency-injection-in-go
This is the code repository for Hands-On Dependency Injection in Go, published by Packt.
Develop clean Go code that is easier to read, maintain, and test
Hands-On Dependency Injection in Go takes you on a journey, refactoring existing code to adopt dependency injection (DI) using various methods available in Go.
This book covers the following exciting features:
If you feel this book is for you, get your copy today!
All of the code is organized into folders. For example, ch02.
The code will look like the following:
html, body, #map {
height: 100%;
margin: 0;
padding: 0
}
Following is what you need for this book: Hands-On Dependency Injection in Go is for programmers with a few year s experience in any language and a basic understanding of Go. If you wish to produce clean, loosely coupled code that is inherently easier to test, this book is for you.
The easiest way to obtain the source code is to use go get
.
This will ensure that the code is placed in the correct directory and should be then runnable and testable.
To download this repo use go get github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/...
In this repository, there is 1 folder for every chapter of the book, named chXX where XX is the chapter number.
The code provided are expanded versions of the code presented in the book. While it will compile and typically
will not throw an error when passed into go test
it is not designed to be executed.
From chapter 4 onwards, there is an acme
directory included with the code that chapter.
The acme
directory is the code for the sample service presented in the book with the changes discussed in that chapter
already applied.
You will also find 2 additional directories in the root of the repository:
The easiest way to create and populate the database required by the sample service is by running the following:
mysql < ./resources/create.sql
Depending on your settings you may want to provide a username and password like this:
mysql -u [your username] -p < ./resources/create.sql
This will create a database called acme
with 1 table and 4 records.
The sample service uses a free currency conversion service. In order to successfully run all the examples, you will need to sign up here and obtain an API Key.
Now that you have your MySQL and CurrencyLayer credentials you can create a config for the sample service.
default-config.json
(found next to this file) to config.json
config.json
in your favorite editor"dsn"
setting. Should be in the form:
"[username]:[password]@tcp(localhost:3306)/[database name]?autocommit=true"
"exchangeRateAPIKey"
setting. Should be in the form: "1234567890abcdef1234567890abcdef"
To run sample service for a particular chapter:
cd $GOPATH/src/github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/
ACME_CONFIG=$GOPATH/src/github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/config.json go run ./ch04/acme/main.go
As we have multiple files and tests in the main
package, we cannot use the standard go run ./ch10/acme/main.go
to run the service.
Instead we need to modify the command to go run ./ch10/acme/main.go ./ch10/acme/wire_gen.go
To run sample service for a particular chapter you can use a command similar to the follow (which is for ch04):
cd $GOPATH/src/github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/
ACME_CONFIG=$GOPATH/src/github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/config.json go test ./ch04/...
With the following software and hardware list you can run all code files present in the book (Chapter 1-12).
Chapter | Software required | OS required |
---|---|---|
1-12 | Go 1.10.x+ | Windows, Mac OS X, and Linux (Any) |
4-12 | MySQL 5.7.x+ | Windows, Mac OS X, and Linux (Any) |
4-12 | CurrencyLayer | Windows, Mac OS X, and Linux (Any) |
Corey Scott is a senior software engineer currently living in Melbourne, Australia. He’s been programming professionally since 2000, with the last 5 years spent building large-scale distributed services in Go. An occasional technical speaker and blogger on a variety of software-related topics, he is passionate about designing and building quality software. He believes that software engineering is a craft that should be honed, debated, and continuously improved. He takes a pragmatic, non-zealot approach to coding and is always up for a good debate about software engineering, continuous delivery, testing, or clean coding.
Click here if you have any feedback or suggestions.
If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.