Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Go: Design Patterns for Real-World Projects

You're reading from   Go: Design Patterns for Real-World Projects Build production-ready solutions in Go using cutting-edge technology and techniques

Arrow left icon
Product type Course
Published in Jun 2017
Publisher Packt
ISBN-13 9781788390552
Length 1091 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (3):
Arrow left icon
Mario Castro Contreras Mario Castro Contreras
Author Profile Icon Mario Castro Contreras
Mario Castro Contreras
Mat Ryer Mat Ryer
Author Profile Icon Mat Ryer
Mat Ryer
Vladimir Vivien Vladimir Vivien
Author Profile Icon Vladimir Vivien
Vladimir Vivien
Arrow right icon
View More author details
Toc

Table of Contents (38) Chapters Close

Go: Design Patterns for Real-World Projects
Credits
Preface
Bibliography
1. A First Step in Go FREE CHAPTER 2. Go Language Essentials 3. Go Control Flow 4. Data Types 5. Functions in Go 6. Go Packages and Programs 7. Composite Types 8. Methods, Interfaces, and Objects 9. Concurrency 10. Data IO in Go 11. Writing Networked Services 12. Code Testing 13. Ready... Steady... Go! 14. Creational Patterns - Singleton, Builder, Factory, Prototype, and Abstract Factory Design Patterns 15. Structural Patterns - Composite, Adapter, and Bridge Design Patterns 16. Structural Patterns - Proxy, Facade, Decorator, and Flyweight Design Patterns 17. Behavioral Patterns - Strategy, Chain of Responsibility, and Command Design Patterns 18. Behavioral Patterns - Template, Memento, and Interpreter Design Patterns 19. Behavioral Patterns - Visitor, State, Mediator, and Observer Design Patterns 20. Introduction to Gos Concurrency 21. Concurrency Patterns - Barrier, Future, and Pipeline Design Patterns 22. Concurrency Patterns - Workers Pool and Publish/Subscriber Design Patterns 23. Chat Application with Web Sockets 24. Adding User Accounts 25. Three Ways to Implement Profile Pictures 26. Command-Line Tools to Find Domain Names 27. Building Distributed Systems and Working with Flexible Data 28. Exposing Data and Functionality through a RESTful Data Web Service API 29. Random Recommendations Web Service 30. Filesystem Backup 31. Building a Q&A Application for Google App Engine 32. Micro-services in Go with the Go kit Framework 33. Deploying Go Applications Using Docker 1. Good Practices for a Stable Go Environment

A JSON API server


Armed with the information from the last section, it is possible to use the HTTP package to create services over HTTP. Earlier we discussed the perils of creating services using raw TCP directly when we created a server for our global monetary currency service. In this section, we explore how to create an API server for the same service using HTTP as the underlying protocol. The new HTTP-based service has the following design goals:

  • Use HTTP as the transport protocol

  • Use JSON for structured communication between client and server

  • Clients query the server for currency information using JSON-formatted requests

  • The server respond using JSON-formatted responses

The following shows the code involved in the implementation of the new service. This time, the server will use the curr1 package (see github.com/vladimirvivien/learning-go /ch11/curr1) to load and query ISO 4217 currency data from a local CSV file.

The code in the curr1 package defines two types, CurrencyRequest and Currency...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime