所需积分/C币:9 2018-08-14 10:27:17 1.27MB PDF
收藏 收藏

go语言开发教程,go web开发电子书 Webapps in Go go go 电子书
Tweet this book! Please help Suraj Patil by spreading the word about this book on Twitter The suggested tweet for this book is just bought Webapps in Go by (@igeeko The suggested hashtag for this book is#WebDev goanti Textbook Find out what other people are saying about the book by clicking on this link to search for this hashtag on twitter https://twitter.com/searchq=#webdevgoanTitextbook Akshay Agarwal: For introducing me to the FOSS world Hrishikesh Nandedkar: For guiding me in the right direction Contents Installation ystem requirements Install the go tools Tools The toolchain Hello. go Why go? Variables data structures 12 Variables 12 Underlying data structures 16 Important points.·,, 17 array;slce,map· 19 Control statements and functions 28 Control statement 28 Functions 31 Struct 41 Basics of struct Object-oriented 48 methods 48 Interface 57 Interface 57 Concurrency 68 Managing the Workspace 74 Pa ackages 74 Internal deployment 75 Web Programming Basics 77 CONTENTS Http Methods What is a template?···,, Static files 81 Basic web application 83 Handling URLs Serving static files 85 Homework 86 Designing our web app 87 The design 87 Homework 89 Using databases in Go 90 Creating and configuring database 90 Installing sqlite dr Accessing the database 93 Importing driver 93 Retrieving result sets ·······.···· 95 Fetching Data from the Database How Scano Works Preparing queries 88 Single-Row Queries Modifying Data and Using Transactions 101 Statements that Modify Data 101 Working with Transactions 102 Using Prepared Statements 104 Prepared Statements And Connections ····· 104 Avoiding Prepared Statements 104 Prepared Statements in Transactions 105 Parameter Placeholder Syntax 106 Handling Errors ,107 Errors From Iterating Resultsets 107 Errors From Closing resultsets 107 Errors From Query Row 108 Identifying Specific Database Errors 109 Handling Connection Errors 110 Working with NULLs 111 CONTENTS Working with Unknown Columns ,113 The connection pool 115 Surprises, Antipatterns and Limitations ,,,,116 Resource exhaustion 116 Large uint64 values 翻D 116 Connection State mismatch 117 Database-Specific Syntax 117 Multiple result sets 117 Invoking Stored Procedures 117 Multiple Statement Support 118 Database Encapsulation ,120 An Example 123 Homework 126 Working with Forms ..127 CSRF 130 Input validation 00D0 0 ,,135 Uploading files 137 Templates 140 Sub templating 142 Homework 148 Authentication .149 Cook 149 Sessions 150 Users ··· 154 Files 158 Routing ,160 Middlewares ,162 Example ,,163 Building an apt 165 JWT 166 Making an api call 168 Formatting a son document 170 Testing API 170 CONTENTS Writing an client 172 Getting the token 172 Error handling 173 Example 173 Advanced usage 175 Unit Testing 176 Version Control basics 80 Using gi 180 Branching 181 Remote 182 Installation If you know about installation or have installed Go, you can skip to Tools This chapter is taken from install pagez verbatim, except for the changes to be made to adapt to this book's styling format System requirements Go binary distributions are available for these supported operating systems and architectures. Please ensure your system meets these requirements before proceeding If your Os or architecture is not on the list, you may be able to install from source or use gccgo instead perating system Architectures Notes Freebsd 8-sTABle or later amd64 Debian gnu/ kFreeBSD not supported Linux 2.6.23 or later with glibc amd64, 386, arm CentOS/RHEL 5.x not supported; install from source for ARm Mac osⅩ10.7 or later amdo use the clang or gcc that comes with Xcode Windows xp or later amd64,386 use Mingw gcc. No need for cygwin or msys tgcc is required only if you plan to use cgo fYou only need to install the command line tools for Xcode. If you have already ins 4.3+, you can install it from the Components tab of the Downloads preferences pane talled Xcode Install the go tools If you are upgrading from an older version of go you must first remove the existing version. Linux, Mac os x and freebsd tarballs Download the archive and extract it into /usr/local, creating a Go tree in /usr/local/go. For example tar -C /usr/local -xzf gosVERSION $OS-$ARCH. tar. gz 0. tools. md https:/golang.org/doc/install Installation Choose the archive file appropriate for your installation. For instance, if you are installing Go version 1.2.1 for 64-bit x86 on Linux, the archive you want is called go1. 2.1. linux-amd64. tar. gz (Typically these commands must be run as root or through sudo. Add/usr/local/go/bin to the Path environment variable. You can do this by adding this line to your /etc/profile(for a system-wide installation) or SHOME/ profile export PAtH=SPATH /usr/local/go/bin Installing to a custom location The Go binary distributions assume they will be installed in /usr/local/go(or c: \Go under Windows), but it is possible to install the Go tools to a different location. In this case you must set the groot environment variable to point to the directory in which it was installed For example, if you installed Go to your home directory you should add the following commands to $HOME/profile export GOROOT=SHOME/go export PAtH=$PATH: $GOROoT/bin Note: GOROOT must be set only when installing to a custom location Mac os x package installer Download the package file, open it, and follow the prompts to install the Go tools. The package installs the Go distribution to /usr/local/go The package should put the /usr/local/go/bin directory in your PATH environment variable You may need to restart any open Terminal sessions for the change to take effect Windows The Go project provides two installation options for Windows users(besides installing from source) a zip archive that requires you to set some environment variables and an MSi installer that configures your installation automatically MSI installer Open the msi file and follow the prompts to install the Go tools. By default, the installer puts the Go distribution in c: Go The installer should put thec: \Go\bin directory in your PATH environment variable. You may need to restart any open command prompts for the change to take effect

试读 127P Webapps-in-Go-the-anti-textbook
立即下载 低至0.43元/次 身份认证VIP会员低至7折
  • 签到新秀

  • 分享达人

关注 私信
Webapps-in-Go-the-anti-textbook 9积分/C币 立即下载

试读结束, 可继续阅读

9积分/C币 立即下载 >