go net/http 源码阅读

go net/http 源码阅读

实现一个简单的http服务器:

package net_http

import (
	"net/http"
	"testing"
)

func index(response http.ResponseWriter, request *http.Request)  {
	response.WriteHeader(http.StatusOK)
	response.Write([]byte("index"))
}

func TestHttpServer(t *testing.T) {
	tmux := http.NewServeMux()
	tmux.HandleFunc("/", index)
	tmux.HandleFunc("/index", index)
	http.ListenAndServe("0.0.0.0:9055",tmux)
}

处理流程:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/luslin1711/article/details/106116879