|
所在平台: Udemy |
课程主页: https://www.udemy.com/course/building-a-module-in-go-golang/
课程评论:没有评论
课程名称:使用Go (Golang) 构建模块 概述:在Go中处理Web应用程序非常简单,但在开始新的项目时,我们常常会发现自己重复编写相似的代码,例如读取JSON、写入JSON或上传文件等常用功能。为了避免在不同项目间复制粘贴代码,我们可以利用Go模块——这些可重用的代码可以通过简单的“go get”命令包含在项目中。这样,当模块添加了新功能时,任何导入该模块的项目都可以通过更新其依赖关系来利用这些新功能;如果发现了bug,通过更新模块即可修复,所有使用该模块的项目只需运行“go get -u”命令即可获取修复。构建一个强大、安全且经过良好测试的模块并不困难,但需要仔细规划,以确保它能在不同操作系统上运行。 本课程将指导您完成构建一个包含Web应用程序常用任务的模块的步骤,包括: - 读取JSON - 写入JSON - 生成格式良好且信息丰富的错误消息 - 上传一个或多个文件到服务器,并按MIME类型和文件大小限制上传 - 在服务器上创建目录 - 生成随机字符串 - 下载静态文件 - 向远程服务发送JSON - 从字符串创建URL安全的标识符 我们将使用Go 1.18的新工作区工具来构建模块,并确保整个模块经过良好测试。我们的最终模块将不会有任何外部依赖,仅使用Go标准库中的功能。完成本课程后,您将拥有一个Go模块,使您能够更快地启动新的Web应用程序,而无需依赖他人的代码。
Working with web applications in Go is remarkably easy, but it does not take too long to realize that in a lot of cases, we end up writing the same kind of code every time we start a new project. You might need to read JSON, write JSON, upload files, or any of the commonly used features of a given web application. In other words, we often rewrite code that we have already written, many times over.Rather than simply copying and pasting code from one project to another, it makes sense to take advantage of Go modules - reusable code that can be included in a project by simply issuing a "go get" command. That way, if new functionality is added to that module, any project that imports it can take advantage of that functionality simply by updating its dependencies, and if a bug is discovered, you can fix it by updating the module; every project that uses that module gets the bug fix with a single "go get -u" command.Building a robust, secure, well-tested module is not difficult, but it does require careful planning to ensure that it will work across different operating systems.This course will take you through the steps necessary to produce a module that includes many of the tasks commonly used in web applications, including:reading JSONwriting JSONproducing well formatted, informative error messagesuploading one or more files to a server, and limiting uploads by mime type and file sizecreating directories on the servergenerating random stringsdownloading static filesposting JSON to a remote servicecreating a URL safe slug from a stringWe'll build our module using Go 1.18's new workspaces tools, and we'll ensure that the entire module is well-tested.Our final module will not have any external dependencies, and will only use functionality found in Go's standard library.By the time you have finished this course, you'll have a Go module that will make starting a new web application much faster, and you won't be depending on someone else's code to do so.