首页
学习
活动
专区
圈层
工具
发布

01 Go Web基础_20240728 课程笔记,附完整视频教程和源码笔记资料

概述

如果您没有Golang的基础,应该学习如下前置课程。

基础不好的同学每节课的代码最好配合视频进行阅读和学习,如果基础比较扎实,则阅读本教程巩固一下相关知识点即可,遇到不会的知识点再看视频。

视频课程

最近发现越来越多的公司在用Golang了,所以精心整理了一套视频教程给大家,这个是其中的第3部,后续还会有很多。

视频已经录制完成,完整目录截图如下:

课程目录

04 配置读写超时时间.mp4

06 httprouter的第一个使用案例.mp4

10 使用httprouter挂载静态文件目录.mp4

每节课的代码

04 配置读写超时时间.mp4

06 httprouter的第一个使用案例.mp4

package main

import (

"fmt"

"github.com/julienschmidt/httprouter"

"net/http"

"time"

)

func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {

fmt.Fprint(w, "Welcome!\n")

}

func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))

}

func main() {

router := httprouter.New()

router.GET("/", Index)

router.GET("/hello/:name", Hello)

server := &http.Server{

Addr:         "0.0.0.0:8888",

Handler:      router,

ReadTimeout:  5 * time.Second,

WriteTimeout: 5 * time.Second,

}

server.ListenAndServe()

}

package main

import (

"fmt"

"github.com/julienschmidt/httprouter"

"net/http"

"time"

)

func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {

fmt.Fprint(w, "Welcome!\n")

}

func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))

}

func main() {

router := httprouter.New()

router.GET("/", Index)

router.GET("/hello/:name", Hello)

server := &http.Server{

Addr:         "0.0.0.0:8888",

Handler:      router,

ReadTimeout:  5 * time.Second,

WriteTimeout: 5 * time.Second,

}

server.ListenAndServe()

}

10 使用httprouter挂载静态文件目录.mp4

package main

import (

"fmt"

"github.com/zhangdapeng520/zdpgo_httprouter"

"net/http"

"time"

)

func Index(w http.ResponseWriter, r *http.Request, _ zdpgo_httprouter.Params) {

fmt.Fprint(w, "Welcome!\n")

}

func main() {

router := zdpgo_httprouter.New()

router.GET("/", Index)

server := &http.Server{

Addr:         "0.0.0.0:8888",

Handler:      router,

ReadTimeout:  5 * time.Second,

WriteTimeout: 5 * time.Second,

}

server.ListenAndServe()

}

代码截图

在这里插入图片描述总结

本套教程主要讲解Go Web开发的基础知识,特别是讲解了httprouter的用法以及本地化方法,比附上了完整的实战代码。

通过本套课程,能帮你入门Go Web开发,写一些简单的Web程序。

人生苦短,我用Python,我是您身边的Python私教~

  • 发表于:
  • 原文链接https://page.om.qq.com/page/OpzCehJSLv1UrAlPgyEiS2XQ0
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。
领券