SlideShare a Scribd company logo
Go Web Programming 1st Edition Sau Sheong Chang -
PDF Download (2025)
https://ebookultra.com/download/go-web-programming-1st-edition-
sau-sheong-chang/
Visit ebookultra.com today to download the complete set of
ebooks or textbooks
Here are some recommended products for you. Click the link to
download, or explore more at ebookultra.com
Go Building Web Applications 1st Edition Kozyra
https://ebookultra.com/download/go-building-web-applications-1st-
edition-kozyra/
Go Programming Blueprints 2nd Edition Edition Mat Ryer
https://ebookultra.com/download/go-programming-blueprints-2nd-edition-
edition-mat-ryer/
TouchDevelop Programming on the Go 3rd Edition R. Nigel
Horspool
https://ebookultra.com/download/touchdevelop-programming-on-the-
go-3rd-edition-r-nigel-horspool/
Programming the Mobile Web 2nd Edition Maximiliano Firtman
https://ebookultra.com/download/programming-the-mobile-web-2nd-
edition-maximiliano-firtman/
XML Programming Web Applications and Web Services With JSP
and ASP 1st Edition Alexander Nakhimovsky
https://ebookultra.com/download/xml-programming-web-applications-and-
web-services-with-jsp-and-asp-1st-edition-alexander-nakhimovsky/
Programming Web Services with SOAP 1st ed Edition James
Snell
https://ebookultra.com/download/programming-web-services-with-
soap-1st-ed-edition-james-snell/
Programming the Web with Visual Basic NET 1st Edition Lynn
Torkelson
https://ebookultra.com/download/programming-the-web-with-visual-basic-
net-1st-edition-lynn-torkelson/
JG 301 Wilde Sau 1st Edition Marek J. Murawski
https://ebookultra.com/download/jg-301-wilde-sau-1st-edition-marek-j-
murawski/
Go Surf GO SERIES Tim Baker
https://ebookultra.com/download/go-surf-go-series-tim-baker/
Go Web Programming 1st Edition Sau Sheong Chang
Go Web Programming 1st Edition Sau Sheong Chang
Digital Instant Download
Author(s): Sau Sheong Chang
ISBN(s): 9781617292569, 1617292567
Edition: 1
File Details: PDF, 10.66 MB
Year: 2016
Language: english
M A N N I N G
Sau Sheong Chang
Go Web Programming
ii
Go Web Programming
SAU SHEONG CHANG
M A N N I N G
SHELTER ISLAND
iv
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: orders@manning.com
©2016 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in
any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books are
printed on paper that is at least 15 percent recycled and processed without elemental chlorine.
Manning Publications Co. Development editor: Marina Michaels
20 Baldwin Road Technical development editors: Glenn Burnside
PO Box 761 Michael Williams
Shelter Island, NY 11964 Review editor: Ozren Harlovic
Projecteditor: Kevin Sullivan
Copyeditor: Liz Welch
Proofreader: Elizabeth Martin
Technicalproofreader: Jimmy Frasché
Typesetter: Marija Tudor
Cover designer: Marija Tudor
ISBN: 9781617292569
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – EBM – 21 20 19 18 17 16
v
brief contents
PART 1 GO AND WEB APPLICATIONS ......................................... 1
1 ■
Go and web applications 3
2 ■
Go ChitChat 22
PART 2 BASIC WEB APPLICATIONS .......................................... 45
3 ■
Handling requests 47
4 ■
Processing requests 69
5 ■
Displaying content 96
6 ■
Storing data 125
PART 3 BEING REAL ............................................................ 153
7 ■
Go web services 155
8 ■
Testing your application 190
9 ■
Leveraging Go concurrency 223
10 ■
Deploying Go 256
BRIEF CONTENTS
vi
vii
contents
preface xiii
acknowledgments xv
about this book xvii
about the cover illustration xx
PART 1 GO AND WEB APPLICATIONS ............................. 1
1 Go and web applications 3
1.1 Using Go for web applications 4
Scalable web applications and Go 4 ■
Modular web
applications and Go 5 ■
Maintainable web applications and
Go 5 ■
High performing web applications and Go 6
1.2 How web applications work 6
1.3 A quick introduction to HTTP 8
1.4 The coming of web applications 8
1.5 HTTP request 9
Request methods 10 ■
Safe request methods 11 ■
Idempotent
request methods 11 ■
Browser support for request methods 11
Request headers 11
CONTENTS
viii
1.6 HTTP response 12
Response status code 13 ■
Response headers 13
1.7 URI 14
1.8 Introducing HTTP/2 16
1.9 Parts of a web app 16
Handler 16 ■
Template engine 17
1.10 Hello Go 18
1.11 Summary 21
2 Go ChitChat 22
2.1 Let’s ChitChat 23
2.2 Application design 24
2.3 Data model 26
2.4 Receiving and processing requests 27
The multiplexer 27 ■
Serving static files 28 ■
Creating the
handler function 28 ■
Access control using cookies 30
2.5 Generating HTML responses with templates 32
Tidying up 36
2.6 Installing PostgreSQL 37
Linux/FreeBSD 37 ■
Mac OS X 38 ■
Windows 38
2.7 Interfacing with the database 38
2.8 Starting the server 43
2.9 Wrapping up 43
2.10 Summary 44
PART 2 BASIC WEB APPLICATIONS ............................... 45
3 Handling requests 47
3.1 The Go net/http library 48
3.2 Serving Go 50
The Go web server 50 ■
Serving through HTTPS 51
3.3 Handlers and handler functions 55
Handling requests 55 ■
More handlers 56 ■
Handler
functions 57 ■
Chaining handlers and handler functions 59
ServeMux and DefaultServeMux 63 ■
Other multiplexers 64
CONTENTS ix
3.4 Using HTTP/2 66
3.5 Summary 68
4 Processing requests 69
4.1 Requests and responses 69
Request 70 ■
Request URL 70 ■
Request header 71
Request body 73
4.2 HTML forms and Go 74
Form 75 ■
PostForm 77 ■
MultipartForm 78 ■
Files 80
Processing POST requests with JSON body 81
4.3 ResponseWriter 82
Writing to the ResponseWriter 83
4.4 Cookies 87
Cookies with Go 87 ■
Sending cookies to the
browser 88 ■
Getting cookies from the browser 90 ■
Using
cookies for flash messages 92
4.5 Summary 95
5 Displaying content 96
5.1 Templates and template engines 97
5.2 The Go template engine 98
Parsing templates 100 ■
Executing templates 101
5.3 Actions 102
Conditional actions 102 ■
Iterator actions 104
Set actions 105 ■
Include actions 107
5.4 Arguments, variables, and pipelines 110
5.5 Functions 111
5.6 Context awareness 113
Defending against XSS attacks 116 ■
Unescaping
HTML 118
5.7 Nesting templates 119
5.8 Using the block action to define default templates 123
5.9 Summary 124
6 Storing data 125
6.1 In-memory storage 126
CONTENTS
x
6.2 File storage 128
Reading and writing CSV files 130 ■
The gob package 132
6.3 Go and SQL 134
Setting up the database 134 ■
Connecting to the
database 137 ■
Creating a post 138 ■
Retrieving a
post 140 ■
Updating a post 141 ■
Deleting a post 141
Getting all posts 142
6.4 Go and SQL relationships 143
Setting up the databases 143 ■
One-to-many relationship 145
6.5 Go relational mappers 147
Sqlx 148 ■
Gorm 149
6.6 Summary 152
PART 3 BEING REAL ................................................. 153
7 Go web services 155
7.1 Introducing web services 155 7.2
Introducing SOAP-based web services 157
7.3 Introducing REST-based web services 160
Convert action to a resource 162 ■
Make the action a property
of the resource 163
7.4 Parsing and creating XML with Go 163
Parsing XML 163 ■
Creating XML 171
7.5 Parsing and creating JSON with Go 174
Parsing JSON 175 ■
Creating JSON 178
7.6 Creating Go web services 181
7.7 Summary 188
8 Testing your application 190
8.1 Go and testing 191
8.2 Unit testing with Go 191
Skipping test cases 195 ■
Running tests in parallel 196
Benchmarking 197
8.3 HTTP testing with Go 200
8.4 Test doubles and dependency injection 204
Dependency injection with Go 205
CONTENTS xi
8.5 Third-party Go testing libraries 210
Introducing the gocheck testing package 211 ■
Introducing the
Ginkgo testing framework 216
8.6 Summary 221
9 Leveraging Go concurrency 223
9.1 Concurrency isn’t parallelism 223
9.2 Goroutines 225
Using goroutines 225 ■
Goroutines and performance 228
Waiting for goroutines 231
9.3 Channels 232
Synchronization with channels 233 ■
Message passing with
channels 234 ■
Buffered channels 235 ■
Selecting
channels 237
9.4 Concurrency for web applications 240
Creating the photo mosaic 240 ■
The photo mosaic web
application 243 ■
Concurrent photo mosaic web
application 247
9.5 Summary 254
10 Deploying Go 256
10.1 Deploying to servers 257
10.2 Deploying to Heroku 263
10.3 Deploying to Google App Engine 266
10.4 Deploying to Docker 271
What is Docker? 271 ■
Installing Docker 272 ■
Docker
concepts and components 273 ■
Dockerizing a Go web
application 274 ■
Pushing your Docker container to the
internet 276
10.5 Comparison of deployment methods 279
10.6 Summary 280
appendix Installing and setting up Go 281
index 285
CONTENTS
xii
xiii
preface
Web applications have been around in one form or another since the beginning of
the World Wide Web in the mid-1990s. They started by only delivering static web pages
but soon escalated and evolved into a dizzying variety of dynamic systems delivering
data and functions. My own journey in developing applications for the web started
around the same time, in the mid-1990s, and I eventually spent the larger part of my
professional career designing, developing, and managing teams in developing large-
scale web applications. Over the same period of time, I have written web applications
in numerous programming languages and using various frameworks including Java,
Ruby, Node.js, PHP, Perl, Elixir, and even Smalltalk.
I stumbled on Go a few years ago, and what worked very well for me is the simplicity
and refreshing directness of the language. I was even more impressed when I realized
that I could quickly write complete web applications (and services) that are fast and
scalable with only the Go standard libraries. The code is direct, easy to understand, and
can be quickly and easily compiled into a single deployable binary file. I no longer
need to throw in application servers to scale or to make my web application produc-
tion-capable. Needless to say, all of these elements made Go my new favorite language
for writing web applications.
Writing web applications has changed dramatically over the years, from static con-
tent to dynamic data over HTTP, from HTML content delivered from the server to
client-side single-page applications consuming JSON data over HTTP. Almost as soon
as the first web applications were written, web application frameworks appeared, mak-
ing it easier for programmers to write them. Twenty years on, most programming lan-
guages have at least one web application framework—and many have dozens—and
most applications written today are web applications.
PREFACE
xiv
While the popular web application frameworks made it easier to write web applica-
tions, they also concealed a lot of the underlying plumbing. It became increasingly
common to find programmers who don’t even understand how the World Wide Web
works writing web applications. With Go I found a great tool to teach the basics of web
application programming, properly. Writing web applications is direct and simple
again. Everything’s just there—no external libraries and dependencies. It’s all about
HTTP again and how to deliver content and data through it.
So with that in mind, I approached Manning with an idea for a Go programming
language book that focuses on teaching someone how to write web applications from
the ground up, using nothing except the standard libraries. Manning quickly sup-
ported my idea and green-lighted the project. The book has taken a while to come
together, but the feedback from the early access program (MEAP) was encouraging. I
hope you will gain much and enjoy reading this book as much as I enjoyed writing it.
xv
acknowledgments
This book started with an idea to teach the basics of web programming with Go, using
nothing more than the standard libraries. I wasn’t sure if that would work, but the
readers who paid hard-earned money to buy my MEAP along the way gave me encour-
agement and motivation to push the idea through. To my readers, thank you!
Writing books is a team effort, and though my name appears on the front cover of
this one, it only exists because of the efforts of a large number of people:
■
Marina Michaels, my hardworking and efficient editor from the other side of
the world, worked tirelessly alongside me, ever ready to accommodate her
schedule to our dramatically different time zones
■
The Manning extended team: Liz Welch, copyeditor, and Elizabeth Martin,
proofreader, who with their eagle eyes helped spot my mistakes; Candace Gill-
hoolley and Ana Romac, who helped me market and promote this book; and
Kevin Sullivan and Janet Vail, who worked to take my raw manuscript and make
it into a real book
■
Jimmy Frasché, who gave the manuscript a full technical proofread, and my
reviewers, who gave valuable feedback at four stages of manuscript develop-
ment: Alex Jacinto, Alexander Schwartz, Benoit Benedetti, Brian Cooksey,
Doug Sparling, Ferdinando Santacroce, Gualtiero Testa, Harry Shaun Lippy,
James Tyo, Jeff Lim, Lee Brandt, Mike Bright, Quintin Smith, Rebecca Jones,
Ryan Pulling, Sam Zaydel, and Wes Shaddix
■
My friends from the Singapore Go community who helped me spread the word
on my new book as soon as the MEAP came out, especially Kai Hendry, who
made a long video from his comments on my book
ACKNOWLEDGMENTS
xvi
I’d also like to thank the creators of Go—Robert Griesemer, Rob Pike, and Ken
Thompson—as well as contributors to the net/http, html/template, and other web
standard libraries, especially Brad Fitzpatrick, without whom I probably wouldn’t have
anything to write about!
Last but certainly not least, I’d like to thank my family—the love of my life, Wooi
Ying, and my taller-than-me-now son, Kai Wen. I hope that in writing this book, I will
be an inspiration to him and he will soon pick up my book proudly and learn from it.
xvii
about this book
This book introduces the basic concepts of writing a web application using the Go
programming language, from the ground up, using nothing other than the standard
libraries. While there are sections that discuss other libraries and other topics, includ-
ing testing and deploying web applications, the main goal of the book is to teach web
programming using Go standard libraries only.
The reader is assumed to have basic Go programming skills and to know Go syn-
tax. If you don’t know Go programming at all, I would advise you to check out Go in
Action by William Kennedy with Brian Ketelsen and Erik St. Martin, also published by
Manning (www.manning.com/books/go-in-action). Another good book to read is The
Go Programming Language (Addison-Wesley 2015), by Alan Donovan and Brian Ker-
nighan. Alternatively, there are plenty of free tutorials on Go, including the A Tour of
Go from the Go website (tour.golang.org).
Roadmap
The book includes ten chapters and an appendix.
Chapter 1 introduces using Go for web applications, and discusses why it is a good
choice for writing web applications. You’ll also learn about key concepts of what web
applications are, including a brief introduction to HTTP.
Chapter 2 shows you how to build a typical web application with Go, taking you
step by step through the creation of a simple internet forum web.
Chapter 3 gets into the details of handling HTTP requests using the net/http pack-
age. You’ll learn how to write a Go web server to listen to HTTP requests and how to
incorporate handlers and handler functions that process those requests.
ABOUT THIS BOOK
xviii
Chapter 4 continues with the details of handling HTTP requests—specifically, how
Go allows you to process the requests and respond accordingly. You’ll also learn how
to get data from HTML forms and how to use cookies.
Chapter 5 delves into the Go template engine provided in the text/template and
html/template packages. You’ll learn about the various mechanisms provided by Go
and about using layouts in Go.
Chapter 6 discusses storage strategies using Go. You’ll learn about storing data in
memory using structs, in the filesystem using CSV and the gob binary format as well as
using SQL and SQL mappers to access relational databases.
Chapter 7 shows you how to create web services using Go. You’ll learn how to cre-
ate and parse XML as well as JSON with Go, and how a simple web service can be writ-
ten using Go.
Chapter 8 gives insight into the ways you can test your Go web application at vari-
ous levels, including unit testing, benchmark testing, and HTTP testing. This chapter
also briefly discusses third-party testing libraries.
Chapter 9 talks about how you can leverage Go concurrency in your web applica-
tion. You’ll learn about Go concurrency and how you can improve the performance of
a photo-mosaic web application using Go concurrency.
Chapter 10 wraps up the book by showing how you can deploy your web applica-
tion. You’ll learn how to deploy to standalone servers and to the cloud (Heroku and
Google App Engine), as well as in Docker containers.
The appendix provides instructions for installing and setting up Go on different
platforms.
Code conventions and downloads
This book contains many examples of source code both in numbered listings and
inline with normal text. In both cases, source code is formatted in a fixed-width
font like this to separate it from ordinary text. Sometimes code is in bold to high-
light code that has changed from previous steps in the chapter or code that is
discussed in surrounding text.
Also, colors are used to highlight code commands and code output:
curl -i 127.0.0.1:8080/write
HTTP/1.1 200 OK
Date: Tue, 13 Jan 2015 16:16:13 GMT
Content-Length: 95
Content-Type: text/html; charset=utf-8
<html>
<head><title>Go Web Programming</title></head>
<body><h1>Hello World</h1></body>
</html>
ABOUT THIS BOOK xix
Print book readers who want to see this color code highlighting (and all figures in
color) can go to www.manning.com/books/go-web-programming to register and get
their free eBook in PDF, ePub, and Kindle formats.
Code samples used throughout the book are also available at www.manning.com/
books/go-web-programming and at github.com/sausheong/gwp.
About the author
SAU SHEONG CHANG is now the Managing Director of Digital
Technology at Singapore Power. Before that, he was a Director of
Consumer Engineering at PayPal. He is active in the Ruby and
Go developer communities, and has written books, contributed
to open source projects, and spoken at meetups and conferences.
Author Online
Purchase of Go Web Programming includes free access to a private web forum run by
Manning Publications; you can make comments about the book, ask technical ques-
tions, and receive help from the author and from other users. To access the forum
and subscribe to it, point your web browser to www.manning.com/books/go-web-
programming. This page provides information on how to get on the forum after you’re
registered, what kind of help is available, and the rules of conduct on the forum.
Manning’s commitment to our readers is to provide a venue where a meaningful
dialogue between individual readers and between readers and the author can take
place. It’s not a commitment to any specific amount of participation on the part of the
author, whose contribution to the forum remains voluntary (and unpaid). We suggest
you try asking the author some challenging questions lest his interest stray!
The Author Online forum and the archives of previous discussions will be accessi-
ble from the publisher’s website as long as the book is in print.
Other documents randomly have
different content
Go Web Programming 1st Edition Sau Sheong Chang
Go Web Programming 1st Edition Sau Sheong Chang
Go Web Programming 1st Edition Sau Sheong Chang
The Project Gutenberg eBook of The
Profession of Journalism
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: The Profession of Journalism
Editor: Willard Grosvenor Bleyer
Release date: April 30, 2020 [eBook #61982]
Most recently updated: October 17, 2024
Language: English
Credits: Produced by Richard Tonsing 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 THE PROFESSION
OF JOURNALISM ***
Go Web Programming 1st Edition Sau Sheong Chang
THE PROFESSION OF
JOURNALISM
OTHER
COLLECTIONS
drawn from The Atlantic Monthly
are published under the following
titles:—
Atlantic Classics, First Series $1.25
Atlantic Classics, Second
Series $1.25
Headquarters Nights. By
Vernon Kellogg $1.00
The War and the Spirit of
Youth. By Maurice Barrès
and Others $1.00
Pan-Germany: The Disease
and Cure. By André
Chéradame $ .35
The Assault on Humanism. By
Paul Shorey $1.00
Shock at the Front. By
William T. Porter M.D. $1.25
Atlantic Narratives. Edited
by Charles Swain Thomas $1.00
Essays and Essay Writing.
Edited by W. M. Tanner $1.00
THE ATLANTIC MONTHLY
PRESS
BOSTON
Go Web Programming 1st Edition Sau Sheong Chang
THE PROFESSION OF
JOURNALISM
A Collection of Articles on Newspaper Editing
and Publishing, Taken from the Atlantic
Monthly
EDITED WITH AN INTRODUCTION AND NOTES BY
WILLARD GROSVENOR BLEYER, Ph.D.
Author of “Newspaper Writing and Editing” and “Types of News
Writing”; Professor of Journalism in the University of Wisconsin
The Atlantic Monthly Press
BOSTON
Copyright, 1918, by
THE ATLANTIC MONTHLY PRESS, INC.
Go Web Programming 1st Edition Sau Sheong Chang
PREFACE
The purpose of this book is to bring together in convenient form a
number of significant contributions to the discussion of the
newspaper and its problems which have appeared in the Atlantic
Monthly in recent years. Although these articles were intended only
for the readers of that magazine at the time of their original
publication, they have permanent value for the general reader, for
newspaper workers, and for students of journalism.
Practically every phase of journalism is taken up in these articles,
including newspaper publishing, news and editorial policies, the
influence of the press, yellow and sensational journalism, the
problems of the newspaper in small cities, country journalism, the
Associated Press, the law of libel, book-reviewing, dramatic criticism,
“comics,” free-lance writing, and the opportunities in the profession.
For readers who desire to make a further study of any of the
important aspects of the press, a bibliography of such books and
magazine articles as are generally available in public libraries has
been appended.
Most of the authors of the articles in this volume are newspaper
and magazine writers and editors whose long experience in
journalism gives particular value to their analysis of conditions, past
and present. Brief notes on the journalistic work of the writers are
given in the Appendix.
For permission to reprint the articles the editor is indebted to the
writers and to the editor of the Atlantic Monthly.
W. G. B.
University of Wisconsin,
January 12, 1918.
CONTENTS
PAGE
Introduction. Willard Grosvenor
Bleyer ix
Some Aspects of Journalism. Rollo Ogden 1
Press Tendencies and Dangers. Oswald Garrison Villard 20
The Waning Power of the Press. Francis E. Leupp 30
Newspaper Morals. H. L. Mencken 52
Newspaper Morals: A Reply. Ralph Pulitzer 68
The Suppression of Important News. Edward Alsworth Ross 79
The Personal Equation in Journalism. Henry Watterson 97
The Problem of the Associated Press. “An Observer” 112
The Associated Press: A Reply. Melville E. Stone 124
Confessions of a Provincial Editor. “Paracelsus” 133
The Country Editor of To-day. Charles Moreau Harger 151
Sensational Journalism and the Law. George W. Alger 167
The Critic and the Law. Richard Washburn Child 181
Honest Literary Criticism. Charles Miner
Thompson 200
Dramatic Criticism in the American
Press. James S. Metcalfe 224
The Humor of the Colored Supplement. Ralph Bergengren 233
The American Grub Street. James H. Collins 243
Journalism as a Career. Charles Moreau Harger 264
Bibliography 279
Notes on the Writers 290
INTRODUCTION
BY WILLARD GROSVENOR BLEYER
I
“The food of opinion,” as President Wilson has well said, “is the
news of the day.” The daily newspaper, for the majority of
Americans, is the sole purveyor of this food for thought. Citizens of a
democracy must read and assimilate the day’s news in order to form
opinions on current events and issues. Again, for the average citizen
the newspaper is almost the only medium for the interpretation and
discussion of questions of the day. The composite of individual
opinions, which we call public opinion, must express itself in action
to be effective. The newspaper, with its daily reiteration, is the most
powerful force in urging citizens to act in accordance with their
convictions. By reflecting the best sentiment of the community in
which it is published, the newspaper makes articulate intelligent
public opinion that might otherwise remain unexpressed. Since the
success of democracy depends not only upon intelligent public
opinion but upon political action in accordance with such opinion, it
is not too much to say that the future of democratic government in
this country depends upon the character of its newspapers.
Yet most newspaper readers not unnaturally regard the daily paper
as an ephemeral thing to be read hurriedly and cast aside. Few
appreciate the extent to which their opinions are affected by the
newspaper they read. Nevertheless, to every newspaper reader—
which means almost every person in this country—the conditions
under which newspapers are produced and the influences that affect
the character of news and editorials, should be matters of vital
concern.
To newspaper workers and students of journalism the analysis of
the fundamental questions of their profession is of especial
importance. Discussion of current practices must precede all effort to
arrive at definite standards for the profession of journalism. Only
when the newspaper man realizes the probable effect of his work on
the ideas and ideals of thousands of readers, and hence on the
character of our democracy, does he appreciate the full significance
of his news story, headline, or editorial.
The modern newspaper has developed so recently from simple
beginnings into a great, complex institution that no systematic and
extensive study has been made of its problems. Journalism has won
recognition as a profession only within the last seventy-five years,
and professional schools for the training of newspaper writers and
editors have been in existence less than fifteen years. In view of these
conditions, it is not surprising that definite principles and a generally
accepted code of ethics for the practice of the profession have not
been formulated.
Ideal conditions of newspaper editing and publishing are not likely
to be brought about by legislation. So jealous are the American
people of the liberty of their press that they hesitate, even when their
very existence as a nation is threatened, to impose legal restrictions
on the printing of news and opinion. If regulation does come, it
should be the result, as it has been in the professions of law and
medicine, of the creation of an enlightened public opinion in support
of professional standards adopted by journalists themselves.
The present is an auspicious time to discuss such standards. The
world war has put to the test, not only men and machinery, but every
institution of society. Of each organized activity we ask, Is it serving
most effectively the common good? Not simply service to the state,
but service to society, is being demanded more and more of every
individual and every institution. “These are the times which try
men’s souls,” and that try no less the mediums through which men’s
souls find expression. The newspaper, as the purveyor of “food of
opinion” and as the medium for expressing opinion, must measure
up to the test of the times.
II
The first step in a systematic analysis of the principles of
journalism must be a consideration of the function of the newspaper
in a democracy. In the varied and voluminous contents of a typical
newspaper are to be found news of all kinds, editorial comment,
illustrations of current events, recipes, comic strips, fashions,
cartoons, advice on affairs of the heart, short stories, answers to
questions on etiquette, dramatic criticism, chapters of a serial, book
reviews, verse, a “colyum,” and advertisements. What in this
mélange is the one element which distinguishes the newspaper from
all other publications? It is the daily news. Weekly and monthly
periodicals do everything that the newspaper does, except print the
news from day to day.
Whatever other aims a newspaper may have, its primary purpose
must be to give adequate reports of the day’s news. Although various
inducements other than news may be employed to attract some
persons to newspapers who would not otherwise read them
regularly, nevertheless these features must not be so prominent or
attractive that readers with limited time at their disposal will neglect
the day’s news for entertainment.
To assist the public to grasp the significance of the news by means
of editorial interpretation and discussion, to render articulate the
best public sentiment, and to persuade citizens to act in accordance
with their opinions, constitute an important secondary function of
the newspaper. Even though the editorial may seem to exert a less
direct influence upon the opinions and political action of the average
citizen than it did in the period of great editorial leadership,
nevertheless the interpretation and discussion of timely topics in the
editorial columns of the daily press are a force in democratic
government that cannot be disregarded.
Newspapers by their editorials can perform two peculiarly
important services to the public. First, they can show the relation of
state, national, and international questions to the home and business
interests of their readers. Only as the great issues of the day are
brought home to the average reader is he likely to become keenly
interested in their solution. Second, newspapers in their editorials
can point out the connection between local questions and state-wide,
nation-wide, or world-wide movements. Only as questions at issue in
a community are shown in their relation to larger tendencies will the
average reader see them in a perspective that will enable him to think
and act most intelligently.
In addition to fulfilling these two functions, the newspaper may
supply its readers with practical advice and useful information, as
well as with entertaining reading matter and illustrations. There is
more justification for wholesome advice and entertainment in
newspapers that circulate largely among classes whose only reading
matter is the daily paper than there is in papers whose readers obtain
these features from other periodicals. In view of the numberless
cheap, popular magazines in this country, the extent to which daily
newspapers should devote space and money to advice and
entertainment deserves careful consideration. That without such
consideration these features may encroach unjustifiably on news and
editorials seems evident.
III
Since the primary function of the newspaper is to give the day’s
news, the question arises, What is news? If from the point of view of
successful democracy the value of news is determined by the extent
to which it furnishes food for thought on current topics, we are at
once given an important criterion for defining news and measuring
news-values. Thus, news is anything timely which is significant to
newspaper readers in their relation to the community, the state, and
the nation.
This conception of news is not essentially at variance with the
commonly accepted definition of it as anything timely that interests a
number of readers, the best news being that which has greatest
interest for the greatest number. The most vital matters for both men
and women are their home and their business interests, their success
and their happiness. Anything in the day’s news that touches directly
or indirectly these things that are nearest and dearest to them, they
will read with eagerness. As they may not always be able to see at
once the relation of current events and issues to their home,
business, and community interests, it is the duty of the newspaper to
present news in such a way that its significance to the average reader
will be clear. Every newspaper man knows the value of “playing up”
the “local ends” of events that take place outside of the community in
which his paper is published, but this method of bringing home to
readers the significance to them of important news has not been as
fully worked out as it will be. On this basis the best news is that
which can be shown to be most closely related to the interests of the
largest number of readers.
“But newspapers must publish entertaining news stories as well as
significant ones,” insists the advocate of things as they are. This may
be conceded, but only with three important limitations. First, stories
for mere entertainment that deal with events of little or no news-
value must not be allowed to crowd out significant news. Second,
such entertaining news-matter must not be given so much space and
prominence, or be made so attractive, that the average reader with
but limited time in which to read his paper will neglect news of value.
Third, events of importance must not be so treated as to furnish
entertainment primarily, to the subordination of their true
significance. To substitute the hors d’œuvres, relishes, and dessert of
the day’s happenings for nourishing “food of opinion” is to serve an
unbalanced, unwholesome mental diet. The relish should heighten,
not destroy, a taste for good food.
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!
ebookultra.com

More Related Content

PDF
Go Web Programming 1st Edition Sau Sheong Chang
PDF
iPhone in action introduction to Web and SDK development 1st Edition Christop...
PDF
Windows Store App Development C And Xaml 1st Edition Pete Brown
PDF
Windows Store App Development C and XAML Pete Brown
PDF
ASP NET MVC in Action 1st Edition Jeffrey Palermo
PDF
Hello HTML5 CSS3 A user friendly reference guide 1st Edition Rob Crowther
PDF
ASP NET MVC in Action 1st Edition Jeffrey Palermo
PDF
Getting MEAN with Mongo Express Angular and Node 1st Edition Simon Holmes
Go Web Programming 1st Edition Sau Sheong Chang
iPhone in action introduction to Web and SDK development 1st Edition Christop...
Windows Store App Development C And Xaml 1st Edition Pete Brown
Windows Store App Development C and XAML Pete Brown
ASP NET MVC in Action 1st Edition Jeffrey Palermo
Hello HTML5 CSS3 A user friendly reference guide 1st Edition Rob Crowther
ASP NET MVC in Action 1st Edition Jeffrey Palermo
Getting MEAN with Mongo Express Angular and Node 1st Edition Simon Holmes

Similar to Go Web Programming 1st Edition Sau Sheong Chang (20)

PDF
WebWork in Action In Action First Edition Patrick Lightbody
PDF
Getting MEAN with Mongo Express Angular and Node 1st Edition Simon Holmes
PDF
JavaScript Application Design A Build First Approach 1st Edition Nicolas Beva...
PDF
Open Source ESBs in Action 1st Edition Tijs Rademakers
PDF
OSGi in Depth 1st Edition Alexandre De Castro Alves
PDF
Android in Action 3rd Edition W. Frank Ableson
PDF
Open Source ESBs in Action 1st Edition Tijs Rademakers
PDF
Open Source ESBs in Action 1st Edition Tijs Rademakers
PDF
Open Source ESBs in Action 1st Edition Tijs Rademakers
PDF
JavaScript Application Design A Build First Approach 1st Edition Nicolas Beva...
PDF
WebWork in Action In Action First Edition Patrick Lightbody
PDF
WebWork in Action In Action First Edition Patrick Lightbody
PDF
Testing Microservices With Mountebank 1st Edition Brandon Byars
PDF
SOA Governance in Action REST and WS Architectures Jos Dirksen
PDF
React in Action 1st Edition Mark Tielens Thomas
PDF
Open Source ESBs in Action 1st Edition Tijs Rademakers
PDF
Docker In Action Second Edition 2nd Edition Jeff Nickoloff
PDF
Eclipse In Action A Guide For Java Developers 1st Edition David Gallardo
PDF
Hello Html5 Css3 A User Friendly Reference Guide Rob Crowther
PDF
Download full ebook of Azure in Action 1st Edition Chris Hay instant download...
WebWork in Action In Action First Edition Patrick Lightbody
Getting MEAN with Mongo Express Angular and Node 1st Edition Simon Holmes
JavaScript Application Design A Build First Approach 1st Edition Nicolas Beva...
Open Source ESBs in Action 1st Edition Tijs Rademakers
OSGi in Depth 1st Edition Alexandre De Castro Alves
Android in Action 3rd Edition W. Frank Ableson
Open Source ESBs in Action 1st Edition Tijs Rademakers
Open Source ESBs in Action 1st Edition Tijs Rademakers
Open Source ESBs in Action 1st Edition Tijs Rademakers
JavaScript Application Design A Build First Approach 1st Edition Nicolas Beva...
WebWork in Action In Action First Edition Patrick Lightbody
WebWork in Action In Action First Edition Patrick Lightbody
Testing Microservices With Mountebank 1st Edition Brandon Byars
SOA Governance in Action REST and WS Architectures Jos Dirksen
React in Action 1st Edition Mark Tielens Thomas
Open Source ESBs in Action 1st Edition Tijs Rademakers
Docker In Action Second Edition 2nd Edition Jeff Nickoloff
Eclipse In Action A Guide For Java Developers 1st Edition David Gallardo
Hello Html5 Css3 A User Friendly Reference Guide Rob Crowther
Download full ebook of Azure in Action 1st Edition Chris Hay instant download...
Ad

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Insiders guide to clinical Medicine.pdf
PDF
Business Ethics Teaching Materials for college
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Basic Mud Logging Guide for educational purpose
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Institutional Correction lecture only . . .
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
master seminar digital applications in india
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Cell Structure & Organelles in detailed.
human mycosis Human fungal infections are called human mycosis..pptx
Insiders guide to clinical Medicine.pdf
Business Ethics Teaching Materials for college
Anesthesia in Laparoscopic Surgery in India
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Basic Mud Logging Guide for educational purpose
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
01-Introduction-to-Information-Management.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Institutional Correction lecture only . . .
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
master seminar digital applications in india
TR - Agricultural Crops Production NC III.pdf
Cell Structure & Organelles in detailed.
Ad

Go Web Programming 1st Edition Sau Sheong Chang

  • 1. Go Web Programming 1st Edition Sau Sheong Chang - PDF Download (2025) https://ebookultra.com/download/go-web-programming-1st-edition- sau-sheong-chang/ Visit ebookultra.com today to download the complete set of ebooks or textbooks
  • 2. Here are some recommended products for you. Click the link to download, or explore more at ebookultra.com Go Building Web Applications 1st Edition Kozyra https://ebookultra.com/download/go-building-web-applications-1st- edition-kozyra/ Go Programming Blueprints 2nd Edition Edition Mat Ryer https://ebookultra.com/download/go-programming-blueprints-2nd-edition- edition-mat-ryer/ TouchDevelop Programming on the Go 3rd Edition R. Nigel Horspool https://ebookultra.com/download/touchdevelop-programming-on-the- go-3rd-edition-r-nigel-horspool/ Programming the Mobile Web 2nd Edition Maximiliano Firtman https://ebookultra.com/download/programming-the-mobile-web-2nd- edition-maximiliano-firtman/
  • 3. XML Programming Web Applications and Web Services With JSP and ASP 1st Edition Alexander Nakhimovsky https://ebookultra.com/download/xml-programming-web-applications-and- web-services-with-jsp-and-asp-1st-edition-alexander-nakhimovsky/ Programming Web Services with SOAP 1st ed Edition James Snell https://ebookultra.com/download/programming-web-services-with- soap-1st-ed-edition-james-snell/ Programming the Web with Visual Basic NET 1st Edition Lynn Torkelson https://ebookultra.com/download/programming-the-web-with-visual-basic- net-1st-edition-lynn-torkelson/ JG 301 Wilde Sau 1st Edition Marek J. Murawski https://ebookultra.com/download/jg-301-wilde-sau-1st-edition-marek-j- murawski/ Go Surf GO SERIES Tim Baker https://ebookultra.com/download/go-surf-go-series-tim-baker/
  • 5. Go Web Programming 1st Edition Sau Sheong Chang Digital Instant Download Author(s): Sau Sheong Chang ISBN(s): 9781617292569, 1617292567 Edition: 1 File Details: PDF, 10.66 MB Year: 2016 Language: english
  • 6. M A N N I N G Sau Sheong Chang
  • 8. ii
  • 9. Go Web Programming SAU SHEONG CHANG M A N N I N G SHELTER ISLAND
  • 10. iv For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: orders@manning.com ©2016 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without elemental chlorine. Manning Publications Co. Development editor: Marina Michaels 20 Baldwin Road Technical development editors: Glenn Burnside PO Box 761 Michael Williams Shelter Island, NY 11964 Review editor: Ozren Harlovic Projecteditor: Kevin Sullivan Copyeditor: Liz Welch Proofreader: Elizabeth Martin Technicalproofreader: Jimmy Frasché Typesetter: Marija Tudor Cover designer: Marija Tudor ISBN: 9781617292569 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – EBM – 21 20 19 18 17 16
  • 11. v brief contents PART 1 GO AND WEB APPLICATIONS ......................................... 1 1 ■ Go and web applications 3 2 ■ Go ChitChat 22 PART 2 BASIC WEB APPLICATIONS .......................................... 45 3 ■ Handling requests 47 4 ■ Processing requests 69 5 ■ Displaying content 96 6 ■ Storing data 125 PART 3 BEING REAL ............................................................ 153 7 ■ Go web services 155 8 ■ Testing your application 190 9 ■ Leveraging Go concurrency 223 10 ■ Deploying Go 256
  • 13. vii contents preface xiii acknowledgments xv about this book xvii about the cover illustration xx PART 1 GO AND WEB APPLICATIONS ............................. 1 1 Go and web applications 3 1.1 Using Go for web applications 4 Scalable web applications and Go 4 ■ Modular web applications and Go 5 ■ Maintainable web applications and Go 5 ■ High performing web applications and Go 6 1.2 How web applications work 6 1.3 A quick introduction to HTTP 8 1.4 The coming of web applications 8 1.5 HTTP request 9 Request methods 10 ■ Safe request methods 11 ■ Idempotent request methods 11 ■ Browser support for request methods 11 Request headers 11
  • 14. CONTENTS viii 1.6 HTTP response 12 Response status code 13 ■ Response headers 13 1.7 URI 14 1.8 Introducing HTTP/2 16 1.9 Parts of a web app 16 Handler 16 ■ Template engine 17 1.10 Hello Go 18 1.11 Summary 21 2 Go ChitChat 22 2.1 Let’s ChitChat 23 2.2 Application design 24 2.3 Data model 26 2.4 Receiving and processing requests 27 The multiplexer 27 ■ Serving static files 28 ■ Creating the handler function 28 ■ Access control using cookies 30 2.5 Generating HTML responses with templates 32 Tidying up 36 2.6 Installing PostgreSQL 37 Linux/FreeBSD 37 ■ Mac OS X 38 ■ Windows 38 2.7 Interfacing with the database 38 2.8 Starting the server 43 2.9 Wrapping up 43 2.10 Summary 44 PART 2 BASIC WEB APPLICATIONS ............................... 45 3 Handling requests 47 3.1 The Go net/http library 48 3.2 Serving Go 50 The Go web server 50 ■ Serving through HTTPS 51 3.3 Handlers and handler functions 55 Handling requests 55 ■ More handlers 56 ■ Handler functions 57 ■ Chaining handlers and handler functions 59 ServeMux and DefaultServeMux 63 ■ Other multiplexers 64
  • 15. CONTENTS ix 3.4 Using HTTP/2 66 3.5 Summary 68 4 Processing requests 69 4.1 Requests and responses 69 Request 70 ■ Request URL 70 ■ Request header 71 Request body 73 4.2 HTML forms and Go 74 Form 75 ■ PostForm 77 ■ MultipartForm 78 ■ Files 80 Processing POST requests with JSON body 81 4.3 ResponseWriter 82 Writing to the ResponseWriter 83 4.4 Cookies 87 Cookies with Go 87 ■ Sending cookies to the browser 88 ■ Getting cookies from the browser 90 ■ Using cookies for flash messages 92 4.5 Summary 95 5 Displaying content 96 5.1 Templates and template engines 97 5.2 The Go template engine 98 Parsing templates 100 ■ Executing templates 101 5.3 Actions 102 Conditional actions 102 ■ Iterator actions 104 Set actions 105 ■ Include actions 107 5.4 Arguments, variables, and pipelines 110 5.5 Functions 111 5.6 Context awareness 113 Defending against XSS attacks 116 ■ Unescaping HTML 118 5.7 Nesting templates 119 5.8 Using the block action to define default templates 123 5.9 Summary 124 6 Storing data 125 6.1 In-memory storage 126
  • 16. CONTENTS x 6.2 File storage 128 Reading and writing CSV files 130 ■ The gob package 132 6.3 Go and SQL 134 Setting up the database 134 ■ Connecting to the database 137 ■ Creating a post 138 ■ Retrieving a post 140 ■ Updating a post 141 ■ Deleting a post 141 Getting all posts 142 6.4 Go and SQL relationships 143 Setting up the databases 143 ■ One-to-many relationship 145 6.5 Go relational mappers 147 Sqlx 148 ■ Gorm 149 6.6 Summary 152 PART 3 BEING REAL ................................................. 153 7 Go web services 155 7.1 Introducing web services 155 7.2 Introducing SOAP-based web services 157 7.3 Introducing REST-based web services 160 Convert action to a resource 162 ■ Make the action a property of the resource 163 7.4 Parsing and creating XML with Go 163 Parsing XML 163 ■ Creating XML 171 7.5 Parsing and creating JSON with Go 174 Parsing JSON 175 ■ Creating JSON 178 7.6 Creating Go web services 181 7.7 Summary 188 8 Testing your application 190 8.1 Go and testing 191 8.2 Unit testing with Go 191 Skipping test cases 195 ■ Running tests in parallel 196 Benchmarking 197 8.3 HTTP testing with Go 200 8.4 Test doubles and dependency injection 204 Dependency injection with Go 205
  • 17. CONTENTS xi 8.5 Third-party Go testing libraries 210 Introducing the gocheck testing package 211 ■ Introducing the Ginkgo testing framework 216 8.6 Summary 221 9 Leveraging Go concurrency 223 9.1 Concurrency isn’t parallelism 223 9.2 Goroutines 225 Using goroutines 225 ■ Goroutines and performance 228 Waiting for goroutines 231 9.3 Channels 232 Synchronization with channels 233 ■ Message passing with channels 234 ■ Buffered channels 235 ■ Selecting channels 237 9.4 Concurrency for web applications 240 Creating the photo mosaic 240 ■ The photo mosaic web application 243 ■ Concurrent photo mosaic web application 247 9.5 Summary 254 10 Deploying Go 256 10.1 Deploying to servers 257 10.2 Deploying to Heroku 263 10.3 Deploying to Google App Engine 266 10.4 Deploying to Docker 271 What is Docker? 271 ■ Installing Docker 272 ■ Docker concepts and components 273 ■ Dockerizing a Go web application 274 ■ Pushing your Docker container to the internet 276 10.5 Comparison of deployment methods 279 10.6 Summary 280 appendix Installing and setting up Go 281 index 285
  • 19. xiii preface Web applications have been around in one form or another since the beginning of the World Wide Web in the mid-1990s. They started by only delivering static web pages but soon escalated and evolved into a dizzying variety of dynamic systems delivering data and functions. My own journey in developing applications for the web started around the same time, in the mid-1990s, and I eventually spent the larger part of my professional career designing, developing, and managing teams in developing large- scale web applications. Over the same period of time, I have written web applications in numerous programming languages and using various frameworks including Java, Ruby, Node.js, PHP, Perl, Elixir, and even Smalltalk. I stumbled on Go a few years ago, and what worked very well for me is the simplicity and refreshing directness of the language. I was even more impressed when I realized that I could quickly write complete web applications (and services) that are fast and scalable with only the Go standard libraries. The code is direct, easy to understand, and can be quickly and easily compiled into a single deployable binary file. I no longer need to throw in application servers to scale or to make my web application produc- tion-capable. Needless to say, all of these elements made Go my new favorite language for writing web applications. Writing web applications has changed dramatically over the years, from static con- tent to dynamic data over HTTP, from HTML content delivered from the server to client-side single-page applications consuming JSON data over HTTP. Almost as soon as the first web applications were written, web application frameworks appeared, mak- ing it easier for programmers to write them. Twenty years on, most programming lan- guages have at least one web application framework—and many have dozens—and most applications written today are web applications.
  • 20. PREFACE xiv While the popular web application frameworks made it easier to write web applica- tions, they also concealed a lot of the underlying plumbing. It became increasingly common to find programmers who don’t even understand how the World Wide Web works writing web applications. With Go I found a great tool to teach the basics of web application programming, properly. Writing web applications is direct and simple again. Everything’s just there—no external libraries and dependencies. It’s all about HTTP again and how to deliver content and data through it. So with that in mind, I approached Manning with an idea for a Go programming language book that focuses on teaching someone how to write web applications from the ground up, using nothing except the standard libraries. Manning quickly sup- ported my idea and green-lighted the project. The book has taken a while to come together, but the feedback from the early access program (MEAP) was encouraging. I hope you will gain much and enjoy reading this book as much as I enjoyed writing it.
  • 21. xv acknowledgments This book started with an idea to teach the basics of web programming with Go, using nothing more than the standard libraries. I wasn’t sure if that would work, but the readers who paid hard-earned money to buy my MEAP along the way gave me encour- agement and motivation to push the idea through. To my readers, thank you! Writing books is a team effort, and though my name appears on the front cover of this one, it only exists because of the efforts of a large number of people: ■ Marina Michaels, my hardworking and efficient editor from the other side of the world, worked tirelessly alongside me, ever ready to accommodate her schedule to our dramatically different time zones ■ The Manning extended team: Liz Welch, copyeditor, and Elizabeth Martin, proofreader, who with their eagle eyes helped spot my mistakes; Candace Gill- hoolley and Ana Romac, who helped me market and promote this book; and Kevin Sullivan and Janet Vail, who worked to take my raw manuscript and make it into a real book ■ Jimmy Frasché, who gave the manuscript a full technical proofread, and my reviewers, who gave valuable feedback at four stages of manuscript develop- ment: Alex Jacinto, Alexander Schwartz, Benoit Benedetti, Brian Cooksey, Doug Sparling, Ferdinando Santacroce, Gualtiero Testa, Harry Shaun Lippy, James Tyo, Jeff Lim, Lee Brandt, Mike Bright, Quintin Smith, Rebecca Jones, Ryan Pulling, Sam Zaydel, and Wes Shaddix ■ My friends from the Singapore Go community who helped me spread the word on my new book as soon as the MEAP came out, especially Kai Hendry, who made a long video from his comments on my book
  • 22. ACKNOWLEDGMENTS xvi I’d also like to thank the creators of Go—Robert Griesemer, Rob Pike, and Ken Thompson—as well as contributors to the net/http, html/template, and other web standard libraries, especially Brad Fitzpatrick, without whom I probably wouldn’t have anything to write about! Last but certainly not least, I’d like to thank my family—the love of my life, Wooi Ying, and my taller-than-me-now son, Kai Wen. I hope that in writing this book, I will be an inspiration to him and he will soon pick up my book proudly and learn from it.
  • 23. xvii about this book This book introduces the basic concepts of writing a web application using the Go programming language, from the ground up, using nothing other than the standard libraries. While there are sections that discuss other libraries and other topics, includ- ing testing and deploying web applications, the main goal of the book is to teach web programming using Go standard libraries only. The reader is assumed to have basic Go programming skills and to know Go syn- tax. If you don’t know Go programming at all, I would advise you to check out Go in Action by William Kennedy with Brian Ketelsen and Erik St. Martin, also published by Manning (www.manning.com/books/go-in-action). Another good book to read is The Go Programming Language (Addison-Wesley 2015), by Alan Donovan and Brian Ker- nighan. Alternatively, there are plenty of free tutorials on Go, including the A Tour of Go from the Go website (tour.golang.org). Roadmap The book includes ten chapters and an appendix. Chapter 1 introduces using Go for web applications, and discusses why it is a good choice for writing web applications. You’ll also learn about key concepts of what web applications are, including a brief introduction to HTTP. Chapter 2 shows you how to build a typical web application with Go, taking you step by step through the creation of a simple internet forum web. Chapter 3 gets into the details of handling HTTP requests using the net/http pack- age. You’ll learn how to write a Go web server to listen to HTTP requests and how to incorporate handlers and handler functions that process those requests.
  • 24. ABOUT THIS BOOK xviii Chapter 4 continues with the details of handling HTTP requests—specifically, how Go allows you to process the requests and respond accordingly. You’ll also learn how to get data from HTML forms and how to use cookies. Chapter 5 delves into the Go template engine provided in the text/template and html/template packages. You’ll learn about the various mechanisms provided by Go and about using layouts in Go. Chapter 6 discusses storage strategies using Go. You’ll learn about storing data in memory using structs, in the filesystem using CSV and the gob binary format as well as using SQL and SQL mappers to access relational databases. Chapter 7 shows you how to create web services using Go. You’ll learn how to cre- ate and parse XML as well as JSON with Go, and how a simple web service can be writ- ten using Go. Chapter 8 gives insight into the ways you can test your Go web application at vari- ous levels, including unit testing, benchmark testing, and HTTP testing. This chapter also briefly discusses third-party testing libraries. Chapter 9 talks about how you can leverage Go concurrency in your web applica- tion. You’ll learn about Go concurrency and how you can improve the performance of a photo-mosaic web application using Go concurrency. Chapter 10 wraps up the book by showing how you can deploy your web applica- tion. You’ll learn how to deploy to standalone servers and to the cloud (Heroku and Google App Engine), as well as in Docker containers. The appendix provides instructions for installing and setting up Go on different platforms. Code conventions and downloads This book contains many examples of source code both in numbered listings and inline with normal text. In both cases, source code is formatted in a fixed-width font like this to separate it from ordinary text. Sometimes code is in bold to high- light code that has changed from previous steps in the chapter or code that is discussed in surrounding text. Also, colors are used to highlight code commands and code output: curl -i 127.0.0.1:8080/write HTTP/1.1 200 OK Date: Tue, 13 Jan 2015 16:16:13 GMT Content-Length: 95 Content-Type: text/html; charset=utf-8 <html> <head><title>Go Web Programming</title></head> <body><h1>Hello World</h1></body> </html>
  • 25. ABOUT THIS BOOK xix Print book readers who want to see this color code highlighting (and all figures in color) can go to www.manning.com/books/go-web-programming to register and get their free eBook in PDF, ePub, and Kindle formats. Code samples used throughout the book are also available at www.manning.com/ books/go-web-programming and at github.com/sausheong/gwp. About the author SAU SHEONG CHANG is now the Managing Director of Digital Technology at Singapore Power. Before that, he was a Director of Consumer Engineering at PayPal. He is active in the Ruby and Go developer communities, and has written books, contributed to open source projects, and spoken at meetups and conferences. Author Online Purchase of Go Web Programming includes free access to a private web forum run by Manning Publications; you can make comments about the book, ask technical ques- tions, and receive help from the author and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/books/go-web- programming. This page provides information on how to get on the forum after you’re registered, what kind of help is available, and the rules of conduct on the forum. Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It’s not a commitment to any specific amount of participation on the part of the author, whose contribution to the forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions lest his interest stray! The Author Online forum and the archives of previous discussions will be accessi- ble from the publisher’s website as long as the book is in print.
  • 26. Other documents randomly have different content
  • 30. The Project Gutenberg eBook of The Profession of Journalism
  • 31. 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: The Profession of Journalism Editor: Willard Grosvenor Bleyer Release date: April 30, 2020 [eBook #61982] Most recently updated: October 17, 2024 Language: English Credits: Produced by Richard Tonsing 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 THE PROFESSION OF JOURNALISM ***
  • 34. OTHER COLLECTIONS drawn from The Atlantic Monthly are published under the following titles:—
  • 35. Atlantic Classics, First Series $1.25 Atlantic Classics, Second Series $1.25 Headquarters Nights. By Vernon Kellogg $1.00 The War and the Spirit of Youth. By Maurice Barrès and Others $1.00 Pan-Germany: The Disease and Cure. By André Chéradame $ .35 The Assault on Humanism. By Paul Shorey $1.00 Shock at the Front. By William T. Porter M.D. $1.25 Atlantic Narratives. Edited by Charles Swain Thomas $1.00 Essays and Essay Writing. Edited by W. M. Tanner $1.00 THE ATLANTIC MONTHLY PRESS BOSTON
  • 37. THE PROFESSION OF JOURNALISM A Collection of Articles on Newspaper Editing and Publishing, Taken from the Atlantic Monthly EDITED WITH AN INTRODUCTION AND NOTES BY WILLARD GROSVENOR BLEYER, Ph.D. Author of “Newspaper Writing and Editing” and “Types of News Writing”; Professor of Journalism in the University of Wisconsin The Atlantic Monthly Press BOSTON
  • 38. Copyright, 1918, by THE ATLANTIC MONTHLY PRESS, INC.
  • 40. PREFACE The purpose of this book is to bring together in convenient form a number of significant contributions to the discussion of the newspaper and its problems which have appeared in the Atlantic Monthly in recent years. Although these articles were intended only for the readers of that magazine at the time of their original publication, they have permanent value for the general reader, for newspaper workers, and for students of journalism. Practically every phase of journalism is taken up in these articles, including newspaper publishing, news and editorial policies, the influence of the press, yellow and sensational journalism, the problems of the newspaper in small cities, country journalism, the Associated Press, the law of libel, book-reviewing, dramatic criticism, “comics,” free-lance writing, and the opportunities in the profession. For readers who desire to make a further study of any of the important aspects of the press, a bibliography of such books and magazine articles as are generally available in public libraries has been appended. Most of the authors of the articles in this volume are newspaper and magazine writers and editors whose long experience in journalism gives particular value to their analysis of conditions, past and present. Brief notes on the journalistic work of the writers are given in the Appendix. For permission to reprint the articles the editor is indebted to the writers and to the editor of the Atlantic Monthly. W. G. B. University of Wisconsin, January 12, 1918.
  • 42. PAGE Introduction. Willard Grosvenor Bleyer ix Some Aspects of Journalism. Rollo Ogden 1 Press Tendencies and Dangers. Oswald Garrison Villard 20 The Waning Power of the Press. Francis E. Leupp 30 Newspaper Morals. H. L. Mencken 52 Newspaper Morals: A Reply. Ralph Pulitzer 68 The Suppression of Important News. Edward Alsworth Ross 79 The Personal Equation in Journalism. Henry Watterson 97 The Problem of the Associated Press. “An Observer” 112 The Associated Press: A Reply. Melville E. Stone 124 Confessions of a Provincial Editor. “Paracelsus” 133 The Country Editor of To-day. Charles Moreau Harger 151 Sensational Journalism and the Law. George W. Alger 167 The Critic and the Law. Richard Washburn Child 181 Honest Literary Criticism. Charles Miner Thompson 200 Dramatic Criticism in the American Press. James S. Metcalfe 224 The Humor of the Colored Supplement. Ralph Bergengren 233
  • 43. The American Grub Street. James H. Collins 243 Journalism as a Career. Charles Moreau Harger 264 Bibliography 279 Notes on the Writers 290
  • 44. INTRODUCTION BY WILLARD GROSVENOR BLEYER I “The food of opinion,” as President Wilson has well said, “is the news of the day.” The daily newspaper, for the majority of Americans, is the sole purveyor of this food for thought. Citizens of a democracy must read and assimilate the day’s news in order to form opinions on current events and issues. Again, for the average citizen the newspaper is almost the only medium for the interpretation and discussion of questions of the day. The composite of individual opinions, which we call public opinion, must express itself in action to be effective. The newspaper, with its daily reiteration, is the most powerful force in urging citizens to act in accordance with their convictions. By reflecting the best sentiment of the community in which it is published, the newspaper makes articulate intelligent public opinion that might otherwise remain unexpressed. Since the success of democracy depends not only upon intelligent public opinion but upon political action in accordance with such opinion, it is not too much to say that the future of democratic government in this country depends upon the character of its newspapers. Yet most newspaper readers not unnaturally regard the daily paper as an ephemeral thing to be read hurriedly and cast aside. Few appreciate the extent to which their opinions are affected by the newspaper they read. Nevertheless, to every newspaper reader— which means almost every person in this country—the conditions under which newspapers are produced and the influences that affect
  • 45. the character of news and editorials, should be matters of vital concern. To newspaper workers and students of journalism the analysis of the fundamental questions of their profession is of especial importance. Discussion of current practices must precede all effort to arrive at definite standards for the profession of journalism. Only when the newspaper man realizes the probable effect of his work on the ideas and ideals of thousands of readers, and hence on the character of our democracy, does he appreciate the full significance of his news story, headline, or editorial. The modern newspaper has developed so recently from simple beginnings into a great, complex institution that no systematic and extensive study has been made of its problems. Journalism has won recognition as a profession only within the last seventy-five years, and professional schools for the training of newspaper writers and editors have been in existence less than fifteen years. In view of these conditions, it is not surprising that definite principles and a generally accepted code of ethics for the practice of the profession have not been formulated. Ideal conditions of newspaper editing and publishing are not likely to be brought about by legislation. So jealous are the American people of the liberty of their press that they hesitate, even when their very existence as a nation is threatened, to impose legal restrictions on the printing of news and opinion. If regulation does come, it should be the result, as it has been in the professions of law and medicine, of the creation of an enlightened public opinion in support of professional standards adopted by journalists themselves. The present is an auspicious time to discuss such standards. The world war has put to the test, not only men and machinery, but every institution of society. Of each organized activity we ask, Is it serving most effectively the common good? Not simply service to the state, but service to society, is being demanded more and more of every individual and every institution. “These are the times which try men’s souls,” and that try no less the mediums through which men’s souls find expression. The newspaper, as the purveyor of “food of opinion” and as the medium for expressing opinion, must measure up to the test of the times.
  • 46. II The first step in a systematic analysis of the principles of journalism must be a consideration of the function of the newspaper in a democracy. In the varied and voluminous contents of a typical newspaper are to be found news of all kinds, editorial comment, illustrations of current events, recipes, comic strips, fashions, cartoons, advice on affairs of the heart, short stories, answers to questions on etiquette, dramatic criticism, chapters of a serial, book reviews, verse, a “colyum,” and advertisements. What in this mélange is the one element which distinguishes the newspaper from all other publications? It is the daily news. Weekly and monthly periodicals do everything that the newspaper does, except print the news from day to day. Whatever other aims a newspaper may have, its primary purpose must be to give adequate reports of the day’s news. Although various inducements other than news may be employed to attract some persons to newspapers who would not otherwise read them regularly, nevertheless these features must not be so prominent or attractive that readers with limited time at their disposal will neglect the day’s news for entertainment. To assist the public to grasp the significance of the news by means of editorial interpretation and discussion, to render articulate the best public sentiment, and to persuade citizens to act in accordance with their opinions, constitute an important secondary function of the newspaper. Even though the editorial may seem to exert a less direct influence upon the opinions and political action of the average citizen than it did in the period of great editorial leadership, nevertheless the interpretation and discussion of timely topics in the editorial columns of the daily press are a force in democratic government that cannot be disregarded. Newspapers by their editorials can perform two peculiarly important services to the public. First, they can show the relation of state, national, and international questions to the home and business interests of their readers. Only as the great issues of the day are
  • 47. brought home to the average reader is he likely to become keenly interested in their solution. Second, newspapers in their editorials can point out the connection between local questions and state-wide, nation-wide, or world-wide movements. Only as questions at issue in a community are shown in their relation to larger tendencies will the average reader see them in a perspective that will enable him to think and act most intelligently. In addition to fulfilling these two functions, the newspaper may supply its readers with practical advice and useful information, as well as with entertaining reading matter and illustrations. There is more justification for wholesome advice and entertainment in newspapers that circulate largely among classes whose only reading matter is the daily paper than there is in papers whose readers obtain these features from other periodicals. In view of the numberless cheap, popular magazines in this country, the extent to which daily newspapers should devote space and money to advice and entertainment deserves careful consideration. That without such consideration these features may encroach unjustifiably on news and editorials seems evident.
  • 48. III Since the primary function of the newspaper is to give the day’s news, the question arises, What is news? If from the point of view of successful democracy the value of news is determined by the extent to which it furnishes food for thought on current topics, we are at once given an important criterion for defining news and measuring news-values. Thus, news is anything timely which is significant to newspaper readers in their relation to the community, the state, and the nation. This conception of news is not essentially at variance with the commonly accepted definition of it as anything timely that interests a number of readers, the best news being that which has greatest interest for the greatest number. The most vital matters for both men and women are their home and their business interests, their success and their happiness. Anything in the day’s news that touches directly or indirectly these things that are nearest and dearest to them, they will read with eagerness. As they may not always be able to see at once the relation of current events and issues to their home, business, and community interests, it is the duty of the newspaper to present news in such a way that its significance to the average reader will be clear. Every newspaper man knows the value of “playing up” the “local ends” of events that take place outside of the community in which his paper is published, but this method of bringing home to readers the significance to them of important news has not been as fully worked out as it will be. On this basis the best news is that which can be shown to be most closely related to the interests of the largest number of readers. “But newspapers must publish entertaining news stories as well as significant ones,” insists the advocate of things as they are. This may be conceded, but only with three important limitations. First, stories for mere entertainment that deal with events of little or no news- value must not be allowed to crowd out significant news. Second, such entertaining news-matter must not be given so much space and prominence, or be made so attractive, that the average reader with
  • 49. but limited time in which to read his paper will neglect news of value. Third, events of importance must not be so treated as to furnish entertainment primarily, to the subordination of their true significance. To substitute the hors d’œuvres, relishes, and dessert of the day’s happenings for nourishing “food of opinion” is to serve an unbalanced, unwholesome mental diet. The relish should heighten, not destroy, a taste for good food.
  • 50. 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! ebookultra.com